-
Notifications
You must be signed in to change notification settings - Fork 606
feat(a2a): add A2AAgent class #1441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(a2a): add A2AAgent class #1441
Conversation
…face for remote A2A protocol based agents
…d function + reduce use of Any type
…y constructor parameters
- Fix invoke_async to delegate to stream_async (prevents returning first incomplete event) - Add async context manager support (__aenter__/__aexit__) and explicit aclose() method - Improve __del__ cleanup to handle event loop edge cases - Change logger.info to logger.debug for consistency with project standards - Simplify factory creation with _create_default_factory() helper method - Add comprehensive documentation to A2AStreamEvent - Improve test fixture pattern with pytest fixture for subprocess management - Add comprehensive e2e tests for invoke_async, stream_async, and context manager Addresses PR strands-agents#1174 review comments: - Comment strands-agents#2: Critical bug - invoke_async now waits for complete events - Comment strands-agents#5: Code duplication - invoke_async delegates to stream_async - Comment strands-agents#6: Async cleanup - proper async context manager pattern - Comment strands-agents#3: Logging level - changed to debug - Comment strands-agents#4: Factory simplification - extracted helper method - Comment strands-agents#12: Documentation - documented A2AStreamEvent behavior - Comment strands-agents#9: Test fixture - using pytest fixture pattern - Comment strands-agents#10: Test coverage - added comprehensive e2e tests
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Code Review: A2AAgent ImplementationThanks for addressing the feedback from the original PR! This is a solid implementation that follows SDK patterns well. I've done a thorough review and have some observations and suggestions below. ✅ Strengths1. Excellent Test CoverageThe PR includes comprehensive testing across multiple levels:
This is exemplary test coverage for a new feature. 2. Clean API DesignThe class adheres to the
The API is intuitive and consistent with existing SDK agents. 3. Good Documentation
4. Proper Resource Management
5. Code Quality ImprovementsThe changes from the original PR are all positive:
🔍 Issues & SuggestionsCritical: Missing Public API Export
Current state: # This DOESN'T work:
from strands.agent import A2AAgent # ImportError!
# Users must do:
from strands.agent.a2a_agent import A2AAgent # AwkwardFix needed in from .a2a_agent import A2AAgent
__all__ = [
"Agent",
"AgentBase",
"AgentResult",
"A2AAgent", # Add this
# ... rest
]Optionally, also export from top-level Medium: Inconsistent Streaming DefaultThe PR description mentions:
This is implemented in def _create_default_factory(self) -> ClientFactory:
"""Create default A2A client factory with streaming config."""
config = ClientConfig(httpx_client=httpx_client, streaming=True)
return ClientFactory(config)Questions:
Suggestion: Add a comment explaining why def _create_default_factory(self) -> ClientFactory:
"""Create default A2A client factory with streaming enabled.
Streaming must be enabled for both invoke_async and stream_async
to receive incremental updates from the remote agent.
"""Minor: Type Annotation InconsistencyIn result: AgentResult | None = NoneWhile in other places, the code uses Minor: Potential Race Condition in
|
This comment was marked as off-topic.
This comment was marked as off-topic.
| yield A2AStreamEvent(event) | ||
|
|
||
| # Use the last complete event if available, otherwise fall back to last event | ||
| final_event = last_complete_event if last_complete_event is not None else last_event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, can this be simplified to?:
| final_event = last_complete_event if last_complete_event is not None else last_event | |
| final_event = last_complete_event or last_event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we mark this file as private by using an underscore? I don't want folks relying on these implementation details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? I actually want it :)
I think this is the same discussion we have been having with other formats. We have this logic in the SDK, why don't we expose it? It'll make integrating Strands with different ecosystems much easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually want it :)
So then this is an explicit feature that we're committing to backwards compatibility for - that was my primary concern
| return parts | ||
|
|
||
|
|
||
| def convert_response_to_agent_result(response: A2AResponse) -> AgentResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we tested this and/or verified this behavior against a 3P A2A server?
I want to make sure we're conformant to the spec/expectations rather than our own implementation - which can be wrong (per #1401)
And actually, related to that, are we handling both of our implementations (spec mode and non-spec mode?)
| A2AStreamEvents. | ||
| """ | ||
|
|
||
| def __init__(self, a2a_event: A2AResponse) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a follow-up issue for this?
| description="Test description here", | ||
| callback_handler=None, | ||
| ) | ||
| a2a_server = A2AServer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get an integ test that also tests with enable_a2a_compliant_streaming=True - per #1401
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And related to my other question, is there an integ test that we can have against a 3P A2A server for interop verification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran it against the a2a samples, everything seems to be working
Test summary:
Tested the Strands `A2AAgent` client against 3 third-party A2A servers from the official `a2a-samples` repository (HelloWorld, AgentAlice, AgentCarol). **All 15 tests passed (100%)** - agent card discovery, async invocation, streaming, and multiple messages all work correctly. Streaming works well with both streaming-enabled servers (receives chunked events) and non-streaming servers (graceful fallback). The client is fully interoperable with A2A reference implementations using JSON-RPC over HTTP.
Description
Picking up from @awsarron's work in #1174 to address review feedback.
A2AAgent makes it simple to consume remote A2A agents and invoke them like any other Strands Agent. This PR addresses the open review comments from the original implementation.
Changes from original PR:
logger.infotologger.debugfor agent card discovery and message sending_create_default_factory()helper methodinvoke_asyncto delegate tostream_async(ensures consistent behavior)A2AStreamEventexplaining when events are emitted__del__cleanup behaviorExample usage (unchanged from original):
Follow-ups:
Related Issues
#907
Resolves review comments from #1174
Documentation PR
TODO
Type of Change
New feature
Testing
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
diff of a2a agent compared to original PR
REV2
streaming=Trueby default with the client. Otherwise streaming would require both custom client and using stream async. Right now both stream async and invoke async would work normally.