The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(vision): computer_use capture and vision_analyze share one native-vision gate
teknium1edb30c1072a6
diff --git a/tests/tools/test_computer_use_vision_routing.py b/tests/tools/test_computer_use_vision_routing.pyindex 416b4934296..6d9de104b5e 100644--- a/tests/tools/test_computer_use_vision_routing.py+++ b/tests/tools/test_computer_use_vision_routing.py@@ -207,3 +207,25 @@ class TestModuleSurface:assert hasattr(vision_routing, name)assert callable(getattr(vision_routing, name))+++class TestGateAgreementWithVisionAnalyze:+ """The capture route and the ``vision_analyze`` fast path derive from one predicate, so the lane never+ depends on which tool asked (#115248: deepseek/deepseek-flash went native in one and aux in the other)."""++ def test_catalog_vision_model_off_the_provider_whitelist_stays_native(self):+ from tools.computer_use import vision_routing++ cfg = {"agent": {"image_input_mode": "native"}}+ with patch("agent.image_routing._lookup_supports_vision", return_value=True), \+ patch("tools.vision_tools._supports_media_in_tool_results", return_value=False), \+ patch("tools.vision_tools._profile_rejects_tool_media", return_value=False):+ assert vision_routing.should_route_capture_to_aux_vision("deepseek", "deepseek-flash", cfg) is False++ def test_profile_veto_still_routes_a_catalog_vision_model_to_aux(self):+ from tools.computer_use import vision_routing++ with patch("agent.image_routing._lookup_supports_vision", return_value=True), \+ patch("tools.vision_tools._supports_media_in_tool_results", return_value=False), \+ patch("tools.vision_tools._profile_rejects_tool_media", return_value=True):+ assert vision_routing.should_route_capture_to_aux_vision("xiaomi", "mimo-v2.5", {}) is Truediff --git a/tools/computer_use/vision_routing.py b/tools/computer_use/vision_routing.pyindex 2c6b72461f0..1a68cf347d2 100644--- a/tools/computer_use/vision_routing.py+++ b/tools/computer_use/vision_routing.py@@ -8,7 +8,8 @@ Decision order (mirrors ``vision_analyze``):who pay for a vision model want it used.2. User-declared ``supports_vision`` for the active route (escape hatch for custom/local VLMs absent from models.dev)→ honour it (True → multimodal).-3. Provider+model carries images inside tool-result messages AND models.dev says ``supports_vision=True`` → multimodal.+3. The shared ``vision_analyze`` gate (profile veto, then provider tool-result media OR catalog vision) says yes AND+ the capability lookup says ``supports_vision=True`` → multimodal.4. Everything else (non-vision model, provider rejecting multimodal tool results, lookup failure) → aux routing.Fails *closed* toward aux routing when metadata is missing or ambiguous: a screenshot sent to a model that cannot read@@ -62,17 +63,18 @@ def _lookup_supports_vision(provider: str, model: str, cfg: Optional[Dict[str, Alogger.debug("computer_use vision_routing: caps lookup failed for %s:%s — %s", provider, model, exc)return None-def _provider_accepts_multimodal_tool_result(provider: str, model: str) -> Optional[bool]:- """Whether *provider*+*model* carries images inside tool-result messages; reuses ``tools.vision_tools`` to stay in- lockstep with the ``vision_analyze`` fast path. None on import failure so callers fall back to aux, not guess."""+def _provider_accepts_multimodal_tool_result(provider: str, model: str, cfg: Optional[Dict[str, Any]] = None) -> Optional[bool]:+ """Whether *provider*+*model* may carry images inside tool-result messages — the SAME predicate the+ ``vision_analyze`` fast path uses (#115248: the two gates disagreed for deepseek/deepseek-flash, so the route+ depended on which tool asked). None on import failure so callers fall back to aux, not guess."""if not provider:return Nonetry:- from tools.vision_tools import _supports_media_in_tool_results+ from tools.vision_tools import _accepts_tool_result_imagesexcept Exception as exc: # pragma: no cover - defensivelogger.debug("computer_use vision_routing: tool-result support lookup failed: %s", exc)return None- return bool(_supports_media_in_tool_results(provider, model))+ return bool(_accepts_tool_result_images(provider, model, cfg))def should_route_capture_to_aux_vision(provider: str, model: str, cfg: Optional[Dict[str, Any]]) -> bool:"""True iff the screenshot should be pre-analysed via aux vision; False keeps the multimodal envelope. *provider* is@@ -88,7 +90,7 @@ def should_route_capture_to_aux_vision(provider: str, model: str, cfg: Optional[user_declared = _lookup_user_declared_supports_vision(provider, model, cfg)if isinstance(user_declared, bool): # True → multimodal, False → auxreturn not user_declared- if not _provider_accepts_multimodal_tool_result(provider, model):+ if not _provider_accepts_multimodal_tool_result(provider, model, cfg):return Truereturn _lookup_supports_vision(provider, model, cfg) is not Truediff --git a/tools/vision_tools.py b/tools/vision_tools.pyindex 861a5f689d3..7df14bbe2d1 100644--- a/tools/vision_tools.py+++ b/tools/vision_tools.py@@ -457,27 +457,33 @@ def _supports_media_in_tool_results(provider: str, model: str) -> bool:return False+def _accepts_tool_result_images(provider: str, model: str, cfg: Optional[Dict[str, Any]]) -> bool:+ """One gate for both native lanes — the ``vision_analyze`` fast path and the ``computer_use`` capture route+ (#115248): the profile's ``supports_vision_tool_messages=False`` veto first, then either the provider's tool+ results are known to carry media or the capability lookup (config override → catalog → probes → profile)+ attests the model as vision-capable."""+ if _profile_rejects_tool_media(provider, model):+ return False+ if _supports_media_in_tool_results(provider, model):+ return True+ from agent.image_routing import _lookup_supports_vision+ return _lookup_supports_vision(provider, model, cfg) is True++def _should_use_native_vision_fast_path() -> bool:"""True when image routing resolves to ``native`` AND the provider accepts images in toolresults, or the user set the ``model.supports_vision`` override (escape hatch forcustom/local providers). Any failure → False."""try:from agent.auxiliary_client import _read_main_provider, _read_main_model- from agent.image_routing import decide_image_input_mode, _lookup_supports_vision+ from agent.image_routing import decide_image_input_modefrom hermes_cli.config import load_configprovider = _read_main_provider()model = _read_main_model()cfg = load_config()if decide_image_input_mode(provider, model, cfg) != "native":return False- # The profile veto applies ahead of the capability lookup too: a- # model marked vision-capable by models.dev / custom_providers must- # not re-open the multimodal-envelope route the profile rejects.- if _profile_rejects_tool_media(provider, model):- return False- return (- _supports_media_in_tool_results(provider, model)- or _lookup_supports_vision(provider, model, cfg) is True)+ return _accepts_tool_result_images(provider, model, cfg)except Exception as exc:logger.debug("Native vision fast-path check failed: %s", exc)return False