Skip to content

The agent that grows with you

fix(model): preserve unknown custom capabilities

KoNit-K24e4d442d924
diff --git a/agent/image_routing.py b/agent/image_routing.py
index 099c6d9014b..949a46da527 100644
--- a/agent/image_routing.py
+++ b/agent/image_routing.py
@@ -287,7 +287,7 @@ def _probe_models_dev(provider: str, model: str, cfg: Optional[Dict[str, Any]])
# historical network-on-cold-cache behavior for this one path; the fetch is cached (4h TTL) and
# backoff-limited after failures.
caps = get_model_capabilities(provider, model, allow_network=True)
- return None if caps is None else bool(caps.supports_vision)
+ return None if caps is None else caps.supports_vision
def _probe_ollama(provider: str, model: str, cfg: Optional[Dict[str, Any]]) -> Optional[bool]:
diff --git a/agent/models_dev.py b/agent/models_dev.py
index 6b6b4d1e501..53f11129cfc 100644
--- a/agent/models_dev.py
+++ b/agent/models_dev.py
@@ -99,8 +99,8 @@ class ProviderInfo:
class ModelCapabilities:
"""Structured capability metadata for a model from models.dev."""
supports_tools: bool = True
- supports_vision: bool = False
- supports_reasoning: bool = False
+ supports_vision: Optional[bool] = None
+ supports_reasoning: Optional[bool] = None
context_window: int = 200000
max_output_tokens: int = 8192
model_family: str = ""
@@ -565,8 +565,8 @@ def lookup_models_dev_context(provider: str, model: str, *, allow_network: bool
# or models.dev id; model ids match exactly, then case-insensitively (mirroring catalog lookup).
# Resolution semantics: 1. 2. See #84482, #8731.
_OVERRIDE_WARNED_KEYS: set = set()
-# Safe defaults for models absent from the catalog (tools on, vision/reasoning off, 200K context);
-# shared by get_model_capabilities and get_model_info so the two unknown-model paths agree.
+# Safe defaults for models absent from the catalog (tools on, 200K context). Capability fields stay
+# absent so get_model_capabilities can preserve their unknown/fail-open semantics.
_UNKNOWN_MODEL_BASE: Dict[str, Any] = {"limit": {"context": 200000, "output": 8192}, "tool_call": True}
# Account-gated models may be usable before models.dev has indexed them. Keep
@@ -719,11 +719,16 @@ def _merge_catalog_entry_with_override(raw: Dict[str, Any], override: Dict[str,
return merged
+def _builtin_model_metadata(provider: str, model: str) -> Optional[Dict[str, Any]]:
+ """Built-in metadata for a provider/model pair, if Hermes has a vendor-specific entry."""
+ provider_key = PROVIDER_TO_MODELS_DEV.get((provider or "").strip(), (provider or "").strip())
+ return _BUILTIN_MODEL_METADATA.get((provider_key, (model or "").strip().lower()))
+
+
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 a
catalog miss (selected AFTER lookup: _default only fills misses); None when neither exists."""
- provider_key = PROVIDER_TO_MODELS_DEV.get((provider or "").strip(), (provider or "").strip())
- builtin = _BUILTIN_MODEL_METADATA.get((provider_key, (model or "").strip().lower()))
+ builtin = _builtin_model_metadata(provider, model)
base = entry if entry is not None else builtin
override = _override_for(provider, model, catalog_hit=base is not None)
return base if override is None else _merge_catalog_entry_with_override(base if base is not None else _UNKNOWN_MODEL_BASE, override)
@@ -748,13 +753,18 @@ def get_model_capabilities(provider: str, model: str, *, allow_network: bool = F
"""
models = _get_provider_models(provider, allow_network=allow_network)
entry = _find_model_entry(models, model, provider) if models is not None else None
+ unknown_base = entry is None and _builtin_model_metadata(provider, model) is None
raw = _apply_overrides(provider, model, entry)
if raw is None:
return None
return ModelCapabilities(
supports_tools=bool(raw.get("tool_call", False)),
- supports_vision=_entry_supports_vision(raw),
- supports_reasoning=bool(raw.get("reasoning", False)),
+ supports_vision=(
+ None
+ if unknown_base and "attachment" not in raw and "modalities" not in raw
+ else _entry_supports_vision(raw)
+ ),
+ supports_reasoning=None if unknown_base and "reasoning" not in raw else bool(raw.get("reasoning", False)),
context_window=_extract_limit(raw, "context") or 200000,
max_output_tokens=_extract_limit(raw, "output") or 8192,
model_family=raw.get("family", "") or "",
diff --git a/hermes_cli/inventory.py b/hermes_cli/inventory.py
index 2d4f80047ff..6fea7326f0c 100644
--- a/hermes_cli/inventory.py
+++ b/hermes_cli/inventory.py
@@ -291,8 +291,8 @@ def _apply_capabilities(rows: list[dict]) -> None:
if get_model_capabilities is not None and slug:
try:
meta = get_model_capabilities(slug, model)
- if meta is not None:
- reasoning = bool(meta.supports_reasoning)
+ if meta is not None and meta.supports_reasoning is not None:
+ reasoning = meta.supports_reasoning
except Exception:
reasoning = True
diff --git a/hermes_cli/main_provider_setup.py b/hermes_cli/main_provider_setup.py
index b44c02a0f5f..2e43ed76f4a 100644
--- a/hermes_cli/main_provider_setup.py
+++ b/hermes_cli/main_provider_setup.py
@@ -665,7 +665,7 @@ def _main_model_reasoning_efforts(model: str, provider: str) -> Optional[list[st
meta = get_model_capabilities(slug, model)
except Exception:
meta = None
- if meta is not None and not meta.supports_reasoning:
+ if meta is not None and meta.supports_reasoning is False:
return None
return list(VALID_REASONING_EFFORTS)
@@ -943,4 +943,4 @@ def _build_provider_picker_rows(config: dict, active: str, provider_labels: dict
ordered.append(("reasoning", "Reasoning effort for the current model...", []))
ordered.append(("aux-config", "Configure auxiliary models...", []))
ordered.append(("cancel", "Leave unchanged", []))
- return ordered, default_idx
\ No newline at end of file
+ return ordered, default_idx
diff --git a/tests/agent/test_image_routing.py b/tests/agent/test_image_routing.py
index f545909e1fa..3a3aa9fd694 100644
--- a/tests/agent/test_image_routing.py
+++ b/tests/agent/test_image_routing.py
@@ -158,6 +158,11 @@ class TestLookupSupportsVisionOverride:
with patch("agent.models_dev.get_model_capabilities", return_value=fake_caps):
assert _lookup_supports_vision("anthropic", "claude-sonnet-4", {}) is True
+ def test_models_dev_unknown_capability_stays_fail_open(self):
+ fake_caps = type("Caps", (), {"supports_vision": None})()
+ with patch("agent.models_dev.get_model_capabilities", return_value=fake_caps):
+ assert _lookup_supports_vision("custom-gateway", "upstream-model", {}) is None
+
def test_ollama_probe_when_models_dev_missing(self):
cfg = {"model": {"base_url": "http://localhost:11434/v1"}}
diff --git a/tests/agent/test_models_dev.py b/tests/agent/test_models_dev.py
index 180fdac8456..d926f14c9f2 100644
--- a/tests/agent/test_models_dev.py
+++ b/tests/agent/test_models_dev.py
@@ -1063,6 +1063,35 @@ class TestModelOverrides:
assert caps.supports_reasoning is False
assert caps.supports_tools is True
+ def test_context_only_override_keeps_unknown_capabilities_unknown(self):
+ """A metadata-only custom-provider override must not claim text-only.
+
+ Unknown is fail-open for the vision and reasoning callers; only an
+ explicit capability override may turn either verdict into ``False``.
+ """
+ overrides = {
+ "custom-gateway": {
+ "upstream-model": {"context_window": 1_000_000},
+ "text-model": {
+ "context_window": 1_000_000,
+ "supports_vision": False,
+ "supports_reasoning": False,
+ },
+ },
+ }
+ with self._setup_overrides(overrides), \
+ patch("agent.models_dev.fetch_models_dev", return_value={}):
+ unknown = get_model_capabilities("custom-gateway", "upstream-model")
+ explicit_false = get_model_capabilities("custom-gateway", "text-model")
+
+ assert unknown is not None
+ assert unknown.context_window == 1_000_000
+ assert unknown.supports_vision is None
+ assert unknown.supports_reasoning is None
+ assert explicit_false is not None
+ assert explicit_false.supports_vision is False
+ assert explicit_false.supports_reasoning is False
+
def test_caps_override_patches_existing_catalog_entry(self):
"""Explicit override patches specific fields on a known entry (#84482)."""
overrides = {
diff --git a/tools/computer_use/vision_routing.py b/tools/computer_use/vision_routing.py
index 52c66322900..2c6b72461f0 100644
--- a/tools/computer_use/vision_routing.py
+++ b/tools/computer_use/vision_routing.py
@@ -45,7 +45,7 @@ def _models_dev_supports_vision(provider: str, model: str, cfg: Optional[Dict[st
"""Raw models.dev capability lookup — fallback when ``agent.image_routing`` is unavailable."""
from agent.models_dev import get_model_capabilities
caps = get_model_capabilities(provider, model)
- return None if caps is None else bool(getattr(caps, "supports_vision", False))
+ return None if caps is None else caps.supports_vision
def _lookup_supports_vision(provider: str, model: str, cfg: Optional[Dict[str, Any]] = None) -> Optional[bool]:
"""Config/models.dev ``supports_vision`` for *(provider, model)*; prefers