Overview
Themessage/stream
method enables real-time communication with A2A agents using Server-Sent Events (SSE). This allows you to receive partial responses as the agent processes your request, providing a more interactive experience.
Streaming Communication: This method uses Server-Sent Events for real-time response streaming. The connection remains open until the agent completes the response.
Request
Headers
Must be
application/json
Must be
text/event-stream
for SSE supportYour API key for authentication
Recommended:
no-cache
for real-time streamingPath Parameters
Unique identifier of the target agent
Body Parameters
JSON-RPC version, must be
"2.0"
Unique identifier for this request (for response correlation)
Must be
"message/stream"
Message parameters object (same structure as message/send)
Response
Server-Sent Events Stream
The response is delivered as a stream of Server-Sent Events. Each event contains a JSON object with the current state of the task.Event Format
Event Data Structure
JSON-RPC version, always
"2.0"
Result object containing the current task state
Request ID (matches the request ID)
Examples
Stream Lifecycle
1. Stream Initiation
1. Stream Initiation
State:
submitted
The request has been received and queued for processing.2. Processing Updates
2. Processing Updates
State:
working
The agent is actively processing the request. May include progress updates.3. Completion
3. Completion
State:
completed
The agent has finished processing and provides the final response.Error Handling
Stream Errors
Errors during streaming are sent as regular JSON-RPC error responses:Connection Management
Connection Handling
Connection Handling
- Keep-Alive: Server maintains connection until completion
- Heartbeat: Server may send ping events to keep connection alive
- Timeout: Connections timeout after 5 minutes of inactivity
- Reconnection: Clients should implement reconnection logic
Error Recovery
Error Recovery
- Network Issues: Implement exponential backoff for reconnection
- Partial Responses: Store received data before reconnecting
- Task Continuation: Use task ID to check status after reconnection
Best Practices
Performance
Performance
- Buffer Management: Process events as they arrive, don’t buffer unnecessarily
- Connection Pooling: Reuse connections when possible
- Timeout Handling: Set appropriate timeouts for long-running tasks
Reliability
Reliability
- Event Parsing: Always validate JSON before parsing
- Final Flag: Check
final
flag to know when stream is complete - Error Handling: Implement proper error handling for network issues
User Experience
User Experience
- Progress Indicators: Use progress information to show user feedback
- Partial Results: Display partial content as it arrives
- Cancellation: Provide ability to cancel long-running streams
Comparison with message/send
Feature | message/send | message/stream |
---|---|---|
Response Type | Single response | Multiple events |
Real-time Updates | No | Yes |
Progress Tracking | No | Yes |
Connection | Request/Response | Persistent |
Use Case | Quick queries | Long-running tasks |
Complexity | Simple | Moderate |