Aegra streams agent execution to clients using Server-Sent Events (SSE). This gives you real-time token-by-token output, tool call updates, and state changes as they happen.Documentation Index
Fetch the complete documentation index at: https://docs.aegra.dev/llms.txt
Use this file to discover all available pages before exploring further.
Quick example
Stream modes
Control what data you receive by settingstream_mode on the run. You can pass a single mode as a string or multiple modes as a list.
| Mode | What it streams |
|---|---|
values | Full state snapshot after each node execution |
updates | Only the state changes (delta) produced by each node |
messages | LLM tokens and tool calls as (message, metadata) tuples with accumulation into messages/partial and messages/complete events |
messages-tuple | Raw message tuples without accumulation (JavaScript graph compatibility) |
custom | User-defined data emitted from inside nodes via get_stream_writer() |
events | Low-level LangGraph astream_events for fine-grained tracing |
debug | Checkpoint and task result events (auto-enabled on all streams) |
debug and updates are used internally on every stream for checkpoint tracking and interrupt detection, but their events are only sent to the client if you explicitly request them in stream_mode. When updates is not requested, only interrupt events (human-in-the-loop) are forwarded — remapped as values events for compatibility.Custom streaming
Send custom data from inside graph nodes usingget_stream_writer():
custom in the stream modes:
Using multiple modes
event field tells you which mode each chunk comes from.
Event types
During streaming, you’ll receive these event types:| Event | Description |
|---|---|
metadata | Run metadata (run_id, attempt number) — sent first |
values | Full state snapshot (when using values mode) |
updates | State delta from a single node (when using updates mode) |
messages/partial | Partial message chunk (streaming token) |
messages/complete | Complete message after all tokens received |
messages/metadata | Message metadata (run_id) |
custom | User-defined data from get_stream_writer() |
events | LangGraph internal events (when using events mode) |
debug | Debug checkpoint and task result events |
error | Error during execution |
end | Stream complete |
Streaming endpoints
Create and stream
The most common pattern — create a run and stream its output in one call:POST /threads/{thread_id}/runs/stream under the hood.
Stream an existing run
If you created a background run, you can stream it later:Last-Event-ID header. If the connection drops, the client can reconnect and receive events from where it left off.
Wait for completion
If you don’t need streaming but want to wait for the result:POST /threads/{thread_id}/runs/wait and returns the final output.
Subgraph streaming
If your graph uses subgraphs, you can stream events from them too:Disconnection behavior
By default, when a client disconnects during streaming, the run is cancelled. You can change this:| Value | Behavior |
|---|---|
"cancel" (default) | Cancel the run when client disconnects |
"continue" | Run continues in the background; reconnect later to get results |
: heartbeat) every KEEPALIVE_INTERVAL_SECS (default 5s, truncated to whole seconds, minimum 1s), so idle proxies (Nginx 60s, AWS ALB, Cloudflare) won’t drop long-running silent agents — for example, a graph node holding an upstream WebSocket without emitting events. The wire-format matches LangGraph Platform, so existing SSE clients (the LangGraph SDK, browser EventSource, httpx-sse) silently ignore these lines per the W3C spec. Only a real client disconnect — not an idle proxy timeout — triggers automatic cancellation.
Background runs
For long-running tasks, you can create a run in the background and check on it later:Cancelling runs
Cancel or interrupt a running execution:SSE reconnection
Aegra stores streaming events in a replay buffer (Redis Lists whenREDIS_BROKER_ENABLED=true, in-memory list in dev mode) for replay. If your connection drops:
- Track the last event ID you received
- Reconnect to
GET /threads/{thread_id}/runs/{run_id}/streamwithLast-Event-IDheader - You’ll receive all events from where you left off
In production deployments, SSE events are delivered via Redis pub/sub from workers — the client’s SSE connection and the worker executing the run can be on different instances. See the worker architecture guide for details on how this works.