#20572: feat (agents): add force option to imageModel for cheaper/better vision routing
agents
size: M
Cluster:
Image Model Enhancements
## 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
#8062: feat: add image pre-analysis with imageModel for non-vision models
by mylukin · 2026-02-03
78.3%
#23467: feat: support image model resolution from media tool config
by sreerevanth · 2026-02-22
77.1%
#11349: fix(agents): do not filter fallback models by models allowlist
by liuxiaopai-ai · 2026-02-07
73.5%
#4459: fix: enable image input for Kimi K2.5 and refresh stale config mode...
by manikv12 · 2026-01-30
73.1%
#21963: fix(cli): models fallbacks add now includes primary model in allowlist
by ashiabbott · 2026-02-20
73.0%
#8660: fix: respect agents.defaults.models.*.params.maxTokens in image tool
by dbottme · 2026-02-04
72.6%
#13376: fix: pass model directly to agent for sub-agent runs
by jrbobbyhansen-pixel · 2026-02-10
72.2%
#22064: fix(failover): bypass models allowlist for configured fallback models
by winston-bepresent · 2026-02-20
72.2%
#7570: fix: allow models from providers with auth profiles configured
by DonSqualo · 2026-02-03
71.9%
#11464: feat(models): add forward-compat fallback for gemini-3-pro-image
by ben-milanko · 2026-02-07
71.8%