yaab.serve¶
FastAPI serving: /run, streaming SSE, A2A endpoints.
yaab.serve ¶
Serve agents over HTTP — a FastAPI app and an A2A-compatible server.
fastapi_server_app(agent) returns a ready-to-mount ASGI app exposing:
GET /.well-known/agent.json— the A2A Agent Card (discovery);POST /run— run the agent (YAAB-native;backgroundsubmits it as a task and returns202immediately);GET /runs/GET /runs/{id}/POST /runs/{id}/cancel— the run lifecycle API (poll status, list, remotely cancel an in-flight run);POST /a2a/tasks— A2A task submission (agent-to-agent);GET /health— liveness.
With no extra wiring the app behaves exactly as before: an in-process registry holds runs, a background submission fires a task, and only an in-memory view is available. Passing durable backends makes the same endpoints production-grade:
run_storeturns a background run into a durable queued row drained by an in-process :class:~yaab.runs.worker.RunWorker, so the run survives a restart and is visible (and cancellable) from any replica;approval_storeadds out-of-band human sign-off — list, approve, deny, and resume parked runs over HTTP;trace_storepersists each run's per-step timeline so a debugger can replay it with model/tool/token/cost/latency detail (/runs/{id}/eventsand/runs/{id}/trace);run_checkpointermakes background runs fault-tolerant (resume from the last step after a crash) and is the seam approvals resume through;cron_storeadds durable schedules (/crons).
Every new parameter defaults to None (today's behavior, byte-for-byte). The
new endpoints return a clean 404 when their backing store is not configured.
Authentication is pluggable via :mod:yaab.auth; the resolved identity flows
into the run context and the audit log. FastAPI is an optional dependency,
imported lazily so importing YAAB never requires a web stack.
fastapi_server_app ¶
fastapi_server_app(agent: Any, *, runner: Any | None = None, auth: AuthScheme | None = None, base_url: str = '', run_store: Any | None = None, approval_store: Any | None = None, trace_store: Any | None = None, run_checkpointer: Any | None = None, cron_store: Any | None = None, worker: Any | None = None) -> Any
Build a FastAPI app that serves agent (YAAB-native + A2A endpoints).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Any
|
The agent to serve. |
required |
runner
|
Any | None
|
An explicit :class: |
None
|
auth
|
AuthScheme | None
|
Pluggable auth scheme (defaults to no auth). |
None
|
base_url
|
str
|
Public base URL advertised on the agent card. |
''
|
run_store
|
Any | None
|
A durable run store. When set, a background |
None
|
approval_store
|
Any | None
|
A durable approval store enabling the out-of-band
sign-off endpoints ( |
None
|
trace_store
|
Any | None
|
A durable per-run trace store enabling the history/trace
endpoints ( |
None
|
run_checkpointer
|
Any | None
|
A checkpointer that makes background runs
fault-tolerant and is the seam approvals resume through. When |
None
|
cron_store
|
Any | None
|
A durable schedule store enabling |
None
|
worker
|
Any | None
|
Controls the in-process queue worker. |
None
|
serve ¶
serve(agent: Any, *, host: str = '127.0.0.1', port: int = 8000, auth: AuthScheme | None = None, run_store: Any | None = None, approval_store: Any | None = None, trace_store: Any | None = None, run_checkpointer: Any | None = None, cron_store: Any | None = None) -> None
Run the agent's FastAPI app with uvicorn (blocking).
Durable backends (run_store/approval_store/trace_store/
run_checkpointer/cron_store) are forwarded so a production deployment
gets durable background runs, out-of-band sign-off, and a persisted trace.