/** * Agent Process Manager * * Manages per-agent persistent CLI processes with persona-specific * system prompts and channel isolation. * * Channel key format: {source}:{channelId}:{agentId} * Example: "discord:123456789:developer" */ import { EventEmitter } from 'events'; import { PersistentProcessPool, type PersistentProcessOptions } from '../agent/persistent-cli-process.js'; import type { MultiAgentConfig, MultiAgentRuntimeOptions } from './types.js'; import { type AgentRuntimeProcess } from './runtime-process.js'; import type { EphemeralAgentDef } from './workflow-types.js'; /** * Agent Process Manager * * Features: * - One persistent CLI process per agent per channel * - Persona file loading and system prompt injection * - Automatic process lifecycle management * * Events: * - 'process-created': { agentId: string, process: AgentRuntimeProcess } */ export declare class AgentProcessManager extends EventEmitter { private config; private processPool; private codexProcessPool; private permissionManager; private runtimeOptions; private readonly tracePromptMs; private readonly dumpConductorPrompt; /** Cached persona content: Map */ private personaCache; /** Bot user ID map for mention-based delegation: agentId → Discord userId */ private botUserIdMap; /** Whether mention-based delegation is enabled */ private mentionDelegationEnabled; /** Default options for all processes */ private defaultOptions; constructor(config: MultiAgentConfig, defaultOptions?: Partial, runtimeOptions?: MultiAgentRuntimeOptions); /** * Update configuration (for hot reload) */ updateConfig(config: MultiAgentConfig): void; private getAgentBackend; /** * Set the bot user ID map for mention-based delegation * Clears persona cache to regenerate system prompts with mention info */ setBotUserIdMap(map: Map): void; /** * Enable or disable mention-based delegation * Clears persona cache to regenerate system prompts */ setMentionDelegation(enabled: boolean): void; private isEphemeralAgent; private clearPersonaCache; /** * Build channel key for process pool * Format: {source}:{channelId}:{agentId} */ buildChannelKey(source: string, channelId: string, agentId: string): string; /** * Parse channel key */ parseChannelKey(channelKey: string): { source: string; channelId: string; agentId: string; }; /** * Get or create a process for an agent in a channel */ getProcess(source: string, channelId: string, agentId: string, overrides?: { requestTimeout?: number; }): Promise; /** * Get a shared singleton process for system-level agents (e.g., memory agent). * Unlike getProcess() which creates per-channel processes, this returns * a single persistent process shared across all channels. * * Uses fixed channelKey: `__system__::` */ getSharedProcess(agentId: string, overrides?: { requestTimeout?: number; }): Promise; /** * Factory: create a runner for a given backend. * Claude runners are managed by PersistentProcessPool (returned separately). * Codex runners are created here as standalone instances. */ private createCodexRunner; /** * Load persona system prompt for an agent */ loadPersona(agentId: string): Promise; /** * Build system prompt with persona content */ private buildSystemPrompt; private buildToolsSection; private deriveCodeActAllowedTools; private filterCodeActAllowedTools; private shouldTracePrompt; private shouldInjectBmadBlock; /** * Resolve the preferred model ID for a given backend from config. * Scans registered agents to find the first model matching the backend. * Falls back to runtimeOptions.model for claude, 'unknown' otherwise. */ resolveModelForBackend(backend: string): string; /** * Build installed skills prompt section */ private buildSkillsPrompt; private shouldOmitSkillCatalog; /** * Build BMAD planning context block for Conductor's system prompt. * Returns an explicit marker on failure for easier diagnosis. */ private buildBmadBlock; /** * Build default persona when file is missing */ private buildDefaultPersona; /** * Stop a specific agent's process in a channel */ stopProcess(source: string, channelId: string, agentId: string): void; /** * Stop all processes for a channel (all agents) */ stopChannelProcesses(source: string, channelId: string): void; /** * Stop all processes for an agent (all channels) */ stopAgentProcesses(agentId: string): void; /** * Stop all processes */ stopAll(): void; /** * Get number of active processes */ getActiveCount(): number; /** * Get all active channel keys */ getActiveChannels(): string[]; /** * Get states of all agent processes, aggregated by agentId. * Returns the "most active" state per agent (busy > starting > idle > dead). */ getAgentStates(): Map; /** * Register an ephemeral agent definition (for workflow orchestration). * The agent is added to config.agents so getProcess() can find it. */ registerEphemeralAgent(agentDef: EphemeralAgentDef): Promise; /** * Unregister ephemeral agents and clean up their processes. */ unregisterEphemeralAgents(agentDefs: EphemeralAgentDef[]): void; /** * Reload persona for an agent (clears cache) */ reloadPersona(agentId: string): void; /** * Reload all personas */ reloadAllPersonas(): void; /** * Get process pool (for advanced usage) */ getProcessPool(): PersistentProcessPool; /** * Check if an agent has an active process in a channel */ hasActiveProcess(source: string, channelId: string, agentId: string): boolean; /** * Get agent IDs with active processes in a given channel */ getActiveAgentsInChannel(source: string, channelId: string): string[]; } //# sourceMappingURL=agent-process-manager.d.ts.map