The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(providers): opencode-go vision models stay on the Go endpoint and attach images natively
teknium1a750c091292d
diff --git a/agent/models_dev.py b/agent/models_dev.pyindex 6f5becea778..097fd12704d 100644--- a/agent/models_dev.py+++ b/agent/models_dev.py@@ -761,12 +761,27 @@ def _builtin_model_metadata(provider: str, model: str) -> Optional[Dict[str, Anyreturn _BUILTIN_MODEL_METADATA.get((provider_key, (model or "").strip().lower()))+def _relay_vision_marker_metadata(provider: str, model: str) -> Optional[Dict[str, Any]]:+ """Fill-gap base for an OpenCode Zen/Go ``*-vision*`` model id the catalog does not know. The relays+ resell vendor previews (``deepseek-v4-flash-vision-exp``) before models.dev indexes them, and the id's+ ``-vision`` token is the vendor's own capability marker; without it ``image_input_mode: auto`` treats+ the model as text-only and detours images through the lossy describe path (#96066). Every other field+ keeps the unknown-model defaults, so only vision is claimed."""+ from hermes_cli.models import opencode_provider_family++ if "-vision" not in (model or "").strip().lower() or opencode_provider_family(provider) is None:+ return None+ return {**_UNKNOWN_MODEL_BASE, "modalities": {"input": ["text", "image"], "output": ["text"]}}++def _apply_overrides(provider: str, model: str, entry: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]:"""*entry* patched by its override; ``_UNKNOWN_MODEL_BASE`` patched by a fill-gap override on acatalog miss (selected AFTER lookup: _default only fills misses); None when neither exists."""builtin = _builtin_model_metadata(provider, model)base = entry if entry is not None else builtinoverride = _override_for(provider, model, catalog_hit=base is not None)+ if base is None:+ base = _relay_vision_marker_metadata(provider, model)return base if override is None else _merge_catalog_entry_with_override(base if base is not None else _UNKNOWN_MODEL_BASE, override)diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.pyindex 402c44438e4..90486834514 100644--- a/hermes_cli/model_switch.py+++ b/hermes_cli/model_switch.py@@ -1569,6 +1569,17 @@ _PROVIDER_API_MODE_OVERRIDES: dict[str, Any] = {**dict.fromkeys(("nous", "nous-portal", "nousresearch"), _nous_api_mode)}+def model_derived_api_mode(provider: str, model: str, api_key: str = "") -> Optional[str]:+ """api_mode re-derived from the FINAL model for providers that serve several wire formats behind one+ endpoint (OpenCode Zen/Go and custom providers extending a family slug, Copilot, Nous); None when the+ provider's wire is fixed by its endpoint. A persisted api_mode from an earlier model of such a provider+ is never authoritative — resume paths must call this instead of honoring the row (#96066)."""+ from hermes_cli.models import opencode_provider_family+ key = str(provider or "").strip().lower()+ override = _PROVIDER_API_MODE_OVERRIDES.get(opencode_provider_family(key) or key)+ return override(key, model, api_key) if override is not None else None++def _build_switch_result(st: _Switch) -> ModelSwitchResult:"""COMMON PATH part 3: final api_mode / base_url shaping, metadata, warnings."""override = _PROVIDER_API_MODE_OVERRIDES.get(st.target_provider)diff --git a/tests/agent/test_models_dev.py b/tests/agent/test_models_dev.pyindex eae6ce2253c..4a20cffe76c 100644--- a/tests/agent/test_models_dev.py+++ b/tests/agent/test_models_dev.py@@ -1491,3 +1491,26 @@ class TestOpenRouterRoutingVariantCatalogLookup:with patch("agent.models_dev.fetch_models_dev", return_value=self.REGISTRY):assert lookup_models_dev_context("openrouter", "z-ai/glm-5.2:free") == 256000assert lookup_models_dev_context("openrouter", "z-ai/glm-5.3-flash:free") is None+++class TestOpencodeRelayVisionMarker:+ """#96066: an OpenCode Zen/Go ``*-vision*`` model id the catalog does not know is still vision-capable,+ so ``image_input_mode: auto`` attaches native pixels; everything else about it stays unknown."""++ @pytest.mark.parametrize("provider", ["opencode-go", "opencode-zen", "opencode-go-bridge"])+ def test_vision_marker_fills_the_catalog_gap_for_opencode_family(self, provider):+ with patch("agent.models_dev.fetch_models_dev", return_value={}):+ caps = get_model_capabilities(provider, "deepseek-v4-flash-vision-exp")+ assert caps is not None and caps.supports_vision is True+ assert caps.supports_reasoning is None # only vision is claimed++ def test_marker_needs_the_family_and_catalog_data_stays_authoritative(self):+ registry = {"opencode-go": {"id": "opencode-go", "models": {+ "deepseek-v4-flash-vision-exp": {"id": "deepseek-v4-flash-vision-exp", "modalities": {"input": ["text"]},+ "limit": {"context": 500000}}}}}+ with patch("agent.models_dev.fetch_models_dev", return_value={}):+ assert get_model_capabilities("opencode-go", "deepseek-v4-flash") is None+ assert get_model_capabilities("deepseek", "some-vision-model") is None+ with patch("agent.models_dev.fetch_models_dev", return_value=registry):+ caps = get_model_capabilities("opencode-go", "deepseek-v4-flash-vision-exp")+ assert caps.supports_vision is False and caps.context_window == 500000diff --git a/tests/tui_gateway/test_make_agent_provider.py b/tests/tui_gateway/test_make_agent_provider.pyindex bdeefbb27c2..4108bb2596c 100644--- a/tests/tui_gateway/test_make_agent_provider.py+++ b/tests/tui_gateway/test_make_agent_provider.py@@ -140,3 +140,28 @@ def test_apply_model_switch_does_not_leak_process_env():# Sibling session is completely untouched.assert sess_a["model_override"] is Noneassert sess_a["agent"].model == "minimax/m3"+++def test_resumed_row_cannot_pin_stale_wire_onto_per_model_provider():+ """#96066: a persisted opencode-go row written while the session ran an anthropic_messages model must not+ route deepseek-v4-flash-vision-exp through the Anthropic wire or the other family's relay URL on resume;+ the route is re-derived from the target model. Fixed-wire providers keep honoring their row."""+ from tui_gateway import server++ def fake_resolve(**kwargs):+ provider = kwargs["requested"]+ fresh = {"opencode-go": ("chat_completions", "https://opencode.ai/zen/go/v1"),+ "anthropic": ("anthropic_messages", "https://api.anthropic.com")}[provider]+ return {"provider": provider, "requested_provider": provider, "api_mode": fresh[0], "base_url": fresh[1],+ "api_key": "k", "source": "config"}++ with patch("hermes_cli.runtime_provider.resolve_runtime_provider", side_effect=fake_resolve):+ for stale_url in ("https://opencode.ai/zen/go", "https://opencode.ai/zen/v1"):+ _, runtime = server._resolve_agent_model_runtime(+ {"model": "deepseek-v4-flash-vision-exp", "provider": "opencode-go",+ "base_url": stale_url, "api_mode": "anthropic_messages"}, None)+ assert (runtime["api_mode"], runtime["base_url"]) == ("chat_completions", "https://opencode.ai/zen/go/v1")+ _, runtime = server._resolve_agent_model_runtime(+ {"model": "claude-opus-4-6", "provider": "anthropic",+ "base_url": "https://my-proxy.example", "api_mode": "anthropic_messages"}, None)+ assert (runtime["api_mode"], runtime["base_url"]) == ("anthropic_messages", "https://my-proxy.example")diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex 40bf6bcb17b..80f6cef4f96 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -2270,9 +2270,26 @@ def _resolve_agent_model_runtime(model_override, provider_override) -> tuple[str# Live supervisor beat any persisted loopback URL for this identity.overrides.pop("base_url", None)resolution.runtime.update({k: v for k, v in overrides.items() if v})+ if overrides:+ _rederive_per_model_route(model, resolution.runtime)return model, resolution.runtime+def _rederive_per_model_route(model: str, runtime: dict) -> None:+ """A row's persisted api_mode/base_url were written for whichever model the session last ran. Providers+ that pick the wire per model (OpenCode Zen/Go, Copilot, Nous) must re-derive both from the target model,+ or a resumed opencode-go session keeps a MiniMax-era anthropic_messages route (and its /v1-stripped or+ other-family relay URL) for a chat_completions model like deepseek-v4-flash-vision-exp (#96066)."""+ from hermes_cli.model_switch import model_derived_api_mode+ from hermes_cli.models import normalize_opencode_base_url+ provider = str(runtime.get("requested_provider") or runtime.get("provider") or "")+ api_mode = model_derived_api_mode(provider, model)+ if api_mode is None:+ return+ runtime["api_mode"] = api_mode+ runtime["base_url"] = normalize_opencode_base_url(provider, api_mode, runtime.get("base_url"))++def _startup_system_prompt(cfg: dict, task_id: str) -> str:"""Config ephemeral system prompt + HERMES_TUI_SKILLS preload block. Hard-fails only when EVERY requestedskill is missing (cli.py parity): a typo'd name must not auto-block the Kanban task."""