Skip to main content
Stream agent responses chunk by chunk for real-time output. Ideal for chatbots, long responses, and interactive applications.

Quick Start


Enabling Streaming

Pass stream=True to agent.run():

AgentStream Object

Each chunk is an AgentStream object:

Methods


Basic Streaming

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