The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(local-runtime): vision capability answers from the server, not a cloud catalog
emozilla031b2264090c
diff --git a/agent/image_routing.py b/agent/image_routing.pyindex a3762fccd4a..17a0e2696f5 100644--- a/agent/image_routing.py+++ b/agent/image_routing.py@@ -429,6 +429,28 @@ def _lookup_supports_vision(return overrideif not provider or not model:return None++ # Managed local runtime: the server that would receive the image is+ # the authority on whether it can see (its /props reports modalities+ # when a vision projector is loaded; the catalog covers staged-but-+ # unloaded models). Cloud catalogs have never heard of a local GGUF,+ # so without this answer every local model reads as text-only and+ # images detour to a cloud auxiliary — wrong twice for a local-first+ # user (broken feature, and a screenshot leaving the machine).+ try:+ from hermes_cli.local_runtime.capabilities import (+ is_managed_provider,+ managed_model_supports_vision,+ )++ if is_managed_provider(provider, _resolve_inference_base_url(cfg, provider) or ""):+ managed = managed_model_supports_vision(model)+ if managed is not None:+ return managed+ except Exception as exc: # pragma: no cover - defensive+ logger.debug("image_routing: managed-runtime caps lookup failed for %s:%s — %s",+ provider, model, exc)+caps = Nonetry:from agent.models_dev import get_model_capabilitiesdiff --git a/hermes_cli/local_runtime/capabilities.py b/hermes_cli/local_runtime/capabilities.pynew file mode 100644index 00000000000..9d979e343a4--- /dev/null+++ b/hermes_cli/local_runtime/capabilities.py@@ -0,0 +1,110 @@+"""Capability answers for models served by the managed runtime.++Capability lookups (vision, and whatever comes next) consult cloud-shaped+catalogs that have never heard of a local GGUF, so a vision-capable local+model reads as text-only and images detour to an auxiliary cloud model —+the wrong behavior twice over for a local-first user (broken feature, and+a screenshot silently leaving the machine).++The managed runtime can answer from ground truth instead, best source+first:++1. The RUNNING child's /props: llama-server reports a ``modalities`` block+ when a vision projector is loaded. The server that will receive the+ image says whether it can see — no inference, no catalog.+2. The catalog entry's declared capability (the ``vision`` tag + mmproj+ asset) for staged-but-unloaded models: what the model WILL support once+ its projector loads beside it.+3. None — not one of ours, or nothing known; the caller falls through to+ its other sources.+"""++from __future__ import annotations++import json+import logging+import urllib.request++logger = logging.getLogger(__name__)++_LLAMACPP_ALIASES = frozenset({"llamacpp", "llama.cpp", "llama-cpp"})+++def is_managed_provider(provider: str, base_url: str = "") -> bool:+ """True when this provider/base_url pair points at the managed server.+ ``custom`` only counts when the base_url IS the managed endpoint —+ background lookups must never claim someone else's custom server."""+ p = (provider or "").strip().lower()+ if p in _LLAMACPP_ALIASES:+ return True+ if p == "custom" and base_url:+ try:+ from hermes_cli.local_runtime.growth import is_managed_endpoint++ return is_managed_endpoint(base_url)+ except Exception: # noqa: BLE001+ return False+ return False+++def _props_modalities(model_id: str) -> "bool | None":+ """Ask the running server whether this loaded child sees images.+ None when the server is down, the model isn't loaded, or the build+ doesn't report modalities."""+ try:+ from hermes_cli.local_runtime.endpoint import _state_endpoint++ state = _state_endpoint()+ if state is None:+ return None+ base = state["base_url"].rsplit("/v1", 1)[0]+ req = urllib.request.Request(+ f"{base}/props?model={model_id}",+ headers={"Authorization": f"Bearer {state.get('api_key', '')}"})+ with urllib.request.urlopen(req, timeout=3) as r:+ props = json.load(r)+ modalities = props.get("modalities")+ if isinstance(modalities, dict) and "vision" in modalities:+ return bool(modalities["vision"])+ return None+ except Exception: # noqa: BLE001+ return None+++def managed_model_supports_vision(model_id: str) -> "bool | None":+ """Ground-truth vision capability for a staged model, or None when the+ model isn't ours / nothing is known (caller keeps falling through)."""+ if not model_id:+ return None++ # Only answer for models actually staged with us.+ try:+ from hermes_cli.local_runtime.bootstrap import staged_model_ids++ if model_id not in staged_model_ids():+ return None+ except Exception: # noqa: BLE001+ return None++ live = _props_modalities(model_id)+ if live is not None:+ return live++ # Staged but not loaded (or an older server build): the catalog knows+ # whether this model ships a vision projector.+ try:+ from hermes_cli.local_runtime.bootstrap import assets_dir+ from hermes_cli.local_runtime.catalog import find_entry_for_model++ hit = find_entry_for_model(model_id)+ if hit is None:+ return None+ entry = hit[0]+ if entry.mmproj is None:+ return False+ # Capability requires the projector to actually be on disk — a+ # model downloaded before its mmproj (partial delete, old layout)+ # genuinely cannot see.+ return (assets_dir() / entry.mmproj.local_name).exists()+ except Exception: # noqa: BLE001+ return Nonediff --git a/tests/hermes_cli/test_managed_vision_capability.py b/tests/hermes_cli/test_managed_vision_capability.pynew file mode 100644index 00000000000..4a17d54eebf--- /dev/null+++ b/tests/hermes_cli/test_managed_vision_capability.py@@ -0,0 +1,110 @@+"""Vision capability for managed local models answers from ground truth.++Cloud capability catalogs have never heard of a local GGUF, so without a+managed-runtime answer every local model reads as text-only: pasted images+detour to a cloud auxiliary (a screenshot leaving a local-first machine)+or fail outright. The lookup chain must consult the managed runtime+between the user's config override and the cloud catalog."""++from __future__ import annotations++import pytest+++def hermes_home(tmp_path, monkeypatch):+ home = tmp_path / ".hermes"+ home.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(home))+ import importlib++ import hermes_constants++ importlib.reload(hermes_constants)+ yield home+ importlib.reload(hermes_constants)+++def _stage(home_root, name):+ # Machine-scoped models dir (the shared root — tmp HERMES_HOME IS the root here).+ from hermes_cli.local_runtime.bootstrap import models_dir++ mdir = models_dir()+ mdir.mkdir(parents=True, exist_ok=True)+ (mdir / f"{name}.gguf").write_bytes(b"GGUF" + b"\x00" * 32)+++def test_not_ours_returns_none(hermes_home):+ from hermes_cli.local_runtime.capabilities import managed_model_supports_vision++ assert managed_model_supports_vision("gpt-4o") is None+++def test_catalog_vision_model_with_projector_on_disk(hermes_home):+ """Staged catalog model with an mmproj present: True (server down —+ the catalog + on-disk projector answer)."""+ from hermes_cli.local_runtime.bootstrap import assets_dir+ from hermes_cli.local_runtime.capabilities import managed_model_supports_vision+ from hermes_cli.local_runtime.catalog import CATALOG++ entry = next(e for e in CATALOG if e.mmproj is not None)+ variant = entry.variants[-1]+ _stage(hermes_home, variant.model_id)+ adir = assets_dir()+ adir.mkdir(parents=True, exist_ok=True)+ (adir / entry.mmproj.local_name).write_bytes(b"GGUF mmproj")++ assert managed_model_supports_vision(variant.model_id) is True+++def test_catalog_vision_model_missing_projector_is_blind(hermes_home):+ """Same model, projector NOT on disk: False — it genuinely cannot see,+ and claiming otherwise sends an image to a model that errors on it."""+ from hermes_cli.local_runtime.capabilities import managed_model_supports_vision+ from hermes_cli.local_runtime.catalog import CATALOG++ entry = next(e for e in CATALOG if e.mmproj is not None)+ variant = entry.variants[-1]+ _stage(hermes_home, variant.model_id)++ assert managed_model_supports_vision(variant.model_id) is False+++def test_live_props_beats_catalog(hermes_home, monkeypatch):+ """A running child's modalities report wins over the catalog: the+ server that will receive the image is the authority."""+ import hermes_cli.local_runtime.capabilities as caps++ from hermes_cli.local_runtime.catalog import CATALOG++ entry = next(e for e in CATALOG if e.mmproj is not None)+ variant = entry.variants[-1]+ _stage(hermes_home, variant.model_id)+ # Catalog would say False (no projector staged) — live props says True.+ monkeypatch.setattr(caps, "_props_modalities", lambda mid: True)+ assert caps.managed_model_supports_vision(variant.model_id) is True+++def test_lookup_chain_consults_managed_runtime(hermes_home, monkeypatch):+ """_lookup_supports_vision: user override wins, then the managed+ answer, and the cloud catalog is never reached for a managed model."""+ import agent.image_routing as ir++ monkeypatch.setattr(+ "hermes_cli.local_runtime.capabilities.managed_model_supports_vision",+ lambda mid: True)++ def catalog_must_not_run(*a, **k):+ raise AssertionError("cloud catalog consulted for a managed model")++ monkeypatch.setattr("agent.models_dev.get_model_capabilities",+ catalog_must_not_run)++ got = ir._lookup_supports_vision("llamacpp", "Some-Local-Model", {})+ assert got is True++ # Explicit user override still outranks the managed answer.+ cfg = {"model": {"provider": "llamacpp", "name": "Some-Local-Model",+ "supports_vision": False}}+ got = ir._lookup_supports_vision("llamacpp", "Some-Local-Model", cfg)+ assert got is False