Skip to main content
Agent that calls Stream and emits lifecycle events as the loop runs — text deltas, tool calls, run finished. Source: examples/agent_with_stream/

What it demonstrates

  • Stream() returning an AgentStream handle; Events() for the event channel
  • Handling TEXT_MESSAGE_CONTENT, tool lifecycle events, and RUN_FINISHED
  • Built-in tools with auto-approval

Run

From examples/:

Key code

See Streaming for all event types and AG-UI Protocol for frontend integration.

Expected output

Tokens print to stdout as they arrive, with no trailing newline until the run finishes:
With 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