This document describes the model resolution and fallback system, which ensures that agents and categories are assigned appropriate models based on available providers. The system operates at two distinct times: install-time (via CLI) and runtime (via the configuration pipeline and session hooks).
The model resolution system manages the complexity of supporting built-in agents and categories across a fragmented landscape of AI providers. The system provides:
AGENT_MODEL_REQUIREMENTS packages/model-core/src/agent-model-requirements.ts3-183RuntimeFallbackHook monitors for retryable errors (429, 500, 503, 529) and triggers an automatic switch to the next available model in the fallback chain packages/omo-opencode/src/hooks/runtime-fallback/auto-retry-dispatch.ts126-142Sources: packages/model-core/src/agent-model-requirements.ts3-183 packages/model-core/src/model-family-detectors.ts1-85 packages/omo-opencode/src/hooks/runtime-fallback/auto-retry-dispatch.ts1-142
The system transitions from high-level requirements (e.g., "Sisyphus needs a reasoning model") to specific code entities that manage the resolution and recovery lifecycle.
Sources: packages/model-core/src/agent-model-requirements.ts3-183 packages/model-core/src/model-resolution-pipeline.ts40-41 packages/omo-opencode/src/hooks/runtime-fallback/auto-retry-dispatch.ts16-34
At runtime, the system determines the specific capabilities of a resolved model (e.g., does it support "thinking" or specific modalities like PDF?).
The function getModelCapabilities resolves capabilities by checking multiple sources in order of priority:
claude-opus-4-7-thinking to canonical IDs packages/model-core/src/model-capabilities/get-model-capabilities.ts179-188Fuzzy matching and family detection are handled by specialized detectors that normalize string separators and casing packages/model-core/src/model-family-detectors.ts1-85
| Detector Function | Normalization Rule | Example Matches |
|---|---|---|
isGptModel | .toLowerCase().includes("gpt") | openai/gpt-5.5, github-copilot/gpt-4o |
isClaudeOpus47OrLaterModel | major > 4 or (major == 4 and minor >= 7) | claude-opus-4.7, claude-fable-5 |
isKimiK27Model | Regex /kimi-k2[.\-]?7/ | opencode-go/kimi-k2.7, k2p7 |
isGeminiModel | Prefix check for google/ or google-vertex/ | google/gemini-3.1-pro |
Sources: packages/model-core/src/model-capabilities/get-model-capabilities.ts1-225 packages/model-core/src/model-family-detectors.ts1-85
The RuntimeFallbackHook intercepts errors and performs a "headless resume" with a different model.
The createAutoRetryDispatcher manages the transition between a failed model and its fallback packages/omo-opencode/src/hooks/runtime-fallback/auto-retry-dispatch.ts16-34 It handles complex session states such as:
This diagram bridges conceptual resolution to specific code entities.
Sources: packages/omo-opencode/src/hooks/runtime-fallback/auto-retry-dispatch.ts116-125 packages/model-core/src/agent-model-requirements.ts3-183 packages/model-core/src/model-family-detectors.ts1-85
The system relies on ModelRequirement definitions which specify a primary fallbackChain packages/model-core/src/agent-model-requirements.ts3-5
Different agents have tailored fallback chains based on their reasoning requirements packages/model-core/src/agent-model-requirements.ts3-183:
claude-opus-4-7 (max) -> kimi-k2.6 -> gpt-5.5 (medium) packages/model-core/src/agent-model-requirements.ts4-31gpt-5.4-mini-fast or qwen3.5-plus packages/model-core/src/agent-model-requirements.ts63-86Sources: packages/model-core/src/agent-model-requirements.ts3-183 packages/model-core/src/model-requirement-types.ts1
Refresh this wiki