The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(models): custom providers can inherit a vendor catalog; unknown models get no synthesized output cap
teknium1d1c6786d1e19
diff --git a/agent/models_dev.py b/agent/models_dev.pyindex 53f11129cfc..cefa0774d37 100644--- a/agent/models_dev.py+++ b/agent/models_dev.py@@ -102,7 +102,7 @@ class ModelCapabilities:supports_vision: Optional[bool] = Nonesupports_reasoning: Optional[bool] = Nonecontext_window: int = 200000- max_output_tokens: int = 8192+ max_output_tokens: Optional[int] = Nonemodel_family: str = ""@@ -150,6 +150,34 @@ def _dict_or_empty(value: Any) -> Dict[str, Any]:return value if isinstance(value, dict) else {}+def _configured_catalog_provider(provider: str) -> Optional[str]:+ """``catalog_provider`` declared on a custom provider's ``providers.<name>`` row (or legacy+ ``custom_providers[]`` entry): the catalogued vendor whose models it resells. None when unset."""+ name = (provider or "").strip()+ if name.lower().startswith("custom:"):+ name = name[len("custom:"):]+ if not name or name in PROVIDER_TO_MODELS_DEV:+ return None+ alias = _dict_or_empty(_cfg_get("providers", name, default=None)).get("catalog_provider")+ if not alias:+ legacy = _cfg_get("custom_providers", default=None)+ alias = next((e.get("catalog_provider") for e in (legacy if isinstance(legacy, list) else [])+ if isinstance(e, dict) and str(e.get("name") or "").strip() == name), None)+ alias = str(alias or "").strip()+ return alias or None+++def _models_dev_id(provider: str) -> Optional[str]:+ """models.dev provider id for a Hermes provider id, or None. A custom provider reaches the+ catalog only through its configured ``catalog_provider`` alias (#112649)."""+ key = (provider or "").strip()+ mdev_id = PROVIDER_TO_MODELS_DEV.get(key)+ if mdev_id is None:+ alias = _configured_catalog_provider(key)+ mdev_id = PROVIDER_TO_MODELS_DEV.get(alias, alias) if alias else None+ return mdev_id++def _cfg_get(*keys: str, default: Any) -> Any:"""``cfg_get`` over the read-only config; *default* on any failure."""try:@@ -462,7 +490,7 @@ def _registry_models(mdev_id: str, *, allow_network: bool) -> Optional[Dict[str,def _get_provider_models(provider: str, *, allow_network: bool = False) -> Optional[Dict[str, Any]]:"""Resolve a Hermes provider ID to its models dict, or None if unknown.``allow_network`` defaults to False — hot-path callers must never block."""- mdev_id = PROVIDER_TO_MODELS_DEV.get(provider)+ mdev_id = _models_dev_id(provider)return _registry_models(mdev_id, allow_network=allow_network) if mdev_id else None@@ -565,9 +593,9 @@ 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, 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}+# Safe defaults for models absent from the catalog (tools on, 200K context). Capability fields and the+# output limit stay absent so consumers see them as unknown instead of a synthesized value.+_UNKNOWN_MODEL_BASE: Dict[str, Any] = {"limit": {"context": 200000}, "tool_call": True}# Account-gated models may be usable before models.dev has indexed them. Keep# their capabilities available for an explicitly selected/discovered model@@ -721,7 +749,7 @@ def _merge_catalog_entry_with_override(raw: Dict[str, Any], override: Dict[str,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())+ provider_key = _models_dev_id(provider) or (provider or "").strip()return _BUILTIN_MODEL_METADATA.get((provider_key, (model or "").strip().lower()))@@ -766,7 +794,7 @@ def get_model_capabilities(provider: str, model: str, *, allow_network: bool = F),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,+ max_output_tokens=_extract_limit(raw, "output"),model_family=raw.get("family", "") or "",)@@ -843,7 +871,7 @@ def _parse_provider_info(provider_id: str, raw: Dict[str, Any]) -> ProviderInfo:def get_provider_info(provider_id: str, *, allow_network: bool = True) -> Optional[ProviderInfo]:"""Provider metadata by Hermes or models.dev ID, or None if not cataloged. ``allow_network`` defaults to True (interactive setup)."""- mdev_id = PROVIDER_TO_MODELS_DEV.get(provider_id, provider_id)+ mdev_id = _models_dev_id(provider_id) or provider_idraw = _registry_provider(mdev_id, allow_network)return _parse_provider_info(mdev_id, raw) if raw is not None else None@@ -858,7 +886,7 @@ def get_model_info(provider_id: str, model_id: str, *, allow_network: bool = Falthis boundary, and sub-dicts (``limit``, ``modalities``) are merged rather than clobbered. See #84482,#8731."""- mdev_id = PROVIDER_TO_MODELS_DEV.get(provider_id, provider_id)+ mdev_id = _models_dev_id(provider_id) or provider_idmodels = _registry_models(mdev_id, allow_network=allow_network)mid, entry = next(_iter_model_entries(models, model_id, suffix_fallback=False, provider=provider_id), (model_id, None)) if models is not None else (model_id, None)# Not in catalog — an override (explicit or _default) may still provide it.diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 8594bf93a53..9a02f6cde0b 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -1094,7 +1094,7 @@ _KNOWN_ROOT_KEYS = frozenset(DEFAULT_CONFIG.keys()) | _EXTRA_KNOWN_ROOT_KEYS_VALID_CUSTOM_PROVIDER_FIELDS = {"name", "base_url", "api_key", "api_mode", "model", "models","context_length", "rate_limit_delay", "extra_body",- "ssl_ca_cert", "ssl_verify", "key_env"}+ "ssl_ca_cert", "ssl_verify", "key_env", "catalog_provider"}# Fields that look like they should be inside custom_providers, not at root_CUSTOM_PROVIDER_LIKE_FIELDS = {"base_url", "api_key", "rate_limit_delay", "api_mode"}diff --git a/hermes_cli/config_providers.py b/hermes_cli/config_providers.pyindex 80f07823e43..e3fe82769ad 100644--- a/hermes_cli/config_providers.py+++ b/hermes_cli/config_providers.py@@ -117,7 +117,8 @@ _KNOWN_PROVIDER_KEYS = {"name", "api", "url", "base_url", "api_key", "key_env", "api_key_env", "key_cmd","api_mode", "transport", "model", "default_model", "models", "models_discovered","context_length", "rate_limit_delay", "request_timeout_seconds", "stale_timeout_seconds",- "discover_models", "extra_body", "extra_headers", "capabilities", "ssl_ca_cert", "ssl_verify"}+ "discover_models", "extra_body", "extra_headers", "capabilities", "ssl_ca_cert", "ssl_verify",+ "catalog_provider"}def _pick_provider_base_url(entry: Dict[str, Any], provider_key: str) -> str:@@ -238,6 +239,8 @@ def _normalize_custom_provider_entry(api_mode = _stripped("api_mode", "transport")_put("api_mode", _canonical_api_mode(api_mode) if api_mode else "")_put("model", _stripped("model", "default_model"))+ # Catalogued vendor whose models this endpoint resells (metadata lookups only, never routing).+ _put("catalog_provider", _stripped("catalog_provider"))# ``models_discovered`` marks a mapping auto-discovered by Hermes, not hand-curated.models_dict, discovered = _normalize_provider_models(entry.get("models"))@@ -285,7 +288,7 @@ def _custom_provider_entry_to_provider_config(for field in ("name", "api_key", "key_env", "key_cmd", "models", "models_discovered", "context_length","rate_limit_delay", "discover_models", "extra_body", "extra_headers",- "ssl_ca_cert", "ssl_verify"):+ "ssl_ca_cert", "ssl_verify", "catalog_provider"):if field in normalized:provider_entry[field] = normalized[field]if "model" in normalized:diff --git a/tests/agent/test_models_dev.py b/tests/agent/test_models_dev.pyindex d926f14c9f2..3b7a03d046c 100644--- a/tests/agent/test_models_dev.py+++ b/tests/agent/test_models_dev.py@@ -852,6 +852,66 @@ class TestGetModelCapabilities:assert alias is not None and alias.supports_vision is Trueassert pro is None+ def test_metadata_only_override_on_custom_provider_leaves_capabilities_unknown(self):+ """A custom provider's ``model_overrides`` entry that only corrects ``context_window`` must not+ synthesize an output cap or capability flags from the unknown-model template (#112649)."""+ overrides = {"925llm": {"deepseek-v4.1-flash": {"context_window": 1_000_000}}}+ with patch("agent.models_dev._load_model_overrides", return_value=overrides), \+ patch("agent.models_dev.fetch_models_dev", return_value={}):+ caps = get_model_capabilities("925llm", "deepseek-v4.1-flash")+ info = get_model_info("925llm", "deepseek-v4.1-flash")++ assert caps is not None+ assert caps.context_window == 1_000_000+ assert caps.max_output_tokens is None+ assert caps.supports_vision is None+ assert caps.supports_reasoning is None+ assert info is not None and info.max_output == 0+++class TestCatalogProviderAlias:+ """``providers.<name>.catalog_provider`` lets a custom provider inherit a catalogued vendor's+ model metadata (#112649)."""++ @staticmethod+ def _cfg(config):+ def _cfg_get(*keys, default=None):+ node = config+ for key in keys:+ if not isinstance(node, dict) or key not in node:+ return default+ node = node[key]+ return node+ return patch("agent.models_dev._cfg_get", side_effect=_cfg_get)++ def test_alias_reaches_builtin_and_catalog_metadata(self):+ config = {"providers": {"925llm": {"api": "http://gw.internal/v1", "catalog_provider": "deepseek"}}}+ registry = {"deepseek": {"id": "deepseek", "models": {+ "deepseek-chat": {"id": "deepseek-chat", "limit": {"context": 128000, "output": 8000},+ "tool_call": True, "reasoning": False,+ "modalities": {"input": ["text"], "output": ["text"]}}}}}+ with self._cfg(config), patch("agent.models_dev.fetch_models_dev", return_value=registry):+ builtin = get_model_capabilities("925llm", "deepseek-v4.1-flash")+ prefixed = get_model_capabilities("custom:925llm", "deepseek-v4.1-flash")+ catalog = get_model_capabilities("925llm", "deepseek-chat")+ ctx = lookup_models_dev_context("925llm", "deepseek-chat")+ info = get_model_info("925llm", "deepseek-chat")++ assert builtin is not None and builtin.supports_vision is True and builtin.max_output_tokens == 384_000+ assert prefixed == builtin+ assert catalog is not None and catalog.supports_vision is False and catalog.max_output_tokens == 8000+ assert ctx == 128000+ assert info is not None and info.provider_id == "deepseek" and info.context_window == 128000++ def test_without_alias_custom_provider_stays_unknown(self):+ """Control: no alias → no vendor inheritance, and a legacy ``custom_providers`` row can alias too."""+ config = {"providers": {"925llm": {"api": "http://gw.internal/v1"}},+ "custom_providers": [{"name": "legacy-gw", "base_url": "http://x/v1", "catalog_provider": "deepseek"}]}+ with self._cfg(config), patch("agent.models_dev.fetch_models_dev", return_value={}):+ assert get_model_capabilities("925llm", "deepseek-v4.1-flash") is None+ legacy = get_model_capabilities("legacy-gw", "deepseek-v4.1-flash")+ assert legacy is not None and legacy.supports_vision is True+# ---------------------------------------------------------------------------# Per-model metadata overrides (model_overrides config)@@ -1223,7 +1283,7 @@ class TestModelOverrides:assert info.family == "llava"assert info.context_window == 8192assert uncapped_info is not None- assert info.max_output == uncapped_info.max_output > 0+ assert info.max_output == uncapped_info.max_output == 0 # unknown model: no synthesized output capassert info.tool_call is Trueassert info.reasoning is False@@ -1344,7 +1404,7 @@ class TestModelOverrides:info = get_model_info("custom:my-vllm", "my-model")assert info is not Noneassert info.context_window == 200000- assert info.max_output == 8192+ assert info.max_output == 0 # unknown model: output limit is not synthesizedassert info.tool_call is Trueassert info.reasoning is Truediff --git a/tests/hermes_cli/test_provider_config_validation.py b/tests/hermes_cli/test_provider_config_validation.pyindex 892a8876c62..d853c432c88 100644--- a/tests/hermes_cli/test_provider_config_validation.py+++ b/tests/hermes_cli/test_provider_config_validation.py@@ -67,6 +67,16 @@ class TestNormalizeCustomProviderEntry:assert result is not Noneassert result["base_url"] == "${PROVIDER_A_BASE_URL}"+ def test_catalog_provider_is_a_known_key_and_survives_normalization(self, caplog):+ """``catalog_provider`` (vendor alias for metadata lookups, #112649) is accepted without an+ unknown-key warning and carried on the normalized entry."""+ entry = {"base_url": "https://gw.example.com/v1", "key_env": "GW_KEY", "catalog_provider": "deepseek"}+ with caplog.at_level(logging.WARNING):+ result = _normalize_custom_provider_entry(entry, provider_key="925llm")+ assert result is not None+ assert result["catalog_provider"] == "deepseek"+ assert not [r for r in caplog.records if "unknown config keys" in r.message.lower()]+def test_numeric_yaml_name_and_key_become_strings(self):"""Unquoted YAML `name: 2070` / key 2070 must not be dropped as non-str."""diff --git a/website/docs/integrations/providers.md b/website/docs/integrations/providers.mdindex 18d7fdca43f..a37c8c79ab2 100644--- a/website/docs/integrations/providers.md+++ b/website/docs/integrations/providers.md@@ -1340,7 +1340,7 @@ providers:transport: anthropic_messages # for Anthropic-compatible proxies```-Each entry accepts: `api` (the endpoint base URL — `base_url`/`url` are accepted aliases), `name` (optional display name; defaults to the dict key), `key_env` or inline `api_key` or `key_cmd` (see below), `transport` (`chat_completions` / `anthropic_messages` / `codex_responses`), `default_model`, `models`, `context_length`, `discover_models`, `extra_body`, `extra_headers`, `ssl_ca_cert` / `ssl_verify`, and `enabled: false` to hide an entry without deleting it.+Each entry accepts: `api` (the endpoint base URL — `base_url`/`url` are accepted aliases), `name` (optional display name; defaults to the dict key), `key_env` or inline `api_key` or `key_cmd` (see below), `transport` (`chat_completions` / `anthropic_messages` / `codex_responses`), `default_model`, `models`, `context_length`, `discover_models`, `extra_body`, `extra_headers`, `ssl_ca_cert` / `ssl_verify`, `catalog_provider` (see below), and `enabled: false` to hide an entry without deleting it.#### Command-minted credentials (`key_cmd`)@@ -1428,7 +1428,19 @@ model:The same key is honored on per-named-provider models (`providers.<name>.models.<id>.supports_vision`) and accepts standard YAML booleans (`true/false/yes/no/on/off/1/0`).-A `model_overrides` entry that only corrects metadata (for example `context_window`) for a model the catalog does not know leaves vision and reasoning capability **unknown** — `vision_analyze`, `video_analyze` and the reasoning-effort picker stay available. Only an explicit `supports_vision: false` / `supports_reasoning: false` in the override marks the model as text-only or non-reasoning.+A `model_overrides` entry that only corrects metadata (for example `context_window`) for a model the catalog does not know leaves vision and reasoning capability and the output-token limit **unknown** — `vision_analyze`, `video_analyze` and the reasoning-effort picker stay available. Only an explicit `supports_vision: false` / `supports_reasoning: false` in the override marks the model as text-only or non-reasoning.++**Inheriting a catalogued vendor's metadata (`catalog_provider`).** When a named custom provider (a gateway, proxy or reseller) serves models that Hermes already knows under a built-in provider, point the entry at that vendor and its models inherit the catalogued context window, output limit, vision and reasoning flags — no `model_overrides` needed:++```yaml+providers:+ my-gateway:+ api: https://gateway.example.com/v1+ key_env: GATEWAY_API_KEY+ catalog_provider: deepseek # metadata lookups use DeepSeek's catalog entries+```++`catalog_provider` accepts a Hermes provider id (`deepseek`, `anthropic`, `openai`, …) or a models.dev id. It affects metadata lookups only — requests still go to your `api` URL with your credentials — and an explicit `model_overrides` entry for the same model still wins.Switch between them mid-session with the triple syntax: