← Back to PRs

#17021: fix(agents): read models from gateway config first

by Limitless2023 open 2026-02-15 09:57 View on GitHub →
agents stale size: S
Fixes #16976 ## Problem Per-agent models.json is a static snapshot written at agent creation time. When gateway config adds new models (e.g., new Ollama models), agents fall back to default model instead of using the newly configured models. ## Root Cause resolveModel() checked models.json FIRST before checking the gateway config. The gateway config is always fresh, but the per-agent models.json is stale. ## Solution Check gateway config (cfg.models.providers) FIRST before falling back to models.json. This ensures agents always use the latest models from the gateway config. ## Impact - Agents automatically use newly added models without manual models.json updates - No need to restart gateway or recreate agents after config changes - Models.json becomes a secondary fallback (for backward compatibility) <!-- greptile_comment --> <h3>Greptile Summary</h3> Refactors `resolveModel()` to check gateway config (`cfg.models.providers`) before falling back to per-agent `models.json`, ensuring agents always use fresh models from gateway config instead of stale snapshots. **Major changes:** - Gateway config now checked first (lines 77-90), so newly added models are immediately available - `models.json` becomes secondary fallback (lines 93-96) - Forward-compat and generic provider fallbacks remain in correct order **Critical issue:** - Line 95 drops the `normalizeModelCompat()` wrapper from the models.json path (previously line 118 in old code). This breaks ZAI models resolved from models.json—they won't have `supportsDeveloperRole: false` set and will attempt to use the developer role, causing API failures. <h3>Confidence Score: 2/5</h3> - This PR contains a critical logical error that will break ZAI models - The refactor correctly inverts the priority (gateway config first, models.json second), but introduces a regression by dropping `normalizeModelCompat()` on the models.json path. This will cause ZAI `openai-completions` models to fail at runtime when resolved from models.json. - src/agents/pi-embedded-runner/model.ts line 95 requires immediate attention <sub>Last reviewed commit: 6ab83b6</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs