diff --git a/run_agent.py b/run_agent.py index 5fdb73487a3d7..75c5dba8b4ffe 100644 --- a/run_agent.py +++ b/run_agent.py @@ -9356,9 +9356,13 @@ def _build_api_kwargs(self, api_messages: list) -> dict: if _ephemeral_out is not None: self._ephemeral_max_output_tokens = None + # Provider-profile transports still need the shared non-vision + # image fallback before chat-completions kwargs are built. + _msgs_for_chat = self._prepare_messages_for_non_vision_model(api_messages) + return _ct.build_kwargs( model=self.model, - messages=api_messages, + messages=_msgs_for_chat, tools=self.tools, base_url=self.base_url, timeout=self._resolved_api_call_timeout(), diff --git a/tests/run_agent/test_run_agent.py b/tests/run_agent/test_run_agent.py index 5bc485e0711c4..3d0d4db86c682 100644 --- a/tests/run_agent/test_run_agent.py +++ b/tests/run_agent/test_run_agent.py @@ -4086,6 +4086,27 @@ def test_max_tokens_none_when_unset(self, agent): class TestAnthropicImageFallback: + def test_build_api_kwargs_provider_profile_applies_non_vision_fallback(self, agent): + agent.api_mode = "chat_completions" + agent.provider = "openrouter" + agent.model = "qwen/qwen3-235b-a22b" + agent.reasoning_config = None + + api_messages = [{ + "role": "user", + "content": [ + {"type": "text", "text": "Describe this image"}, + {"type": "image_url", "image_url": {"url": "https://example.com/cat.png"}}, + ], + }] + transformed = [{"role": "user", "content": "[Image description: a cat] Describe this image"}] + + with patch.object(agent, "_prepare_messages_for_non_vision_model", return_value=transformed) as mock_prepare: + kwargs = agent._build_api_kwargs(api_messages) + + mock_prepare.assert_called_once_with(api_messages) + assert kwargs["messages"] == transformed + def test_build_api_kwargs_converts_multimodal_user_image_to_text(self, agent): agent.api_mode = "anthropic_messages" agent.reasoning_config = None