Quick Start
Enabling Streaming
Passstream=True to agent.run():
AgentStream Object
Each chunk is anAgentStream object:
| Property | Type | Description |
|---|---|---|
content | str | Content of this chunk |
delta | str | Delta/difference from previous |
done | bool | True if this is the final chunk |
session_id | str | Session identifier |
chunk_index | int | Index of this chunk |
metadata | dict | Chunk-specific metadata |
structured_data | BaseModel | Parsed structured output (final chunk only) |
artifact_files | List[Artifact] | Generated files (final chunk only) |
Methods
Basic Streaming
Print as Received
Collect Full Response
Using list()
Streaming with Sessions
Maintain conversation context while streaming:Progress Tracking
Chunk Counter
Character Counter
Streaming with File Output
Access generated files in the final chunk:Streaming with Structured Output
Get structured data in the final chunk:UI Integration
Web Application
Console Chat Interface
Async Streaming (Conceptual)
Error Handling
Examples
Real-time Typewriter Effect
Progress Bar
Logging Streamed Output
Stream to File
Best Practices
Always Handle done Flag
Use flush=True
Handle Empty Chunks
Clean Session Management
When to Use Streaming
| Use Case | Streaming | Non-Streaming |
|---|---|---|
| Chatbot UI | Yes | - |
| Long responses | Yes | - |
| Real-time feedback | Yes | - |
| Background processing | - | Yes |
| Quick responses | - | Yes |
| File/Image only | - | Yes |