/** * Delegation Manager * * Enables Tier 1 agents to delegate tasks to Tier 2/3 agents. * Parses DELEGATE::{agent_id}::{task} patterns from agent responses * and executes the delegation workflow. * * Supports two delegation modes: * - **Synchronous:** DELEGATE::{agent_id}::{task} — waits for result * - **Background:** DELEGATE_BG::{agent_id}::{task} — returns immediately, runs async * * Constraints: * - Only Tier 1 agents with can_delegate=true can delegate * - Maximum delegation depth of 1 (no re-delegation) * - Circular delegation prevention */ import type { AgentPersonaConfig } from './types.js'; import { ToolPermissionManager } from './tool-permission-manager.js'; import type { AgentLoopResult } from '../agent/types.js'; /** * Parsed delegation request */ export interface DelegationRequest { /** Agent ID that initiated the delegation */ fromAgentId: string; /** Target agent ID to delegate to */ toAgentId: string; /** Task description to delegate */ task: string; /** Original response content (without the DELEGATE pattern) */ originalContent: string; /** Whether this is a background (async) delegation */ background: boolean; } /** * Result of a delegation execution */ export interface DelegationResult { /** Whether delegation was successful */ success: boolean; /** Delegated agent's full response (if successful) */ agentLoopResult?: AgentLoopResult; /** Delegated agent's text response (if successful) */ response?: string; /** Error message (if failed) */ error?: string; /** Duration of delegation in ms */ duration?: number; } /** * Recorded delegation history entry */ export interface DelegationHistoryEntry { id: string; fromAgentId: string; toAgentId: string; task: string; background: boolean; status: 'active' | 'completed' | 'failed'; startedAt: string; completedAt: string | null; duration: number | null; error: string | null; } /** * Callback to send a message to a channel (for notifications) */ export type DelegationNotifyCallback = (message: string) => Promise; /** * Callback to get an agent's response for a given prompt */ export type DelegationExecuteCallback = (agentId: string, prompt: string) => Promise; /** * Delegation Manager */ export declare class DelegationManager { private permissionManager; private agents; /** Active delegations for circular prevention: Set */ private activeDelegations; /** In-memory ring buffer of delegation history (max 100 entries) */ private history; private historyMaxSize; private historyCounter; /** Sessions DB for agent_activity logging */ private sessionsDb; setSessionsDb(db: import('../sqlite.js').default): void; constructor(agents: AgentPersonaConfig[], permissionManager?: ToolPermissionManager); parseDelegation(agentId: string, response: string): DelegationRequest | null; parseAllDelegations(agentId: string, response: string): DelegationRequest[]; /** * Check if a delegation is allowed. */ getAgentConfig(agentId: string): Record | null; isDelegationAllowed(fromId: string, toId: string): { allowed: boolean; reason: string; }; /** * Execute a delegation request. */ executeDelegation(request: DelegationRequest, executeCallback: DelegationExecuteCallback, notifyCallback?: DelegationNotifyCallback): Promise; private logToActivity; /** * Update the agent list (for hot reload). */ updateAgents(agents: AgentPersonaConfig[]): void; /** * Get active delegation count (for monitoring). */ getActiveDelegationCount(): number; /** * Get recent delegation history. */ getRecentDelegations(limit?: number): DelegationHistoryEntry[]; /** * Add entry to ring buffer, evict oldest if full. */ private addHistoryEntry; /** * Build the prompt sent to the delegated agent. * Public so gateway tool handlers can call it directly. */ buildDelegationPrompt(fromAgentId: string, task: string): string; } //# sourceMappingURL=delegation-manager.d.ts.map