mirror of
https://github.com/codeany-ai/open-agent-sdk-typescript.git
synced 2026-04-25 07:00:49 +09:00
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:
@@ -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(
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user