Workshop notes
Real-Time Agents with FastAPI and WebSockets
Workshop notes for moving from request-response agents to observable, event-driven systems.
- agents
- fastapi
- websockets
- python
Most agent tutorials return one final response. Real applications need to expose the work in between: tool calls, partial answers, approvals, errors, and cancellation.
This workshop builds that path with FastAPI and WebSockets.
Learning goals
By the end, participants can:
- model an agent run as a stream of typed events
- send progress from the server without coupling the UI to one framework
- pause for human approval and resume the same run
- handle disconnects, cancellation, and tool failures
- persist enough state to debug a failed session
A small event contract
class AgentEvent(BaseModel):
run_id: str
sequence: int
type: Literal["status", "token", "tool", "approval", "error", "done"]
payload: dict
The event contract is more durable than the internal agent framework. The UI listens to domain events, not private callback objects.
Workshop flow
- Build a request-response agent endpoint.
- Introduce an event bus inside the run.
- Stream events over a WebSocket.
- Add a tool approval pause.
- Simulate a disconnect and resume.
- Inspect the trace and improve the failure state.
The result is not a chat animation. It is an observable execution protocol.