Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

[Feat] New provider - Agent Gateway, add pydantic ai agents (#18013)

Ishaan Jaffa4fb0df02819
diff --git a/litellm/a2a_protocol/litellm_completion_bridge/handler.py b/litellm/a2a_protocol/litellm_completion_bridge/handler.py
index cc222d3ee18..1916b04454a 100644
--- a/litellm/a2a_protocol/litellm_completion_bridge/handler.py
+++ b/litellm/a2a_protocol/litellm_completion_bridge/handler.py
@@ -18,6 +18,7 @@ from litellm.a2a_protocol.litellm_completion_bridge.transformation import (
A2ACompletionBridgeTransformation,
A2AStreamingContext,
)
+from litellm.a2a_protocol.providers.config_manager import A2AProviderConfigManager
class A2ACompletionBridgeHandler:
@@ -44,6 +45,29 @@ class A2ACompletionBridgeHandler:
Returns:
A2A SendMessageResponse dict
"""
+ # Get provider config for custom_llm_provider
+ custom_llm_provider = litellm_params.get("custom_llm_provider")
+ a2a_provider_config = A2AProviderConfigManager.get_provider_config(
+ custom_llm_provider=custom_llm_provider
+ )
+
+ # If provider config exists, use it
+ if a2a_provider_config is not None:
+ if api_base is None:
+ raise ValueError(f"api_base is required for {custom_llm_provider}")
+
+ verbose_logger.info(
+ f"A2A: Using provider config for {custom_llm_provider}"
+ )
+
+ response_data = await a2a_provider_config.handle_non_streaming(
+ request_id=request_id,
+ params=params,
+ api_base=api_base,
+ )
+
+ return response_data
+
# Extract message from params
message = params.get("message", {})
@@ -119,6 +143,30 @@ class A2ACompletionBridgeHandler:
Yields:
A2A streaming response events
"""
+ # Get provider config for custom_llm_provider
+ custom_llm_provider = litellm_params.get("custom_llm_provider")
+ a2a_provider_config = A2AProviderConfigManager.get_provider_config(
+ custom_llm_provider=custom_llm_provider
+ )
+
+ # If provider config exists, use it
+ if a2a_provider_config is not None:
+ if api_base is None:
+ raise ValueError(f"api_base is required for {custom_llm_provider}")
+
+ verbose_logger.info(
+ f"A2A: Using provider config for {custom_llm_provider} (streaming)"
+ )
+
+ async for chunk in a2a_provider_config.handle_streaming(
+ request_id=request_id,
+ params=params,
+ api_base=api_base,
+ ):
+ yield chunk
+
+ return
+
# Extract message from params
message = params.get("message", {})
diff --git a/litellm/a2a_protocol/providers/__init__.py b/litellm/a2a_protocol/providers/__init__.py
new file mode 100644
index 00000000000..873a5a83749
--- /dev/null
+++ b/litellm/a2a_protocol/providers/__init__.py
@@ -0,0 +1,11 @@
+"""
+A2A Protocol Providers.
+
+This module contains provider-specific implementations for the A2A protocol.
+"""
+
+from litellm.a2a_protocol.providers.base import BaseA2AProviderConfig
+from litellm.a2a_protocol.providers.config_manager import A2AProviderConfigManager
+
+__all__ = ["BaseA2AProviderConfig", "A2AProviderConfigManager"]
+
diff --git a/litellm/a2a_protocol/providers/base.py b/litellm/a2a_protocol/providers/base.py
new file mode 100644
index 00000000000..656bc78d6d2
--- /dev/null
+++ b/litellm/a2a_protocol/providers/base.py
@@ -0,0 +1,63 @@
+"""
+Base configuration for A2A protocol providers.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Any, AsyncIterator, Dict, Optional
+
+
+class BaseA2AProviderConfig(ABC):
+ """
+ Base configuration class for A2A protocol providers.
+
+ Each provider should implement this interface to define how to handle
+ A2A requests for their specific agent type.
+ """
+
+ @abstractmethod
+ async def handle_non_streaming(
+ self,
+ request_id: str,
+ params: Dict[str, Any],
+ api_base: str,
+ **kwargs,
+ ) -> Dict[str, Any]:
+ """
+ Handle non-streaming A2A request.
+
+ Args:
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ api_base: Base URL of the agent
+ **kwargs: Additional provider-specific parameters
+
+ Returns:
+ A2A SendMessageResponse dict
+ """
+ pass
+
+ @abstractmethod
+ async def handle_streaming(
+ self,
+ request_id: str,
+ params: Dict[str, Any],
+ api_base: str,
+ **kwargs,
+ ) -> AsyncIterator[Dict[str, Any]]:
+ """
+ Handle streaming A2A request.
+
+ Args:
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ api_base: Base URL of the agent
+ **kwargs: Additional provider-specific parameters
+
+ Yields:
+ A2A streaming response events
+ """
+ # This is an abstract method - subclasses must implement
+ # The yield is here to make this a generator function
+ if False: # pragma: no cover
+ yield {}
+
diff --git a/litellm/a2a_protocol/providers/config_manager.py b/litellm/a2a_protocol/providers/config_manager.py
new file mode 100644
index 00000000000..e0703ec466b
--- /dev/null
+++ b/litellm/a2a_protocol/providers/config_manager.py
@@ -0,0 +1,48 @@
+"""
+A2A Provider Config Manager.
+
+Manages provider-specific configurations for A2A protocol.
+"""
+
+from typing import Optional
+
+from litellm.a2a_protocol.providers.base import BaseA2AProviderConfig
+
+
+class A2AProviderConfigManager:
+ """
+ Manager for A2A provider configurations.
+
+ Similar to ProviderConfigManager in litellm.utils but specifically for A2A providers.
+ """
+
+ @staticmethod
+ def get_provider_config(
+ custom_llm_provider: Optional[str],
+ ) -> Optional[BaseA2AProviderConfig]:
+ """
+ Get the provider configuration for a given custom_llm_provider.
+
+ Args:
+ custom_llm_provider: The provider identifier (e.g., "pydantic_ai_agents")
+
+ Returns:
+ Provider configuration instance or None if not found
+ """
+ if custom_llm_provider is None:
+ return None
+
+ if custom_llm_provider == "pydantic_ai_agents":
+ from litellm.a2a_protocol.providers.pydantic_ai_agents.config import (
+ PydanticAIProviderConfig,
+ )
+
+ return PydanticAIProviderConfig()
+
+ # Add more providers here as needed
+ # elif custom_llm_provider == "another_provider":
+ # from litellm.a2a_protocol.providers.another_provider.config import AnotherProviderConfig
+ # return AnotherProviderConfig()
+
+ return None
+
diff --git a/litellm/a2a_protocol/providers/litellm_completion/README.md b/litellm/a2a_protocol/providers/litellm_completion/README.md
new file mode 100644
index 00000000000..a809e9bf55e
--- /dev/null
+++ b/litellm/a2a_protocol/providers/litellm_completion/README.md
@@ -0,0 +1,74 @@
+# A2A to LiteLLM Completion Bridge
+
+Routes A2A protocol requests through `litellm.acompletion`, enabling any LiteLLM-supported provider to be invoked via A2A.
+
+## Flow
+
+```
+A2A Request → Transform → litellm.acompletion → Transform → A2A Response
+```
+
+## SDK Usage
+
+Use the existing `asend_message` and `asend_message_streaming` functions with `litellm_params`:
+
+```python
+from litellm.a2a_protocol import asend_message, asend_message_streaming
+from a2a.types import SendMessageRequest, SendStreamingMessageRequest, MessageSendParams
+from uuid import uuid4
+
+# Non-streaming
+request = SendMessageRequest(
+ id=str(uuid4()),
+ params=MessageSendParams(
+ message={"role": "user", "parts": [{"kind": "text", "text": "Hello!"}], "messageId": uuid4().hex}
+ )
+)
+response = await asend_message(
+ request=request,
+ api_base="http://localhost:2024",
+ litellm_params={"custom_llm_provider": "langgraph", "model": "agent"},
+)
+
+# Streaming
+stream_request = SendStreamingMessageRequest(
+ id=str(uuid4()),
+ params=MessageSendParams(
+ message={"role": "user", "parts": [{"kind": "text", "text": "Hello!"}], "messageId": uuid4().hex}
+ )
+)
+async for chunk in asend_message_streaming(
+ request=stream_request,
+ api_base="http://localhost:2024",
+ litellm_params={"custom_llm_provider": "langgraph", "model": "agent"},
+):
+ print(chunk)
+```
+
+## Proxy Usage
+
+Configure an agent with `custom_llm_provider` in `litellm_params`:
+
+```yaml
+agents:
+ - agent_name: my-langgraph-agent
+ agent_card_params:
+ name: "LangGraph Agent"
+ url: "http://localhost:2024" # Used as api_base
+ litellm_params:
+ custom_llm_provider: langgraph
+ model: agent
+```
+
+When an A2A request hits `/a2a/{agent_id}/message/send`, the bridge:
+
+1. Detects `custom_llm_provider` in agent's `litellm_params`
+2. Transforms A2A message → OpenAI messages
+3. Calls `litellm.acompletion(model="langgraph/agent", api_base="http://localhost:2024")`
+4. Transforms response → A2A format
+
+## Classes
+
+- `A2ACompletionBridgeTransformation` - Static methods for message format conversion
+- `A2ACompletionBridgeHandler` - Static methods for handling requests (streaming/non-streaming)
+
diff --git a/litellm/a2a_protocol/providers/litellm_completion/__init__.py b/litellm/a2a_protocol/providers/litellm_completion/__init__.py
new file mode 100644
index 00000000000..3f2b88bfaa3
--- /dev/null
+++ b/litellm/a2a_protocol/providers/litellm_completion/__init__.py
@@ -0,0 +1,6 @@
+"""
+LiteLLM Completion bridge provider for A2A protocol.
+
+Routes A2A requests through litellm.acompletion based on custom_llm_provider.
+"""
+
diff --git a/litellm/a2a_protocol/providers/litellm_completion/handler.py b/litellm/a2a_protocol/providers/litellm_completion/handler.py
new file mode 100644
index 00000000000..57388a5d0ed
--- /dev/null
+++ b/litellm/a2a_protocol/providers/litellm_completion/handler.py
@@ -0,0 +1,295 @@
+"""
+Handler for A2A to LiteLLM completion bridge.
+
+Routes A2A requests through litellm.acompletion based on custom_llm_provider.
+
+A2A Streaming Events (in order):
+1. Task event (kind: "task") - Initial task creation with status "submitted"
+2. Status update (kind: "status-update") - Status change to "working"
+3. Artifact update (kind: "artifact-update") - Content/artifact delivery
+4. Status update (kind: "status-update") - Final status "completed" with final=true
+"""
+
+from typing import Any, AsyncIterator, Dict, Optional
+
+import litellm
+from litellm._logging import verbose_logger
+from litellm.a2a_protocol.litellm_completion_bridge.pydantic_ai_transformation import (
+ PydanticAITransformation,
+)
+from litellm.a2a_protocol.litellm_completion_bridge.transformation import (
+ A2ACompletionBridgeTransformation,
+ A2AStreamingContext,
+)
+
+
+class A2ACompletionBridgeHandler:
+ """
+ Static methods for handling A2A requests via LiteLLM completion.
+ """
+
+ @staticmethod
+ async def handle_non_streaming(
+ request_id: str,
+ params: Dict[str, Any],
+ litellm_params: Dict[str, Any],
+ api_base: Optional[str] = None,
+ ) -> Dict[str, Any]:
+ """
+ Handle non-streaming A2A request via litellm.acompletion.
+
+ Args:
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ litellm_params: Agent's litellm_params (custom_llm_provider, model, etc.)
+ api_base: API base URL from agent_card_params
+
+ Returns:
+ A2A SendMessageResponse dict
+ """
+ # Check if this is a Pydantic AI agent request
+ custom_llm_provider = litellm_params.get("custom_llm_provider")
+ if custom_llm_provider == "pydantic_ai_agents":
+ if api_base is None:
+ raise ValueError("api_base is required for Pydantic AI agents")
+
+ verbose_logger.info(
+ f"Pydantic AI: Routing to Pydantic AI agent at {api_base}"
+ )
+
+ # Send request directly to Pydantic AI agent
+ response_data = await PydanticAITransformation.send_non_streaming_request(
+ api_base=api_base,
+ request_id=request_id,
+ params=params,
+ )
+
+ return response_data
+
+ # Extract message from params
+ message = params.get("message", {})
+
+ # Transform A2A message to OpenAI format
+ openai_messages = A2ACompletionBridgeTransformation.a2a_message_to_openai_messages(
+ message
+ )
+
+ # Get completion params
+ custom_llm_provider = litellm_params.get("custom_llm_provider")
+ model = litellm_params.get("model", "agent")
+
+ # Build full model string if provider specified
+ # Skip prepending if model already starts with the provider prefix
+ if custom_llm_provider and not model.startswith(f"{custom_llm_provider}/"):
+ full_model = f"{custom_llm_provider}/{model}"
+ else:
+ full_model = model
+
+ verbose_logger.info(
+ f"A2A completion bridge: model={full_model}, api_base={api_base}"
+ )
+
+ # Build completion params dict
+ completion_params = {
+ "model": full_model,
+ "messages": openai_messages,
+ "api_base": api_base,
+ "stream": False,
+ }
+ # Add litellm_params (contains api_key, client_id, client_secret, tenant_id, etc.)
+ litellm_params_to_add = {
+ k: v for k, v in litellm_params.items()
+ if k not in ("model", "custom_llm_provider")
+ }
+ completion_params.update(litellm_params_to_add)
+
+ # Call litellm.acompletion
+ response = await litellm.acompletion(**completion_params)
+
+ # Transform response to A2A format
+ a2a_response = A2ACompletionBridgeTransformation.openai_response_to_a2a_response(
+ response=response,
+ request_id=request_id,
+ )
+
+ verbose_logger.info(f"A2A completion bridge completed: request_id={request_id}")
+
+ return a2a_response
+
+ @staticmethod
+ async def handle_streaming(
+ request_id: str,
+ params: Dict[str, Any],
+ litellm_params: Dict[str, Any],
+ api_base: Optional[str] = None,
+ ) -> AsyncIterator[Dict[str, Any]]:
+ """
+ Handle streaming A2A request via litellm.acompletion with stream=True.
+
+ Emits proper A2A streaming events:
+ 1. Task event (kind: "task") - Initial task with status "submitted"
+ 2. Status update (kind: "status-update") - Status "working"
+ 3. Artifact update (kind: "artifact-update") - Content delivery
+ 4. Status update (kind: "status-update") - Final "completed" status
+
+ Args:
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ litellm_params: Agent's litellm_params (custom_llm_provider, model, etc.)
+ api_base: API base URL from agent_card_params
+
+ Yields:
+ A2A streaming response events
+ """
+ # Check if this is a Pydantic AI agent request
+ custom_llm_provider = litellm_params.get("custom_llm_provider")
+ if custom_llm_provider == "pydantic_ai_agents":
+ if api_base is None:
+ raise ValueError("api_base is required for Pydantic AI agents")
+
+ verbose_logger.info(
+ f"Pydantic AI: Faking streaming for Pydantic AI agent at {api_base}"
+ )
+
+ # Get non-streaming response first
+ response_data = await PydanticAITransformation.send_non_streaming_request(
+ api_base=api_base,
+ request_id=request_id,
+ params=params,
+ )
+
+ # Convert to fake streaming
+ async for chunk in PydanticAITransformation.fake_streaming_from_response(
+ response_data=response_data,
+ request_id=request_id,
+ ):
+ yield chunk
+
+ return
+
+ # Extract message from params
+ message = params.get("message", {})
+
+ # Create streaming context
+ ctx = A2AStreamingContext(
+ request_id=request_id,
+ input_message=message,
+ )
+
+ # Transform A2A message to OpenAI format
+ openai_messages = A2ACompletionBridgeTransformation.a2a_message_to_openai_messages(
+ message
+ )
+
+ # Get completion params
+ custom_llm_provider = litellm_params.get("custom_llm_provider")
+ model = litellm_params.get("model", "agent")
+
+ # Build full model string if provider specified
+ # Skip prepending if model already starts with the provider prefix
+ if custom_llm_provider and not model.startswith(f"{custom_llm_provider}/"):
+ full_model = f"{custom_llm_provider}/{model}"
+ else:
+ full_model = model
+
+ verbose_logger.info(
+ f"A2A completion bridge streaming: model={full_model}, api_base={api_base}"
+ )
+
+ # Build completion params dict
+ completion_params = {
+ "model": full_model,
+ "messages": openai_messages,
+ "api_base": api_base,
+ "stream": True,
+ }
+ # Add litellm_params (contains api_key, client_id, client_secret, tenant_id, etc.)
+ litellm_params_to_add = {
+ k: v for k, v in litellm_params.items()
+ if k not in ("model", "custom_llm_provider")
+ }
+ completion_params.update(litellm_params_to_add)
+
+ # 1. Emit initial task event (kind: "task", status: "submitted")
+ task_event = A2ACompletionBridgeTransformation.create_task_event(ctx)
+ yield task_event
+
+ # 2. Emit status update (kind: "status-update", status: "working")
+ working_event = A2ACompletionBridgeTransformation.create_status_update_event(
+ ctx=ctx,
+ state="working",
+ final=False,
+ message_text="Processing request...",
+ )
+ yield working_event
+
+ # Call litellm.acompletion with streaming
+ response = await litellm.acompletion(**completion_params)
+
+ # 3. Accumulate content and emit artifact update
+ accumulated_text = ""
+ chunk_count = 0
+ async for chunk in response: # type: ignore[union-attr]
+ chunk_count += 1
+
+ # Extract delta content
+ content = ""
+ if chunk is not None and hasattr(chunk, "choices") and chunk.choices:
+ choice = chunk.choices[0]
+ if hasattr(choice, "delta") and choice.delta:
+ content = choice.delta.content or ""
+
+ if content:
+ accumulated_text += content
+
+ # Emit artifact update with accumulated content
+ if accumulated_text:
+ artifact_event = A2ACompletionBridgeTransformation.create_artifact_update_event(
+ ctx=ctx,
+ text=accumulated_text,
+ )
+ yield artifact_event
+
+ # 4. Emit final status update (kind: "status-update", status: "completed", final: true)
+ completed_event = A2ACompletionBridgeTransformation.create_status_update_event(
+ ctx=ctx,
+ state="completed",
+ final=True,
+ )
+ yield completed_event
+
+ verbose_logger.info(
+ f"A2A completion bridge streaming completed: request_id={request_id}, chunks={chunk_count}"
+ )
+
+
+# Convenience functions that delegate to the class methods
+async def handle_a2a_completion(
+ request_id: str,
+ params: Dict[str, Any],
+ litellm_params: Dict[str, Any],
+ api_base: Optional[str] = None,
+) -> Dict[str, Any]:
+ """Convenience function for non-streaming A2A completion."""
+ return await A2ACompletionBridgeHandler.handle_non_streaming(
+ request_id=request_id,
+ params=params,
+ litellm_params=litellm_params,
+ api_base=api_base,
+ )
+
+
+async def handle_a2a_completion_streaming(
+ request_id: str,
+ params: Dict[str, Any],
+ litellm_params: Dict[str, Any],
+ api_base: Optional[str] = None,
+) -> AsyncIterator[Dict[str, Any]]:
+ """Convenience function for streaming A2A completion."""
+ async for chunk in A2ACompletionBridgeHandler.handle_streaming(
+ request_id=request_id,
+ params=params,
+ litellm_params=litellm_params,
+ api_base=api_base,
+ ):
+ yield chunk
diff --git a/litellm/a2a_protocol/providers/litellm_completion/transformation.py b/litellm/a2a_protocol/providers/litellm_completion/transformation.py
new file mode 100644
index 00000000000..bbe7daa9fc4
--- /dev/null
+++ b/litellm/a2a_protocol/providers/litellm_completion/transformation.py
@@ -0,0 +1,286 @@
+"""
+Transformation utilities for A2A <-> OpenAI message format conversion.
+
+A2A Message Format:
+{
+ "role": "user",
+ "parts": [{"kind": "text", "text": "Hello!"}],
+ "messageId": "abc123"
+}
+
+OpenAI Message Format:
+{"role": "user", "content": "Hello!"}
+
+A2A Streaming Events:
+- Task event (kind: "task") - Initial task creation with status "submitted"
+- Status update (kind: "status-update") - Status changes (working, completed)
+- Artifact update (kind: "artifact-update") - Content/artifact delivery
+"""
+
+from datetime import datetime, timezone
+from typing import Any, Dict, List, Optional
+from uuid import uuid4
+
+from litellm._logging import verbose_logger
+
+
+class A2AStreamingContext:
+ """
+ Context holder for A2A streaming state.
+ Tracks task_id, context_id, and message accumulation.
+ """
+
+ def __init__(self, request_id: str, input_message: Dict[str, Any]):
+ self.request_id = request_id
+ self.task_id = str(uuid4())
+ self.context_id = str(uuid4())
+ self.input_message = input_message
+ self.accumulated_text = ""
+ self.has_emitted_task = False
+ self.has_emitted_working = False
+
+
+class A2ACompletionBridgeTransformation:
+ """
+ Static methods for transforming between A2A and OpenAI message formats.
+ """
+
+ @staticmethod
+ def a2a_message_to_openai_messages(
+ a2a_message: Dict[str, Any],
+ ) -> List[Dict[str, str]]:
+ """
+ Transform an A2A message to OpenAI message format.
+
+ Args:
+ a2a_message: A2A message with role, parts, and messageId
+
+ Returns:
+ List of OpenAI-format messages
+ """
+ role = a2a_message.get("role", "user")
+ parts = a2a_message.get("parts", [])
+
+ # Map A2A roles to OpenAI roles
+ openai_role = role
+ if role == "user":
+ openai_role = "user"
+ elif role == "assistant":
+ openai_role = "assistant"
+ elif role == "system":
+ openai_role = "system"
+
+ # Extract text content from parts
+ content_parts = []
+ for part in parts:
+ kind = part.get("kind", "")
+ if kind == "text":
+ text = part.get("text", "")
+ content_parts.append(text)
+
+ content = "\n".join(content_parts) if content_parts else ""
+
+ verbose_logger.debug(
+ f"A2A -> OpenAI transform: role={role} -> {openai_role}, content_length={len(content)}"
+ )
+
+ return [{"role": openai_role, "content": content}]
+
+ @staticmethod
+ def openai_response_to_a2a_response(
+ response: Any,
+ request_id: Optional[str] = None,
+ ) -> Dict[str, Any]:
+ """
+ Transform a LiteLLM ModelResponse to A2A SendMessageResponse format.
+
+ Args:
+ response: LiteLLM ModelResponse object
+ request_id: Original A2A request ID
+
+ Returns:
+ A2A SendMessageResponse dict
+ """
+ # Extract content from response
+ content = ""
+ if hasattr(response, "choices") and response.choices:
+ choice = response.choices[0]
+ if hasattr(choice, "message") and choice.message:
+ content = choice.message.content or ""
+
+ # Build A2A message
+ a2a_message = {
+ "role": "agent",
+ "parts": [{"kind": "text", "text": content}],
+ "messageId": uuid4().hex,
+ }
+
+ # Build A2A response
+ a2a_response = {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "result": {
+ "message": a2a_message,
+ },
+ }
+
+ verbose_logger.debug(
+ f"OpenAI -> A2A transform: content_length={len(content)}"
+ )
+
+ return a2a_response
+
+ @staticmethod
+ def _get_timestamp() -> str:
+ """Get current timestamp in ISO format with timezone."""
+ return datetime.now(timezone.utc).isoformat()
+
+ @staticmethod
+ def create_task_event(
+ ctx: A2AStreamingContext,
+ ) -> Dict[str, Any]:
+ """
+ Create the initial task event with status 'submitted'.
+
+ This is the first event emitted in an A2A streaming response.
+ """
+ return {
+ "id": ctx.request_id,
+ "jsonrpc": "2.0",
+ "result": {
+ "contextId": ctx.context_id,
+ "history": [
+ {
+ "contextId": ctx.context_id,
+ "kind": "message",
+ "messageId": ctx.input_message.get("messageId", uuid4().hex),
+ "parts": ctx.input_message.get("parts", []),
+ "role": ctx.input_message.get("role", "user"),
+ "taskId": ctx.task_id,
+ }
+ ],
+ "id": ctx.task_id,
+ "kind": "task",
+ "status": {
+ "state": "submitted",
+ },
+ },
+ }
+
+ @staticmethod
+ def create_status_update_event(
+ ctx: A2AStreamingContext,
+ state: str,
+ final: bool = False,
+ message_text: Optional[str] = None,
+ ) -> Dict[str, Any]:
+ """
+ Create a status update event.
+
+ Args:
+ ctx: Streaming context
+ state: Status state ('working', 'completed')
+ final: Whether this is the final event
+ message_text: Optional message text for 'working' status
+ """
+ status: Dict[str, Any] = {
+ "state": state,
+ "timestamp": A2ACompletionBridgeTransformation._get_timestamp(),
+ }
+
+ # Add message for 'working' status
+ if state == "working" and message_text:
+ status["message"] = {
+ "contextId": ctx.context_id,
+ "kind": "message",
+ "messageId": str(uuid4()),
+ "parts": [{"kind": "text", "text": message_text}],
+ "role": "agent",
+ "taskId": ctx.task_id,
+ }
+
+ return {
+ "id": ctx.request_id,
+ "jsonrpc": "2.0",
+ "result": {
+ "contextId": ctx.context_id,
+ "final": final,
+ "kind": "status-update",
+ "status": status,
+ "taskId": ctx.task_id,
+ },
+ }
+
+ @staticmethod
+ def create_artifact_update_event(
+ ctx: A2AStreamingContext,
+ text: str,
+ ) -> Dict[str, Any]:
+ """
+ Create an artifact update event with content.
+
+ Args:
+ ctx: Streaming context
+ text: The text content for the artifact
+ """
+ return {
+ "id": ctx.request_id,
+ "jsonrpc": "2.0",
+ "result": {
+ "artifact": {
+ "artifactId": str(uuid4()),
+ "name": "response",
+ "parts": [{"kind": "text", "text": text}],
+ },
+ "contextId": ctx.context_id,
+ "kind": "artifact-update",
+ "taskId": ctx.task_id,
+ },
+ }
+
+ @staticmethod
+ def openai_chunk_to_a2a_chunk(
+ chunk: Any,
+ request_id: Optional[str] = None,
+ is_final: bool = False,
+ ) -> Optional[Dict[str, Any]]:
+ """
+ Transform a LiteLLM streaming chunk to A2A streaming format.
+
+ NOTE: This method is deprecated for streaming. Use the event-based
+ methods (create_task_event, create_status_update_event,
+ create_artifact_update_event) instead for proper A2A streaming.
+
+ Args:
+ chunk: LiteLLM ModelResponse chunk
+ request_id: Original A2A request ID
+ is_final: Whether this is the final chunk
+
+ Returns:
+ A2A streaming chunk dict or None if no content
+ """
+ # Extract delta content
+ content = ""
+ if chunk is not None and hasattr(chunk, "choices") and chunk.choices:
+ choice = chunk.choices[0]
+ if hasattr(choice, "delta") and choice.delta:
+ content = choice.delta.content or ""
+
+ if not content and not is_final:
+ return None
+
+ # Build A2A streaming chunk (legacy format)
+ a2a_chunk = {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "result": {
+ "message": {
+ "role": "agent",
+ "parts": [{"kind": "text", "text": content}],
+ "messageId": uuid4().hex,
+ },
+ "final": is_final,
+ },
+ }
+
+ return a2a_chunk
diff --git a/litellm/a2a_protocol/providers/pydantic_ai_agents/__init__.py b/litellm/a2a_protocol/providers/pydantic_ai_agents/__init__.py
new file mode 100644
index 00000000000..2187400b2d1
--- /dev/null
+++ b/litellm/a2a_protocol/providers/pydantic_ai_agents/__init__.py
@@ -0,0 +1,17 @@
+"""
+Pydantic AI agent provider for A2A protocol.
+
+Pydantic AI agents follow A2A protocol but don't support streaming natively.
+This provider handles fake streaming by converting non-streaming responses into streaming chunks.
+"""
+
+from litellm.a2a_protocol.providers.pydantic_ai_agents.config import (
+ PydanticAIProviderConfig,
+)
+from litellm.a2a_protocol.providers.pydantic_ai_agents.handler import PydanticAIHandler
+from litellm.a2a_protocol.providers.pydantic_ai_agents.transformation import (
+ PydanticAITransformation,
+)
+
+__all__ = ["PydanticAIHandler", "PydanticAITransformation", "PydanticAIProviderConfig"]
+
diff --git a/litellm/a2a_protocol/providers/pydantic_ai_agents/config.py b/litellm/a2a_protocol/providers/pydantic_ai_agents/config.py
new file mode 100644
index 00000000000..acf09554e5e
--- /dev/null
+++ b/litellm/a2a_protocol/providers/pydantic_ai_agents/config.py
@@ -0,0 +1,51 @@
+"""
+Pydantic AI provider configuration.
+"""
+
+from typing import Any, AsyncIterator, Dict
+
+from litellm.a2a_protocol.providers.base import BaseA2AProviderConfig
+from litellm.a2a_protocol.providers.pydantic_ai_agents.handler import PydanticAIHandler
+
+
+class PydanticAIProviderConfig(BaseA2AProviderConfig):
+ """
+ Provider configuration for Pydantic AI agents.
+
+ Pydantic AI agents follow A2A protocol but don't support streaming natively.
+ This config provides fake streaming by converting non-streaming responses into streaming chunks.
+ """
+
+ async def handle_non_streaming(
+ self,
+ request_id: str,
+ params: Dict[str, Any],
+ api_base: str,
+ **kwargs,
+ ) -> Dict[str, Any]:
+ """Handle non-streaming request to Pydantic AI agent."""
+ return await PydanticAIHandler.handle_non_streaming(
+ request_id=request_id,
+ params=params,
+ api_base=api_base,
+ timeout=kwargs.get("timeout", 60.0),
+ )
+
+ async def handle_streaming(
+ self,
+ request_id: str,
+ params: Dict[str, Any],
+ api_base: str,
+ **kwargs,
+ ) -> AsyncIterator[Dict[str, Any]]:
+ """Handle streaming request with fake streaming."""
+ async for chunk in PydanticAIHandler.handle_streaming(
+ request_id=request_id,
+ params=params,
+ api_base=api_base,
+ timeout=kwargs.get("timeout", 60.0),
+ chunk_size=kwargs.get("chunk_size", 50),
+ delay_ms=kwargs.get("delay_ms", 10),
+ ):
+ yield chunk
+
diff --git a/litellm/a2a_protocol/providers/pydantic_ai_agents/handler.py b/litellm/a2a_protocol/providers/pydantic_ai_agents/handler.py
new file mode 100644
index 00000000000..6680a9fe487
--- /dev/null
+++ b/litellm/a2a_protocol/providers/pydantic_ai_agents/handler.py
@@ -0,0 +1,106 @@
+"""
+Handler for Pydantic AI agents.
+
+Pydantic AI agents follow A2A protocol but don't support streaming natively.
+This handler provides fake streaming by converting non-streaming responses into streaming chunks.
+"""
+
+from typing import Any, AsyncIterator, Dict
+
+from litellm._logging import verbose_logger
+from litellm.a2a_protocol.providers.pydantic_ai_agents.transformation import (
+ PydanticAITransformation,
+)
+
+
+class PydanticAIHandler:
+ """
+ Handler for Pydantic AI agent requests.
+
+ Provides:
+ - Direct non-streaming requests to Pydantic AI agents
+ - Fake streaming by converting non-streaming responses into streaming chunks
+ """
+
+ @staticmethod
+ async def handle_non_streaming(
+ request_id: str,
+ params: Dict[str, Any],
+ api_base: str,
+ timeout: float = 60.0,
+ ) -> Dict[str, Any]:
+ """
+ Handle non-streaming request to Pydantic AI agent.
+
+ Args:
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ api_base: Base URL of the Pydantic AI agent
+ timeout: Request timeout in seconds
+
+ Returns:
+ A2A SendMessageResponse dict
+ """
+ verbose_logger.info(
+ f"Pydantic AI: Routing to Pydantic AI agent at {api_base}"
+ )
+
+ # Send request directly to Pydantic AI agent
+ response_data = await PydanticAITransformation.send_non_streaming_request(
+ api_base=api_base,
+ request_id=request_id,
+ params=params,
+ timeout=timeout,
+ )
+
+ return response_data
+
+ @staticmethod
+ async def handle_streaming(
+ request_id: str,
+ params: Dict[str, Any],
+ api_base: str,
+ timeout: float = 60.0,
+ chunk_size: int = 50,
+ delay_ms: int = 10,
+ ) -> AsyncIterator[Dict[str, Any]]:
+ """
+ Handle streaming request to Pydantic AI agent with fake streaming.
+
+ Since Pydantic AI agents don't support streaming natively, this method:
+ 1. Makes a non-streaming request
+ 2. Converts the response into streaming chunks
+
+ Args:
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ api_base: Base URL of the Pydantic AI agent
+ timeout: Request timeout in seconds
+ chunk_size: Number of characters per chunk
+ delay_ms: Delay between chunks in milliseconds
+
+ Yields:
+ A2A streaming response events
+ """
+ verbose_logger.info(
+ f"Pydantic AI: Faking streaming for Pydantic AI agent at {api_base}"
+ )
+
+ # Get raw task response first (not the transformed A2A format)
+ raw_response = await PydanticAITransformation.send_and_get_raw_response(
+ api_base=api_base,
+ request_id=request_id,
+ params=params,
+ timeout=timeout,
+ )
+
+ # Convert raw task response to fake streaming chunks
+ async for chunk in PydanticAITransformation.fake_streaming_from_response(
+ response_data=raw_response,
+ request_id=request_id,
+ chunk_size=chunk_size,
+ delay_ms=delay_ms,
+ ):
+ yield chunk
+
+
diff --git a/litellm/a2a_protocol/providers/pydantic_ai_agents/transformation.py b/litellm/a2a_protocol/providers/pydantic_ai_agents/transformation.py
new file mode 100644
index 00000000000..67c2154f6c9
--- /dev/null
+++ b/litellm/a2a_protocol/providers/pydantic_ai_agents/transformation.py
@@ -0,0 +1,523 @@
+"""
+Transformation layer for Pydantic AI agents.
+
+Pydantic AI agents follow A2A protocol but don't support streaming.
+This module provides fake streaming by converting non-streaming responses into streaming chunks.
+"""
+
+import asyncio
+from typing import Any, AsyncIterator, Dict, Optional
+from uuid import uuid4
+
+import httpx
+
+from litellm._logging import verbose_logger
+
+
+class PydanticAITransformation:
+ """
+ Transformation layer for Pydantic AI agents.
+
+ Handles:
+ - Direct A2A requests to Pydantic AI endpoints
+ - Polling for task completion (since Pydantic AI doesn't support streaming)
+ - Fake streaming by chunking non-streaming responses
+ """
+
+ @staticmethod
+ def _remove_none_values(obj: Any) -> Any:
+ """
+ Recursively remove None values from a dict/list structure.
+
+ FastA2A/Pydantic AI servers don't accept None values for optional fields -
+ they expect those fields to be omitted entirely.
+
+ Args:
+ obj: Dict, list, or other value to clean
+
+ Returns:
+ Cleaned object with None values removed
+ """
+ if isinstance(obj, dict):
+ return {
+ k: PydanticAITransformation._remove_none_values(v)
+ for k, v in obj.items()
+ if v is not None
+ }
+ elif isinstance(obj, list):
+ return [
+ PydanticAITransformation._remove_none_values(item)
+ for item in obj
+ if item is not None
+ ]
+ else:
+ return obj
+
+ @staticmethod
+ def _params_to_dict(params: Any) -> Dict[str, Any]:
+ """
+ Convert params to a dict, handling Pydantic models.
+
+ Args:
+ params: Dict or Pydantic model
+
+ Returns:
+ Dict representation of params
+ """
+ if hasattr(params, "model_dump"):
+ # Pydantic v2 model
+ return params.model_dump(mode="python", exclude_none=True)
+ elif hasattr(params, "dict"):
+ # Pydantic v1 model
+ return params.dict(exclude_none=True)
+ elif isinstance(params, dict):
+ return params
+ else:
+ # Try to convert to dict
+ return dict(params)
+
+ @staticmethod
+ async def _poll_for_completion(
+ client: httpx.AsyncClient,
+ endpoint: str,
+ task_id: str,
+ request_id: str,
+ max_attempts: int = 30,
+ poll_interval: float = 0.5,
+ ) -> Dict[str, Any]:
+ """
+ Poll for task completion using tasks/get method.
+
+ Args:
+ client: HTTPX async client
+ endpoint: API endpoint URL
+ task_id: Task ID to poll for
+ request_id: JSON-RPC request ID
+ max_attempts: Maximum polling attempts
+ poll_interval: Seconds between poll attempts
+
+ Returns:
+ Completed task response
+ """
+ for attempt in range(max_attempts):
+ poll_request = {
+ "jsonrpc": "2.0",
+ "id": f"{request_id}-poll-{attempt}",
+ "method": "tasks/get",
+ "params": {"id": task_id},
+ }
+
+ response = await client.post(
+ endpoint,
+ json=poll_request,
+ headers={"Content-Type": "application/json"},
+ )
+ response.raise_for_status()
+ poll_data = response.json()
+
+ result = poll_data.get("result", {})
+ status = result.get("status", {})
+ state = status.get("state", "")
+
+ verbose_logger.debug(
+ f"Pydantic AI: Poll attempt {attempt + 1}/{max_attempts}, state={state}"
+ )
+
+ if state == "completed":
+ return poll_data
+ elif state in ("failed", "canceled"):
+ raise Exception(f"Task {task_id} ended with state: {state}")
+
+ await asyncio.sleep(poll_interval)
+
+ raise TimeoutError(f"Task {task_id} did not complete within {max_attempts * poll_interval} seconds")
+
+ @staticmethod
+ async def _send_and_poll_raw(
+ api_base: str,
+ request_id: str,
+ params: Any,
+ timeout: float = 60.0,
+ ) -> Dict[str, Any]:
+ """
+ Send a request to Pydantic AI agent and return the raw task response.
+
+ This is an internal method used by both non-streaming and streaming handlers.
+ Returns the raw Pydantic AI task format with history/artifacts.
+
+ Args:
+ api_base: Base URL of the Pydantic AI agent
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ timeout: Request timeout in seconds
+
+ Returns:
+ Raw Pydantic AI task response (with history/artifacts)
+ """
+ # Convert params to dict if it's a Pydantic model
+ params_dict = PydanticAITransformation._params_to_dict(params)
+
+ # Remove None values - FastA2A doesn't accept null for optional fields
+ params_dict = PydanticAITransformation._remove_none_values(params_dict)
+
+ # Ensure the message has 'kind': 'message' as required by FastA2A/Pydantic AI
+ if "message" in params_dict:
+ params_dict["message"]["kind"] = "message"
+
+ # Build A2A JSON-RPC request using message/send method for FastA2A compatibility
+ a2a_request = {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "method": "message/send",
+ "params": params_dict,
+ }
+
+ # FastA2A uses root endpoint (/) not /messages
+ endpoint = api_base.rstrip("/")
+
+ verbose_logger.info(
+ f"Pydantic AI: Sending non-streaming request to {endpoint}"
+ )
+
+ # Send request to Pydantic AI agent
+ async with httpx.AsyncClient(timeout=timeout) as client:
+ response = await client.post(
+ endpoint,
+ json=a2a_request,
+ headers={"Content-Type": "application/json"},
+ )
+ response.raise_for_status()
+ response_data = response.json()
+
+ # Check if task is already completed
+ result = response_data.get("result", {})
+ status = result.get("status", {})
+ state = status.get("state", "")
+
+ if state != "completed":
+ # Need to poll for completion
+ task_id = result.get("id")
+ if task_id:
+ verbose_logger.info(
+ f"Pydantic AI: Task {task_id} submitted, polling for completion..."
+ )
+ response_data = await PydanticAITransformation._poll_for_completion(
+ client=client,
+ endpoint=endpoint,
+ task_id=task_id,
+ request_id=request_id,
+ )
+
+ verbose_logger.info(f"Pydantic AI: Received completed response for request_id={request_id}")
+
+ return response_data
+
+ @staticmethod
+ async def send_non_streaming_request(
+ api_base: str,
+ request_id: str,
+ params: Any,
+ timeout: float = 60.0,
+ ) -> Dict[str, Any]:
+ """
+ Send a non-streaming A2A request to Pydantic AI agent and wait for completion.
+
+ Args:
+ api_base: Base URL of the Pydantic AI agent (e.g., "http://localhost:9999")
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message (dict or Pydantic model)
+ timeout: Request timeout in seconds
+
+ Returns:
+ Standard A2A non-streaming response format with message
+ """
+ # Get raw task response
+ raw_response = await PydanticAITransformation._send_and_poll_raw(
+ api_base=api_base,
+ request_id=request_id,
+ params=params,
+ timeout=timeout,
+ )
+
+ # Transform to standard A2A non-streaming format
+ return PydanticAITransformation._transform_to_a2a_response(
+ response_data=raw_response,
+ request_id=request_id,
+ )
+
+ @staticmethod
+ async def send_and_get_raw_response(
+ api_base: str,
+ request_id: str,
+ params: Any,
+ timeout: float = 60.0,
+ ) -> Dict[str, Any]:
+ """
+ Send a request to Pydantic AI agent and return the raw task response.
+
+ Used by streaming handler to get raw response for fake streaming.
+
+ Args:
+ api_base: Base URL of the Pydantic AI agent
+ request_id: A2A JSON-RPC request ID
+ params: A2A MessageSendParams containing the message
+ timeout: Request timeout in seconds
+
+ Returns:
+ Raw Pydantic AI task response (with history/artifacts)
+ """
+ return await PydanticAITransformation._send_and_poll_raw(
+ api_base=api_base,
+ request_id=request_id,
+ params=params,
+ timeout=timeout,
+ )
+
+ @staticmethod
+ def _transform_to_a2a_response(
+ response_data: Dict[str, Any],
+ request_id: str,
+ ) -> Dict[str, Any]:
+ """
+ Transform Pydantic AI task response to standard A2A non-streaming format.
+
+ Pydantic AI returns a task with history/artifacts, but the standard A2A
+ non-streaming format expects:
+ {
+ "jsonrpc": "2.0",
+ "id": "...",
+ "result": {
+ "message": {
+ "role": "agent",
+ "parts": [{"kind": "text", "text": "..."}],
+ "messageId": "..."
+ }
+ }
+ }
+
+ Args:
+ response_data: Pydantic AI task response
+ request_id: Original request ID
+
+ Returns:
+ Standard A2A non-streaming response format
+ """
+ # Extract the agent response text
+ full_text, message_id, parts = PydanticAITransformation._extract_response_text(
+ response_data
+ )
+
+ # Build standard A2A message
+ a2a_message = {
+ "role": "agent",
+ "parts": parts if parts else [{"kind": "text", "text": full_text}],
+ "messageId": message_id,
+ }
+
+ # Return standard A2A non-streaming format
+ return {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "result": {
+ "message": a2a_message,
+ },
+ }
+
+ @staticmethod
+ def _extract_response_text(response_data: Dict[str, Any]) -> tuple[str, str, list]:
+ """
+ Extract response text from completed task response.
+
+ Pydantic AI returns completed tasks with:
+ - history: list of messages (user and agent)
+ - artifacts: list of result artifacts
+
+ Args:
+ response_data: Completed task response
+
+ Returns:
+ Tuple of (full_text, message_id, parts)
+ """
+ result = response_data.get("result", {})
+
+ # Try to extract from artifacts first (preferred for results)
+ artifacts = result.get("artifacts", [])
+ if artifacts:
+ for artifact in artifacts:
+ parts = artifact.get("parts", [])
+ for part in parts:
+ if part.get("kind") == "text":
+ text = part.get("text", "")
+ if text:
+ return text, str(uuid4()), parts
+
+ # Fall back to history - get the last agent message
+ history = result.get("history", [])
+ for msg in reversed(history):
+ if msg.get("role") == "agent":
+ parts = msg.get("parts", [])
+ message_id = msg.get("messageId", str(uuid4()))
+ full_text = ""
+ for part in parts:
+ if part.get("kind") == "text":
+ full_text += part.get("text", "")
+ if full_text:
+ return full_text, message_id, parts
+
+ # Fall back to message field (original format)
+ message = result.get("message", {})
+ if message:
+ parts = message.get("parts", [])
+ message_id = message.get("messageId", str(uuid4()))
+ full_text = ""
+ for part in parts:
+ if part.get("kind") == "text":
+ full_text += part.get("text", "")
+ return full_text, message_id, parts
+
+ return "", str(uuid4()), []
+
+ @staticmethod
+ async def fake_streaming_from_response(
+ response_data: Dict[str, Any],
+ request_id: str,
+ chunk_size: int = 50,
+ delay_ms: int = 10,
+ ) -> AsyncIterator[Dict[str, Any]]:
+ """
+ Convert a non-streaming A2A response into fake streaming chunks.
+
+ Emits proper A2A streaming events:
+ 1. Task event (kind: "task") - Initial task with status "submitted"
+ 2. Status update (kind: "status-update") - Status "working"
+ 3. Artifact update chunks (kind: "artifact-update") - Content delivery in chunks
+ 4. Status update (kind: "status-update") - Final "completed" status
+
+ Args:
+ response_data: Non-streaming A2A response dict (completed task)
+ request_id: A2A JSON-RPC request ID
+ chunk_size: Number of characters per chunk (default: 50)
+ delay_ms: Delay between chunks in milliseconds (default: 10)
+
+ Yields:
+ A2A streaming response events
+ """
+ # Extract the response text from completed task
+ full_text, message_id, parts = PydanticAITransformation._extract_response_text(
+ response_data
+ )
+
+ # Extract input message from raw response for history
+ result = response_data.get("result", {})
+ history = result.get("history", [])
+ input_message = {}
+ for msg in history:
+ if msg.get("role") == "user":
+ input_message = msg
+ break
+
+ # Generate IDs for streaming events
+ task_id = str(uuid4())
+ context_id = str(uuid4())
+ artifact_id = str(uuid4())
+ input_message_id = input_message.get("messageId", str(uuid4()))
+
+ # 1. Emit initial task event (kind: "task", status: "submitted")
+ # Format matches A2ACompletionBridgeTransformation.create_task_event
+ task_event = {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "result": {
+ "contextId": context_id,
+ "history": [
+ {
+ "contextId": context_id,
+ "kind": "message",
+ "messageId": input_message_id,
+ "parts": input_message.get("parts", [{"kind": "text", "text": ""}]),
+ "role": "user",
+ "taskId": task_id,
+ }
+ ],
+ "id": task_id,
+ "kind": "task",
+ "status": {
+ "state": "submitted",
+ },
+ },
+ }
+ yield task_event
+
+ # 2. Emit status update (kind: "status-update", status: "working")
+ # Format matches A2ACompletionBridgeTransformation.create_status_update_event
+ working_event = {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "result": {
+ "contextId": context_id,
+ "final": False,
+ "kind": "status-update",
+ "status": {
+ "state": "working",
+ },
+ "taskId": task_id,
+ },
+ }
+ yield working_event
+
+ # Small delay to simulate processing
+ await asyncio.sleep(delay_ms / 1000.0)
+
+ # 3. Emit artifact update chunks (kind: "artifact-update")
+ # Format matches A2ACompletionBridgeTransformation.create_artifact_update_event
+ if full_text:
+ # Split text into chunks
+ for i in range(0, len(full_text), chunk_size):
+ chunk_text = full_text[i:i + chunk_size]
+ is_last_chunk = (i + chunk_size) >= len(full_text)
+
+ artifact_event = {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "result": {
+ "contextId": context_id,
+ "kind": "artifact-update",
+ "taskId": task_id,
+ "artifact": {
+ "artifactId": artifact_id,
+ "parts": [
+ {
+ "kind": "text",
+ "text": chunk_text,
+ }
+ ],
+ },
+ },
+ }
+ yield artifact_event
+
+ # Add delay between chunks (except for last chunk)
+ if not is_last_chunk:
+ await asyncio.sleep(delay_ms / 1000.0)
+
+ # 4. Emit final status update (kind: "status-update", status: "completed", final: true)
+ completed_event = {
+ "jsonrpc": "2.0",
+ "id": request_id,
+ "result": {
+ "contextId": context_id,
+ "final": True,
+ "kind": "status-update",
+ "status": {
+ "state": "completed",
+ },
+ "taskId": task_id,
+ },
+ }
+ yield completed_event
+
+ verbose_logger.info(
+ f"Pydantic AI: Fake streaming completed for request_id={request_id}"
+ )
+
+
diff --git a/litellm/proxy/public_endpoints/agent_create_fields.json b/litellm/proxy/public_endpoints/agent_create_fields.json
index 347a58a7675..c559b61a76f 100644
--- a/litellm/proxy/public_endpoints/agent_create_fields.json
+++ b/litellm/proxy/public_endpoints/agent_create_fields.json
@@ -144,6 +144,28 @@
"litellm_params_template": {
"custom_llm_provider": "azure_ai"
}
+ },
+ {
+ "agent_type": "pydantic_ai_agents",
+ "agent_type_display_name": "Pydantic AI",
+ "description": "Connect to Pydantic AI agents via A2A protocol (with fake streaming support)",
+ "logo_url": "/ui/assets/logos/pydantic.svg",
+ "use_a2a_form_fields": true,
+ "credential_fields": [
+ {
+ "key": "api_base",
+ "label": "Agent URL",
+ "placeholder": "http://localhost:9999",
+ "tooltip": "The base URL for your Pydantic AI agent server",
+ "required": true,
+ "field_type": "text",
+ "default_value": "http://localhost:9999",
+ "include_in_litellm_params": true
+ }
+ ],
+ "litellm_params_template": {
+ "custom_llm_provider": "pydantic_ai_agents"
+ }
}
]
diff --git a/tests/agent_tests/test_a2a.py b/tests/agent_tests/test_a2a.py
index eeab2680564..1550d61f7b0 100644
--- a/tests/agent_tests/test_a2a.py
+++ b/tests/agent_tests/test_a2a.py
@@ -21,10 +21,7 @@ from litellm.types.utils import StandardLoggingPayload
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
-
from a2a.types import MessageSendParams, SendMessageRequest
-
-
@pytest.mark.asyncio
async def test_asend_message_with_client_decorator():
"""
@@ -165,3 +162,163 @@ async def test_a2a_logging_payload():
# This confirms the A2A cost calculator is working
assert response_cost is not None, "response_cost should not be None"
assert response_cost == 0.0, f"response_cost should be 0.0 for A2A, got: {response_cost}"
+
+
+async def test_pydantic_ai_non_streaming():
+ """
+ Test non-streaming requests to Pydantic AI agents.
+
+ Pydantic AI agents follow A2A protocol but don't support streaming.
+ This test validates non-streaming requests work correctly.
+ """
+ litellm._turn_on_debug()
+ from litellm.a2a_protocol import asend_message
+
+ # Build the request
+ send_message_payload = {
+ "message": {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Hello from Pydantic AI test!",
+ }
+ ],
+ "messageId": uuid4().hex,
+ },
+ }
+
+ request = SendMessageRequest(
+ id=str(uuid4()),
+ params=MessageSendParams(**send_message_payload),
+ )
+
+ # Send message using Pydantic AI provider
+ response = await asend_message(
+ request=request,
+ api_base="http://localhost:9999",
+ litellm_params={"custom_llm_provider": "pydantic_ai_agents"},
+ )
+
+ # Print response for debugging
+ print("\n=== Pydantic AI Non-Streaming Response ===")
+ print(response.model_dump(mode="json", exclude_none=True))
+
+ # Basic assertions
+ assert response is not None
+ assert hasattr(response, "result")
+
+ # Verify result structure
+ result = response.result
+ assert result is not None
+
+ # Pydantic AI returns a task with history/artifacts, not a direct message
+ # Check for either format
+ result_dict = result if isinstance(result, dict) else result.model_dump(mode="python", exclude_none=True)
+ has_message = "message" in result_dict
+ has_history = "history" in result_dict
+ has_artifacts = "artifacts" in result_dict
+
+ assert has_message or has_history or has_artifacts, (
+ f"Result should contain 'message', 'history', or 'artifacts'. Got: {list(result_dict.keys())}"
+ )
+
+ # If it's a task response (Pydantic AI style), verify we got agent response
+ if has_history:
+ history = result_dict.get("history", [])
+ agent_messages = [m for m in history if m.get("role") == "agent"]
+ assert len(agent_messages) > 0, "Should have at least one agent message in history"
+
+ # Verify agent message has text content
+ agent_msg = agent_messages[-1]
+ parts = agent_msg.get("parts", [])
+ text_parts = [p for p in parts if p.get("kind") == "text"]
+ assert len(text_parts) > 0, "Agent message should have text content"
+ print(f"\nAgent response: {text_parts[0].get('text')}")
+
+
+async def test_pydantic_ai_fake_streaming():
+ """
+ Test fake streaming for Pydantic AI agents.
+
+ Pydantic AI agents don't support streaming natively.
+ This test validates that fake streaming works by converting
+ non-streaming responses into streaming chunks.
+ """
+ litellm._turn_on_debug()
+ from litellm.a2a_protocol import asend_message_streaming
+
+ # Build the request
+ from a2a.types import SendStreamingMessageRequest
+
+ send_message_payload = {
+ "message": {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Hello from Pydantic AI streaming test!",
+ }
+ ],
+ "messageId": uuid4().hex,
+ },
+ }
+
+ request = SendStreamingMessageRequest(
+ id=str(uuid4()),
+ params=MessageSendParams(**send_message_payload),
+ )
+
+ # Send streaming message using Pydantic AI provider
+ print("\n=== Pydantic AI Fake Streaming Response ===")
+ chunks_received = 0
+ task_event_received = False
+ working_event_received = False
+ artifact_event_received = False
+ completed_event_received = False
+
+ async for chunk in asend_message_streaming(
+ request=request,
+ api_base="http://localhost:9999",
+ litellm_params={"custom_llm_provider": "pydantic_ai_agents"},
+ ):
+ chunks_received += 1
+ print(f"\nChunk {chunks_received}:")
+
+ # Convert chunk to dict for inspection
+ chunk_dict = chunk.model_dump(mode="json", exclude_none=True) if hasattr(chunk, "model_dump") else chunk
+ print(json.dumps(chunk_dict, indent=2))
+
+ # Check event types
+ result = chunk_dict.get("result", {})
+ kind = result.get("kind")
+
+ if kind == "task":
+ task_event_received = True
+ elif kind == "status-update":
+ status = result.get("status", {})
+ state = status.get("state")
+ if state == "working":
+ working_event_received = True
+ elif state == "completed":
+ completed_event_received = True
+ elif kind == "artifact-update":
+ artifact_event_received = True
+
+ print(f"\n=== Streaming Summary ===")
+ print(f"Total chunks received: {chunks_received}")
+ print(f"Task event received: {task_event_received}")
+ print(f"Working event received: {working_event_received}")
+ print(f"Artifact event received: {artifact_event_received}")
+ print(f"Completed event received: {completed_event_received}")
+
+ # Verify we received chunks
+ assert chunks_received > 0, "Should receive at least one chunk"
+
+ # Verify all required event types were received
+ assert task_event_received, "Should receive task event"
+ assert working_event_received, "Should receive working status event"
+ assert artifact_event_received, "Should receive artifact update event"
+ assert completed_event_received, "Should receive completed status event"
diff --git a/tests/litellm/a2a_protocol/providers/pydantic_ai_agents/test_pydantic_ai_agent_transformation.py b/tests/litellm/a2a_protocol/providers/pydantic_ai_agents/test_pydantic_ai_agent_transformation.py
new file mode 100644
index 00000000000..7b10c46c2fd
--- /dev/null
+++ b/tests/litellm/a2a_protocol/providers/pydantic_ai_agents/test_pydantic_ai_agent_transformation.py
@@ -0,0 +1,99 @@
+"""
+Tests for Pydantic AI agents transformation.
+
+Tests the helper functions and response transformation without making real API calls.
+"""
+
+import os
+import sys
+
+import pytest
+
+sys.path.insert(0, os.path.abspath("../../../../.."))
+
+from litellm.a2a_protocol.providers.pydantic_ai_agents.transformation import (
+ PydanticAITransformation,
+)
+
+
+class TestPydanticAITransformation:
+ """Tests for PydanticAITransformation helper methods."""
+
+ def test_remove_none_values(self):
+ """
+ Test that _remove_none_values recursively removes None values from dicts.
+ FastA2A servers reject None values for optional fields.
+ """
+ input_data = {
+ "message": {
+ "role": "user",
+ "parts": [{"kind": "text", "text": "Hello"}],
+ "contextId": None,
+ "taskId": None,
+ "metadata": None,
+ },
+ "configuration": None,
+ "metadata": {"key": "value", "empty": None},
+ }
+
+ result = PydanticAITransformation._remove_none_values(input_data)
+
+ # None values should be removed
+ assert "contextId" not in result["message"]
+ assert "taskId" not in result["message"]
+ assert "metadata" not in result["message"]
+ assert "configuration" not in result
+ assert "empty" not in result["metadata"]
+
+ # Non-None values should be preserved
+ assert result["message"]["role"] == "user"
+ assert result["message"]["parts"] == [{"kind": "text", "text": "Hello"}]
+ assert result["metadata"]["key"] == "value"
+
+ def test_transform_to_a2a_response(self):
+ """
+ Test that _transform_to_a2a_response converts Pydantic AI task format
+ to standard A2A non-streaming response format.
+ """
+ # Pydantic AI returns tasks with history/artifacts
+ pydantic_ai_response = {
+ "jsonrpc": "2.0",
+ "id": "req-123",
+ "result": {
+ "id": "task-456",
+ "kind": "task",
+ "status": {"state": "completed"},
+ "history": [
+ {
+ "role": "user",
+ "parts": [{"kind": "text", "text": "What is 2+2?"}],
+ "messageId": "msg-user-1",
+ },
+ {
+ "role": "agent",
+ "parts": [{"kind": "text", "text": "The answer is 4."}],
+ "messageId": "msg-agent-1",
+ },
+ ],
+ "artifacts": [
+ {
+ "artifactId": "artifact-1",
+ "name": "response",
+ "parts": [{"kind": "text", "text": "The answer is 4."}],
+ }
+ ],
+ },
+ }
+
+ result = PydanticAITransformation._transform_to_a2a_response(
+ response_data=pydantic_ai_response,
+ request_id="req-123",
+ )
+
+ # Should return standard A2A format with message
+ assert result["jsonrpc"] == "2.0"
+ assert result["id"] == "req-123"
+ assert "message" in result["result"]
+ assert result["result"]["message"]["role"] == "agent"
+ assert result["result"]["message"]["parts"][0]["text"] == "The answer is 4."
+
diff --git a/ui/litellm-dashboard/public/assets/logos/pydantic.svg b/ui/litellm-dashboard/public/assets/logos/pydantic.svg
new file mode 100644
index 00000000000..0ff8e5c44c7
--- /dev/null
+++ b/ui/litellm-dashboard/public/assets/logos/pydantic.svg
@@ -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>
diff --git a/ui/litellm-dashboard/src/components/agents/add_agent_form.tsx b/ui/litellm-dashboard/src/components/agents/add_agent_form.tsx
index f44d71cbada..f4e0137bd06 100644
--- a/ui/litellm-dashboard/src/components/agents/add_agent_form.tsx
+++ b/ui/litellm-dashboard/src/components/agents/add_agent_form.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react";
-import { Modal, Form, message, Select } from "antd";
+import { Modal, Form, message, Select, Input } from "antd";
import { Button } from "@tremor/react";
import { createAgentCall, getAgentCreateMetadata, AgentCreateInfo } from "../networking";
import AgentFormFields from "./agent_form_fields";
@@ -57,6 +57,26 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({
if (agentType === "a2a") {
agentData = buildAgentDataFromForm(values);
+ } else if (selectedAgentTypeInfo?.use_a2a_form_fields) {
+ // A2A-compatible agents use the standard A2A form builder
+ // but need to add litellm_params from the agent type config
+ agentData = buildAgentDataFromForm(values);
+
+ // Merge litellm_params_template
+ if (selectedAgentTypeInfo.litellm_params_template) {
+ agentData.litellm_params = {
+ ...agentData.litellm_params,
+ ...selectedAgentTypeInfo.litellm_params_template,
+ };
+ }
+
+ // Add credential fields to litellm_params
+ for (const field of selectedAgentTypeInfo.credential_fields) {
+ const value = values[field.key];
+ if (value && field.include_in_litellm_params !== false) {
+ agentData.litellm_params[field.key] = value;
+ }
+ }
} else if (selectedAgentTypeInfo) {
agentData = buildDynamicAgentData(values, selectedAgentTypeInfo);
}
@@ -167,6 +187,35 @@ const AddAgentForm: React.FC<AddAgentFormProps> = ({
<div className="mt-6">
{agentType === "a2a" ? (
<AgentFormFields showAgentName={true} />
+ ) : selectedAgentTypeInfo?.use_a2a_form_fields ? (
+ // A2A-compatible agents (like Pydantic AI) use full A2A form fields
+ // plus any additional credential fields
+ <>
+ <AgentFormFields showAgentName={true} />
+ {selectedAgentTypeInfo.credential_fields.length > 0 && (
+ <div className="mt-4 p-4 border border-gray-200 rounded-lg">
+ <h4 className="text-sm font-medium text-gray-700 mb-3">
+ {selectedAgentTypeInfo.agent_type_display_name} Settings
+ </h4>
+ {selectedAgentTypeInfo.credential_fields.map((field) => (
+ <Form.Item
+ key={field.key}
+ label={field.label}
+ name={field.key}
+ rules={field.required ? [{ required: true, message: `Please enter ${field.label}` }] : undefined}
+ tooltip={field.tooltip}
+ initialValue={field.default_value}
+ >
+ {field.field_type === "password" ? (
+ <Input.Password placeholder={field.placeholder || ""} />
+ ) : (
+ <Input placeholder={field.placeholder || ""} />
+ )}
+ </Form.Item>
+ ))}
+ </div>
+ )}
+ </>
) : selectedAgentTypeInfo ? (
<DynamicAgentFormFields agentTypeInfo={selectedAgentTypeInfo} />
) : null}
diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx
index 65c41c5aab4..ddabc6f5212 100644
--- a/ui/litellm-dashboard/src/components/networking.tsx
+++ b/ui/litellm-dashboard/src/components/networking.tsx
@@ -215,6 +215,7 @@ export interface AgentCreateInfo {
credential_fields: AgentCredentialFieldMetadata[];
litellm_params_template?: Record<string, string> | null;
model_template?: string | null;
+ use_a2a_form_fields?: boolean;
}
export interface PublicModelHubInfo {