HTTP server¶
The optional FastAPI adapter over a run queue. See the Control plane over HTTP guide.
Requires the server extra: pip install 'agent-workflow-sdk[server]'.
agentflow.server
¶
An HTTP adapter over the control-plane run queue (optional server extra).
This is the thin service layer DESIGN.md defers to: a FastAPI app that maps 1:1
onto :class:~agentflow.controlplane.queue.RunQueue methods, so a run can be
enqueued, inspected, resumed, or cancelled over HTTP from anywhere. It adds no
behavior the queue does not already have.
from agentflow import PostgresRunQueue
from agentflow.server import create_app
app = create_app(PostgresRunQueue(dsn)) # an ASGI app; serve with uvicorn
What it exposes is the enqueue and observe plane: POST /runs, GET
/runs/{id}, GET /runs, POST /runs/{id}/resume, POST
/runs/{id}/cancel, GET /stats, GET /healthz. The worker protocol
(claim / heartbeat / complete) is deliberately not exposed —
those mutate run state and belong to workers, which talk to the queue directly
(in-process or via the same Postgres queue), not over this API.
Scope, stated plainly: there is no authentication, authorization, rate limiting, or multi-tenancy here — DESIGN.md defers those as properties of a service. Run this inside your own trust boundary, or behind a reverse proxy that supplies them. It is an adapter, not a hardened public endpoint.
Requires the server extra: pip install 'agent-workflow-sdk[server]'.
Serve the returned ASGI app with any ASGI server (e.g. uvicorn), which you
install separately.
create_app
¶
create_app(queue: RunQueue, *, pool_health: Callable[[], Any] | None = None, title: str = 'AgentFlow control plane') -> FastAPI
Build a FastAPI app over queue.
queue is any :class:~agentflow.controlplane.queue.RunQueue (Memory for
a single process, Postgres for a shared/durable one). pool_health, if
given, is a zero-arg callable returning a
:class:~agentflow.controlplane.records.PoolHealth (typically
pool.health); GET /healthz reports it when present. The app adds no
behavior of its own — every route forwards to a queue method.
Source code in agentflow/server/app.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
Wire models¶
The request and response bodies that cross the HTTP boundary. These are Pydantic models, so they also drive the generated OpenAPI schema served at /openapi.json and the interactive docs at /docs.
agentflow.server.app
¶
FastAPI app factory mapping HTTP routes onto a RunQueue.
Each route is a direct adapter over one queue method; see the package docstring
for the exposed surface and the explicit non-goals (no auth, no worker
protocol). Response/request shapes are Pydantic models so the generated OpenAPI
docs (/docs) are accurate.
Note: this module intentionally does NOT use from __future__ import
annotations. FastAPI resolves endpoint annotations with get_type_hints,
which cannot re-evaluate a stringized Depends(get_queue) that references a
function-local dependency — real annotation objects are required.
EnqueueRequest
¶
Bases: BaseModel
Body for POST /runs — ask to run a registered graph.
Source code in agentflow/server/app.py
ResumeRequest
¶
Bases: BaseModel
Body for POST /runs/{run_id}/resume — answer an interrupted run.
Source code in agentflow/server/app.py
RunResponse
¶
Bases: BaseModel
One run's queue record.
Source code in agentflow/server/app.py
CancelResponse
¶
StatsResponse
¶
Bases: BaseModel