Merge pull request #1647 from code-yeongyu/fix/subagent-type-respect-model-config-1357
fix(delegate-task): resolve user agent model config in subagent_type path (#1357)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import type { CategoriesConfig, GitMasterConfig, BrowserAutomationProvider } from "../../config/schema"
|
||||
import type { CategoriesConfig, GitMasterConfig, BrowserAutomationProvider, AgentOverrides } from "../../config/schema"
|
||||
import type { ModelFallbackInfo } from "../../features/task-toast-manager/types"
|
||||
import type { DelegateTaskArgs, ToolContextWithMetadata, OpencodeClient } from "./types"
|
||||
import { DEFAULT_CATEGORIES, CATEGORY_DESCRIPTIONS, isPlanAgent } from "./constants"
|
||||
@@ -15,7 +15,7 @@ import { subagentSessions, getSessionAgent } from "../../features/claude-code-se
|
||||
import { log, getAgentToolRestrictions, resolveModelPipeline, promptWithModelSuggestionRetry, promptSyncWithModelSuggestionRetry } from "../../shared"
|
||||
import { fetchAvailableModels, isModelAvailable } from "../../shared/model-availability"
|
||||
import { readConnectedProvidersCache } from "../../shared/connected-providers-cache"
|
||||
import { CATEGORY_MODEL_REQUIREMENTS } from "../../shared/model-requirements"
|
||||
import { AGENT_MODEL_REQUIREMENTS, CATEGORY_MODEL_REQUIREMENTS } from "../../shared/model-requirements"
|
||||
import { storeToolMetadata } from "../../features/tool-metadata-store"
|
||||
|
||||
const SISYPHUS_JUNIOR_AGENT = "sisyphus-junior"
|
||||
@@ -28,6 +28,7 @@ export interface ExecutorContext {
|
||||
gitMasterConfig?: GitMasterConfig
|
||||
sisyphusJuniorModel?: string
|
||||
browserProvider?: BrowserAutomationProvider
|
||||
agentOverrides?: AgentOverrides
|
||||
onSyncSessionCreated?: (event: { sessionID: string; parentID: string; title: string }) => Promise<void>
|
||||
}
|
||||
|
||||
@@ -856,8 +857,8 @@ export async function resolveSubagentExecution(
|
||||
executorCtx: ExecutorContext,
|
||||
parentAgent: string | undefined,
|
||||
categoryExamples: string
|
||||
): Promise<{ agentToUse: string; categoryModel: { providerID: string; modelID: string } | undefined; error?: string }> {
|
||||
const { client } = executorCtx
|
||||
): Promise<{ agentToUse: string; categoryModel: { providerID: string; modelID: string; variant?: string } | undefined; error?: string }> {
|
||||
const { client, agentOverrides } = executorCtx
|
||||
|
||||
if (!args.subagent_type?.trim()) {
|
||||
return { agentToUse: "", categoryModel: undefined, error: `Agent name cannot be empty.` }
|
||||
@@ -886,7 +887,7 @@ Create the work plan directly - that's your job as the planning agent.`,
|
||||
}
|
||||
|
||||
let agentToUse = agentName
|
||||
let categoryModel: { providerID: string; modelID: string } | undefined
|
||||
let categoryModel: { providerID: string; modelID: string; variant?: string } | undefined
|
||||
|
||||
try {
|
||||
const agentsResult = await client.app.agents()
|
||||
@@ -923,7 +924,41 @@ Create the work plan directly - that's your job as the planning agent.`,
|
||||
|
||||
agentToUse = matchedAgent.name
|
||||
|
||||
if (matchedAgent.model) {
|
||||
const agentNameLower = agentToUse.toLowerCase()
|
||||
const agentOverride = agentOverrides?.[agentNameLower as keyof typeof agentOverrides]
|
||||
?? (agentOverrides ? Object.entries(agentOverrides).find(([key]) => key.toLowerCase() === agentNameLower)?.[1] : undefined)
|
||||
const agentRequirement = AGENT_MODEL_REQUIREMENTS[agentNameLower]
|
||||
|
||||
if (agentOverride?.model || agentRequirement) {
|
||||
const connectedProviders = readConnectedProvidersCache()
|
||||
const availableModels = await fetchAvailableModels(client, {
|
||||
connectedProviders: connectedProviders ?? undefined,
|
||||
})
|
||||
|
||||
const matchedAgentModelStr = matchedAgent.model
|
||||
? `${matchedAgent.model.providerID}/${matchedAgent.model.modelID}`
|
||||
: undefined
|
||||
|
||||
const resolution = resolveModelPipeline({
|
||||
intent: {
|
||||
userModel: agentOverride?.model,
|
||||
categoryDefaultModel: matchedAgentModelStr,
|
||||
},
|
||||
constraints: { availableModels },
|
||||
policy: {
|
||||
fallbackChain: agentRequirement?.fallbackChain,
|
||||
systemDefaultModel: undefined,
|
||||
},
|
||||
})
|
||||
|
||||
if (resolution) {
|
||||
const parsed = parseModelString(resolution.model)
|
||||
if (parsed) {
|
||||
const variantToUse = agentOverride?.variant ?? resolution.variant
|
||||
categoryModel = variantToUse ? { ...parsed, variant: variantToUse } : parsed
|
||||
}
|
||||
}
|
||||
} else if (matchedAgent.model) {
|
||||
categoryModel = matchedAgent.model
|
||||
}
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user