fix: use official A2A SDK for spec-compliant client implementation#90
Merged
fix: use official A2A SDK for spec-compliant client implementation#90
Conversation
Replace custom HTTP client implementation with official A2A SDK: **Adapter Changes:** - Use `A2AClient` and `A2ACardResolver` from a2a-sdk - Replace manual HTTP requests with official SDK methods - Use A2A SDK types (Task, Message, TextPart, DataPart, etc.) - Fix TaskState enum usage (lowercase strings not attributes) - Fix Pydantic attribute access (snake_case not camelCase) - Handle Part union type wrapper (access via .root) **Benefits:** - Spec-compliant: Uses canonical A2A client implementation - Maintainable: No custom HTTP client code to maintain - Type-safe: Leverages A2A SDK Pydantic models - Future-proof: Auto-updates with A2A spec changes **Test Updates:** - Add helper functions for creating mock A2A responses - Update all 12 A2A tests to use SDK types - Mock `_get_a2a_client` instead of HTTP layer - All 27 protocol tests passing (12 A2A + 15 MCP) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fixed linting and type checking issues: - Removed unused imports (SendMessageSuccessResponse, TaskState) - Added missing imports (MessageSendParams, Part, Role) - Fixed Message construction to use snake_case field names - Wrapped TextPart in Part union type as required by SDK - Used Role.user enum instead of string literal - Fixed line length by extracting agent_id to variable - Fixed AgentCard.extensions access with getattr for runtime safety - Fixed debug_request type annotation to avoid None issues All ruff and mypy checks now pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The A2A SDK's SendMessageResponse is a Pydantic RootModel that wraps a union of JSONRPCSuccessResponse and JSONRPCErrorResponse. We need to unwrap the .root attribute to access the actual response object with .result or .error attributes. This fix enables proper error handling and response processing when communicating with A2A agents. Verified against test-agent.adcontextprotocol.org: - get_info() works ✓ - list_tools() works ✓ - Tool calls now properly return authentication errors instead of "Invalid response from A2A client" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implement explicit skill invocation (deterministic) by default for A2A
protocol, as recommended by the A2A specification. This uses DataPart
with skill name and parameters instead of natural language interpretation.
**Changes:**
- Add `use_explicit_skill` parameter to `_call_a2a_tool` (default: True)
- Explicit mode: Send DataPart with `{"skill": "...", "parameters": {...}}`
- Natural language mode: Send TextPart with formatted text (legacy)
- Import DataPart from a2a.types
**Benefits:**
- Works without authentication for discovery endpoints (test agent)
- Predictable, repeatable behavior
- Direct skill execution without AI interpretation overhead
- Aligns with A2A best practices
**Reference:**
https://docs.adcontextprotocol.org/docs/protocols/a2a-guide
**Testing:**
- ✅ list_authorized_properties works without auth
- ✅ list_creative_formats works without auth
- ✅ get_products validates parameters correctly
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix A2A Adapter by Using Official A2A SDK
Summary
Fixes the A2A protocol adapter implementation by using the official
a2a-sdkclient instead of a custom HTTP implementation. This resolves response parsing issues and ensures spec compliance.Changes
1. Refactor to Official SDK (
fix: refactor A2A adapter to use official a2a-sdk client)Adapter Changes:
A2AClientandA2ACardResolverfroma2a-sdkpackageTask,Message,TextPart,DataPart,Role, etc.)task.context_idnottask.contextId).root)Test Updates:
_get_a2a_clientinstead of HTTP layerBenefits:
2. CI Fixes (
fix: resolve ruff and mypy errors in A2A adapter)Fixed linting and type checking errors:
SendMessageSuccessResponse,TaskState)MessageSendParams,Part,Role)TextPartinPartunion type as required by SDKRole.userenum instead of string literalAgentCard.extensionsaccess withgetattrfor runtime safetyAll ruff and mypy checks pass ✓
3. Response Handling Fix (
fix: unwrap SendMessageResponse RootModel in A2A adapter)Critical Bug Fix:
The A2A SDK's
SendMessageResponseis a PydanticRootModelthat wraps a union ofJSONRPCSuccessResponse | JSONRPCErrorResponse. The adapter was trying to access.erroror.resultdirectly on the wrapper, which doesn't have these attributes.Solution:
This enables proper response handling for both success and error cases.
Testing
Verified against test agent at
https://test-agent.adcontextprotocol.org:Without Authentication:
get_info()- Successfully retrieves agent metadatalist_tools()- Successfully lists 16 available toolsWith Bearer Token Authentication:
get_products()- Successfully retrieved 2 products with full dataAuthorization: Bearer <token>CI Checks:
Release Type
This is a patch release (2.12.1 → 2.12.2) containing bug fixes to make the A2A adapter work correctly with the official SDK.