WithStream(true) that emits lifecycle events as the loop runs — text deltas, tool calls, run finished.
Source: examples/agent_with_stream/
What it demonstrates
Stream()returning<-chan AgentEvent- Handling
TEXT_MESSAGE_CONTENT, tool lifecycle events, andRUN_FINISHED - Built-in tools with auto-approval
Run
Fromexamples/:
Key code
Enable streaming at construction, then consume the event channel:Expected output
Tokens print to stdout as they arrive, with no trailing newline until the run finishes:SHOW_LLM_USAGE=true a usage footer follows on a new line. Tool lifecycle events are consumed silently in this example — add a case for AgentEventTypeToolCallStart to log them.
Learn more
Streaming
Event types and consumption patterns
Stream + Conversation
Streaming with persisted history
AG-UI
SSE server for web frontends