Quick Start
1
Serve teams, flows, and WebSocket chat
Pass
teams= and flows= to AgentOS — each one becomes its own route, and /api/chat/stream is always available.2
Call every surface
Teams and flows are plain
POST endpoints; the chat stream is a WebSocket.How It Works
A team or flow call acquires that instance’s lock, invokes the async entry point first, and offloads a sync target to a thread. A WebSocket frame clones and binds a per-request agent, then streams its reply as delta frames.Endpoint reference
Three surfaces resolve under the default/api prefix (AgentOSConfig.api_prefix).
Request and response shapes
Teams and flows share one request model; the WebSocket exchanges JSON frames.POST /api/teams/{team_name}/run
POST /api/teams/{team_name}/run
Request:Response:
POST /api/flows/{flow_name}/run
POST /api/flows/{flow_name}/run
Same shape as teams, with Response:
flow instead of team.Request:WS /api/chat/stream frames
WS /api/chat/stream frames
Authentication (WebSocket)
The HTTP api-key middleware does not run on the WebSocket handshake. When you configureAgentOSConfig(api_key=...) or set PRAISONAI_AGENTOS_API_KEY, the WS endpoint checks the token itself and rejects unauthenticated clients with close code 1008 before accept(). Pass the token via Authorization: Bearer, X-API-Key, or ?api_key= in the URL — browsers can only use the query form. Comparison uses hmac.compare_digest.
Concurrency and session isolation
Teams and flows serialise per instance; chat clones its agent per request.- Each team and flow has a lazy per-instance
asyncio.Lock— concurrent calls to the same instance queue, while different instances run in parallel (teams/flows carry mutable run state and cannot run re-entrantly). - Per-request chat uses an isolated agent clone via
_isolate_agent()(chat history is not shared across callers), including agents withhandoffs.clone_for_channeltagshandoffs=[...]tool closures with_praison_handoff_sourceand rebinds the delegation tool to the clone, so the handoff graph still works andchat_historyis never shared across callers. Plain mocks and lightweight callables that don’t support isolation still fall back to the template. - WebSocket calls use the exact same
_isolate_agent()helper asPOST /chat.
Choosing the right surface
Pick the surface that matches the interaction shape.Best Practices
Give every team and flow a stable name
Give every team and flow a stable name
The lookup matches
getattr(team, "name", None) against the path. Without a name, the call silently returns 404.Attach a launch token in production
Attach a launch token in production
Set
AgentOSConfig(api_key=...) (or PRAISONAI_AGENTOS_API_KEY) so the WebSocket endpoint isn’t an unauthenticated back door — the HTTP api-key middleware does not cover the WS handshake.Treat WebSocket errors as sticky
Treat WebSocket errors as sticky
The socket stays open on
{"error": ...}, so a retry can send another frame without a new handshake.An agent with an output guardrail streams as one frame
An agent with an output guardrail streams as one frame
Streaming yields tokens before the full response exists, so output guardrails cannot validate chunks. When
agent.guardrail is set, /api/chat/stream falls back to {"response": ...} followed by {"done": true} to preserve validation.When the client disconnects, the server stops the stream
When the client disconnects, the server stops the stream
The worker that pumps
iter_stream is signalled to close as soon as the WebSocket is gone, so a stalled model or tool call does not pin the handler.Construct one instance per concurrent caller
Construct one instance per concurrent caller
Teams and flows serialise same-instance calls. For true concurrency, build multiple team/flow instances — one per concurrent caller.
Related
AgentOS Read Endpoints
Health, agents, approvals, and other read routes.
AgentOS Serve Reload
Hot-reload agents without restarting the server.
Session Persistence
Carry conversation state across calls with
session_id.Approval Protocol
Gate risky tool calls behind an approval registry.

