diff --git a/litellm/proxy/agent_endpoints/auth/managed_authorization.py b/litellm/proxy/agent_endpoints/auth/managed_authorization.py index 0212f2b7032..2195b58750a 100644 --- a/litellm/proxy/agent_endpoints/auth/managed_authorization.py +++ b/litellm/proxy/agent_endpoints/auth/managed_authorization.py @@ -208,12 +208,12 @@ _INVOCATION_COST: Final = TypeAdapter(Annotated[float, Field(ge=0, allow_inf_nan def invocation_target(route: str, body: Mapping[str, object]) -> str | None: - model: Final = body.get("model") - if isinstance(model, str) and model.startswith("a2a/"): - return model.removeprefix("a2a/") or None components: Final = tuple(route.strip("/").split("/")) path: Final = components[1:] if components and components[0] == "v1" else components - return path[1] if len(path) >= 2 and path[0] == "a2a" else None + if len(path) >= 2 and path[0] == "a2a": + return path[1] + model: Final = body.get("model") + return model.removeprefix("a2a/") or None if isinstance(model, str) and model.startswith("a2a/") else None async def prepare_agent_invocation( diff --git a/tests/test_litellm/proxy/agent_endpoints/auth/test_managed_authorization.py b/tests/test_litellm/proxy/agent_endpoints/auth/test_managed_authorization.py index ec352511d50..4d0ae200a4c 100644 --- a/tests/test_litellm/proxy/agent_endpoints/auth/test_managed_authorization.py +++ b/tests/test_litellm/proxy/agent_endpoints/auth/test_managed_authorization.py @@ -198,6 +198,8 @@ async def test_agent_history_outage_does_not_permit_legacy_fallback() -> None: "route,body,expected", [ ("/a2a/agent", {}, "agent"), + ("/a2a/agent", {"model": "a2a/nonexistent"}, "agent"), + ("/v1/a2a/agent/message/send", {"model": "a2a/other"}, "agent"), ("/v1/a2a/agent/", {}, "agent"), ("/v1/chat/completions", {"model": "a2a/Readable name"}, "Readable name"), ("/v1/chat/completions", {"model": "a2a/"}, None),