Skip to main content
Streaming enables real-time response delivery, providing immediate feedback and better user experience for long-running agent operations.

Why Stream?

  • Immediate Feedback: Users see responses as they’re generated
  • Better UX: Perceived performance improvement
  • Tool Visibility: See tool calls and reasoning in real-time
  • Lower Latency: First token appears faster
  • Cancellation: Stop generation early if needed

Quick Start

Enable streaming with the stream_chat method:

Stream Event Types

Agentor emits structured events during streaming:

JSON Serialization

Get events as JSON strings for easy transmission:
Example JSON event:

HTTP Streaming

Serve streaming responses over HTTP:

Built-in Server Streaming

Agentor’s built-in server supports streaming out of the box:
Client request with streaming:

A2A Protocol Streaming

Stream responses using the A2A protocol:

Advanced Streaming Patterns

Custom Event Filtering

Filter specific event types:

Progress Tracking

Track completion progress:

Buffered Streaming

Buffer and process events in batches:

Multi-Agent Streaming

Stream from multiple agents concurrently:

WebSocket Streaming

For bidirectional streaming, use WebSockets:
WebSocket client:

Error Handling

Handle streaming errors gracefully:

Best Practices

Performance Tips

  • Use serialize=True (default) when sending over network
  • Use serialize=False for local processing to avoid JSON overhead
  • Buffer small chunks for better network efficiency
  • Set appropriate timeouts based on expected response time
  • Close streams properly to free resources

Next Steps

Last modified on May 5, 2026