/** * Enhanced Agent Swarm for Multi-Provider Coordination * * This extends the base AgentSwarm with improved capabilities for: * - Managing specialized agents with different LLM providers * - More sophisticated inter-agent communication * - Better task decomposition and workload distribution * - Dynamic provider selection based on task types */ import { Agent } from './agent'; import { AgentSwarm } from './agent-swarm'; import { RunOptions, RunResult } from './types'; import { ProviderType } from './provider-interface'; import { Logger } from '../utils/logger'; /** * Configuration for agent specialization */ export interface AgentSpecialization { name: string; description: string; capabilities: string[]; preferredTaskTypes: string[]; provider: ProviderType; } /** * Enhanced task assignment with metadata */ export interface EnhancedAgentTask { id: string; agentId: string; description: string; dependencies: string[]; status: 'pending' | 'in_progress' | 'completed' | 'failed'; priority: 'low' | 'medium' | 'high'; taskType: string; estimatedEffort: 'low' | 'medium' | 'high'; result?: string; error?: string; startTime?: number; endTime?: number; } /** * Detailed coordination plan with metadata */ export interface EnhancedSwarmPlan { id: string; originalTask: string; tasks: EnhancedAgentTask[]; created: number; updated: number; status: 'created' | 'in_progress' | 'completed' | 'failed'; metadata: { expectedCompletionTime?: number; requiresExternalData: boolean; collaborationLevel: 'low' | 'medium' | 'high'; criticalPath?: string[]; }; } /** * Configuration for creating an enhanced agent swarm */ export interface EnhancedAgentSwarmConfig { agents: Agent[]; coordinator?: Agent; planningStrategy?: 'sequential' | 'parallel' | 'hierarchical'; maxConcurrentAgents?: number; agentSpecializations?: Record; enabledCommunicationChannels?: string[]; } /** * Agent communication message */ export interface AgentMessage { id: string; fromAgentId: string; toAgentId: string | 'broadcast'; content: string; timestamp: number; type: 'question' | 'answer' | 'update' | 'request' | 'feedback'; relatedTaskId?: string; } /** * EnhancedAgentSwarm extends the base AgentSwarm with more sophisticated * coordination capabilities, especially for multi-provider scenarios */ export declare class EnhancedAgentSwarm extends AgentSwarm { private agentSpecializations; private communicationLog; private enabledCommunicationChannels; private originalTask; protected swarmLogger: Logger; /** * Creates a new enhanced agent swarm * * @param config - Configuration for the swarm */ constructor(config: EnhancedAgentSwarmConfig); /** * Initialize default specializations based on agent providers */ private initializeDefaultSpecializations; /** * Creates an enhanced coordination plan with better task allocation * based on agent specializations * * @param task - The task to create a plan for * @returns Promise resolving to the created plan */ createEnhancedCoordinationPlan(task: string): Promise; /** * Enhanced execution method that incorporates agent specializations * and improved communication between agents * * @param task - The task to execute * @param options - Execution options * @returns Promise resolving to the execution result */ runEnhanced(options: RunOptions): Promise; /** * Execute a plan with high collaboration between agents, including * inter-agent communication * * @param plan - The plan to execute * @param options - Execution options * @returns Promise resolving to the execution result */ private executeWithHighCollaboration; /** * Execute a plan with focus on external data gathering and processing * * @param plan - The plan to execute * @param options - Execution options * @returns Promise resolving to the execution result */ private executeWithExternalDataFocus; /** * Find relevant results from previous tasks that could help with a current task */ private findRelevantResults; /** * Parse enhanced tasks from the coordinator's response */ private parseEnhancedTasksFromResponse; /** * Infer dependencies between tasks based on the response using the advanced dependency system */ private inferDependencies; /** * Basic dependency inference as a fallback if the advanced system fails */ private inferDependenciesBasic; /** * Fallback parsing method when structured parsing fails */ /** * Create default tasks for all agents based on their specializations */ private createDefaultTasksForAgents; private fallbackTaskParsing; /** * Normalize priority string to 'low', 'medium', or 'high' */ private normalizePriority; /** * Normalize effort string to 'low', 'medium', or 'high' */ private normalizeEffort; /** * Determine the collaboration level needed for a set of tasks */ private determineCollaborationLevel; /** * Calculate the critical path of tasks (tasks that must be completed * in sequence and determine the minimum completion time) */ private calculateCriticalPath; /** * Enable direct communication between agents * * @param fromAgentId - ID of the sending agent * @param toAgentId - ID of the receiving agent or 'broadcast' for all * @param content - Message content * @param type - Message type * @param relatedTaskId - Optional related task ID * @returns ID of the sent message */ sendAgentMessage(fromAgentId: string, toAgentId: string | 'broadcast', content: string, type?: AgentMessage['type'], relatedTaskId?: string): string; /** * Get messages sent to a specific agent * * @param agentId - ID of the agent * @returns Array of messages sent to the agent */ getMessagesForAgent(agentId: string): AgentMessage[]; /** * Get the coordinator agent * * @returns The coordinator agent */ getCoordinator(): Agent; }