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]

fix(a2a): normalize agent card protocolBinding casing before transport match

miland6f9bce4bb7c
diff --git a/litellm/a2a_protocol/card_resolver.py b/litellm/a2a_protocol/card_resolver.py
index d14d892256b..8070d88b761 100644
--- a/litellm/a2a_protocol/card_resolver.py
+++ b/litellm/a2a_protocol/card_resolver.py
@@ -4,6 +4,7 @@ Custom A2A Card Resolver for LiteLLM.
Extends the A2A SDK's card resolver to support multiple well-known paths.
"""
+from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Final
from litellm._logging import verbose_logger
@@ -48,6 +49,33 @@ def is_localhost_or_internal_url(url: str | None) -> bool:
return any(pattern in url_lower for pattern in LOCALHOST_URL_PATTERNS)
+_CANONICAL_PROTOCOL_BINDINGS: Final = MappingProxyType(
+ {
+ "jsonrpc": "JSONRPC",
+ "http+json": "HTTP+JSON",
+ "grpc": "GRPC",
+ }
+)
+
+
+def normalize_agent_card_protocol_bindings(agent_card: "AgentCard") -> "AgentCard":
+ """
+ Canonicalize protocolBinding casing on the card's supported interfaces.
+
+ Some A2A servers (e.g. LangGraph Platform) serve agent cards with lowercase
+ bindings like "jsonrpc", but a2a-sdk's ClientFactory matches bindings
+ case-sensitively against its uppercase TransportProtocol constants and fails
+ with "no compatible transports found." for spec-adjacent casings.
+ """
+ interfaces: Final = getattr(agent_card, "supported_interfaces", None) or ()
+ for interface in interfaces:
+ binding: str = getattr(interface, "protocol_binding", "") or ""
+ canonical = _CANONICAL_PROTOCOL_BINDINGS.get(binding.lower())
+ if canonical is not None and binding != canonical:
+ interface.protocol_binding = canonical
+ return agent_card
+
+
def get_agent_card_url(agent_card: "AgentCard") -> str | None:
"""Return the agent endpoint URL from the resolved SDK card."""
url: Final = getattr(agent_card, "url", None)
diff --git a/litellm/a2a_protocol/main.py b/litellm/a2a_protocol/main.py
index 1c6ebf0b95c..2d4267cc0db 100644
--- a/litellm/a2a_protocol/main.py
+++ b/litellm/a2a_protocol/main.py
@@ -73,6 +73,7 @@ except ImportError:
from litellm.a2a_protocol.card_resolver import (
LiteLLMA2ACardResolver,
get_agent_card_url,
+ normalize_agent_card_protocol_bindings,
)
from litellm.a2a_protocol.exception_mapping_utils import (
handle_a2a_localhost_retry,
@@ -782,13 +783,17 @@ async def create_a2a_client(
if extra_headers:
verbose_proxy_logger.debug("A2A client created with extra_headers=%s", list(extra_headers.keys()))
+ resolver: Final = A2ACardResolver(httpx_client=httpx_client, base_url=base_url)
+ agent_card: Final = normalize_agent_card_protocol_bindings(
+ await resolver.get_agent_card(http_kwargs={"headers": extra_headers} if extra_headers else None)
+ )
+
a2a_client: Final = await create_client( # pyright: ignore[reportOptionalCall]
- base_url,
+ agent_card,
client_config=ClientConfig( # pyright: ignore[reportOptionalCall]
httpx_client=httpx_client,
streaming=streaming,
),
- resolver_http_kwargs={"headers": extra_headers} if extra_headers else None,
)
# Stash LiteLLM-owned handles on the client so the localhost-retry path can reuse
# the configured httpx client and this agent's headers without excavating
@@ -799,9 +804,7 @@ async def create_a2a_client(
if extra_headers
else None
)
- agent_card: Final = getattr(a2a_client, "_card", None)
- if agent_card is not None:
- a2a_client._litellm_agent_card = agent_card
+ a2a_client._litellm_agent_card = agent_card
verbose_logger.info("A2A client created for %s", base_url)
diff --git a/tests/test_litellm/a2a_protocol/test_main.py b/tests/test_litellm/a2a_protocol/test_main.py
index 08f6b9f25bb..29aa3aaabd7 100644
--- a/tests/test_litellm/a2a_protocol/test_main.py
+++ b/tests/test_litellm/a2a_protocol/test_main.py
@@ -176,10 +176,32 @@ _AGENT_A_HEADERS = {"x-agent-token": "token-for-a", "x-tenant": "tenant-a"}
_AGENT_B_HEADERS = {"x-agent-token": "token-for-b", "x-tenant": "tenant-b"}
+_V1_RPC_REPLY = {
+ "jsonrpc": "2.0",
+ "id": "reply",
+ "result": {"message": {"messageId": "reply-1", "role": "ROLE_AGENT", "parts": [{"text": "pong"}]}},
+}
+
+
+_LOWERCASE_BINDING_CARD = {
+ "name": "langgraph-agent",
+ "version": "1.0.0",
+ "capabilities": {"streaming": True},
+ "defaultInputModes": ["text/plain"],
+ "defaultOutputModes": ["text/plain"],
+ "skills": [],
+ "supportedInterfaces": [
+ {"url": "http://127.0.0.1:9/", "protocolBinding": "jsonrpc", "protocolVersion": "1.0"}
+ ],
+}
+
+
class _RequestRecorder:
"""Records the headers httpx put on the wire, per outbound request."""
- def __init__(self):
+ def __init__(self, card=_AGENT_CARD, rpc_reply=_RPC_REPLY):
+ self.card = card
+ self.rpc_reply = rpc_reply
self.card_requests = []
self.rpc_requests = []
self.client = None
@@ -188,23 +210,23 @@ class _RequestRecorder:
headers = {k.lower(): v for k, v in request.headers.items()}
if request.method == "GET":
self.card_requests.append(headers)
- return httpx.Response(200, json=_AGENT_CARD)
+ return httpx.Response(200, json=self.card)
self.rpc_requests.append(headers)
- return httpx.Response(200, json=_RPC_REPLY)
+ return httpx.Response(200, json=self.rpc_reply)
def _a2a_client_cache_key(timeout: float) -> str:
return "async_httpx_client" + f"timeout_{timeout}" + httpxSpecialProvider.A2AProvider
-async def _seed_shared_a2a_client() -> _RequestRecorder:
+async def _seed_shared_a2a_client(card=_AGENT_CARD, rpc_reply=_RPC_REPLY) -> _RequestRecorder:
"""Put the one A2A client the cache will hand out behind a mock transport.
Seeding has to happen on the test's own event loop, because the client cache keys on
it. The injected client is a real httpx.AsyncClient, so the merge of per-request
headers over client defaults, which is what these tests are about, stays real.
"""
- recorder = _RequestRecorder()
+ recorder = _RequestRecorder(card=card, rpc_reply=rpc_reply)
handler = AsyncHTTPHandler(timeout=DEFAULT_A2A_AGENT_TIMEOUT)
owned_client = handler.client
handler.client = httpx.AsyncClient(transport=httpx.MockTransport(recorder))
@@ -311,6 +333,19 @@ async def test_streaming_send_carries_only_its_own_caller_headers(isolated_clien
assert received["b"]["x-tenant"] == "tenant-b"
+async def test_lowercase_protocol_binding_in_agent_card_still_gets_a_client(isolated_client_cache):
+ """LangGraph Platform serves cards with protocolBinding "jsonrpc"; a2a-sdk matches
+ bindings case-sensitively, so without normalization client creation raises
+ ValueError("no compatible transports found.")."""
+ await _seed_shared_a2a_client(card=_LOWERCASE_BINDING_CARD, rpc_reply=_V1_RPC_REPLY)
+
+ a2a_client = await create_a2a_client(base_url="http://127.0.0.1:9")
+ response = await _send_message(a2a_client, _send_request("lc"))
+
+ assert type(response.root.result).__name__ == "Message"
+
+
@pytest.mark.asyncio
async def test_agent_card_fetch_carries_the_callers_headers(isolated_client_cache):
"""Agent cards can sit behind the same auth as the agent, so the card fetch must stay