Overview
LiteLLM provides a comprehensive wrapper around the Agent-to-Agent (A2A) protocol, enabling seamless communication with A2A-compliant agents. The A2A protocol standardizes how agents communicate, allowing different agent frameworks to interact seamlessly.Key Features
- Automatic agent card resolution
- Built-in retry logic for localhost URLs
- Integrated logging and cost tracking
- Support for both streaming and non-streaming requests
- Compatible with multiple agent providers (LangGraph, Pydantic AI, etc.)
Installation
Install the A2A SDK alongside LiteLLM:Quick Start
Class-Based Interface
For more structured code, use theA2AClient class:
Completion Bridge
The A2A protocol includes a “completion bridge” that allows non-A2A providers to be accessed through the A2A interface:Using LangGraph via A2A
Using LangGraph via A2A
Using Bedrock AgentCore via A2A
Using Bedrock AgentCore via A2A
Advanced Features
Agent Card Resolution
LiteLLM automatically resolves agent cards from multiple well-known paths:/agent.json(standard A2A path)/.well-known/agent.json(alternative path)/(root path with JSON content-type)
Localhost URL Retry Logic
Many agents deploy with localhost URLs in their agent cards. LiteLLM automatically detects and corrects this:Cost Tracking
LiteLLM tracks token usage and costs for A2A agents:Custom Headers
Pass custom headers for authentication or tracing:Error Handling
Proxy Integration
Use A2A agents through the LiteLLM Proxy:config.yaml
Best Practices
Reuse Clients
Reuse Clients
Create clients once and reuse them for multiple requests:
Handle Streaming Properly
Handle Streaming Properly
Always consume streaming responses fully:
Set Appropriate Timeouts
Set Appropriate Timeouts
Configure timeouts based on agent complexity:
Reference
Source Code
- A2A Protocol implementation:
litellm/a2a_protocol/ - Main functions:
litellm/a2a_protocol/main.py:134 - Client class:
litellm/a2a_protocol/client.py:21 - Exceptions:
litellm/a2a_protocol/exceptions.py:12