-
Notifications
You must be signed in to change notification settings - Fork 603
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.
Replace hardcoded time.sleep(5) with proper health check polling that: - Polls the /.well-known/agent.json endpoint until server responds - Uses 30 second timeout (vs fixed 5s sleep) - Provides clear error message if server fails to start - Runs faster when server starts quickly This fixes flaky integration tests in CI environments where 5 seconds may not be sufficient for the A2A server to fully initialize. Related to: strands-agents#1441
|
Hi @mkmeral! 👋 I noticed the CI failures here might be related to the flaky The fix:
PR #1457 has all tests passing (14/15 - only Once #1457 is merged, it should help stabilize the CI for this PR. 🦆 |
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.