AG-UI chat streaming
One endpoint: POST /v1/chat/v2/completions (behind the gateway: /api/backend/v1/chat/v2/completions). Accepted requests return an SSE stream of AG-UI events; requests rejected before streaming starts return a plain HTTP error (400/403/404/409/422/500) without a RUN_ERROR event.

Flow
- The frontend (
page_helpers.makeApiRequest()andMucgptAgUiAgent.runAgent()from@ag-ui/client) sends the run request through the API gateway. chat_router.ag_ui_chat_endpointauthenticates the user, parses the native AG-UIRunAgentInputor the legacy MUCGPT body, validates messages and model, takes the Valkey run lock per conversation (409 if busy) and prepares persistence: ownership check, and only the newest message is sent when a checkpoint already exists.init_agent()assembles model, tools (local + MCP), the file backend and the checkpointer.MUCGPTAgentExecutor.run_agui_with_streaming()drivesgraph.astream(...)and maps updates to AG-UI events; Langfuse tracing wraps the run.- The
EventEncoderstreams the events astext/event-stream; the@ag-ui/clientSSE parser expands*_CHUNKevents into START/CONTENT/END, and the chat UI renders answer text, tool steps, canvas edits and token usage.
Events sent by agent_executor.py
| Event | Meaning |
|---|---|
RUN_STARTED | run begins |
TEXT_MESSAGE_CHUNK | answer tokens |
TOOL_CALL_CHUNK / TOOL_CALL_RESULT | tool step; the live activity label is the tool's status_message argument |
CUSTOM (canvas) | live canvas edits |
RUN_FINISHED | token usage · interrupt outcome when a tool waits for approval |
STATE_SNAPSHOT · MESSAGES_SNAPSHOT | best-effort snapshots before an interrupted RUN_FINISHED; snapshot failures are logged, RUN_FINISHED can still be sent |
RUN_ERROR | exception caught in the executor's graph-streaming block |
The request-side contract (request shapes, version negotiation, the forwardedProps.mucgpt namespace, the vision gate) is documented in the AG-UI chat contract; persistence behavior in conversation persistence.