achat/chat surface.
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 speaks its native chat surface.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), except whenhandoffsare configured on the template — those agents stay on the shared template becauseclone_for_channeldrops handoffs, so delegation isn’t silently lost. - 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.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.

