[Fix] A2a Agent Gateway Fixes - A2A agents deployed with localhost/internal URLs in their agent cards (e.g., http://0.0.0.0:8001/)#20604
Merged
ishaan-jaff merged 16 commits intomainfrom Feb 6, 2026
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile OverviewGreptile Summary
Confidence Score: 2/5
|
| Filename | Overview |
|---|---|
| litellm/a2a_protocol/init.py | Re-exported new A2A exception types from the package surface via all. |
| litellm/a2a_protocol/card_resolver.py | Added localhost/internal URL detection and a helper to rewrite agent_card.url to the provided base_url; resolver fallback logic unchanged. |
| litellm/a2a_protocol/exception_mapping_utils.py | Introduced exception mapping/retry helpers; contains reliance on A2AClient private attributes and potential None-call when a2a SDK missing. |
| litellm/a2a_protocol/exceptions.py | Added custom A2A exception hierarchy with httpx.Response compatibility fields for LiteLLM error handling. |
| litellm/a2a_protocol/main.py | Added retry-on-localhost URL logic for streaming and non-streaming calls; current control flow can fall through without a response and uses private client internals when recreating clients. |
| litellm/constants.py | Added LOCALHOST_URL_PATTERNS and CONNECTION_ERROR_PATTERNS constants used by A2A retry/error mapping. |
| tests/agent_tests/local_only_agent_tests/local_vertex_agent.py | Moved local Vertex agent script under local_only_agent_tests; no functional changes. |
| tests/agent_tests/local_only_agent_tests/test_a2a.py | Moved existing A2A agent tests to local_only_agent_tests; no functional changes. |
| tests/agent_tests/local_only_agent_tests/test_a2a_completion_bridge.py | Moved existing completion bridge tests to local_only_agent_tests; no functional changes. |
| tests/agent_tests/test_a2a_agent.py | Added env-dependent integration tests but does not skip when A2A_AGENT_URL is unset, so it will fail in CI by passing None api_base. |
| tests/test_litellm/a2a_protocol/test_card_resolver.py | Added unit tests for localhost URL detection and card URL rewriting helpers. |
Sequence Diagram
sequenceDiagram
participant U as Caller
participant LM as litellm.a2a_protocol.main
participant CC as create_a2a_client
participant CR as LiteLLMA2ACardResolver
participant A2A as a2a.client.A2AClient
participant AG as A2A Agent
U->>LM: asend_message(request, api_base)
alt no a2a_client provided
LM->>CC: create_a2a_client(base_url=api_base)
CC->>CR: get_agent_card()
CR->>AG: GET /.well-known/agent-card.json
alt 404 / fails
CR->>AG: GET /.well-known/agent.json
end
CR-->>CC: AgentCard(url=card.url)
CC->>A2A: new A2AClient(httpx_client, agent_card)
A2A-->>LM: a2a_client
end
LM->>A2A: send_message(request)
alt connection error + agent_card.url is localhost
A2A--x LM: Exception
LM->>LM: map_a2a_exception(e, card_url, api_base)
LM-->>LM: raises A2ALocalhostURLError
LM->>LM: handle_a2a_localhost_retry()
LM->>A2A: new A2AClient(agent_card.url := api_base)
LM->>A2A: send_message(request) (retry)
else success
A2A-->>LM: SendMessageResponse
end
LM-->>U: LiteLLMSendMessageResponse
Comment on lines
+258
to
+266
| # Retry loop: if connection fails due to localhost URL in agent card, retry with fixed URL | ||
| a2a_response = None | ||
| for _ in range(2): # max 2 attempts: original + 1 retry | ||
| try: | ||
| a2a_response = await a2a_client.send_message(request) | ||
| break # success, exit retry loop | ||
| except A2ALocalhostURLError as e: | ||
| # Localhost URL error - fix and retry | ||
| a2a_client = handle_a2a_localhost_retry( |
Contributor
There was a problem hiding this comment.
Retry loop can fall through
In asend_message(), the for _ in range(2) loop can complete without setting a2a_response (e.g., first attempt raises A2ALocalhostURLError, you retry, and the second attempt raises another A2ALocalhostURLError; that except block doesn’t continue/raise, so the loop ends and hits assert a2a_response is not None). This will surface as an AssertionError instead of a meaningful A2A exception. The loop should deterministically re-raise the last mapped exception on the final attempt.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Fix] A2a Agent Gateway Fixes - A2A agents deployed with localhost/internal URLs in their agent cards (e.g., http://0.0.0.0:8001/)
This PR fixes an issue where A2A agents deployed with localhost/internal URLs in their agent cards (e.g., http://0.0.0.0:8001/) cause connection failures. LiteLLM now automatically detects this misconfiguration and retries with the correct public URL.
Problem
Many A2A agents are deployed with development URLs left in their agent cards. When LiteLLM fetches the agent card and uses the URL specified in it, the request fails because localhost or 0.0.0.0 is not reachable from the client.
Customer-reported error:
a2a.client.errors.A2AClientHTTPError: HTTP Error 503: Network communication error: Cannot connect to host localhost:8000
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
✅ Test
Changes