← Back to PRs

#20572: feat (agents): add force option to imageModel for cheaper/better vision routing

by primevalsoup open 2026-02-19 03:25 View on GitHub →
agents size: M
## Summary - Adds `force: true` to `imageModel` config so images are always routed through `imageModel` even when the primary model has native vision - Lets users pick a cheaper model (e.g. Gemini 3 Flash at ~$0.05/M tokens vs Sonnet at $3/M), a better vision model, or both — independent of what the primary model supports - Falls back to native vision injection if `imageModel` analysis fails ## Config example \`\`\`json { "agents": { "defaults": { "model": { "primary": "anthropic/claude-sonnet-4-5-20250929" }, "imageModel": { "primary": "openrouter/google/gemini-3-flash-preview", "force": true } } } } \`\`\` ## Notes This extends the concept from PR #8062 (image pre-analysis for non-vision models) by adding `force` so vision-capable primary models can also benefit. If #8062 merges first, the pre-analysis logic in `image-pre-analysis.ts` can be consolidated. ## Test plan - [x] `pnpm build` + `pnpm tsgo` — no errors - [x] `force: true` → gateway log shows `Image pre-analysis: using openrouter/google/gemini-3-flash-preview` - [x] `force: false` → no pre-analysis log, native vision used instead - [ ] Misconfigure imageModel → falls back to native vision 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds `force: true` option to `imageModel` config, enabling users to route images through a cheaper/better vision model even when the primary model has native vision support. The implementation extends existing image pre-analysis logic by adding a `force` flag to the config schema and routing decisions in `attempt.ts:962-997`. **Key changes:** - New `force?: boolean` field in `ImageModelConfig` and Zod schema - `shouldUseImagePreAnalysis` now returns true when `force: true` OR primary lacks vision - `detectAndLoadPromptImages` gains `forceDetect` param to load images even if primary lacks vision - New file `image-pre-analysis.ts` with text description formatting logic **Issue found:** - Fallback to native vision in `attempt.ts:985-996` doesn't check if primary model supports vision, causing potential cascading failures when pre-analysis fails for non-vision models <h3>Confidence Score: 3/5</h3> - Safe to merge after fixing the fallback logic bug - Score reflects a critical logical error in error-handling fallback path that could cause cascading failures when imageModel fails for non-vision primary models. The core feature implementation is sound (config schema, routing decisions, pre-analysis), but the fallback doesn't verify the primary model supports vision before attempting native injection. Once fixed, this would be a 4. - `src/agents/pi-embedded-runner/run/attempt.ts` needs the fallback guard fix before merge <sub>Last reviewed commit: 93a92b1</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs