mirror of
https://github.com/tiennm99/litellm.git
synced 2026-06-17 20:48:32 +00:00
[Docs] Add docs on using pydantic ai agents with LiteLLM A2a gateway (#18026)
* init A2AProviderConfigManager * move file * move file * add pydnatic ai folder * init providers * test_pydantic_ai_non_streaming * fix import * INIT pydantic * use_a2a_form_fields * test_vertex_agent_engine_streaming * add agent_engine * init transform for agent engine * init agent engine * VertexAgentEngineSSEStreamIterator * sample * ui add new fields * fix vertex_credentials * working SSE iterator * TestVertexAgentEngineTransformRequest * fix code QA check * stash docs * docs fix * fix logo * docs fix * doc pydantic ai * docs pydantic ai * new provider * docs fix
This commit is contained in:
@@ -16,7 +16,7 @@ Add A2A Agents on LiteLLM AI Gateway, Invoke agents in A2A Protocol, track reque
|
||||
|
||||
| Feature | Supported |
|
||||
|---------|-----------|
|
||||
| Supported Agent Providers | A2A, LangGraph, Azure AI Foundry, Bedrock AgentCore |
|
||||
| Supported Agent Providers | A2A, Pydantic AI, LangGraph, Azure AI Foundry, Bedrock AgentCore |
|
||||
| Logging | ✅ |
|
||||
| Load Balancing | ✅ |
|
||||
| Streaming | ✅ |
|
||||
@@ -45,6 +45,7 @@ You can add A2A-compatible agents through the LiteLLM Admin UI.
|
||||
|
||||
The URL should be the invocation URL for your A2A agent (e.g., `http://localhost:10001`).
|
||||
|
||||
|
||||
### Add Azure AI Foundry Agents
|
||||
|
||||
Follow [this guide, to add your azure ai foundry agent to LiteLLM Agent Gateway](./providers/azure_ai_agents#litellm-a2a-gateway)
|
||||
@@ -57,6 +58,10 @@ Follow [this guide, to add your langgraph agent to LiteLLM Agent Gateway](./prov
|
||||
|
||||
Follow [this guide, to add your bedrock agentcore agent to LiteLLM Agent Gateway](./providers/bedrock_agentcore#litellm-a2a-gateway)
|
||||
|
||||
### Add Pydantic AI Agents
|
||||
|
||||
Follow [this guide, to add your pydantic ai agent to LiteLLM Agent Gateway](./providers/pydantic_ai_agent#litellm-a2a-gateway)
|
||||
|
||||
## Invoking your Agents
|
||||
|
||||
Use the [A2A Python SDK](https://pypi.org/project/a2a/) to invoke agents through LiteLLM.
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
# Pydantic AI Agents
|
||||
|
||||
Call Pydantic AI Agents via LiteLLM's A2A Gateway.
|
||||
|
||||
| Property | Details |
|
||||
|----------|---------|
|
||||
| Description | Pydantic AI agents with native A2A support via the `to_a2a()` method. LiteLLM provides fake streaming support for agents that don't natively stream. |
|
||||
| Provider Route on LiteLLM | A2A Gateway |
|
||||
| Supported Endpoints | `/v1/a2a/message/send` |
|
||||
| Provider Doc | [Pydantic AI Agents ↗](https://ai.pydantic.dev/agents/) |
|
||||
|
||||
## LiteLLM A2A Gateway
|
||||
|
||||
All Pydantic AI agents need to be exposed as A2A agents using the `to_a2a()` method. Once your agent server is running, you can add it to the LiteLLM Gateway.
|
||||
|
||||
### 1. Setup Pydantic AI Agent Server
|
||||
|
||||
LiteLLM requires Pydantic AI agents to follow the [A2A (Agent-to-Agent) protocol](https://github.com/google/A2A). Pydantic AI has native A2A support via the `to_a2a()` method, which exposes your agent as an A2A-compliant server.
|
||||
|
||||
#### Install Dependencies
|
||||
|
||||
```bash
|
||||
pip install pydantic-ai fasta2a uvicorn
|
||||
```
|
||||
|
||||
#### Create Agent
|
||||
|
||||
```python title="agent.py"
|
||||
from pydantic_ai import Agent
|
||||
|
||||
agent = Agent('openai:gpt-4o-mini', instructions='Be helpful!')
|
||||
|
||||
@agent.tool_plain
|
||||
def get_weather(city: str) -> str:
|
||||
"""Get weather for a city."""
|
||||
return f"Weather in {city}: Sunny, 72°F"
|
||||
|
||||
@agent.tool_plain
|
||||
def calculator(expression: str) -> str:
|
||||
"""Evaluate a math expression."""
|
||||
return str(eval(expression))
|
||||
|
||||
# Native A2A server - Pydantic AI handles it automatically
|
||||
app = agent.to_a2a()
|
||||
```
|
||||
|
||||
#### Run Server
|
||||
|
||||
```bash
|
||||
uvicorn agent:app --host 0.0.0.0 --port 9999
|
||||
```
|
||||
|
||||
Server runs at `http://localhost:9999`
|
||||
|
||||
### 2. Navigate to Agents
|
||||
|
||||
From the sidebar, click "Agents" to open the agent management page, then click "+ Add New Agent".
|
||||
|
||||
### 3. Select Pydantic AI Agent Type
|
||||
|
||||
Click "A2A Standard" to see available agent types, then select "Pydantic AI".
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### 4. Configure the Agent
|
||||
|
||||
Fill in the following fields:
|
||||
|
||||
- **Agent Name** - A unique identifier for your agent (e.g., `test-pydantic-agent`)
|
||||
- **Agent URL** - The URL where your Pydantic AI agent is running. We use `http://localhost:9999` because that's where we started our Pydantic AI agent server in the previous step.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### 5. Create Agent
|
||||
|
||||
Click "Create Agent" to save your configuration.
|
||||
|
||||

|
||||
|
||||
### 6. Test in Playground
|
||||
|
||||
Go to "Playground" in the sidebar to test your agent.
|
||||
|
||||

|
||||
|
||||
### 7. Select A2A Endpoint
|
||||
|
||||
Click the endpoint dropdown and search for "a2a", then select `/v1/a2a/message/send`.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### 8. Select Your Agent and Send a Message
|
||||
|
||||
Pick your Pydantic AI agent from the dropdown and send a test message.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
## Further Reading
|
||||
|
||||
- [Pydantic AI Documentation](https://ai.pydantic.dev/)
|
||||
- [Pydantic AI Agents](https://ai.pydantic.dev/agents/)
|
||||
- [A2A Agent Gateway](../a2a.md)
|
||||
- [A2A Cost Tracking](../a2a_cost_tracking.md)
|
||||
@@ -738,6 +738,7 @@ const sidebars = {
|
||||
"providers/petals",
|
||||
"providers/publicai",
|
||||
"providers/predibase",
|
||||
"providers/pydantic_ai_agent",
|
||||
"providers/ragflow",
|
||||
"providers/recraft",
|
||||
"providers/replicate",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120">
|
||||
<path
|
||||
fill="#e92063"
|
||||
d="M 119.18,86.64 98.02,57.3 c 0,0 0,0 0,0 L 63.77,9.8 c -1.74,-2.4 -5.76,-2.4 -7.49,0 l -34.24,47.49 c 0,0 0,0 0,0 L 0.87,86.64 c -0.86,1.2 -1.1,2.73 -0.65,4.13 0.46,1.4 1.55,2.5 2.95,2.96 l 55.41,18.14 c 0,0 0,0 0.01,9e-4 0.46,0.15 0.94,0.23 1.43,0.23 0.49,0 0.97,-0.08 1.43,-0.23 0,0 0,0 0.01,0 L 116.87,93.73 c 1.4,-0.46 2.5,-1.55 2.95,-2.96 0.46,-1.4 0.22,-2.93 -0.65,-4.13 z m -59.15,-66.25 22.21,30.8 -20.77,-6.8 c -0.16,-0.05 -0.33,-0.04 -0.49,-0.08 -0.16,-0.04 -0.32,-0.06 -0.48,-0.08 -0.16,-0.02 -0.31,-0.08 -0.47,-0.08 -0.16,0 -0.31,0.06 -0.47,0.08 -0.17,0.02 -0.32,0.04 -0.48,0.08 -0.16,0.03 -0.33,0.03 -0.48,0.08 h 0 l -20.64,6.76 -0.13,0.04 22.21,-30.8 z m -31.38,43.52 24.18,-7.92 2.58,-0.84 V 101.12 L 12.06,86.92 Z m 36,37.2 V 55.15 l 26.76,8.76 16.59,23 z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 880 B |
@@ -1946,6 +1946,23 @@
|
||||
"rerank": false,
|
||||
"a2a": true
|
||||
}
|
||||
},
|
||||
"pydantic_ai_agents": {
|
||||
"display_name": "Pydantic AI Agents (`pydantic_ai_agents`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/pydantic_ai_agent",
|
||||
"endpoints": {
|
||||
"chat_completions": false,
|
||||
"messages": false,
|
||||
"responses": false,
|
||||
"embeddings": false,
|
||||
"image_generations": false,
|
||||
"audio_transcriptions": false,
|
||||
"audio_speech": false,
|
||||
"moderations": false,
|
||||
"batches": false,
|
||||
"rerank": false,
|
||||
"a2a": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user