Add A2A (Agent-to-Agent) protocol support#217
Conversation
- Add BedrockAgentCoreA2AApp class for hosting A2A agents - Add A2A models (AgentCard, AgentSkill, JsonRpcRequest/Response, etc.) - Add @entrypoint decorator for message handling - Support JSON-RPC 2.0 protocol on port 9000 - Export A2A classes from runtime module - Add comprehensive unit tests (54 tests)
|
@sundargthb, |
| from urllib.parse import quote | ||
|
|
||
|
|
||
| class JsonRpcErrorCode(int, Enum): |
There was a problem hiding this comment.
the codes here match this page but contradicts with the A2A Protocol contract page.. need to check the valid range
| return JSONResponse(card_dict) | ||
| except Exception as e: | ||
| self.logger.exception("Failed to serve Agent Card") | ||
| return JSONResponse({"error": str(e)}, status_code=500) |
There was a problem hiding this comment.
str(e) is passed directly into the JSON-RPC error response. ... internal exception details (paths, library errors, connection strings) can reach external agents ? the HTTP app.py has the same str(e) pattern — so this isn't new to the PR, it's consistent with existing code. But A2A is explicitly cross-organizational (A2A Enterprise Features)
| self.logger.exception("Request failed (%.3fs)", duration) | ||
| return self._jsonrpc_error_response( | ||
| body.get("id") if "body" in dir() else None, | ||
| JsonRpcErrorCode.INTERNAL_ERROR, |
There was a problem hiding this comment.
same comment as _handle_agent_card..
| ) | ||
|
|
||
|
|
||
| class A2ARequestContextFormatter(logging.Formatter): |
There was a problem hiding this comment.
The HTTP app has @async_task, add_async_task()/complete_async_task(), and force_ping_status()/clear_forced_ping_status(). Without these, developers can't signal HealthyBusy during long-running agent workflows, which means the runtime may incorrectly scale down or over-route. Can either finish the port from app.py or remove the unused attributes/logic
Add missing A2A protocol standard error codes (-32001 to -32007) alongside existing AgentCore Runtime error codes (-32501 to -32505). The two sets serve different layers: protocol-level (task management) vs infrastructure-level (throttling, resource management). Added corresponding tests. Addresses review feedback on PR aws#217 regarding error code alignment between A2A protocol spec and AWS AgentCore documentation. https://claude.ai/code/session_01Fnc4LHzBPBej7FK7ooT2La
- Remove unused imports (JsonRpcRequest, pytest) in tests - Initialize body=None before try block; replace `"body" in dir()` with `body is not None` - Add `isinstance(body, dict)` guard so non-object JSON payloads return INVALID_REQUEST (-32600) instead of INTERNAL_ERROR (-32603) - Use `_convert_to_serializable()` / `_safe_serialize_to_json_string()` for both streaming and non-streaming paths so dataclass helpers (A2AArtifact, etc.) serialize correctly - Fall back to `request.base_url` when AGENTCORE_RUNTIME_URL is unset so the agent card always contains a reachable URL - Add tests for dataclass serialization (sync + streaming) and non-object payload rejection
0a85319 to
ee117a9
Compare
|
@sundargthb Thanks for your review! Fixed it. |
Summary
This PR adds support for the A2A (Agent-to-Agent) protocol, enabling agents to communicate with each other using the JSON-RPC 2.0 protocol.
New Features
New Files
src/bedrock_agentcore/runtime/a2a_app.py- Main A2A application classsrc/bedrock_agentcore/runtime/a2a_models.py- A2A data modelstests/bedrock_agentcore/runtime/test_a2a_app.py- Unit tests for A2A apptests/bedrock_agentcore/runtime/test_a2a_models.py- Unit tests for A2A modelsUsage Example
Test Plan