/** * Multi-Agent Handler Base * * Abstract base class for platform-specific multi-agent handlers. * Contains shared infrastructure (orchestrator, process manager, queues, * delegation, background tasks) so Discord and Slack handlers only * implement platform-specific messaging and formatting. */ import type { MultiAgentConfig, AgentPersonaConfig, ChainState, MultiAgentRuntimeOptions } from './types.js'; import { MultiAgentOrchestrator } from './orchestrator.js'; import { AgentProcessManager } from './agent-process-manager.js'; import { type SharedContextManager } from './shared-context.js'; import type { PersistentProcessOptions } from '../agent/persistent-cli-process.js'; import { AgentMessageQueue } from './agent-message-queue.js'; import { BackgroundTaskManager } from './background-task-manager.js'; import { SystemReminderService } from './system-reminder.js'; import { DelegationManager } from './delegation-manager.js'; import { WorkTracker } from './work-tracker.js'; import type { GatewayToolExecutor } from '../agent/gateway-tool-executor.js'; import type { PromptCallbacks } from '../agent/types.js'; import { WorkflowEngine } from './workflow-engine.js'; import { CouncilEngine } from './council-engine.js'; import type { WorkflowProgressEvent, CouncilProgressEvent } from './workflow-types.js'; /** Default timeout for agent responses (5 minutes) */ export declare const AGENT_TIMEOUT_MS: () => number; /** * Response from a single agent */ export interface AgentResponse { /** Agent ID */ agentId: string; /** Agent configuration */ agent: AgentPersonaConfig; /** Formatted content (with agent prefix) */ content: string; /** Raw content from Claude */ rawContent: string; /** Response duration in ms */ duration?: number; /** Message ID (set after sending) */ messageId?: string; } /** * Multi-agent response result */ export interface MultiAgentResponse { /** Selected agent IDs */ selectedAgents: string[]; /** Selection reason */ reason: 'explicit_trigger' | 'keyword_match' | 'default_agent' | 'free_chat' | 'category_match' | 'delegation' | 'ultrawork' | 'mention_chain' | 'none'; /** Individual agent responses */ responses: AgentResponse[]; } /** * Abstract base class for platform-specific multi-agent handlers. * * Subclasses must implement: * - getPlatformName() - 'discord' | 'slack' * - formatBold(text) - platform-specific bold formatting * - extractMentionedAgentIds(content) - platform-specific mention extraction * - platformCleanup() - platform-specific cleanup on stopAll() */ export declare abstract class MultiAgentHandlerBase { protected logger: { debug: (message: string, ...args: unknown[]) => void; log: (message: string, ...args: unknown[]) => void; info: (message: string, ...args: unknown[]) => void; warn: (message: string, ...args: unknown[]) => void; error: (message: string, ...args: unknown[]) => void; }; protected config: MultiAgentConfig; protected orchestrator: MultiAgentOrchestrator; protected processManager: AgentProcessManager; protected sharedContext: SharedContextManager; protected messageQueue: AgentMessageQueue; protected backgroundTaskManager: BackgroundTaskManager; protected systemReminder: SystemReminderService; protected delegationManager: DelegationManager; protected workTracker: WorkTracker; protected gatewayToolExecutor: GatewayToolExecutor | null; protected workflowEngine: WorkflowEngine; protected councilEngine: CouncilEngine; /** Whether multi-bot mode is initialized */ protected multiBotInitialized: boolean; /** Dedup map for delegation mentions with timestamps (prevents double processing) */ protected processedMentions: Map; /** Cleanup interval handle for periodic tasks (queue expiry + mention dedup) */ private cleanupInterval; /** TTL for processed mention entries (5 minutes) */ protected static get MENTION_TTL_MS(): number; /** Cleanup interval period (1 minute) */ protected static get CLEANUP_INTERVAL_MS(): number; /** Platform identifier for process manager calls */ protected abstract getPlatformName(): 'discord' | 'slack'; /** Platform-specific bold formatting */ abstract formatBold(text: string): string; /** Platform-specific mention extraction from message content */ abstract extractMentionedAgentIds(content: string): string[]; /** Platform-specific cleanup called during stopAll() */ protected abstract platformCleanup(): Promise; /** Send a notification message to a channel (for background task status, queue expiry, etc.) */ protected abstract sendChannelNotification(channelId: string, message: string): Promise; constructor(config: MultiAgentConfig, processOptions?: Partial, runtimeOptions?: MultiAgentRuntimeOptions); /** * Setup idle event listeners for agent processes (F7) */ protected setupIdleListeners(): void; /** * Try to drain queued messages immediately (when no idle process exists to trigger drain). * Creates a new process if needed and drains if the process is idle. */ protected tryDrainNow(agentId: string, source: string, channelId: string): Promise; /** * Platform-specific queued response handler */ protected abstract sendQueuedResponse(agentId: string, message: import('./agent-message-queue.js').QueuedMessage, response: string): Promise; /** * Clean up old processed mention entries based on TTL */ protected cleanupProcessedMentions(): void; /** * Check if multi-agent mode is enabled */ isEnabled(): boolean; /** * Check if mention-based delegation is enabled */ isMentionDelegationEnabled(): boolean; /** * Format agent response with display name prefix */ protected formatAgentResponse(agent: AgentPersonaConfig, response: string): string; /** * Get orchestrator for direct access */ getOrchestrator(): MultiAgentOrchestrator; /** * Get process manager for direct access */ getProcessManager(): AgentProcessManager; /** * Get delegation manager for API access */ getDelegationManager(): DelegationManager; /** * Get shared context manager */ getSharedContext(): SharedContextManager; getBackgroundTaskManager(): BackgroundTaskManager; getSystemReminder(): SystemReminderService; /** * Get work tracker instance */ getWorkTracker(): WorkTracker; /** * Set the gateway tool executor for handling tool_use blocks from agents. */ setGatewayToolExecutor(executor: GatewayToolExecutor): void; /** * Parse ```tool_call blocks from response text (Gateway Tools mode). * Returns array of parsed tool calls. */ protected parseToolCallsFromText(text: string): Array<{ name: string; input: Record; }>; /** * Remove ```tool_call blocks from text (to avoid showing raw JSON to users). */ protected removeToolCallBlocks(text: string): string; /** * Parse and execute gateway tool calls from response text. * Returns the cleaned text (with tool_call blocks removed). * Tool calls are fire-and-forget (results not returned to Claude). */ protected executeTextToolCalls(responseText: string): Promise; /** * Build agent availability status section for prompt injection. * Shows busy/idle state and queue size for each agent except the current one. */ protected buildAgentStatusSection(excludeAgentId: string): string; /** * Get workflow engine instance */ getWorkflowEngine(): WorkflowEngine; /** * Check if a Conductor response contains a workflow plan and execute it. * Returns the workflow result or null if no plan was found. */ tryExecuteWorkflow(conductorResponse: string, channelId: string, source: 'discord' | 'slack', onProgress?: (event: WorkflowProgressEvent) => void, createStepCallbacks?: (agentId: string) => { callbacks: PromptCallbacks; cleanup: () => Promise; }): Promise<{ result: string; directMessage: string; failed?: string; } | null>; /** * Get council engine instance */ getCouncilEngine(): CouncilEngine; /** * Check if a Conductor response contains a council_plan and execute it. * Returns the council result or null if no plan was found. */ tryExecuteCouncil(conductorResponse: string, channelId: string, source: 'discord' | 'slack', onProgress?: (event: CouncilProgressEvent) => void): Promise<{ result: string; directMessage: string; } | null>; /** * Format ephemeral agent response with workflow prefix */ protected formatEphemeralAgentResponse(agentDisplayName: string, content: string): string; /** * Get chain state for a channel (for debugging) */ getChainState(channelId: string): ChainState; /** * Stop all agent processes and bots */ stopAll(): Promise; } //# sourceMappingURL=multi-agent-base.d.ts.map