Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
21 changes: 21 additions & 0 deletions tests/run_agent/test_run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading