/** * SubAgentManager: tracks active sub-agents, enforces concurrency limits, * manages lifecycle, and delivers background completion notifications. * * Each sub-agent is an independent CortexAgent instance tracked by task ID. * The manager does not own the CortexAgent; it tracks references and * coordinates lifecycle events for the consumer. * * References: * - docs/cortex/tools/sub-agent.md * - docs/cortex/plans/phase-4-sub-agents-and-skills.md */ import type { SubAgentResult, TrackedSubAgent } from './types.js'; export interface SubAgentManagerConfig { /** Maximum concurrent sub-agents. Default: 4. */ maxConcurrent: number; } export interface SubAgentLifecycleHooks { onSpawned?: (taskId: string, instructions: string, background: boolean) => void; onCompleted?: (taskId: string, result: string, status: string, usage: unknown) => void; onFailed?: (taskId: string, error: string) => void; } export declare class SubAgentManager { private readonly agents; private readonly maxConcurrent; private hooks; constructor(config?: Partial); /** * Set lifecycle hooks. Called by CortexAgent to wire consumer event handlers. */ setHooks(hooks: SubAgentLifecycleHooks): void; /** * Check if another sub-agent can be spawned within the concurrency limit. */ canSpawn(): boolean; /** * Get the number of currently active sub-agents. */ get activeCount(): number; /** * Get the concurrency limit. */ get limit(): number; /** * Register a newly spawned sub-agent. * Returns false if the concurrency limit would be exceeded. */ track(entry: TrackedSubAgent): boolean; /** * Mark a sub-agent as completed and remove it from tracking. */ complete(taskId: string, result: SubAgentResult): void; /** * Mark a sub-agent as failed and remove it from tracking. */ fail(taskId: string, error: string): void; /** * Get a tracked sub-agent by task ID. */ get(taskId: string): TrackedSubAgent | undefined; /** * Update tool activity for a running sub-agent. * Called when child tool_call_start events are forwarded via EventBridge. */ updateToolActivity(taskId: string, toolName: string, summary: string): void; /** * Get all active sub-agent task IDs. */ getActiveTaskIds(): string[]; /** * Get completion promises for all background sub-agents. * Used to build follow-up messages when background agents complete. */ getBackgroundCompletions(): Array<{ taskId: string; completion: Promise; }>; /** * Cancel all active sub-agents. Called during parent destroy(). * Aborts each sub-agent and removes it from tracking. * * @param abortFn - Function to abort a CortexAgent (passed to avoid circular dep) */ cancelAll(abortFn: (agent: unknown) => Promise): Promise; /** * Clean up all state. Called during parent destroy(). */ destroy(): void; } //# sourceMappingURL=sub-agent-manager.d.ts.map