The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(vision): honor routed tool message veto
KoNit-K04060eae2a94
diff --git a/agent/vision_message_prep.py b/agent/vision_message_prep.pyindex 9a0e4c51723..08862dd97d6 100644--- a/agent/vision_message_prep.py+++ b/agent/vision_message_prep.py@@ -146,10 +146,11 @@ class VisionMessagePrepMixin:"""True if the active provider accepts list-type tool content (some, e.g. Xiaomi MiMo, takemultimodal user messages but 400 on list-type tool content; profile ``supports_vision_tool_messages``)."""try:- from providers import get_provider_profile- profile = get_provider_profile((getattr(self, "provider", "") or "").strip())- if profile is not None:- return getattr(profile, "supports_vision_tool_messages", True)+ from providers import routed_model_rejects_vision_tool_messages+ return not routed_model_rejects_vision_tool_messages(+ (getattr(self, "provider", "") or "").strip(),+ (getattr(self, "model", "") or "").strip(),+ )except Exception:passreturn True # default: assume compatiblediff --git a/providers/__init__.py b/providers/__init__.pyindex 59d1c75de8b..1648881e836 100644--- a/providers/__init__.py+++ b/providers/__init__.py@@ -47,6 +47,11 @@ _ALIASES: dict[str, str] = {}_PROVIDER_LIST_CACHE: list[ProviderProfile] | None = None_discovered = False+# These APIs accept a ``vendor/model`` identifier while the request is sent to+# the aggregator. A target provider can have stricter message-shape support+# than the aggregator's generic OpenAI-compatible transport profile.+_AGGREGATOR_MODEL_PREFIX_PROVIDERS = frozenset({"openrouter"})+# Repo-root ``plugins/model-providers/`` — populated at discovery time._BUNDLED_PLUGINS_DIR = (Path(__file__).resolve().parent.parent / "plugins" / "model-providers"@@ -83,6 +88,29 @@ def get_provider_profile(name: str) -> ProviderProfile | None:return profile+def routed_model_rejects_vision_tool_messages(provider: str, model: str) -> bool:+ """Whether an active route or its aggregator-targeted model rejects image tool parts.++ ``openrouter`` sends vendor-prefixed model IDs (for example,+ ``xiaomi/mimo-v2.5``), but its own profile cannot describe every routed+ provider's tool-message compatibility. Preserve the transport profile as+ the default and consult a registered target profile only for known+ aggregators. Missing or unrecognized identities deliberately fail open.+ """+ provider_name = str(provider or "").strip().lower()+ profile = get_provider_profile(provider_name)+ if profile is not None and profile.supports_vision_tool_messages is False:+ return True+ if provider_name not in _AGGREGATOR_MODEL_PREFIX_PROVIDERS:+ return False++ target_name, separator, _ = str(model or "").strip().partition("/")+ if not separator or not target_name:+ return False+ target_profile = get_provider_profile(target_name.strip().lower())+ return target_profile is not None and target_profile.supports_vision_tool_messages is False++def list_providers() -> list[ProviderProfile]:"""Return all registered provider profiles (one per canonical name)."""global _PROVIDER_LIST_CACHEdiff --git a/tests/agent/test_vision_tool_messages.py b/tests/agent/test_vision_tool_messages.pyindex efcb67730fc..0d95a1f06ad 100644--- a/tests/agent/test_vision_tool_messages.py+++ b/tests/agent/test_vision_tool_messages.py@@ -67,6 +67,11 @@ class TestProviderSupportsVisionToolMessages:agent = _make_agent("xiaomi", "mimo-v2.5")assert agent._provider_supports_vision_tool_messages() is False+ def test_openrouter_xiaomi_route_returns_false(self):+ """An aggregator must retain its routed model's tool-message veto."""+ agent = _make_agent("openrouter", "xiaomi/mimo-v2.5")+ assert agent._provider_supports_vision_tool_messages() is False+@@ -90,6 +95,17 @@ class TestToolResultContentProactiveDowngrade:assert isinstance(content, str)assert "screenshot captured" in content+ def test_openrouter_xiaomi_route_downgrades_to_text_summary(self):+ """OpenRouter must not bypass Xiaomi's list-type tool-message veto."""+ agent = _make_agent("openrouter", "xiaomi/mimo-v2.5")+ result = _multimodal_result(text="aggregated screenshot captured")++ with patch.object(agent, "_model_supports_vision", return_value=True):+ content = agent._tool_result_content_for_active_model("browser_screenshot", result)++ assert isinstance(content, str)+ assert "aggregated screenshot captured" in content+def test_xiaomi_non_multimodal_passes_through(self):"""Non-multimodal results should pass through unchanged."""agent = _make_agent("xiaomi", "mimo-v2.5")@@ -150,4 +166,3 @@ class TestProviderProfileField:assert profile is not Noneassert profile.supports_vision_tool_messages is False-diff --git a/tests/tools/test_vision_native_fast_path.py b/tests/tools/test_vision_native_fast_path.pyindex 82b7cb57ce9..a6c675836f0 100644--- a/tests/tools/test_vision_native_fast_path.py+++ b/tests/tools/test_vision_native_fast_path.py@@ -96,6 +96,10 @@ class TestSupportsMediaInToolResults:tool-result content, #89981)."""assert _supports_media_in_tool_results("xiaomi", "mimo-v2.5") is False+ def test_openrouter_xiaomi_route_keeps_profile_tool_message_veto(self):+ """The OpenRouter transport must not re-open Xiaomi's unsafe fast path."""+ assert _supports_media_in_tool_results("openrouter", "xiaomi/mimo-v2.5") is False+def test_profile_veto_applies_even_when_vision_capable_lookup_agrees(self):"""A capability source marking the model vision-capable must notre-open the native fast path for a provider that rejects it."""@@ -114,6 +118,23 @@ class TestSupportsMediaInToolResults:finally:clear_runtime_main()+ def test_openrouter_xiaomi_route_vetoes_native_fast_path(self):+ """A vision-capable catalog entry cannot override a routed Xiaomi veto."""+ from tools.vision_tools import _should_use_native_vision_fast_path+ from agent.auxiliary_client import set_runtime_main, clear_runtime_main+ from agent import image_routing++ set_runtime_main("openrouter", "xiaomi/mimo-v2.5")+ try:+ with patch.object(+ image_routing, "decide_image_input_mode", return_value="native"+ ), patch.object(+ image_routing, "_lookup_supports_vision", return_value=True+ ):+ assert _should_use_native_vision_fast_path() is False+ finally:+ clear_runtime_main()+# ─── _build_native_vision_tool_result ────────────────────────────────────────diff --git a/tools/vision_tools.py b/tools/vision_tools.pyindex a16c228d8a6..506abe33625 100644--- a/tools/vision_tools.py+++ b/tools/vision_tools.py@@ -414,7 +414,7 @@ _TOOL_RESULT_MEDIA_PROVIDERS = frozenset({_GEMINI_PROVIDERS = frozenset({"google", "gemini", "google-gemini", "google-vertex-gemini"})-def _profile_rejects_tool_media(provider: str) -> bool:+def _profile_rejects_tool_media(provider: str, model: str = "") -> bool:"""Hard veto: the provider's ``ProviderProfile`` declares``supports_vision_tool_messages=False`` — images are accepted in usermessages but list-type tool-result content is rejected with 400@@ -423,9 +423,8 @@ def _profile_rejects_tool_media(provider: str) -> bool:and the image never enters context (#89981)."""try:- from providers import get_provider_profile- profile = get_provider_profile(str(provider or "").strip().lower())- return profile is not None and profile.supports_vision_tool_messages is False+ from providers import routed_model_rejects_vision_tool_messages+ return routed_model_rejects_vision_tool_messages(provider, model)except Exception:return False@@ -435,7 +434,7 @@ def _supports_media_in_tool_results(provider: str, model: str) -> bool:providers are False (caller falls back to aux-LLM text) unless their ``ProviderProfile``declares ``supports_vision``; ``supports_vision_tool_messages=False`` is a hard veto."""p = provider.strip().lower() if isinstance(provider, str) else ""- if not p or _profile_rejects_tool_media(p):+ if not p or _profile_rejects_tool_media(p, model):return Falseif p in _TOOL_RESULT_MEDIA_PROVIDERS:return True@@ -466,7 +465,7 @@ def _should_use_native_vision_fast_path() -> bool:# 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):+ if _profile_rejects_tool_media(provider, model):return Falsereturn (_supports_media_in_tool_results(provider, model)