Streaming Responses
Learn how to use streaming responses with AxCrew agents
Understanding Streaming Responses
AxCrew extends the AxLLM streamingForward() method to support streaming responses from agents, allowing you to receive and process agent outputs in real-time. This is particularly useful for:
- Interactive applications that need to display responses as they're generated
- Improving perceived responsiveness of your application
- Providing immediate feedback to users
Basic Streaming Usage
To use streaming responses, call an agent's streamingForward() method, which returns an async generator:
The above example assumes your agent's output signature includes a reply field (e.g., ... -> reply:string ...). If your agent's signature is different, adjust the code to extract the appropriate field from chunk.delta.
Using the onStream Callback
You can also use the onStream callback option with the regular forward() method:
Streaming with Sub-agents
Internally, AxLLM uses streaming by default when one agent calls another agent. There's nothing additional you need to do to enable it.
Key Streaming Features
- Real-time response processing: Display content as it's generated
- Support for both direct and sub-agent usage: Works across agent hierarchies
- Customizable stream handling: Use callbacks to process chunks
- Compatible with all agent types: Works with any provider that supports streaming
- Maintains cost tracking: Streaming doesn't affect metrics collection
Limitations
While streaming provides many benefits, be aware of some limitations:
- Function Calls: When an agent uses functions (tools), some providers may temporarily pause the stream while the function is executed
- Formatting: Markdown, code formatting, and styled content may appear in pieces before the complete format is visible
- Provider Support: Not all AI providers support streaming equally well
- Network Reliability: Streaming is more susceptible to network hiccups than single requests