/** * Task Tool - LLM-controlled sub-agent spawning * * This tool allows the agent to spawn specialized sub-agents for complex tasks. * It implements the "Hybrid" approach where both programmatic and LLM-controlled * sub-agent spawning are supported. * * Enhanced features: * - Context inheritance modes (isolated, inherit, inherit-summary) * - Thoroughness levels for exploration agents * - Tool inheritance & filtering * - Event streaming from sub-agents * - Extended built-in agent types */ import type { Tool } from '../types.js'; import type { Agent, AgentEvent } from '../../agent.js'; import type { LLMProvider } from '../../providers/types.js'; /** * Context inheritance mode for sub-agents */ export type ContextMode = 'isolated' | 'inherit' | 'inherit-summary'; /** * Thoroughness level for exploration agents */ export type ThoroughnessLevel = 'quick' | 'medium' | 'thorough'; /** * Input parameters for task tool */ export interface TaskInput { /** * A short (3-5 word) description of the task */ description: string; /** * Detailed task prompt for the sub-agent to perform */ prompt: string; /** * The type of specialized agent to use (e.g., 'explore', 'code-review', 'general') */ subagent_type: string; /** * Optional model to use for this agent (e.g., 'sonnet', 'opus', 'haiku') */ model?: string; /** * Context inheritance mode (default: from agent type config) * - 'isolated': Fresh context, no parent history * - 'inherit': Receives parent's full message history * - 'inherit-summary': Receives summarized parent context */ context_mode?: ContextMode; /** * Thoroughness level for exploration agents (default: 'medium') * - 'quick': Fast searches, basic analysis * - 'medium': Balanced depth and speed * - 'thorough': Comprehensive analysis, multiple passes */ thoroughness?: ThoroughnessLevel; } /** * Result of task tool execution */ export interface TaskResult { /** * The sub-agent's response */ response: string; /** * The agent type that was used */ agentType: string; /** * Number of iterations the sub-agent took */ iterations: number; /** * Tool calls made by the sub-agent */ toolCalls: number; } /** * Configuration for a pre-defined agent type */ export interface AgentTypeConfig { /** * Description of what this agent type does */ description: string; /** * System prompt for this agent type */ systemPrompt?: string; /** * Tools available to this agent type (tool names or Tool instances) */ tools?: (string | Tool)[]; /** * Skills available to this agent type */ skills?: string[]; /** * Maximum iterations for this agent type */ maxIterations?: number; /** * Default model for this agent type */ defaultModel?: string; /** * Default context inheritance mode */ contextMode?: ContextMode; /** * Whether this agent type supports thoroughness levels */ supportsThoroughness?: boolean; /** * Tool inheritance mode: * - 'none': Only use tools specified in this config * - 'all': Inherit all parent tools plus config tools * - 'filter': Inherit parent tools filtered by allowedTools/deniedTools */ toolInheritance?: 'none' | 'all' | 'filter'; /** * Tool names to allow (whitelist) when toolInheritance is 'filter' */ allowedTools?: string[]; /** * Tool names to deny (blacklist) when toolInheritance is 'filter' */ deniedTools?: string[]; } /** * Sub-agent event with source information */ export interface SubAgentEventInfo { /** * Name of the sub-agent that emitted this event */ agentName: string; /** * Type of the sub-agent */ agentType: string; /** * Tool use ID for correlation with parent tool call */ toolUseId?: string; /** * The original event from the sub-agent */ event: AgentEvent; } /** * Options for creating a task tool */ export interface TaskToolOptions { /** * The parent agent that will spawn sub-agents */ parentAgent: Agent; /** * Available agent types and their configurations */ agentTypes: Record; /** * Provider factory for creating sub-agent providers * Called with model name, returns LLM provider */ providerFactory?: (model: string) => LLMProvider; /** * Maximum concurrent sub-agents (default: 3) */ maxConcurrent?: number; /** * Default timeout for sub-agent execution in ms (default: 300000 = 5 min) */ defaultTimeout?: number; /** * Called when a sub-agent is spawned. * @param agentType - The type of agent being spawned * @param description - Description of the task * @param toolUseId - Tool use ID for correlation (enables parallel tracking) */ onSpawn?: (agentType: string, description: string, toolUseId?: string) => void; /** * Called when a sub-agent completes. * @param agentType - The type of agent that completed * @param result - The task result * @param toolUseId - Tool use ID for correlation (enables parallel tracking) */ onComplete?: (agentType: string, result: TaskResult, toolUseId?: string) => void; /** * Called when a sub-agent emits an event (for real-time streaming) * Only called if enableEventStreaming is true */ onSubAgentEvent?: (eventInfo: SubAgentEventInfo) => void; /** * Enable event streaming from sub-agents (default: false) * When enabled, sub-agent events are forwarded to onSubAgentEvent */ enableEventStreaming?: boolean; } /** * Create a task tool for LLM-controlled sub-agent spawning */ export declare function createTaskTool(options: TaskToolOptions): Tool; /** * Default agent type configurations */ export declare const defaultAgentTypes: Record;