feat: auto-detect model provider and apply appropriate options (#146)
When overriding an agent's model to a different provider, the agent
now automatically gets provider-appropriate reasoning options:
- GPT models: `reasoningEffort`, `textVerbosity`
- Anthropic models: `thinking` with `budgetTokens`
## Why utils.ts changes are required
The original flow merges overrides onto pre-built agent configs:
mergeAgentConfig(sisyphusAgent, { model: "gpt-5.2" })
// Result: { model: "gpt-5.2", thinking: {...} }
The `thinking` config persists because it exists in the pre-built
`sisyphusAgent`. GPT models ignore `thinking` and need `reasoningEffort`.
The fix: call the agent factory with the resolved model, so the factory
can return the correct provider-specific config:
buildAgent(createSisyphusAgent, "gpt-5.2")
// Result: { model: "gpt-5.2", reasoningEffort: "medium" }
Closes #144
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { AgentConfig } from "@opencode-ai/sdk"
|
||||
import type { BuiltinAgentName, AgentOverrideConfig, AgentOverrides } from "./types"
|
||||
import { sisyphusAgent } from "./sisyphus"
|
||||
import { oracleAgent } from "./oracle"
|
||||
import type { BuiltinAgentName, AgentOverrideConfig, AgentOverrides, AgentFactory } from "./types"
|
||||
import { createSisyphusAgent } from "./sisyphus"
|
||||
import { createOracleAgent } from "./oracle"
|
||||
import { librarianAgent } from "./librarian"
|
||||
import { exploreAgent } from "./explore"
|
||||
import { frontendUiUxEngineerAgent } from "./frontend-ui-ux-engineer"
|
||||
@@ -9,9 +9,11 @@ import { documentWriterAgent } from "./document-writer"
|
||||
import { multimodalLookerAgent } from "./multimodal-looker"
|
||||
import { deepMerge } from "../shared"
|
||||
|
||||
const allBuiltinAgents: Record<BuiltinAgentName, AgentConfig> = {
|
||||
Sisyphus: sisyphusAgent,
|
||||
oracle: oracleAgent,
|
||||
type AgentSource = AgentFactory | AgentConfig
|
||||
|
||||
const agentSources: Record<BuiltinAgentName, AgentSource> = {
|
||||
Sisyphus: createSisyphusAgent,
|
||||
oracle: createOracleAgent,
|
||||
librarian: librarianAgent,
|
||||
explore: exploreAgent,
|
||||
"frontend-ui-ux-engineer": frontendUiUxEngineerAgent,
|
||||
@@ -19,6 +21,14 @@ const allBuiltinAgents: Record<BuiltinAgentName, AgentConfig> = {
|
||||
"multimodal-looker": multimodalLookerAgent,
|
||||
}
|
||||
|
||||
function isFactory(source: AgentSource): source is AgentFactory {
|
||||
return typeof source === "function"
|
||||
}
|
||||
|
||||
function buildAgent(source: AgentSource, model?: string): AgentConfig {
|
||||
return isFactory(source) ? source(model) : source
|
||||
}
|
||||
|
||||
export function createEnvContext(directory: string): string {
|
||||
const now = new Date()
|
||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
@@ -67,37 +77,29 @@ export function createBuiltinAgents(
|
||||
): Record<string, AgentConfig> {
|
||||
const result: Record<string, AgentConfig> = {}
|
||||
|
||||
for (const [name, config] of Object.entries(allBuiltinAgents)) {
|
||||
for (const [name, source] of Object.entries(agentSources)) {
|
||||
const agentName = name as BuiltinAgentName
|
||||
|
||||
if (disabledAgents.includes(agentName)) {
|
||||
continue
|
||||
}
|
||||
|
||||
let finalConfig = config
|
||||
const override = agentOverrides[agentName]
|
||||
const model = override?.model ?? (agentName === "Sisyphus" ? systemDefaultModel : undefined)
|
||||
|
||||
let config = buildAgent(source, model)
|
||||
|
||||
if ((agentName === "Sisyphus" || agentName === "librarian") && directory && config.prompt) {
|
||||
const envContext = createEnvContext(directory)
|
||||
finalConfig = {
|
||||
...config,
|
||||
prompt: config.prompt + envContext,
|
||||
}
|
||||
}
|
||||
|
||||
const override = agentOverrides[agentName]
|
||||
|
||||
if (agentName === "Sisyphus" && systemDefaultModel && !override?.model) {
|
||||
finalConfig = {
|
||||
...finalConfig,
|
||||
model: systemDefaultModel,
|
||||
}
|
||||
config = { ...config, prompt: config.prompt + envContext }
|
||||
}
|
||||
|
||||
if (override) {
|
||||
result[name] = mergeAgentConfig(finalConfig, override)
|
||||
} else {
|
||||
result[name] = finalConfig
|
||||
const { model: _, ...restOverride } = override
|
||||
config = mergeAgentConfig(config, restOverride)
|
||||
}
|
||||
|
||||
result[name] = config
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user