/** * In-process scoped subagents (agent-loop-capability-port sprint 10). * * Builds the `spawn_subagent` ToolDef + handler for `AgenticLoopParams.subagents`. * The handler resolves a configured `SubagentDef` by name and runs it as a * NESTED `runAgenticLoop` call with a fresh message history, a scoped tool * subset, optional per-agent model/effort/maxTurns overrides, and the SAME * parent `Budget` instance — combined spend stays visible and a child can * never out-spend a parent ceiling. Only the child's `finalText` returns to * the parent (as this tool's result); the parent's own context grows by that * summary alone. * * One-level hard cap (nonGoal #1): the child ALWAYS gets `subagents: undefined` * — recursive subagent nesting is not supported. * * Import-cycle note: this module imports the loop's TYPES only * (`AgenticLoopParams`/`AgenticLoopResult`), never the `runAgenticLoop` * VALUE. The loop passes its own (hoisted) function reference in via * `BuildSubagentOpts.runLoop`, keeping runtime dependencies one-directional * (agentic-loop.ts -> subagents.ts, never the reverse). */ import type { LLMClient, ToolDef } from "../providers/types.js"; import type { ToolHandler } from "./tools/index.js"; import type { AgenticLoopParams, AgenticLoopResult } from "./agentic-loop.js"; /** A programmatically-declared subagent a parent loop can delegate a bounded subtask to. */ export interface SubagentDef { name: string; description: string; systemPrompt: string; /** Subset of the PARENT's tool NAMES this subagent may use. */ tools: string[]; /** Model shorthand override (e.g. "sonnet", "haiku"). Absent => inherit the parent's client/model. */ model?: string; effort?: AgenticLoopParams["effort"]; /** Max nested-loop turns. Defaults to 10 when omitted. */ maxTurns?: number; } export interface BuildSubagentOpts { /** * REQUIRED to break the subagents.ts <-> agentic-loop.ts import cycle — the * loop passes its own `runAgenticLoop` function reference; tests pass a fake. */ runLoop: (params: AgenticLoopParams) => Promise; /** * Injected for tests so `def.model` needs no real provider/API key. * Defaults to the real `createClient` factory (provider inferred from the * model shorthand — mirrors how role entry points build their own clients). */ clientFactory?: (model: string) => LLMClient; } /** * Build the `spawn_subagent` ToolDef + handler for a parent loop's * `AgenticLoopParams.subagents`. `runAgenticLoop` registers the returned tool * BEFORE its own loop starts (when `params.subagents?.length`); the handler * resolves the requested subagent by name and runs it as a fresh, scoped, * budget-shared nested loop. */ export declare function buildSubagentTool(defs: SubagentDef[], parentParams: AgenticLoopParams, opts: BuildSubagentOpts): { tool: ToolDef; handler: ToolHandler; }; //# sourceMappingURL=subagents.d.ts.map