Agent.Stream returns an AgentStream handle. Call Events for the live channel. For a final result without live tokens, use Run instead.
AgentStream methods
Status / Cancel / Done / Get match AgentRun. Streaming adds Events.
Enable streaming
Create an agent, then callStream. Stream enables LLM token deltas and delivers AG-UI lifecycle events:
LLM token deltas (TEXT_MESSAGE_CONTENT) are emitted only when the underlying LLMClient reports IsStreamSupported() as true (OpenAI, Anthropic, Gemini, DeepSeek, and Ollama do). If the provider does not support streaming, you still get lifecycle and tool events — the assistant text arrives as a complete message rather than partial deltas.
Stream:
Event guarantees
On all runtimes, the event channel is guaranteed to close only after a terminalRUN_FINISHED or RUN_ERROR event is delivered when the run itself ends. This holds even on Temporal if:
- Your process crashes during streaming
- The stream connection fails transiently
- You cancel the Events context (subscriber disconnect) — the agent run continues; reconnect with
GetAgentStream
GetAgentStream with a saved offset, you will not miss the terminal event (offsets may redeliver — discard duplicates at or below the saved offset).
For in-process streaming, a stream error (rare) will still deliver a terminal event before channel close.
When using Temporal for crash-recovery, always save both the run ID and offset before processing each event. If your process crashes between reading an event and saving its offset, only that one event will replay on reconnect.
Disable LLM token streaming
By default,Stream enables LLM token streaming — the model emits partial text as TEXT_MESSAGE_CONTENT deltas. Lifecycle events (tools, approvals, RUN_FINISHED, …) still stream either way.
To turn off token deltas and receive a single complete assistant message instead, set DisableTokenStreaming on AgentStreamOptions:
Event types
Stream events are typedAgentEvent values. Use ev.Type() and type-assert to the concrete struct to access fields.
Lifecycle
Text output
Tool calls
Reasoning
Custom (approvals and delegation)
Parse approval events with
ParseCustomEventApproval / ParseCustomEventDelegation, then call AgentStream.Approve with the ApprovalToken. See Approvals for the full flow.
Displaying streamed text
When sub-agents are configured, events from delegated runs fan in to the parent stream. UseAgentName on typed events to identify which agent emitted them. Multiple RUN_FINISHED events may appear before the root run finishes — each corresponds to one completed sub-agent run.
Token usage from Stream
Aggregated token counts are onResult.LLMUsage inside AgentRunFinishedEvent:
Reconnect with GetAgentStream
On a durable runtime (Temporal or Restate), persistagentStream.ID() and each event’s offset before handling the event. After a process crash, reconnect and resume — the run keeps executing server-side:
GetAgentStream or Events does not stop the run — use AgentStream.Cancel for that. After reconnect, WithTimeout (if set) starts fresh. Full cancel/timeout rules: Timeouts & Modes.
LocalRuntime does not support crash reconnect — non-zero offsets return ErrStreamOffsetNotSupported. Full protocol: Durable Execution. Runnable demo: Reconnect.
Streaming with conversation history
PassConversationOptions on AgentStreamOptions to share history across turns while streaming:
AG-UI protocol
Stream events follow the AG-UI open protocol. Serialize any event withevent.ToJSON() and forward over SSE or WebSocket to a compatible frontend. See AG-UI Protocol.
Examples
Stream example
Partial tokens, tool events, and RUN_FINISHED handling
Reconnect
Resume a stream from a saved offset after a crash
AG-UI
SSE server + CopilotKit UI over AG-UI events
Run
AgentRun — Get, Done, Status, Cancel