Skip to content

The agent that grows with you

fix(provider): resolve named fallback before local alias

fangliquan204ebafb3d75
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index a5ad96e9ffe..c86c5717aa4 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -5374,15 +5374,18 @@ def resolve_provider_client(
explicit_base_url, explicit_api_key, api_mode, main_runtime, is_vision, task,
)
branch = _EXPLICIT_PROVIDER_BRANCHES.get(provider)
+ # A configured provider whose name collides with a local-server alias is still a named
+ # provider. Resolve it before the alias's generic ``custom`` branch, which otherwise loses
+ # the configured base_url and can fall through to an unrelated credentialed provider.
+ if branch is None or original_provider in _LOCAL_SERVER_ALIASES:
+ try:
+ result = _resolve_named_custom_branch(req)
+ except ImportError:
+ result = None
+ if result is not None:
+ return result
if branch is not None:
return branch(req)
- # Named custom providers; an ImportError anywhere in the arm falls through to the built-ins.
- try:
- result = _resolve_named_custom_branch(req)
- except ImportError:
- result = None
- if result is not None:
- return result
if provider == "azure-foundry":
return _resolve_azure_foundry_branch(req)
return _resolve_registry_branch(req)
diff --git a/tests/agent/test_auxiliary_named_custom_providers.py b/tests/agent/test_auxiliary_named_custom_providers.py
index 1090e79977a..5f1098398dd 100644
--- a/tests/agent/test_auxiliary_named_custom_providers.py
+++ b/tests/agent/test_auxiliary_named_custom_providers.py
@@ -394,6 +394,25 @@ class TestCustomProviderAliasCollision:
# Built-in kimi-coding points at api.moonshot.ai
assert "moonshot" in base_url or "kimi" in base_url, f"unexpected base_url {base_url!r}"
+ def test_named_llamacpp_wins_over_local_server_alias(self, tmp_path):
+ _write_config(tmp_path, {
+ "model": {"provider": "openrouter", "default": "anthropic/claude-sonnet-4.6"},
+ "providers": {
+ "llamacpp": {
+ "base_url": "http://127.0.0.1:8081/v1",
+ "model": "local-model",
+ },
+ },
+ })
+ from agent.auxiliary_client import resolve_provider_client
+ from openai import OpenAI
+
+ client, model = resolve_provider_client("llamacpp", model="local-model", raw_codex=True)
+
+ assert isinstance(client, OpenAI)
+ assert str(client.base_url).rstrip("/") == "http://127.0.0.1:8081/v1"
+ assert model == "local-model"
+
def test_explicit_overrides_applied_on_api_key_branch(self, tmp_path, monkeypatch):
"""Explicit base_url/api_key from the caller must override the
registered provider's defaults on the API-key branch. Used by