Basic streaming
Useagent.stream() to stream agent responses:
Stream iterators
Polos provides multiple ways to consume streamed responses:Text chunks
Stream only the text content:All events
Access full event stream including tool calls, steps, and metadata:Final text
Get the complete accumulated text after streaming finishes:Complete result
Get the full result object with usage stats, tool calls, and metadata:Lifecycle events
By default, agents emit lifecycle events during execution - regardless of whether you useagent.run() or agent.stream(). These events help you track progress and display status to users.
Event types
agent_start
- Marks the beginning of agent execution
- Contains agent ID and initial configuration
agent_finish
- Marks the end of execution
- Includes usage statistics (tokens, cost)
- Contains final result
step_start
- Indicates a workflow step has begun - for example, LLM or tool call
step_finish
- Confirms step completion
- Includes step output and duration
text_delta (only with agent.stream())
- Incremental text chunks as the LLM generates them
- Real-time content streaming
tool_call (only with agent.stream())
- Emitted when the agent asks for a tool execution
- Includes tool name and arguments
- The results of the tool execution are available via step_finish event when the tool finishes execution
Using lifecycle events
Stream with agent.run()
Even when usingagent.run() (non-streaming), lifecycle events are still emitted. You can listen to them separately:
Building UIs with streaming
Basic text streaming UI
Rich progress UI
Error handling in streams
Streams automatically handle errors and emit error events:Key takeaways
stream.text_chunks- Simple text-only streamingstream.events- Full access to lifecycle events, tool calls, and metadatastream.text()- Get complete accumulated textstream.result()- Get full result with usage and tool information- Lifecycle events - Emitted for both
agent.run()andagent.stream() - Rich UIs - Use events to show tool execution, progress, and real-time updates