fix: subagent inherits parent agent's provider, model, and apiType

Spawned subagents now inherit the parent agent's LLM provider config
(apiType, apiKey, baseURL, model) via ToolContext instead of falling
back to process.env. This fixes failures when the parent agent is
configured via code (not env vars), especially with OpenAI-compatible
endpoints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
idoubi
2026-04-04 00:25:08 +08:00
parent 85dff47d74
commit 366438d2ef
3 changed files with 18 additions and 7 deletions
+3
View File
@@ -457,6 +457,9 @@ export class QueryEngine {
const context: ToolContext = {
cwd: this.config.cwd,
abortSignal: this.config.abortSignal,
provider: this.provider,
model: this.config.model,
apiType: this.provider.apiType,
}
const MAX_CONCURRENCY = parseInt(
+9 -7
View File
@@ -101,13 +101,15 @@ export const AgentTool: ToolDefinition = {
const systemPrompt = agentDef?.prompt ||
'You are a helpful assistant. Complete the given task using the available tools.'
// Resolve model and create provider for subagent
const subModel = input.model || process.env.CODEANY_MODEL || 'claude-sonnet-4-6'
const apiType = (process.env.CODEANY_API_TYPE as ApiType) || 'anthropic-messages'
const provider = createProvider(apiType, {
apiKey: process.env.CODEANY_API_KEY,
baseURL: process.env.CODEANY_BASE_URL,
})
// Inherit provider and model from parent agent context, fall back to env vars
const subModel = input.model || context.model || process.env.CODEANY_MODEL || 'claude-sonnet-4-6'
const provider = context.provider ?? createProvider(
(context.apiType || process.env.CODEANY_API_TYPE as ApiType) || 'anthropic-messages',
{
apiKey: process.env.CODEANY_API_KEY,
baseURL: process.env.CODEANY_BASE_URL,
},
)
// Create subagent engine
const engine = new QueryEngine({
+6
View File
@@ -191,6 +191,12 @@ export interface ToolInputSchema {
export interface ToolContext {
cwd: string
abortSignal?: AbortSignal
/** Parent agent's LLM provider (inherited by subagents) */
provider?: import('./providers/types.js').LLMProvider
/** Parent agent's model ID */
model?: string
/** Parent agent's API type */
apiType?: import('./providers/types.js').ApiType
}
export interface ToolResult {