AgentSDK
Streaming Responses
Get real-time responses with tool execution updates.
Basic Streaming
Chunk Types
Content Chunks
Tool Result Chunks
Error Chunks
Complete Example
Different Providers
Error Handling
Configuration
All chat_with_tools
parameters work with streaming:
Building a Chat Interface
Performance Tips
- Buffer content: Collect chunks before displaying for smoother output
- Handle tool updates: Show tool usage to keep users informed
- Timeout handling: Set reasonable timeouts for long operations
- Error recovery: Gracefully handle stream interruptions
Comparison with Non-Streaming
Feature | chat_with_tools | chat_with_tools_stream |
---|---|---|
Speed | Wait for complete response | Real-time updates |
User Experience | All at once | Progressive |
Tool Feedback | Final results only | Live tool execution |
Error Handling | Single try/catch | Per-chunk handling |
Memory Usage | Full response in memory | Chunk-by-chunk |