Overview
The Agent-to-Agent (A2A) protocol enables standardized communication between agents built with different frameworks and technologies. The Microsoft Agent Framework provides full support for both hosting A2A-compliant agents and consuming external A2A agents.Learn more about the A2A protocol at a2a-protocol.org
Key Concepts
Agent Discovery
A2A agents expose an AgentCard at/.well-known/agent.json that describes:
- Agent name and description
- Available skills and capabilities
- Supported input/output modes
- API endpoints
Communication Modes
- Non-streaming: Request-response pattern for simple interactions
- Streaming: Server-Sent Events (SSE) for real-time updates
- Background tasks: Long-running operations with continuation tokens
Task States
A2A tasks progress through states:working: Task is being processedcompleted: Task finished successfullyfailed: Task encountered an errorcancelled: Task was cancelled
Consuming A2A Agents
Connect to external A2A-compliant agents:Hosting A2A Agents
Expose your agents via the A2A protocol:Using Azure Functions
TheAgentFunctionApp automatically exposes A2A-compliant endpoints:
Custom A2A Server
Implement A2A protocol manually for custom hosting:AgentCard Structure
The AgentCard describes your agent’s capabilities:A2A Skills as Tools
Use A2A agent skills as tools for another agent:Background Tasks
Handle long-running operations with continuation tokens:Polling for Completion
Implement polling with exponential backoff:Multi-Agent Communication
Orchestrate multiple A2A agents:Error Handling
Handle A2A protocol errors gracefully:Testing A2A Agents
Using .NET Sample Server
For quick testing, use the .NET A2A sample server:Mock A2A Server
Create a mock server for testing:Best Practices
AgentCard Design
AgentCard Design
- Clear descriptions: Make skills discoverable with detailed descriptions
- Relevant tags: Use tags for categorization and searchability
- Provide examples: Include usage examples for each skill
- Specify modes: Declare supported input/output MIME types
Error Handling
Error Handling
- Retry logic: Implement exponential backoff for transient errors
- Timeout management: Set appropriate timeouts for long-running tasks
- Graceful degradation: Handle agent unavailability gracefully
- Detailed errors: Return meaningful error messages in task failures
Performance
Performance
- Connection pooling: Reuse HTTP connections for multiple requests
- Parallel execution: Use
asyncio.gather()for concurrent agent calls - Caching: Cache AgentCards to avoid repeated discovery
- Streaming: Use streaming for long responses to reduce latency
Security
Security
- Authentication: Implement OAuth 2.0 or API key authentication
- HTTPS: Always use HTTPS in production
- Rate limiting: Protect against abuse with rate limits
- Input validation: Validate all inputs before processing
Troubleshooting
AgentCard Not Found
AgentCard Not Found
Error: Cannot retrieve AgentCard at
/.well-known/agent.jsonSolutions:- Verify URL is correct and accessible
- Check CORS configuration if accessing from browser
- Ensure AgentCard endpoint returns valid JSON
- Test with curl:
curl https://agent.com/.well-known/agent.json
Connection Timeouts
Connection Timeouts
Error: Request times out when calling A2A agentSolutions:
- Increase timeout:
httpx.AsyncClient(timeout=120.0) - Use background tasks for long operations
- Implement polling instead of waiting for completion
- Check network connectivity and firewall rules
Task State Errors
Task State Errors
Error: Task remains in
working state indefinitelySolutions:- Implement timeout in polling loop
- Check A2A agent logs for errors
- Verify task is actually processing (check metrics)
- Consider using continuation tokens to resume
Streaming Issues
Streaming Issues
Error: Streaming response disconnects prematurelySolutions:
- Use continuation tokens to resume from last position
- Implement retry logic with exponential backoff
- Check load balancer timeout settings
- Verify SSE configuration on both client and server
Protocol Compliance
Ensure your A2A implementation follows the specification:- ✅ AgentCard at
/.well-known/agent.json - ✅ Proper content negotiation (Accept headers)
- ✅ Task state transitions (working → completed/failed)
- ✅ Continuation token support for resumption
- ✅ SSE format for streaming responses
- ✅ Error responses with proper status codes
Next Steps
Azure Functions
Host A2A agents on Azure Functions
DurableTask
Orchestrate A2A agents with Durable Functions