fix: use get_async_httpx_client in a2a_protocol and add master_key monkeypatch to files tests

- Replace httpx.AsyncClient() with get_async_httpx_client() in a2a_protocol/main.py
  to satisfy the ensure_async_clients_test CI check
- Add httpxSpecialProvider.A2AProvider enum value
- Add master_key=None monkeypatch to test_managed_files_with_loadbalancing

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-03-07 05:38:20 +00:00
parent 5112330ead
commit fe4cff8595
3 changed files with 18 additions and 8 deletions

View file

@ -653,15 +653,22 @@ async def create_a2a_client(
verbose_logger.info(f"Creating A2A client for {base_url}")
# Always create a fresh httpx client per A2A call so that per-agent auth
# headers (extra_headers) are never shared across agents or requests.
# Mutating a cached shared client would cause headers from one agent to
# bleed into requests made to a different agent.
httpx_client = httpx.AsyncClient(
timeout=httpx.Timeout(timeout),
headers=extra_headers or {},
)
# Use get_async_httpx_client with per-agent params so that different agents
# (with different extra_headers) get separate cached clients. The params
# dict is hashed into the cache key, keeping agent auth isolated while
# still reusing connections within the same agent.
_client_params: dict = {"timeout": timeout}
if extra_headers:
# Include sorted header keys in params so each unique header set
# produces a distinct cache key.
_client_params["extra_headers"] = str(sorted(extra_headers.items()))
_async_handler = get_async_httpx_client(
llm_provider=httpxSpecialProvider.A2AProvider,
params=_client_params,
)
httpx_client = _async_handler.client
if extra_headers:
httpx_client.headers.update(extra_headers)
verbose_proxy_logger.debug(
f"A2A client created with extra_headers={list(extra_headers.keys())}"
)

View file

@ -24,6 +24,7 @@ class httpxSpecialProvider(str, Enum):
Search = "search"
MCP = "mcp"
RAG = "rag"
A2AProvider = "a2a_provider"
A2A = "a2a"
PromptManagement = "prompt_management"
UI = "ui"

View file

@ -962,6 +962,8 @@ def test_managed_files_with_loadbalancing(mocker: MockerFixture, monkeypatch, ll
monkeypatch.setattr(
"litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging_obj
)
# Disable auth so the test doesn't depend on master_key state from other tests
monkeypatch.setattr("litellm.proxy.proxy_server.master_key", None)
# Create batch file content
test_file_content = b'{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello"}]}}'