Skip to content
Pyrula

HTTP

create_app returns a FastAPI app that exposes your agents. Pass agents and a store, or let it pick up every @agent imported in the process.

from pyrula.agents import create_app
from pyrula.agents.llm import OpenAILLM
app = create_app(
agents=[support], # or omit to use the registry
store=store,
llm=OpenAILLM(model="gpt-4o-mini"),
)

Run it with any ASGI server:

Terminal window
uvicorn myapp:app

Each agent gets the same set of routes under the prefix (default /agents):

MethodPathPurpose
POST/agents/{agent}Submit a turn. Returns a turn id and stream path.
GET/agents/{agent}/stream/{turn_id}Follow the turn live over SSE.
GET/agents/{agent}/turns/{turn_id}/replayReplay the turn’s events from the start.
GET/agents/{agent}/turns/{turn_id}Current status.
DELETE/agents/{agent}/stream/{turn_id}Cancel the turn.

The live stream and the replay endpoint read the same event stream, so a client that drops can reconnect and catch up from its last event id without losing anything.

Pass an AppOptions to tune the app:

from pyrula.agents import create_app, AppOptions, APIKeyAuth
app = create_app(
store=store,
llm=llm,
options=AppOptions(
prefix="/agents",
auth=APIKeyAuth(...),
cors_origins=["https://app.example.com"],
deployment_mode="separate",
),
)

Useful fields: prefix, auth, deployment_mode, cors_origins, idempotency_ttl_s, sse_keepalive_interval, cancel_on_reader_disconnect, and the health/ready probe paths (/healthz, /readyz by default).

deployment_mode="separate" makes the app submit and stream only, leaving execution to worker processes.

create_app builds a fresh FastAPI app. To add the agent routes to an app you already have, use AgentRouter directly, which is the APIRouter create_app mounts under the hood:

from pyrula.agents import AgentRouter, AgentRouterConfig
router = AgentRouter(worker, config=AgentRouterConfig(...))
existing_app.include_router(router, prefix="/agents")