The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(aux): route OpenCode auxiliary clients by the model's wire, not a persisted api_mode
teknium137f7f0032391
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 8d22c8e0012..6930558f02b 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -4786,6 +4786,12 @@ def _wrap_transport(req: _ResolveRequest, client_obj: Any, final_model_str: str,)client._hermes_aux_effective_provider = "actual"return client+ # OpenCode relay targets pick the wire per model; a task/provider-level api_mode is stale for+ # every other model (#98799), so it is re-derived here like the main runtime does.+ from agent.opencode_affinity import opencode_transport+ _oc_mode, _oc_base = opencode_transport(req.provider, final_model_str, base_url_str)+ if _oc_mode:+ req, base_url_str = req._replace(api_mode=_oc_mode), _oc_baseneeds_codex = not (isinstance(client_obj, CodexAuxiliaryClient) or req.raw_codex) and (@@ -5042,6 +5048,12 @@ def _resolve_named_custom_branch(req: _ResolveRequest) -> Optional[_ResolveResulor "gpt-4o-mini",provider,)+ # An OpenCode-family entry (``opencode-go-bridge``, #85589) persisted the api_mode of whichever+ # model was selected at save time; the relay picks the wire per model (#98799).+ from agent.opencode_affinity import opencode_transport+ _oc_mode, _oc_base = opencode_transport(provider, final_model, custom_base)+ if _oc_mode:+ entry_api_mode, custom_base = _oc_mode, _oc_baselogger.debug("resolve_provider_client: named custom provider %r (%s, api_mode=%s)",provider, final_model, entry_api_mode or "chat_completions")# anthropic_messages: route via AnthropicAuxiliaryClient (mirrors _try_custom_endpoint);diff --git a/agent/opencode_affinity.py b/agent/opencode_affinity.pyindex c4a1628e7cb..c6ba332cca1 100644--- a/agent/opencode_affinity.py+++ b/agent/opencode_affinity.py@@ -12,7 +12,8 @@ so cron fires of one job share a scope.Every OpenCode request — main turn on any transport, auxiliary calls(compression, titles, vision, MoA) — goes through :func:`opencode_session_headers`-so the header cannot drift per code path.+so the header cannot drift per code path. :func:`opencode_transport` is the+matching per-model wire-format decision for the auxiliary client."""from __future__ import annotations@@ -22,6 +23,29 @@ from typing import Any, OptionalOPENCODE_SESSION_HEADER = "x-opencode-session"+def opencode_transport(provider: Optional[str], model: Optional[str], base_url: Optional[str]) -> tuple[Optional[str], str]:+ """``(api_mode, base_url)`` re-derived per model for an OpenCode relay target; ``(None, base_url)`` otherwise.++ OpenCode Zen/Go serve Responses-only (``gpt-*``, ``grok-*``, ``muse-spark``), Anthropic-wire+ (``minimax-*``, ``qwen*``, ``claude-*``) and chat/completions models behind one provider, so a+ provider-level or persisted ``api_mode`` is wrong for every model but the one it was saved for.+ The main runtime (``hermes_cli/runtime_provider.py``) always re-derives from the effective model;+ auxiliary resolution must agree or ``gpt-5.6-luna`` compression 500s on /chat/completions (#98799).+ Built-in families, custom entries named after one (``opencode-go-bridge``, #85589) and opencode.ai+ hosts all count.+ """+ from hermes_cli.models import normalize_opencode_base_url, normalize_opencode_model_id, opencode_model_api_mode+ from hermes_cli.runtime_provider_custom import _opencode_family_for_custom++ url = str(base_url or "")+ family = _opencode_family_for_custom(str(provider or ""), url)+ if family is None:+ return None, url+ # ``<provider>/<model>`` config ids are stripped against the entry name before the family lookup.+ api_mode = opencode_model_api_mode(family, normalize_opencode_model_id(provider, model))+ return api_mode, normalize_opencode_base_url(provider, api_mode, url)++def is_opencode_target(provider: Optional[str], base_url: Optional[str]) -> bool:"""True when *provider* or *base_url* addresses the OpenCode relay.diff --git a/tests/agent/test_auxiliary_opencode_routing.py b/tests/agent/test_auxiliary_opencode_routing.pynew file mode 100644index 00000000000..865bd5b3c58--- /dev/null+++ b/tests/agent/test_auxiliary_opencode_routing.py@@ -0,0 +1,60 @@+"""Auxiliary clients for OpenCode Zen/Go follow the per-model wire table the main runtime uses (#98799).++The relay serves Responses-only, Anthropic-wire and chat/completions models behind one provider, so+the transport must be derived from the resolved model — a provider-level or persisted ``api_mode``+is stale for every other model.+"""++from __future__ import annotations++import pytest+from openai import OpenAI++from agent import auxiliary_client as aux++[email protected](autouse=True)+def _isolated_home(tmp_path, monkeypatch):+ home = tmp_path / ".hermes"+ home.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setenv("OPENCODE_GO_API_KEY", "sk-go-test")+ monkeypatch.setenv("OPENCODE_ZEN_API_KEY", "sk-zen-test")+ (home / "config.yaml").write_text(+ "custom_providers:\n"+ " - name: opencode-go-bridge\n"+ " base_url: https://opencode.ai/zen/go/v1\n"+ " api_key: sk-bridge\n"+ " api_mode: chat_completions\n"+ )+ return home+++_WIRE_BY_MODEL = [+ ("gpt-5.6-luna", aux.CodexAuxiliaryClient),+ ("minimax-m2.5", aux.AnthropicAuxiliaryClient),+ ("glm-5", OpenAI),+]++[email protected]("model, expected", _WIRE_BY_MODEL)[email protected]("stale_api_mode", [None, "chat_completions", "codex_responses"])+def test_builtin_opencode_go_client_follows_the_model_not_the_persisted_mode(model, expected, stale_api_mode):+ client, resolved = aux.resolve_provider_client("opencode-go", model=model, api_mode=stale_api_mode)+ assert resolved == model+ assert type(client) is expected+ async_client, _ = aux.resolve_provider_client("opencode-go", model=model, api_mode=stale_api_mode, async_mode=True)+ assert (type(async_client) is aux.AsyncCodexAuxiliaryClient) == (expected is aux.CodexAuxiliaryClient)++[email protected]("model, expected", _WIRE_BY_MODEL)+def test_named_custom_opencode_family_entry_follows_the_model(model, expected):+ """An ``opencode-go-*`` custom entry persisted one api_mode at save time; each model still gets its own wire."""+ client, resolved = aux.resolve_provider_client("custom:opencode-go-bridge", model=model)+ assert resolved == model+ assert type(client) is expected+ if expected is aux.AnthropicAuxiliaryClient:+ assert str(client._real_client.base_url).rstrip("/") == "https://opencode.ai/zen/go"+ else:+ base = client._real_client.base_url if expected is aux.CodexAuxiliaryClient else client.base_url+ assert str(base).rstrip("/") == "https://opencode.ai/zen/go/v1"diff --git a/website/docs/integrations/providers.md b/website/docs/integrations/providers.mdindex 47125341338..e5ee024f9e7 100644--- a/website/docs/integrations/providers.md+++ b/website/docs/integrations/providers.md@@ -62,7 +62,7 @@ You need at least one way to connect to an LLM. Use `hermes model` to switch proBoth built-in OpenCode providers send an opaque, per-conversation `x-opencode-session` header on every request (main turns on every transport plus auxiliary calls such as compression, titles, approval checks, skills-hub lookups and `/btw` side questions — including the ones that run in the background after the turn has ended; headless Kanban `specify`/`decompose` and dashboard estimate calls use a per-task key). OpenCode uses it to pin a conversation to one backend so its prompt cache stays warm; the value is derived from the Hermes session id (or the Kanban task id) and carries no personal data.-The two built-in OpenCode providers each pin their own relay on `opencode.ai` (`opencode-zen` → `/zen/v1`, `opencode-go` → `/zen/go/v1`). A `model.base_url` left behind by the other relay is healed to the selected provider's relay, and the model you pick (`-m`, `/model`, a fallback entry or a channel override) decides which relay is used — so switching from a Zen model to a Go-only one never sends the request to Zen. A custom provider you define under `providers:` whose name extends a family slug (for example `opencode-go-bridge`) still gets the family's per-model API-mode routing and `/v1` handling, but its `base_url` is taken as declared: name it after the relay it actually points at.+The two built-in OpenCode providers each pin their own relay on `opencode.ai` (`opencode-zen` → `/zen/v1`, `opencode-go` → `/zen/go/v1`). A `model.base_url` left behind by the other relay is healed to the selected provider's relay, and the model you pick (`-m`, `/model`, a fallback entry or a channel override) decides which relay is used — so switching from a Zen model to a Go-only one never sends the request to Zen. A custom provider you define under `providers:` whose name extends a family slug (for example `opencode-go-bridge`) still gets the family's per-model API-mode routing and `/v1` handling, but its `base_url` is taken as declared: name it after the relay it actually points at. Auxiliary tasks (`auxiliary.compression`, titles, vision, MoA) pointed at an OpenCode provider follow the same per-model table, so a Responses-only model such as `gpt-5.6-luna` or an Anthropic-wire one such as `minimax-m2.5` works there exactly as it does for the main conversation.For the official API-key path, see the dedicated [Google Gemini guide](../guides/google-gemini.md).