fix(agent): call _prepare_messages_for_non_vision_model on chat_completions profile path#23818
Closed
gsskk wants to merge 1 commit into
Closed
fix(agent): call _prepare_messages_for_non_vision_model on chat_completions profile path#23818gsskk wants to merge 1 commit into
gsskk wants to merge 1 commit into
Conversation
…etions profile path Mirror the legacy branch: registered providers (opencode-go, deepseek, kimi, openrouter, ...) were skipping the non-vision image fallback because the call sat only in the legacy branch of _build_api_kwargs. Profile-path providers forwarded image_url parts unchanged, and text-only models 400'd with "unknown variant `image_url`". The function short-circuits for vision-capable models and image-less turns, so the added call is free on the common paths. Regression test in test_vision_aware_preprocessing.py exercises the profile branch end-to-end via _build_api_kwargs: a non-vision model on a registered provider must receive text-only messages at the transport layer. Fixes #23733
Author
|
Closing as duplicate — #23743 (and #23750) cover the same fix on the chat_completions profile branch and were opened earlier today. Apologies for the noise; should have checked the open-PR list right after filing the issue. Leaving a pointer in case any of the regression test from this branch ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #23733.
What & Why
_build_api_kwargs(run_agent.py) had two parallel return paths forchat_completions:get_provider_profile()→None, unknown provider): called_prepare_messages_for_non_vision_modelto stripimage_urlparts before they reached non-vision models.opencode-go,deepseek,kimi,openrouter,gemini, etc.): did not call it, soimage_urlparts passed through to the upstream provider.Result: text-only models on any registered provider 400'd with
unknown variant 'image_url'whenever a multimodal request reached/v1/chat/completions(and the same path from any caller that lets the agent build messages from images). The gateway-adapter path (gateway/run.py→_decide_image_input_mode→_enrich_message_with_vision) and thecodex_responsesprofile path both already handle this; the chat_completions profile branch was the lone gap.The fix mirrors the legacy branch: one call to
_prepare_messages_for_non_vision_model(api_messages)immediately before_ct.build_kwargs(...)in the profile branch. The function early-returns when no message contains image parts and again when_model_supports_vision()is true, so the added call is free on the common paths.How to test
The added
TestBuildApiKwargsProfileBranchcovers both directions on the profile path:test_profile_branch_strips_images_for_non_vision_models— fails onmain, passes with the fix. Setsprovider=opencode-go+model=deepseek-v4-pro, calls_build_api_kwargswith animage_urluser message, and asserts the messages handed to the transport contain noimage_urlparts.test_profile_branch_passes_through_when_model_supports_vision— already-passes guard so vision-capable models don't regress to text-only.Platforms
Tested on Linux (Debian trixie). Change is pure Python message-shape manipulation; no file I/O, process management, or terminal handling.
Notes
The full root-cause analysis (including verification on
origin/main64145a199) is in the linked issue.