Skip to content

The agent that grows with you

feat(providers): plugin-declared per-model capability metadata

Ayush Nangiaef0bac6cdd07
diff --git a/agent/models_dev.py b/agent/models_dev.py
index 097fd12704d..cae177db83c 100644
--- a/agent/models_dev.py
+++ b/agent/models_dev.py
@@ -588,6 +588,9 @@ def lookup_models_dev_context(provider: str, model: str, *, allow_network: bool
override_ctx = _override_context_window(provider, model)
if override_ctx is not None:
return override_ctx
+ declared_ctx = _override_int(_provider_model_capabilities(provider, model), "context_window")
+ if declared_ctx is not None:
+ return declared_ctx
models = _get_provider_models(provider, allow_network=allow_network)
catalog_ctx = next((ctx for _mid, entry in _iter_model_entries(models, model, provider=provider) if (ctx := _extract_context(entry))), None) if models is not None else None
return catalog_ctx if catalog_ctx is not None else _default_override_context(provider)
@@ -774,11 +777,25 @@ def _relay_vision_marker_metadata(provider: str, model: str) -> Optional[Dict[st
return {**_UNKNOWN_MODEL_BASE, "modalities": {"input": ["text", "image"], "output": ["text"]}}
+def _provider_model_capabilities(provider: str, model: str) -> Dict[str, Any]:
+ """Exact-model declaration from the registered ``ProviderProfile.model_capabilities`` (canonical
+ ``model_overrides`` schema). The ONE plugin seam: every consumer that reads models.dev through this
+ module (picker badges, image routing, ``/api/model/info``, context lookup) sees it (#102115)."""
+ from providers import get_provider_profile
+
+ profile = get_provider_profile(provider)
+ return profile.model_capabilities.get(model, {}) if profile is not None else {}
+
+
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."""
+ """Catalog/builtin metadata, patched by the plugin's declaration, then by the explicit user override.
+ ``_UNKNOWN_MODEL_BASE`` is the base on a catalog miss; a fill-gap ``_default`` applies only when no
+ source knows the model. None when nothing knows it."""
builtin = _builtin_model_metadata(provider, model)
base = entry if entry is not None else builtin
+ declared = _provider_model_capabilities(provider, model)
+ if declared:
+ base = _merge_catalog_entry_with_override(base if base is not None else _UNKNOWN_MODEL_BASE, declared)
override = _override_for(provider, model, catalog_hit=base is not None)
if base is None:
base = _relay_vision_marker_metadata(provider, model)
diff --git a/providers/base.py b/providers/base.py
index 45b4c6664b0..6f780584d21 100644
--- a/providers/base.py
+++ b/providers/base.py
@@ -126,6 +126,10 @@ class ProviderProfile:
)
# empty = use main model
+ # Per-model metadata in the canonical model_overrides schema. Partial entries
+ # patch catalog metadata; explicit user overrides still win. Exact model IDs.
+ model_capabilities: dict[str, dict[str, Any]] = field(default_factory=dict)
+
# ── Hooks (override in subclass for complex providers) ───
def fetch_account_usage(
diff --git a/tests/agent/test_models_dev_provider_capabilities.py b/tests/agent/test_models_dev_provider_capabilities.py
new file mode 100644
index 00000000000..0c790e6a9c5
--- /dev/null
+++ b/tests/agent/test_models_dev_provider_capabilities.py
@@ -0,0 +1,116 @@
+"""Plugin-distributed model metadata (#102115), without user config edits."""
+
+from copy import deepcopy
+import json
+import os
+from pathlib import Path
+import subprocess
+import sys
+
+import providers
+from providers.base import ProviderProfile
+from agent import models_dev
+
+
+def test_plugin_metadata_resolves_without_catalog_and_user_override_wins(monkeypatch, tmp_path):
+ monkeypatch.setattr(providers, "_REGISTRY", {})
+ monkeypatch.setattr(providers, "_ALIASES", {})
+ monkeypatch.setattr(providers, "_discovered", True)
+ monkeypatch.setattr(models_dev, "_registry_models", lambda *a, **k: None)
+ overrides = {}
+ monkeypatch.setattr(models_dev, "_load_model_overrides", lambda: overrides)
+ declaration = {"tier-high": {"supports_reasoning": False, "supports_vision": True,
+ "supports_tools": True, "context_window": 64000}}
+ original = deepcopy(declaration)
+ providers.register_provider(ProviderProfile(
+ name="fixture-provider", aliases=("fixture-alias",), model_capabilities=declaration))
+
+ for name in ("fixture-provider", "fixture-alias"):
+ caps = models_dev.get_model_capabilities(name, "tier-high")
+ info = models_dev.get_model_info(name, "tier-high")
+ assert caps.supports_reasoning is False
+ assert caps.supports_vision is True
+ assert caps.supports_tools is True
+ assert caps.context_window == info.context_window == 64000
+ assert info.reasoning is False
+ assert models_dev.lookup_models_dev_context(name, "tier-high") == 64000
+ assert models_dev.get_model_capabilities(name, "undeclared") is None
+
+ overrides["fixture-provider"] = {"tier-high": {"supports_reasoning": True}}
+ caps = models_dev.get_model_capabilities("fixture-provider", "tier-high")
+ assert caps.supports_reasoning is True
+ assert caps.supports_vision is True
+ assert caps.context_window == 64000
+ overrides["_default"] = {"context_window": 8000}
+ assert models_dev.lookup_models_dev_context("fixture-provider", "tier-high") == 64000
+ overrides["fixture-provider"]["tier-high"]["context_window"] = 96000
+ assert models_dev.lookup_models_dev_context("fixture-provider", "tier-high") == 96000
+ assert declaration == original
+
+ # Fresh interpreters exercise the real filesystem loader/config reader;
+ # monkeypatched registries above cannot leak into these consumers.
+ home = tmp_path / "profile"
+ plugin = home / "plugins" / "model-providers" / "fixture-provider"
+ plugin.mkdir(parents=True)
+ (plugin / "__init__.py").write_text(
+ "from providers import register_provider\n"
+ "from providers.base import ProviderProfile\n"
+ "register_provider(ProviderProfile(name='fixture-provider', "
+ "aliases=('fixture-alias',), model_capabilities=" + repr(original) + "))\n"
+ )
+ probe = (
+ "import json\n"
+ "from agent.models_dev import get_model_capabilities, lookup_models_dev_context\n"
+ "from hermes_cli.config import load_config_readonly\n"
+ "cfg = load_config_readonly()['model']\n"
+ "p, m = cfg['provider'], cfg['default']\n"
+ "caps = get_model_capabilities(p, m)\n"
+ "print(json.dumps([caps.supports_reasoning, caps.supports_vision, "
+ "caps.context_window, lookup_models_dev_context(p, m)]))\n"
+ )
+ env = {"HOME": str(tmp_path), "HERMES_HOME": str(home), "PATH": os.defpath,
+ "PYTHONIOENCODING": "utf-8"}
+ for provider, patch, expected in (
+ ("fixture-provider", {"_default": {"context_window": 8000}}, [False, True, 64000, 64000]),
+ ("fixture-alias", {}, [False, True, 64000, 64000]),
+ ("fixture-alias", {"fixture-alias": {"tier-high": {
+ "supports_reasoning": True, "context_window": 96000}}}, [True, True, 96000, 96000]),
+ ):
+ # JSON is valid YAML; no third-party serializer needed for the fixture.
+ (home / "config.yaml").write_text(json.dumps({
+ "model": {"provider": provider, "default": "tier-high"},
+ "model_overrides": patch,
+ }))
+ result = subprocess.run(
+ [sys.executable, "-c", probe], cwd=Path(__file__).resolve().parents[2],
+ env=env, capture_output=True, text=True, timeout=30,
+ )
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert json.loads(result.stdout.splitlines()[-1]) == expected
+
+
+def test_partial_plugin_metadata_preserves_unknowns_and_catalog_fields(monkeypatch):
+ monkeypatch.setattr(providers, "_REGISTRY", {})
+ monkeypatch.setattr(providers, "_ALIASES", {})
+ monkeypatch.setattr(providers, "_discovered", True)
+ catalog = {"known": {"reasoning": True, "tool_call": True,
+ "limit": {"context": 32000, "output": 4000},
+ "modalities": {"input": ["text", "image"]}}}
+ original = deepcopy(catalog)
+ monkeypatch.setitem(models_dev.PROVIDER_TO_MODELS_DEV, "fixture-provider", "fixture-provider")
+ monkeypatch.setattr(models_dev, "_registry_models", lambda *a, **k: catalog)
+ monkeypatch.setattr(models_dev, "_load_model_overrides", lambda: {})
+ providers.register_provider(ProviderProfile(name="fixture-provider", model_capabilities={
+ "known": {"context_window": 64000},
+ "unknown": {"context_window": 48000},
+ }))
+ known = models_dev.get_model_capabilities("fixture-provider", "known")
+ assert known.context_window == 64000
+ assert known.max_output_tokens == 4000
+ assert known.supports_reasoning is True
+ assert known.supports_vision is True
+ unknown = models_dev.get_model_capabilities("fixture-provider", "unknown")
+ assert unknown.context_window == 48000
+ assert unknown.supports_reasoning is None
+ assert unknown.supports_vision is None
+ assert catalog == original
diff --git a/website/docs/developer-guide/model-provider-plugin.md b/website/docs/developer-guide/model-provider-plugin.md
index b879ae81de5..14002d4f4d5 100644
--- a/website/docs/developer-guide/model-provider-plugin.md
+++ b/website/docs/developer-guide/model-provider-plugin.md
@@ -17,7 +17,7 @@ Model provider plugins are the third kind of **provider plugin**. The others are
`providers/__init__.py._discover_providers()` runs lazily the first time any code calls `get_provider_profile()` or `list_providers()`. Discovery order:
1. **Bundled plugins** — `<repo>/plugins/model-providers/<name>/` — ship with Hermes
-2. **User plugins** — `$HERMES_HOME/plugins/model-providers/<name>/` — drop in any directory; no restart required for subsequent sessions
+2. **User plugins** — `$HERMES_HOME/plugins/model-providers/<name>/` — drop in a directory; restart an already-running Hermes process to discover it
3. **Installed plugins** — `$HERMES_HOME/plugins/<name>/` (where `hermes plugins install owner/repo` clones) — imported only when `plugin.yaml` declares `kind: model-provider`; every other kind there belongs to the general PluginManager
4. **Legacy single-file** — `<repo>/providers/<name>.py` — back-compat for out-of-tree editable installs
@@ -110,6 +110,50 @@ Full definition in `providers/base.py`. The most useful ones:
| `unsupported_response_formats` | `tuple` | `response_format` types the API rejects outright; auxiliary requests omit them instead of paying a guaranteed 400 (DeepSeek: `("json_schema",)`) |
| `default_aux_model` | str | Cheap model for auxiliary tasks (compression, vision, summarization) |
+## Declaring model capabilities
+
+Hermes resolves per-model capabilities (`supports_reasoning`, `supports_vision`,
+`supports_tools`, `context_window`) from the models.dev catalog, which does not
+know an out-of-tree provider's models. Declare them once on the profile:
+
+```python
+register_provider(ProviderProfile(
+ name="acme",
+ auth_type="api_key",
+ env_vars=("ACME_API_KEY",),
+ base_url="https://api.acme.example/v1",
+ fallback_models=("acme-large-high", "acme-small"),
+ model_capabilities={
+ "acme-large-high": {
+ "supports_reasoning": False, # reasoning tier is fixed by the model id
+ "supports_vision": True,
+ "supports_tools": True,
+ "context_window": 64000,
+ "model_family": "acme",
+ },
+ },
+))
+```
+
+Keys are exact model IDs. Values use the `model_overrides` schema from
+`config.yaml` — the three capability booleans, a positive `context_window`, an
+optional `model_family` — and omitted fields stay unknown (not `False`), so a
+partial entry patches catalog metadata without erasing it.
+
+One declaration feeds every consumer that reads the catalog through
+`agent.models_dev`: the `/model` picker's `reasoning` badge, image routing
+(`decide_image_input_mode` goes `native` for a `supports_vision: True` model
+even when the profile-wide `supports_vision` is unset), context-window lookup,
+and the dashboard's `/api/model/info`. Precedence: explicit user
+`model_overrides.<provider>.<model>` → plugin declaration → catalog → fill-gap
+`_default`. Models the plugin does not declare keep the catalog/heuristic path.
+
+Not covered: the picker's `fast` badge (a model-name heuristic in
+`hermes_cli/models.py::model_supports_fast_mode`), reasoning-effort vocabulary
+(`agent/reasoning_effort.py`), and transport request fields. Declarations do not
+add models to a picker — use `fallback_models` / `fetch_models` for that. The
+registry is discovered once per process: restart Hermes after editing them.
+
## Overridable hooks
Subclass `ProviderProfile` for non-trivial quirks:
@@ -250,7 +294,7 @@ register_provider(ProviderProfile(
))
```
-Next session, `get_provider_profile("gmi").base_url` returns the staging URL. No repo patch, no rebuild. Because user plugins are discovered after bundled ones, the user `register_provider()` call wins.
+In a fresh Hermes process, `get_provider_profile("gmi").base_url` returns the staging URL. No repo patch, no rebuild. Because user plugins are discovered after bundled ones, the user `register_provider()` call wins.
## api_mode selection