Skip to content

The agent that grows with you

fix(aux): keep the /v1 tail on the config path and trim the salvage to two invariants

teknium1200f8a6b4e82
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 519f115db55..604fce113ec 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -520,12 +520,10 @@ def _extract_url_query_params(url: str):
# Warn only once per process about stale OPENAI_BASE_URL.
_stale_base_url_warned = False
-# OpenAI-compatible local servers (Ollama, vLLM, llama.cpp server) are served by the
-# generic custom provider — mirroring hermes_cli.auth._PROVIDER_ALIASES. Without these
-# entries an explicit ``provider: ollama`` aux lane dead-ends in the unknown-provider arm
-# and raises a misleading ``OLLAMA_API_KEY`` error instead of using the lane's base_url
-# (#106010). Their OpenAI wire surface lives under /v1, so a bare host base_url needs
-# the /v1 tail (#106010).
+# Local OpenAI-compatible servers (Ollama, vLLM, llama.cpp) route through the generic custom
+# provider — mirrors hermes_cli.auth._PROVIDER_ALIASES. Without this group an explicit
+# ``provider: ollama`` aux lane matches no registry entry and raises a misleading
+# ``OLLAMA_API_KEY`` error instead of using the lane's base_url (#106010).
_LOCAL_SERVER_ALIASES = {
"ollama": "custom", "vllm": "custom", "llamacpp": "custom",
"llama.cpp": "custom", "llama-cpp": "custom",
@@ -550,14 +548,6 @@ _PROVIDER_ALIASES = {
}
-def _bare_host_base_url(base_url: str) -> bool:
- """True when a base URL is a bare host[:port] with no path component."""
- try:
- return urlparse(str(base_url or "").strip()).path.strip("/") == ""
- except Exception:
- return False
-
-
def _normalize_aux_provider(provider: Optional[str]) -> str:
normalized = (provider or "auto").strip().lower()
if normalized.startswith("custom:"):
@@ -4899,7 +4889,9 @@ def _resolve_custom_branch(req: _ResolveRequest) -> _ResolveResult:
custom_base = custom_key = wrap_base = ""
if req.explicit_base_url:
custom_base = _to_openai_base_url(req.explicit_base_url).strip()
- if req.original_provider in _LOCAL_SERVER_ALIASES and _bare_host_base_url(custom_base):
+ # Ollama/vLLM/llama.cpp serve the OpenAI surface under /v1; a bare host posts to the
+ # native API and 404s (#106010). Only the alias group gets the tail — ``custom`` is verbatim.
+ if req.original_provider in _LOCAL_SERVER_ALIASES and not urlparse(custom_base).path.strip("/"):
custom_base = custom_base.rstrip("/") + "/v1"
if req.api_mode == "anthropic_messages":
wrap_base = (req.explicit_base_url or "").strip().rstrip("/")
@@ -5914,6 +5906,8 @@ def _preserve_provider_with_base_url(prov: Optional[str]) -> bool:
normalized = str(prov or "").strip().lower()
if normalized in {"", "auto", "custom"} or normalized.startswith("custom:"):
return False
+ if normalized in _LOCAL_SERVER_ALIASES:
+ return True # the custom branch applies the /v1 tail only when it still sees the alias
try:
from hermes_cli.providers import get_provider
return get_provider(normalized) is not None
@@ -5984,7 +5978,8 @@ def _resolve_task_provider_model(
if provider:
return provider, resolved_model, base_url, api_key, resolved_api_mode
if cfg_base_url and cfg_api_key:
- return "custom", resolved_model, cfg_base_url, cfg_api_key, resolved_api_mode
+ kept = cfg_provider if str(cfg_provider or "").strip().lower() in _LOCAL_SERVER_ALIASES else "custom"
+ return kept, resolved_model, cfg_base_url, cfg_api_key, resolved_api_mode
if cfg_base_url and cfg_provider and cfg_provider != "auto":
# base_url without api_key: keep the provider so it can resolve credentials from env
# vars instead of locking into "custom".
diff --git a/tests/agent/test_auxiliary_ollama_local_provider.py b/tests/agent/test_auxiliary_ollama_local_provider.py
index 428357a8974..e34a4cde845 100644
--- a/tests/agent/test_auxiliary_ollama_local_provider.py
+++ b/tests/agent/test_auxiliary_ollama_local_provider.py
@@ -1,38 +1,27 @@
-"""Explicit ``provider: ollama`` (and sibling local-server aliases) must route through
-the ``custom`` branch like they do in the main runtime, so an aux lane pointing at a
-local Ollama/vLLM/llama.cpp server with an empty ``api_key`` builds a client with the
-``no-key-required`` placeholder instead of dead-ending in the unknown-provider arm.
-
-The bug (issue #106010): ``agent/auxiliary_client.py`` kept its own copy of the
-provider alias table without the "local server aliases" group that
-``hermes_cli.auth._PROVIDER_ALIASES`` has. An explicit ``provider: ollama`` lane with
-``base_url`` + empty ``api_key`` kept the ollama identity, matched no registry entry,
-and every call raised ``RuntimeError: Provider 'ollama' is set in config.yaml but no
-API key was found`` — while the same endpoint worked as ``provider: custom``.
-
-Secondary fix covered here: the OpenAI-compatible surface of these servers lives
-under ``/v1``, so a bare host base_url (``http://127.0.0.1:11434``) must gain the
-``/v1`` tail or the first request 404s on the server's native API.
+"""Explicit ``provider: ollama`` (and the sibling local-server aliases ``vllm`` / ``llamacpp``)
+must route through the ``custom`` branch in the auxiliary client, as it already does in
+``hermes_cli.auth``: a lane pointing at a local server with an empty ``api_key`` builds a
+client with the ``no-key-required`` placeholder instead of raising
+``Provider 'ollama' is set in config.yaml but no API key was found`` (issue #106010).
+
+Second half of the same report: these servers expose the OpenAI surface under ``/v1``, so
+a bare ``host:port`` base_url gains the tail — but only for the alias group; a literal
+``provider: custom`` base_url is used verbatim and an existing path is never doubled.
"""
from __future__ import annotations
-import os
from unittest.mock import patch
import pytest
@pytest.fixture(autouse=True)
-def _clean_env(monkeypatch):
+def _keyless_environment(monkeypatch):
for key in ("OPENAI_API_KEY", "OPENAI_BASE_URL"):
monkeypatch.delenv(key, raising=False)
-
-
[email protected](autouse=True)
-def _no_same_host_main_key():
- # The key ladder falls back to the main config's key when hosts match; the
- # placeholder assertions below need that rung to stay empty.
+ # The key ladder inherits the main config's key on a host match; the placeholder
+ # assertions below need that rung empty.
with patch("agent.auxiliary_client._read_main_api_key_if_same_host", return_value=None):
yield
@@ -49,85 +38,32 @@ def _client_attr(client, attr: str) -> str:
return ""
-def test_ollama_bare_local_base_url_gets_v1_tail_and_placeholder_key(monkeypatch):
- """provider: ollama + loopback base_url + empty api_key must resolve a client
- (placeholder key, /v1 base) — not return None and raise downstream (#106010)."""
- from agent.auxiliary_client import resolve_provider_client
-
- client, _model = resolve_provider_client(
- "ollama",
- model="llama3.2",
- explicit_base_url="http://127.0.0.1:11434",
- explicit_api_key=None,
- )
- assert client is not None, (
- "explicit provider: ollama with a local base_url must build a client via the "
- "custom branch instead of dead-ending in the unknown-provider arm"
- )
- assert _client_attr(client, "base_url").rstrip("/") == "http://127.0.0.1:11434/v1"
- assert _client_attr(client, "api_key") == "no-key-required"
-
[email protected]("api_key, expected_key", [("", "no-key-required"), ("test-key-123", "test-key-123")])
+def test_ollama_lane_with_bare_local_host_resolves_custom_client_under_v1(monkeypatch, api_key, expected_key):
+ """The reporter's lane, through the real task-config path: keyless gets the placeholder,
+ an explicit key is sent verbatim, and both post to /v1."""
+ from agent import auxiliary_client as ac
-def test_ollama_explicit_api_key_passthrough_with_v1_tail(monkeypatch):
- """An explicit api_key must be honored verbatim (not swapped for the placeholder),
- with the /v1 tail still appended to a bare local base_url."""
- from agent.auxiliary_client import resolve_provider_client
+ lane = {"provider": "ollama", "model": "qwen3.8:27b", "base_url": "http://127.0.0.1:11434", "api_key": api_key}
+ monkeypatch.setattr(ac, "_get_auxiliary_task_config", lambda task: dict(lane) if task == "title_generation" else {})
+ provider, model, base_url, key, _mode = ac._resolve_task_provider_model("title_generation")
- monkeypatch.setenv("HERMES_TEST_FAKE_KEY", "sk-test-local")
- client, _model = resolve_provider_client(
- "ollama",
- model="llama3.2",
- explicit_base_url="http://localhost:11434",
- explicit_api_key=os.environ["HERMES_TEST_FAKE_KEY"],
- )
- assert client is not None
- assert _client_attr(client, "base_url").rstrip("/") == "http://localhost:11434/v1"
- assert _client_attr(client, "api_key") == os.environ["HERMES_TEST_FAKE_KEY"]
-
-
-def test_ollama_base_url_with_path_not_rewritten(monkeypatch):
- """A base_url that already carries a path (e.g. .../v1) must be kept as-is —
- never double-appended."""
- from agent.auxiliary_client import resolve_provider_client
-
- monkeypatch.setenv("HERMES_TEST_FAKE_KEY", "sk-test-local")
- client, _model = resolve_provider_client(
- "ollama",
- model="llama3.2",
- explicit_base_url="http://127.0.0.1:11434/v1",
- explicit_api_key=os.environ["HERMES_TEST_FAKE_KEY"],
- )
- assert client is not None
+ client, _model = ac.resolve_provider_client(provider, model=model, explicit_base_url=base_url, explicit_api_key=key)
+ assert client is not None, "provider: ollama + local base_url must build a client via the custom branch"
assert _client_attr(client, "base_url").rstrip("/") == "http://127.0.0.1:11434/v1"
+ assert _client_attr(client, "api_key") == expected_key
-def test_bare_custom_loopback_base_url_kept_as_is(monkeypatch):
- """Only the local-server aliases get the /v1 tail: a literal ``provider: custom``
- with a bare loopback base keeps its URL verbatim (existing custom semantics)."""
+def test_v1_tail_applies_only_to_bare_alias_hosts_and_never_doubles():
from agent.auxiliary_client import resolve_provider_client
- monkeypatch.setenv("HERMES_TEST_FAKE_KEY", "sk-test-local")
- client, _model = resolve_provider_client(
- "custom",
- model="llama3.2",
- explicit_base_url="http://127.0.0.1:11434",
- explicit_api_key=os.environ["HERMES_TEST_FAKE_KEY"],
+ custom, _ = resolve_provider_client(
+ "custom", model="m", explicit_base_url="http://127.0.0.1:11434", explicit_api_key="test-key-123",
)
- assert client is not None
- assert _client_attr(client, "base_url").rstrip("/") == "http://127.0.0.1:11434"
-
-
-def test_vllm_local_server_alias_routes_the_same_way():
- """Sibling local-server aliases (vllm, llama.cpp) share the custom routing and
- the /v1 tail."""
- from agent.auxiliary_client import resolve_provider_client
+ assert _client_attr(custom, "base_url").rstrip("/") == "http://127.0.0.1:11434"
- client, _model = resolve_provider_client(
- "vllm",
- model="Qwen3-32B",
- explicit_base_url="http://127.0.0.1:8000",
- explicit_api_key=None,
+ with_path, _ = resolve_provider_client(
+ "vllm", model="m", explicit_base_url="http://127.0.0.1:8000/v1", explicit_api_key="test-key-123",
)
- assert client is not None
- assert _client_attr(client, "base_url").rstrip("/") == "http://127.0.0.1:8000/v1"
- assert _client_attr(client, "api_key") == "no-key-required"
+ assert _client_attr(with_path, "base_url").rstrip("/") == "http://127.0.0.1:8000/v1"
+ assert _client_attr(with_path, "api_key") == "test-key-123"
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index 7827f8918fe..f527592035a 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -1427,6 +1427,8 @@ When `base_url` is set, Hermes ignores the provider and calls that endpoint dire
Available providers for auxiliary tasks: `auto`, `main`, plus any provider in the [provider registry](/reference/environment-variables) — `openrouter`, `nous`, `openai-codex`, `copilot`, `copilot-acp`, `anthropic`, `gemini`, `qwen-oauth`, `zai`, `kimi-coding`, `kimi-coding-cn`, `minimax`, `minimax-cn`, `minimax-oauth`, `deepseek`, `nvidia`, `xai`, `xai-oauth`, `ollama-cloud`, `alibaba`, `bedrock`, `huggingface`, `arcee`, `xiaomi`, `kilocode`, `opencode-zen`, `opencode-go`, `opencode-free`, `commandcode`, `commandcode-anthropic`, `ai-gateway`, `azure-foundry` — or any named custom provider from your `providers:` dict (e.g. `provider: "beans"`).
+Local OpenAI-compatible servers work under their own names too: `provider: ollama` (also `vllm`, `llamacpp`, `llama.cpp`) with a `base_url` such as `http://127.0.0.1:11434` and an empty `api_key` routes through the custom endpoint with a placeholder key, and a bare `host:port` base_url gets the `/v1` suffix automatically.
+
:::tip MiniMax OAuth
`minimax-oauth` logs in via browser OAuth (no API key needed). Run `hermes model` and select **MiniMax (OAuth)** to authenticate. Auxiliary tasks use `MiniMax-M2.7-highspeed` automatically. See the [MiniMax OAuth guide](../guides/minimax-oauth.md).
:::