Skip to content

Conversation

@physicsrob
Copy link

This PR implements streaming support for FastA2A using Server-Sent Events (SSE), adding support for the message/stream endpoint.

I plan on following this up with a PR targeting pydantic-ai, which will use this support to add message/stream support for pydantic-ai's Agent.to_a2a2() method.

Core Implementation:

  • Added streaming infrastructure to broker layer with pub/sub pattern for event distribution
  • Implemented message/stream endpoint in applications layer
  • Extended task manager with stream_message() method that yields events as they occur
  • Updated agent card to report streaming capability when enabled

Dependencies:

  • Added sse-starlette>=2.0.0 for SSE response handling
  • Added httpx-sse for test client support

Configuration:

  • Added optional streaming parameter to FastA2A constructor (defaults to False)
  • Streaming is backwards compatible - existing functionality unchanged when disabled

Testing:

  • Added comprehensive test coverage: 32 tests total with 90.18% coverage
  • Tests cover broker pub/sub, streaming endpoints, task manager, and agent capabilities

The implementation follows the A2A protocol v0.2.5 specification for streaming responses. Workers can emit real-time status updates and artifact chunks during task execution using the broker's
send_stream_event() method.

physicsrob and others added 8 commits July 22, 2025 00:44
- Add abstract streaming methods to Broker base class:
  - send_stream_event() for publishing events
  - subscribe_to_stream() for receiving events
- Implement pub-sub pattern in InMemoryBroker:
  - Track subscribers with _event_subscribers dict
  - Use anyio.Lock for thread-safe subscription management
  - Handle automatic cleanup of disconnected subscribers
  - Support final status updates to complete streams
- Add StreamEvent type union and TypeAdapter to schema

Co-Authored-By: Claude <[email protected]>
- Rewrite stream_message to return AsyncGenerator[StreamEvent, None]
- Implement streaming workflow:
  - Create and submit task, yielding it immediately
  - Start task execution asynchronously in background
  - Subscribe to broker event stream and forward all events
- Handle context_id generation and history_length parameter
- Clean up worker imports for better organization
- Add streaming parameter to FastA2A constructor
- Implement message/stream handler that:
  - Parses streaming requests with proper validation
  - Wraps task manager events in JSON-RPC responses
  - Returns Server-Sent Events (SSE) response
- Update agent capabilities to advertise streaming support
- Use camelCase serialization for protocol compliance
- Add sse-starlette>=2.0.0 for Server-Sent Events support
- Add dev dependencies:
  - httpx-sse for testing SSE functionality
  - pytest-asyncio for async test support
- Add comprehensive coverage configuration:
  - Enable branch coverage
  - Configure source paths and omit patterns
  - Add exclusion patterns for abstract methods and TYPE_CHECKING

These dependencies enable the streaming implementation
and improve the development/testing experience.
- Test agent card with all configuration parameters
- Test HTTP HEAD and OPTIONS methods support
- Test caching behavior with ETag and Last-Modified headers
- Test documentation endpoint functionality

These tests ensure the agent card endpoints behave
correctly according to the A2A protocol specification.
- Add test_streaming_integration.py with end-to-end streaming tests
- Add test_broker.py to test pub-sub functionality and edge cases
- Add test_task_manager.py to test streaming message handling
- Test concurrent subscribers, disconnection handling, error cases
- Verify SSE response format and JSON-RPC compliance
@physicsrob
Copy link
Author

cc @Kludex

@physicsrob
Copy link
Author

@Kludex any thoughts on this?

@Coding-Crashkurse
Copy link

@physicsrob Thanks for this, I used this code in my A2A PoC in my company and was pretty happy with it.
Currently I probably will walk away from fasta2a due to the lack of responsiveness from the devs, despite the very good ideas :(

@aristide1997
Copy link

@Kludex @samuelcolvin is anyone able to have a look at this?

@physicsrob
Copy link
Author

@Coding-Crashkurse Thanks! Unfortunately I'm in the same boat. I need to be able to use pydantic-ai agents with A2A (including streaming, deps, etc). I'm going to start investigating other strategies soon.

@Kludex
Copy link
Member

Kludex commented Aug 13, 2025

I'll check it today. Sorry the delay.

@frazerpoggio
Copy link

frazerpoggio commented Oct 9, 2025

Any update on getting this in? @physicsrob @Kludex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants