Skip to main content

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

1

Create an A2A Client

Initialize a client for your agent endpoint:
2

Send a Message

Send messages to the agent:
3

Handle Streaming Responses

Process streaming responses from agents:

Class-Based Interface

For more structured code, use the A2AClient class:

Completion Bridge

The A2A protocol includes a “completion bridge” that allows non-A2A providers to be accessed through the A2A interface:

Advanced Features

Agent Card Resolution

LiteLLM automatically resolves agent cards from multiple well-known paths:
The resolver checks these paths in order:
  1. /agent.json (standard A2A path)
  2. /.well-known/agent.json (alternative path)
  3. / (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
Then call via the proxy:

Best Practices

Create clients once and reuse them for multiple requests:
Always consume streaming responses fully:
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