A graph that runs in one shot tells you nothing until it finishes. Streaming surfaces what’s happening as it happens — node started, node ended, LLM token, custom progress signal. Cognis exposes this through the sameDocumentation Index
Fetch the complete documentation index at: https://cognis.vasanth.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Event-stream contract used everywhere else, plus a graph-specific stream_mode that filters down to what you care about.
The mental model
Three knobs:stream(input, cfg)— the Runnable default. Emits the final state once.stream_events(input, cfg)— everyEventfrom the run, in order. Use when you want everything.stream_mode(input, modes, cfg)— filter events byStreamMode. Use when you want specific channels (deltas, tokens, checkpoints).
stream_mode
StreamMode | What it emits |
|---|---|
Values | Whole state at the end (OnEnd). |
Updates | Per-node deltas (OnNodeEnd). |
Messages | LLM tokens (OnLlmToken), tool starts/ends. |
Tasks | Node-start signals (OnNodeStart). |
Checkpoints | Each persisted snapshot (OnCheckpoint). |
Debug | Everything. |
Custom | Only Event::Custom payloads — node-emitted progress. |
Custom events from a node
Inside anode_fn, the NodeCtx argument exposes a custom-event channel:
StreamMode::Custom to receive only these:
Streaming inside an agent
Agent::stream_events works the same way — the events come out nested under the agent’s run, with node-start / node-end events for the agent’s internal model / tools nodes plus the standard OnLlmToken / OnToolStart / OnToolEnd family.
How it works
- Streaming is just an observer dressed up. Internally,
stream_modeattaches an observer that pushes events into a channel. Same observer trait, different sink. - Filtering is by mode + variant.
StreamModes::matchesis justmatchover the event enum. - Backpressure is real. If the consumer is slow, the channel fills up. The engine eventually waits — make sure your consumer drains.
stream_eventsdoes not start the run; it returns the stream and starts the run in the background. The first event may arrive before the secondawait.
See also
Building agents → Streaming
The agent-level surface.
Observability → Callbacks
Same events, attached to a long-lived observer.
Patterns → Streaming UI
A complete server-side streaming endpoint.