@framers/agentos 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +98 -0
- package/README.md +576 -0
- package/dist/api/AgentOS.d.ts +451 -0
- package/dist/api/AgentOS.d.ts.map +1 -0
- package/dist/api/AgentOS.js +1157 -0
- package/dist/api/AgentOS.js.map +1 -0
- package/dist/api/AgentOSOrchestrator.d.ts +157 -0
- package/dist/api/AgentOSOrchestrator.d.ts.map +1 -0
- package/dist/api/AgentOSOrchestrator.js +679 -0
- package/dist/api/AgentOSOrchestrator.js.map +1 -0
- package/dist/api/interfaces/IAgentOS.d.ts +138 -0
- package/dist/api/interfaces/IAgentOS.d.ts.map +1 -0
- package/dist/api/interfaces/IAgentOS.js +11 -0
- package/dist/api/interfaces/IAgentOS.js.map +1 -0
- package/dist/api/interfaces/IUnifiedAgent.d.ts +126 -0
- package/dist/api/interfaces/IUnifiedAgent.d.ts.map +1 -0
- package/dist/api/interfaces/IUnifiedAgent.js +3 -0
- package/dist/api/interfaces/IUnifiedAgent.js.map +1 -0
- package/dist/api/types/AgentOSInput.d.ts +114 -0
- package/dist/api/types/AgentOSInput.d.ts.map +1 -0
- package/dist/api/types/AgentOSInput.js +13 -0
- package/dist/api/types/AgentOSInput.js.map +1 -0
- package/dist/api/types/AgentOSResponse.d.ts +170 -0
- package/dist/api/types/AgentOSResponse.d.ts.map +1 -0
- package/dist/api/types/AgentOSResponse.js +25 -0
- package/dist/api/types/AgentOSResponse.js.map +1 -0
- package/dist/cognitive_substrate/GMI.d.ts +148 -0
- package/dist/cognitive_substrate/GMI.d.ts.map +1 -0
- package/dist/cognitive_substrate/GMI.js +1003 -0
- package/dist/cognitive_substrate/GMI.js.map +1 -0
- package/dist/cognitive_substrate/GMIManager.d.ts +98 -0
- package/dist/cognitive_substrate/GMIManager.d.ts.map +1 -0
- package/dist/cognitive_substrate/GMIManager.js +517 -0
- package/dist/cognitive_substrate/GMIManager.js.map +1 -0
- package/dist/cognitive_substrate/IGMI.d.ts +469 -0
- package/dist/cognitive_substrate/IGMI.d.ts.map +1 -0
- package/dist/cognitive_substrate/IGMI.js +111 -0
- package/dist/cognitive_substrate/IGMI.js.map +1 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.d.ts +139 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.d.ts.map +1 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.js +14 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.js.map +1 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.d.ts +143 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.d.ts.map +1 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.js +186 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.js.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.d.ts +33 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.d.ts.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.js +138 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.js.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.d.ts +32 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.d.ts.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.js +2 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.js.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts +336 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.js +8 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.js.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.d.ts +78 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.js +9 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.js.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.d.ts +60 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.js +138 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.js.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.d.ts +139 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.js +277 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.js.map +1 -0
- package/dist/cognitive_substrate/personas/definitions/atlas_systems_architect.json +29 -0
- package/dist/cognitive_substrate/personas/definitions/default_assistant_persona.json +346 -0
- package/dist/cognitive_substrate/personas/definitions/default_free_assistant.json +13 -0
- package/dist/cognitive_substrate/personas/definitions/index.d.ts +14 -0
- package/dist/cognitive_substrate/personas/definitions/index.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/definitions/index.js +35 -0
- package/dist/cognitive_substrate/personas/definitions/index.js.map +1 -0
- package/dist/cognitive_substrate/personas/definitions/nerf_generalist.json +11 -0
- package/dist/cognitive_substrate/personas/definitions/v_researcher.json +11 -0
- package/dist/config/AgentOSConfig.d.ts +74 -0
- package/dist/config/AgentOSConfig.d.ts.map +1 -0
- package/dist/config/AgentOSConfig.js +399 -0
- package/dist/config/AgentOSConfig.js.map +1 -0
- package/dist/config/EmbeddingManagerConfiguration.d.ts +190 -0
- package/dist/config/EmbeddingManagerConfiguration.d.ts.map +1 -0
- package/dist/config/EmbeddingManagerConfiguration.js +16 -0
- package/dist/config/EmbeddingManagerConfiguration.js.map +1 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.d.ts +165 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.d.ts.map +1 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.js +69 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.js.map +1 -0
- package/dist/config/RetrievalAugmentorConfiguration.d.ts +98 -0
- package/dist/config/RetrievalAugmentorConfiguration.d.ts.map +1 -0
- package/dist/config/RetrievalAugmentorConfiguration.js +47 -0
- package/dist/config/RetrievalAugmentorConfiguration.js.map +1 -0
- package/dist/config/ToolOrchestratorConfig.d.ts +69 -0
- package/dist/config/ToolOrchestratorConfig.d.ts.map +1 -0
- package/dist/config/ToolOrchestratorConfig.js +11 -0
- package/dist/config/ToolOrchestratorConfig.js.map +1 -0
- package/dist/config/VectorStoreConfiguration.d.ts +223 -0
- package/dist/config/VectorStoreConfiguration.d.ts.map +1 -0
- package/dist/config/VectorStoreConfiguration.js +59 -0
- package/dist/config/VectorStoreConfiguration.js.map +1 -0
- package/dist/config/extension-secrets.json +38 -0
- package/dist/config/extensionSecrets.d.ts +13 -0
- package/dist/config/extensionSecrets.d.ts.map +1 -0
- package/dist/config/extensionSecrets.js +24 -0
- package/dist/config/extensionSecrets.js.map +1 -0
- package/dist/core/agency/AgencyMemoryManager.d.ts +300 -0
- package/dist/core/agency/AgencyMemoryManager.d.ts.map +1 -0
- package/dist/core/agency/AgencyMemoryManager.js +657 -0
- package/dist/core/agency/AgencyMemoryManager.js.map +1 -0
- package/dist/core/agency/AgencyRegistry.d.ts +100 -0
- package/dist/core/agency/AgencyRegistry.d.ts.map +1 -0
- package/dist/core/agency/AgencyRegistry.js +209 -0
- package/dist/core/agency/AgencyRegistry.js.map +1 -0
- package/dist/core/agency/AgencyTypes.d.ts +200 -0
- package/dist/core/agency/AgencyTypes.d.ts.map +1 -0
- package/dist/core/agency/AgencyTypes.js +7 -0
- package/dist/core/agency/AgencyTypes.js.map +1 -0
- package/dist/core/agency/AgentCommunicationBus.d.ts +150 -0
- package/dist/core/agency/AgentCommunicationBus.d.ts.map +1 -0
- package/dist/core/agency/AgentCommunicationBus.js +568 -0
- package/dist/core/agency/AgentCommunicationBus.js.map +1 -0
- package/dist/core/agency/IAgentCommunicationBus.d.ts +469 -0
- package/dist/core/agency/IAgentCommunicationBus.d.ts.map +1 -0
- package/dist/core/agency/IAgentCommunicationBus.js +40 -0
- package/dist/core/agency/IAgentCommunicationBus.js.map +1 -0
- package/dist/core/agency/index.d.ts +18 -0
- package/dist/core/agency/index.d.ts.map +1 -0
- package/dist/core/agency/index.js +18 -0
- package/dist/core/agency/index.js.map +1 -0
- package/dist/core/agents/AgentCore.d.ts +385 -0
- package/dist/core/agents/AgentCore.d.ts.map +1 -0
- package/dist/core/agents/AgentCore.js +527 -0
- package/dist/core/agents/AgentCore.js.map +1 -0
- package/dist/core/agents/AgentFactory.d.ts +123 -0
- package/dist/core/agents/AgentFactory.d.ts.map +1 -0
- package/dist/core/agents/AgentFactory.js +232 -0
- package/dist/core/agents/AgentFactory.js.map +1 -0
- package/dist/core/agents/AgentPoolAgent.d.ts +244 -0
- package/dist/core/agents/AgentPoolAgent.d.ts.map +1 -0
- package/dist/core/agents/AgentPoolAgent.js +697 -0
- package/dist/core/agents/AgentPoolAgent.js.map +1 -0
- package/dist/core/agents/AgentPoolConfig.d.ts +191 -0
- package/dist/core/agents/AgentPoolConfig.d.ts.map +1 -0
- package/dist/core/agents/AgentPoolConfig.js +58 -0
- package/dist/core/agents/AgentPoolConfig.js.map +1 -0
- package/dist/core/agents/IAgent.d.ts +226 -0
- package/dist/core/agents/IAgent.d.ts.map +1 -0
- package/dist/core/agents/IAgent.js +14 -0
- package/dist/core/agents/IAgent.js.map +1 -0
- package/dist/core/agents/IAgentFactory.d.ts +137 -0
- package/dist/core/agents/IAgentFactory.d.ts.map +1 -0
- package/dist/core/agents/IAgentFactory.js +13 -0
- package/dist/core/agents/IAgentFactory.js.map +1 -0
- package/dist/core/agents/tools/Tool.d.ts +17 -0
- package/dist/core/agents/tools/Tool.d.ts.map +1 -0
- package/dist/core/agents/tools/Tool.js +8 -0
- package/dist/core/agents/tools/Tool.js.map +1 -0
- package/dist/core/ai_utilities/HybridUtilityAI.d.ts +1 -0
- package/dist/core/ai_utilities/HybridUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/HybridUtilityAI.js +2 -0
- package/dist/core/ai_utilities/HybridUtilityAI.js.map +1 -0
- package/dist/core/ai_utilities/IUtilityAI.d.ts +212 -0
- package/dist/core/ai_utilities/IUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/IUtilityAI.js +11 -0
- package/dist/core/ai_utilities/IUtilityAI.js.map +1 -0
- package/dist/core/ai_utilities/LLMUtilityAI.d.ts +94 -0
- package/dist/core/ai_utilities/LLMUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/LLMUtilityAI.js +434 -0
- package/dist/core/ai_utilities/LLMUtilityAI.js.map +1 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.d.ts +102 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.js +617 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.js.map +1 -0
- package/dist/core/conversation/ConversationContext.d.ts +259 -0
- package/dist/core/conversation/ConversationContext.d.ts.map +1 -0
- package/dist/core/conversation/ConversationContext.js +450 -0
- package/dist/core/conversation/ConversationContext.js.map +1 -0
- package/dist/core/conversation/ConversationManager.d.ts +223 -0
- package/dist/core/conversation/ConversationManager.d.ts.map +1 -0
- package/dist/core/conversation/ConversationManager.js +558 -0
- package/dist/core/conversation/ConversationManager.js.map +1 -0
- package/dist/core/conversation/ConversationMessage.d.ts +184 -0
- package/dist/core/conversation/ConversationMessage.d.ts.map +1 -0
- package/dist/core/conversation/ConversationMessage.js +66 -0
- package/dist/core/conversation/ConversationMessage.js.map +1 -0
- package/dist/core/evaluation/Evaluator.d.ts +28 -0
- package/dist/core/evaluation/Evaluator.d.ts.map +1 -0
- package/dist/core/evaluation/Evaluator.js +490 -0
- package/dist/core/evaluation/Evaluator.js.map +1 -0
- package/dist/core/evaluation/IEvaluator.d.ts +309 -0
- package/dist/core/evaluation/IEvaluator.d.ts.map +1 -0
- package/dist/core/evaluation/IEvaluator.js +12 -0
- package/dist/core/evaluation/IEvaluator.js.map +1 -0
- package/dist/core/evaluation/LLMJudge.d.ts +105 -0
- package/dist/core/evaluation/LLMJudge.d.ts.map +1 -0
- package/dist/core/evaluation/LLMJudge.js +229 -0
- package/dist/core/evaluation/LLMJudge.js.map +1 -0
- package/dist/core/evaluation/index.d.ts +9 -0
- package/dist/core/evaluation/index.d.ts.map +1 -0
- package/dist/core/evaluation/index.js +9 -0
- package/dist/core/evaluation/index.js.map +1 -0
- package/dist/core/guardrails/IGuardrailService.d.ts +142 -0
- package/dist/core/guardrails/IGuardrailService.d.ts.map +1 -0
- package/dist/core/guardrails/IGuardrailService.js +24 -0
- package/dist/core/guardrails/IGuardrailService.js.map +1 -0
- package/dist/core/guardrails/guardrailDispatcher.d.ts +36 -0
- package/dist/core/guardrails/guardrailDispatcher.d.ts.map +1 -0
- package/dist/core/guardrails/guardrailDispatcher.js +240 -0
- package/dist/core/guardrails/guardrailDispatcher.js.map +1 -0
- package/dist/core/hitl/HumanInteractionManager.d.ts +146 -0
- package/dist/core/hitl/HumanInteractionManager.d.ts.map +1 -0
- package/dist/core/hitl/HumanInteractionManager.js +491 -0
- package/dist/core/hitl/HumanInteractionManager.js.map +1 -0
- package/dist/core/hitl/IHumanInteractionManager.d.ts +521 -0
- package/dist/core/hitl/IHumanInteractionManager.d.ts.map +1 -0
- package/dist/core/hitl/IHumanInteractionManager.js +33 -0
- package/dist/core/hitl/IHumanInteractionManager.js.map +1 -0
- package/dist/core/hitl/index.d.ts +17 -0
- package/dist/core/hitl/index.d.ts.map +1 -0
- package/dist/core/hitl/index.js +17 -0
- package/dist/core/hitl/index.js.map +1 -0
- package/dist/core/knowledge/IKnowledgeGraph.d.ts +351 -0
- package/dist/core/knowledge/IKnowledgeGraph.d.ts.map +1 -0
- package/dist/core/knowledge/IKnowledgeGraph.js +10 -0
- package/dist/core/knowledge/IKnowledgeGraph.js.map +1 -0
- package/dist/core/knowledge/KnowledgeGraph.d.ts +93 -0
- package/dist/core/knowledge/KnowledgeGraph.d.ts.map +1 -0
- package/dist/core/knowledge/KnowledgeGraph.js +601 -0
- package/dist/core/knowledge/KnowledgeGraph.js.map +1 -0
- package/dist/core/knowledge/index.d.ts +8 -0
- package/dist/core/knowledge/index.d.ts.map +1 -0
- package/dist/core/knowledge/index.js +8 -0
- package/dist/core/knowledge/index.js.map +1 -0
- package/dist/core/language/LanguageService.d.ts +77 -0
- package/dist/core/language/LanguageService.d.ts.map +1 -0
- package/dist/core/language/LanguageService.js +305 -0
- package/dist/core/language/LanguageService.js.map +1 -0
- package/dist/core/language/index.d.ts +6 -0
- package/dist/core/language/index.d.ts.map +1 -0
- package/dist/core/language/index.js +6 -0
- package/dist/core/language/index.js.map +1 -0
- package/dist/core/language/interfaces.d.ts +168 -0
- package/dist/core/language/interfaces.d.ts.map +1 -0
- package/dist/core/language/interfaces.js +37 -0
- package/dist/core/language/interfaces.js.map +1 -0
- package/dist/core/language/providers/DeepLTranslationProvider.d.ts +16 -0
- package/dist/core/language/providers/DeepLTranslationProvider.d.ts.map +1 -0
- package/dist/core/language/providers/DeepLTranslationProvider.js +28 -0
- package/dist/core/language/providers/DeepLTranslationProvider.js.map +1 -0
- package/dist/core/language/providers/OpenAITranslationProvider.d.ts +17 -0
- package/dist/core/language/providers/OpenAITranslationProvider.d.ts.map +1 -0
- package/dist/core/language/providers/OpenAITranslationProvider.js +34 -0
- package/dist/core/language/providers/OpenAITranslationProvider.js.map +1 -0
- package/dist/core/language/providers/WhisperDetectionProvider.d.ts +16 -0
- package/dist/core/language/providers/WhisperDetectionProvider.d.ts.map +1 -0
- package/dist/core/language/providers/WhisperDetectionProvider.js +15 -0
- package/dist/core/language/providers/WhisperDetectionProvider.js.map +1 -0
- package/dist/core/llm/IPromptEngine.d.ts +627 -0
- package/dist/core/llm/IPromptEngine.d.ts.map +1 -0
- package/dist/core/llm/IPromptEngine.js +81 -0
- package/dist/core/llm/IPromptEngine.js.map +1 -0
- package/dist/core/llm/PromptEngine.d.ts +108 -0
- package/dist/core/llm/PromptEngine.d.ts.map +1 -0
- package/dist/core/llm/PromptEngine.js +872 -0
- package/dist/core/llm/PromptEngine.js.map +1 -0
- package/dist/core/llm/providers/AIModelProviderManager.d.ts +74 -0
- package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -0
- package/dist/core/llm/providers/AIModelProviderManager.js +263 -0
- package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -0
- package/dist/core/llm/providers/IProvider.d.ts +327 -0
- package/dist/core/llm/providers/IProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/IProvider.js +39 -0
- package/dist/core/llm/providers/IProvider.js.map +1 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts +36 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.js +40 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.d.ts +42 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.js +44 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.d.ts +39 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.js +42 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/ProviderError.d.ts +37 -0
- package/dist/core/llm/providers/errors/ProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/ProviderError.js +36 -0
- package/dist/core/llm/providers/errors/ProviderError.js.map +1 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.d.ts +80 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.js +473 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts +160 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.js +672 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts +51 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js +499 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js.map +1 -0
- package/dist/core/llm/routing/IModelRouter.d.ts +129 -0
- package/dist/core/llm/routing/IModelRouter.d.ts.map +1 -0
- package/dist/core/llm/routing/IModelRouter.js +14 -0
- package/dist/core/llm/routing/IModelRouter.js.map +1 -0
- package/dist/core/llm/routing/ModelRouter.d.ts +157 -0
- package/dist/core/llm/routing/ModelRouter.d.ts.map +1 -0
- package/dist/core/llm/routing/ModelRouter.js +190 -0
- package/dist/core/llm/routing/ModelRouter.js.map +1 -0
- package/dist/core/llm/streaming/StreamingBatcher.d.ts +54 -0
- package/dist/core/llm/streaming/StreamingBatcher.d.ts.map +1 -0
- package/dist/core/llm/streaming/StreamingBatcher.js +173 -0
- package/dist/core/llm/streaming/StreamingBatcher.js.map +1 -0
- package/dist/core/llm/streaming/StreamingReconstructor.d.ts +69 -0
- package/dist/core/llm/streaming/StreamingReconstructor.d.ts.map +1 -0
- package/dist/core/llm/streaming/StreamingReconstructor.js +102 -0
- package/dist/core/llm/streaming/StreamingReconstructor.js.map +1 -0
- package/dist/core/marketplace/IMarketplace.d.ts +500 -0
- package/dist/core/marketplace/IMarketplace.d.ts.map +1 -0
- package/dist/core/marketplace/IMarketplace.js +10 -0
- package/dist/core/marketplace/IMarketplace.js.map +1 -0
- package/dist/core/marketplace/Marketplace.d.ts +122 -0
- package/dist/core/marketplace/Marketplace.d.ts.map +1 -0
- package/dist/core/marketplace/Marketplace.js +591 -0
- package/dist/core/marketplace/Marketplace.js.map +1 -0
- package/dist/core/marketplace/index.d.ts +8 -0
- package/dist/core/marketplace/index.d.ts.map +1 -0
- package/dist/core/marketplace/index.js +8 -0
- package/dist/core/marketplace/index.js.map +1 -0
- package/dist/core/observability/ITracer.d.ts +317 -0
- package/dist/core/observability/ITracer.d.ts.map +1 -0
- package/dist/core/observability/ITracer.js +55 -0
- package/dist/core/observability/ITracer.js.map +1 -0
- package/dist/core/observability/Tracer.d.ts +76 -0
- package/dist/core/observability/Tracer.d.ts.map +1 -0
- package/dist/core/observability/Tracer.js +360 -0
- package/dist/core/observability/Tracer.js.map +1 -0
- package/dist/core/observability/index.d.ts +9 -0
- package/dist/core/observability/index.d.ts.map +1 -0
- package/dist/core/observability/index.js +8 -0
- package/dist/core/observability/index.js.map +1 -0
- package/dist/core/orchestration/AgentOrchestrator.d.ts +243 -0
- package/dist/core/orchestration/AgentOrchestrator.d.ts.map +1 -0
- package/dist/core/orchestration/AgentOrchestrator.js +648 -0
- package/dist/core/orchestration/AgentOrchestrator.js.map +1 -0
- package/dist/core/orchestration/IAgentOrchestrator.d.ts +44 -0
- package/dist/core/orchestration/IAgentOrchestrator.d.ts.map +1 -0
- package/dist/core/orchestration/IAgentOrchestrator.js +4 -0
- package/dist/core/orchestration/IAgentOrchestrator.js.map +1 -0
- package/dist/core/orchestration/helpers.d.ts +12 -0
- package/dist/core/orchestration/helpers.d.ts.map +1 -0
- package/dist/core/orchestration/helpers.js +36 -0
- package/dist/core/orchestration/helpers.js.map +1 -0
- package/dist/core/planning/IPlanningEngine.d.ts +524 -0
- package/dist/core/planning/IPlanningEngine.d.ts.map +1 -0
- package/dist/core/planning/IPlanningEngine.js +32 -0
- package/dist/core/planning/IPlanningEngine.js.map +1 -0
- package/dist/core/planning/PlanningEngine.d.ts +161 -0
- package/dist/core/planning/PlanningEngine.d.ts.map +1 -0
- package/dist/core/planning/PlanningEngine.js +783 -0
- package/dist/core/planning/PlanningEngine.js.map +1 -0
- package/dist/core/planning/index.d.ts +25 -0
- package/dist/core/planning/index.d.ts.map +1 -0
- package/dist/core/planning/index.js +25 -0
- package/dist/core/planning/index.js.map +1 -0
- package/dist/core/sandbox/CodeSandbox.d.ts +86 -0
- package/dist/core/sandbox/CodeSandbox.d.ts.map +1 -0
- package/dist/core/sandbox/CodeSandbox.js +475 -0
- package/dist/core/sandbox/CodeSandbox.js.map +1 -0
- package/dist/core/sandbox/ICodeSandbox.d.ts +249 -0
- package/dist/core/sandbox/ICodeSandbox.d.ts.map +1 -0
- package/dist/core/sandbox/ICodeSandbox.js +24 -0
- package/dist/core/sandbox/ICodeSandbox.js.map +1 -0
- package/dist/core/sandbox/index.d.ts +9 -0
- package/dist/core/sandbox/index.d.ts.map +1 -0
- package/dist/core/sandbox/index.js +8 -0
- package/dist/core/sandbox/index.js.map +1 -0
- package/dist/core/storage/IStorageAdapter.d.ts +483 -0
- package/dist/core/storage/IStorageAdapter.d.ts.map +1 -0
- package/dist/core/storage/IStorageAdapter.js +19 -0
- package/dist/core/storage/IStorageAdapter.js.map +1 -0
- package/dist/core/storage/InMemoryStorageAdapter.d.ts +192 -0
- package/dist/core/storage/InMemoryStorageAdapter.d.ts.map +1 -0
- package/dist/core/storage/InMemoryStorageAdapter.js +343 -0
- package/dist/core/storage/InMemoryStorageAdapter.js.map +1 -0
- package/dist/core/storage/SqlStorageAdapter.d.ts +262 -0
- package/dist/core/storage/SqlStorageAdapter.d.ts.map +1 -0
- package/dist/core/storage/SqlStorageAdapter.js +485 -0
- package/dist/core/storage/SqlStorageAdapter.js.map +1 -0
- package/dist/core/storage/index.d.ts +14 -0
- package/dist/core/storage/index.d.ts.map +1 -0
- package/dist/core/storage/index.js +14 -0
- package/dist/core/storage/index.js.map +1 -0
- package/dist/core/streaming/IStreamClient.d.ts +72 -0
- package/dist/core/streaming/IStreamClient.d.ts.map +1 -0
- package/dist/core/streaming/IStreamClient.js +12 -0
- package/dist/core/streaming/IStreamClient.js.map +1 -0
- package/dist/core/streaming/StreamingManager.d.ts +242 -0
- package/dist/core/streaming/StreamingManager.d.ts.map +1 -0
- package/dist/core/streaming/StreamingManager.js +282 -0
- package/dist/core/streaming/StreamingManager.js.map +1 -0
- package/dist/core/structured/IStructuredOutputManager.d.ts +701 -0
- package/dist/core/structured/IStructuredOutputManager.d.ts.map +1 -0
- package/dist/core/structured/IStructuredOutputManager.js +74 -0
- package/dist/core/structured/IStructuredOutputManager.js.map +1 -0
- package/dist/core/structured/StructuredOutputManager.d.ts +140 -0
- package/dist/core/structured/StructuredOutputManager.d.ts.map +1 -0
- package/dist/core/structured/StructuredOutputManager.js +1015 -0
- package/dist/core/structured/StructuredOutputManager.js.map +1 -0
- package/dist/core/structured/index.d.ts +34 -0
- package/dist/core/structured/index.d.ts.map +1 -0
- package/dist/core/structured/index.js +34 -0
- package/dist/core/structured/index.js.map +1 -0
- package/dist/core/tools/ITool.d.ts +228 -0
- package/dist/core/tools/ITool.d.ts.map +1 -0
- package/dist/core/tools/ITool.js +11 -0
- package/dist/core/tools/ITool.js.map +1 -0
- package/dist/core/tools/IToolOrchestrator.d.ts +131 -0
- package/dist/core/tools/IToolOrchestrator.d.ts.map +1 -0
- package/dist/core/tools/IToolOrchestrator.js +14 -0
- package/dist/core/tools/IToolOrchestrator.js.map +1 -0
- package/dist/core/tools/ToolExecutor.d.ts +143 -0
- package/dist/core/tools/ToolExecutor.d.ts.map +1 -0
- package/dist/core/tools/ToolExecutor.js +364 -0
- package/dist/core/tools/ToolExecutor.js.map +1 -0
- package/dist/core/tools/ToolOrchestrator.d.ts +142 -0
- package/dist/core/tools/ToolOrchestrator.d.ts.map +1 -0
- package/dist/core/tools/ToolOrchestrator.js +373 -0
- package/dist/core/tools/ToolOrchestrator.js.map +1 -0
- package/dist/core/tools/permissions/IToolPermissionManager.d.ts +195 -0
- package/dist/core/tools/permissions/IToolPermissionManager.d.ts.map +1 -0
- package/dist/core/tools/permissions/IToolPermissionManager.js +14 -0
- package/dist/core/tools/permissions/IToolPermissionManager.js.map +1 -0
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts +203 -0
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts.map +1 -0
- package/dist/core/tools/permissions/ToolPermissionManager.js +298 -0
- package/dist/core/tools/permissions/ToolPermissionManager.js.map +1 -0
- package/dist/core/ui/IUIComponent.d.ts +11 -0
- package/dist/core/ui/IUIComponent.d.ts.map +1 -0
- package/dist/core/ui/IUIComponent.js +2 -0
- package/dist/core/ui/IUIComponent.js.map +1 -0
- package/dist/core/usage/UsageLedger.d.ts +81 -0
- package/dist/core/usage/UsageLedger.d.ts.map +1 -0
- package/dist/core/usage/UsageLedger.js +135 -0
- package/dist/core/usage/UsageLedger.js.map +1 -0
- package/dist/core/workflows/IWorkflowEngine.d.ts +42 -0
- package/dist/core/workflows/IWorkflowEngine.d.ts.map +1 -0
- package/dist/core/workflows/IWorkflowEngine.js +2 -0
- package/dist/core/workflows/IWorkflowEngine.js.map +1 -0
- package/dist/core/workflows/WorkflowEngine.d.ts +28 -0
- package/dist/core/workflows/WorkflowEngine.d.ts.map +1 -0
- package/dist/core/workflows/WorkflowEngine.js +309 -0
- package/dist/core/workflows/WorkflowEngine.js.map +1 -0
- package/dist/core/workflows/WorkflowTypes.d.ts +180 -0
- package/dist/core/workflows/WorkflowTypes.d.ts.map +1 -0
- package/dist/core/workflows/WorkflowTypes.js +26 -0
- package/dist/core/workflows/WorkflowTypes.js.map +1 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.d.ts +70 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.d.ts.map +1 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.js +566 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.js.map +1 -0
- package/dist/core/workflows/storage/IWorkflowStore.d.ts +75 -0
- package/dist/core/workflows/storage/IWorkflowStore.d.ts.map +1 -0
- package/dist/core/workflows/storage/IWorkflowStore.js +2 -0
- package/dist/core/workflows/storage/IWorkflowStore.js.map +1 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.d.ts +14 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.d.ts.map +1 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.js +130 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.js.map +1 -0
- package/dist/extensions/ExtensionLoader.d.ts +119 -0
- package/dist/extensions/ExtensionLoader.d.ts.map +1 -0
- package/dist/extensions/ExtensionLoader.js +297 -0
- package/dist/extensions/ExtensionLoader.js.map +1 -0
- package/dist/extensions/ExtensionManager.d.ts +49 -0
- package/dist/extensions/ExtensionManager.d.ts.map +1 -0
- package/dist/extensions/ExtensionManager.js +197 -0
- package/dist/extensions/ExtensionManager.js.map +1 -0
- package/dist/extensions/ExtensionRegistry.d.ts +39 -0
- package/dist/extensions/ExtensionRegistry.d.ts.map +1 -0
- package/dist/extensions/ExtensionRegistry.js +103 -0
- package/dist/extensions/ExtensionRegistry.js.map +1 -0
- package/dist/extensions/MultiRegistryLoader.d.ts +61 -0
- package/dist/extensions/MultiRegistryLoader.d.ts.map +1 -0
- package/dist/extensions/MultiRegistryLoader.js +169 -0
- package/dist/extensions/MultiRegistryLoader.js.map +1 -0
- package/dist/extensions/RegistryConfig.d.ts +86 -0
- package/dist/extensions/RegistryConfig.d.ts.map +1 -0
- package/dist/extensions/RegistryConfig.js +99 -0
- package/dist/extensions/RegistryConfig.js.map +1 -0
- package/dist/extensions/events.d.ts +19 -0
- package/dist/extensions/events.d.ts.map +1 -0
- package/dist/extensions/events.js +2 -0
- package/dist/extensions/events.js.map +1 -0
- package/dist/extensions/index.d.ts +9 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +9 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/manifest.d.ts +52 -0
- package/dist/extensions/manifest.d.ts.map +1 -0
- package/dist/extensions/manifest.js +2 -0
- package/dist/extensions/manifest.js.map +1 -0
- package/dist/extensions/types.d.ts +294 -0
- package/dist/extensions/types.d.ts.map +1 -0
- package/dist/extensions/types.js +12 -0
- package/dist/extensions/types.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/ILogger.d.ts +8 -0
- package/dist/logging/ILogger.d.ts.map +1 -0
- package/dist/logging/ILogger.js +2 -0
- package/dist/logging/ILogger.js.map +1 -0
- package/dist/logging/PinoLogger.d.ts +12 -0
- package/dist/logging/PinoLogger.d.ts.map +1 -0
- package/dist/logging/PinoLogger.js +22 -0
- package/dist/logging/PinoLogger.js.map +1 -0
- package/dist/logging/loggerFactory.d.ts +6 -0
- package/dist/logging/loggerFactory.d.ts.map +1 -0
- package/dist/logging/loggerFactory.js +14 -0
- package/dist/logging/loggerFactory.js.map +1 -0
- package/dist/rag/EmbeddingManager.d.ts +81 -0
- package/dist/rag/EmbeddingManager.d.ts.map +1 -0
- package/dist/rag/EmbeddingManager.js +412 -0
- package/dist/rag/EmbeddingManager.js.map +1 -0
- package/dist/rag/IEmbeddingManager.d.ts +277 -0
- package/dist/rag/IEmbeddingManager.d.ts.map +1 -0
- package/dist/rag/IEmbeddingManager.js +19 -0
- package/dist/rag/IEmbeddingManager.js.map +1 -0
- package/dist/rag/IRetrievalAugmentor.d.ts +208 -0
- package/dist/rag/IRetrievalAugmentor.d.ts.map +1 -0
- package/dist/rag/IRetrievalAugmentor.js +21 -0
- package/dist/rag/IRetrievalAugmentor.js.map +1 -0
- package/dist/rag/IVectorStore.d.ts +351 -0
- package/dist/rag/IVectorStore.d.ts.map +1 -0
- package/dist/rag/IVectorStore.js +15 -0
- package/dist/rag/IVectorStore.js.map +1 -0
- package/dist/rag/IVectorStoreManager.d.ts +121 -0
- package/dist/rag/IVectorStoreManager.d.ts.map +1 -0
- package/dist/rag/IVectorStoreManager.js +13 -0
- package/dist/rag/IVectorStoreManager.js.map +1 -0
- package/dist/rag/RetrievalAugmentor.d.ts +99 -0
- package/dist/rag/RetrievalAugmentor.d.ts.map +1 -0
- package/dist/rag/RetrievalAugmentor.js +674 -0
- package/dist/rag/RetrievalAugmentor.js.map +1 -0
- package/dist/rag/VectorStoreManager.d.ts +90 -0
- package/dist/rag/VectorStoreManager.d.ts.map +1 -0
- package/dist/rag/VectorStoreManager.js +283 -0
- package/dist/rag/VectorStoreManager.js.map +1 -0
- package/dist/rag/implementations/index.d.ts +9 -0
- package/dist/rag/implementations/index.d.ts.map +1 -0
- package/dist/rag/implementations/index.js +9 -0
- package/dist/rag/implementations/index.js.map +1 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.d.ts +132 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.d.ts.map +1 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.js +539 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.js.map +1 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.d.ts +265 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.d.ts.map +1 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.js +755 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.js.map +1 -0
- package/dist/rag/implementations/vector_stores/index.d.ts +10 -0
- package/dist/rag/implementations/vector_stores/index.d.ts.map +1 -0
- package/dist/rag/implementations/vector_stores/index.js +12 -0
- package/dist/rag/implementations/vector_stores/index.js.map +1 -0
- package/dist/rag/index.d.ts +95 -0
- package/dist/rag/index.d.ts.map +1 -0
- package/dist/rag/index.js +97 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/services/user_auth/AuthService.d.ts +13 -0
- package/dist/services/user_auth/AuthService.d.ts.map +1 -0
- package/dist/services/user_auth/AuthService.js +24 -0
- package/dist/services/user_auth/AuthService.js.map +1 -0
- package/dist/services/user_auth/SubscriptionService.d.ts +14 -0
- package/dist/services/user_auth/SubscriptionService.d.ts.map +1 -0
- package/dist/services/user_auth/SubscriptionService.js +34 -0
- package/dist/services/user_auth/SubscriptionService.js.map +1 -0
- package/dist/services/user_auth/types.d.ts +30 -0
- package/dist/services/user_auth/types.d.ts.map +1 -0
- package/dist/services/user_auth/types.js +2 -0
- package/dist/services/user_auth/types.js.map +1 -0
- package/dist/stubs/prismaClient.d.ts +35 -0
- package/dist/stubs/prismaClient.d.ts.map +1 -0
- package/dist/stubs/prismaClient.js +47 -0
- package/dist/stubs/prismaClient.js.map +1 -0
- package/dist/types/rateLimitTypes.d.ts +70 -0
- package/dist/types/rateLimitTypes.d.ts.map +1 -0
- package/dist/types/rateLimitTypes.js +55 -0
- package/dist/types/rateLimitTypes.js.map +1 -0
- package/dist/utils/errors.d.ts +80 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +201 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/uuid.d.ts +11 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +64 -0
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Implements the `AgentPoolAgent`, a specialized type of `AgentCore`
|
|
3
|
+
* that functions as a manager or orchestrator for a collection of other "sub-agents".
|
|
4
|
+
* This agent embodies strategies like routing requests to the most suitable sub-agent,
|
|
5
|
+
* synthesizing responses from multiple sub-agents (mixture of experts), or delegating
|
|
6
|
+
* tasks directly.
|
|
7
|
+
*
|
|
8
|
+
* The `AgentPoolAgent` uses an `IAgentFactory` to instantiate its sub-agents based on
|
|
9
|
+
* IDs provided in its `AgentPoolConfig`. Its behavior is primarily dictated by the
|
|
10
|
+
* `AgentPoolStrategy` defined in its configuration.
|
|
11
|
+
*
|
|
12
|
+
* Key functionalities:
|
|
13
|
+
* - Loads and initializes a set of sub-agents.
|
|
14
|
+
* - Implements various strategies for sub-agent interaction and output generation.
|
|
15
|
+
* - Can maintain a "unified persona" for user-facing interactions, even if sub-agents
|
|
16
|
+
* have distinct characteristics.
|
|
17
|
+
* - Utilizes its own LLM provider and prompt engine for meta-tasks like routing
|
|
18
|
+
* decisions or synthesizing sub-agent outputs.
|
|
19
|
+
* @module backend/agentos/core/agents/AgentPoolAgent
|
|
20
|
+
*/
|
|
21
|
+
import { AgentCore, AgentType, AgentCoreError } from './AgentCore.js';
|
|
22
|
+
import { AgentPoolStrategy } from './AgentPoolConfig.js';
|
|
23
|
+
import { MessageRole } from '../conversation/ConversationMessage.js'; // Ensure ConversationMessage is imported if used directly
|
|
24
|
+
/**
|
|
25
|
+
* A concrete agent implementation that acts as an intelligent coordinator or router
|
|
26
|
+
* for a collection of sub-agents. It encapsulates the logic for selecting,
|
|
27
|
+
* dispatching tasks to, and synthesizing results from its managed sub-agents,
|
|
28
|
+
* all based on a configured `AgentPoolStrategy`.
|
|
29
|
+
*
|
|
30
|
+
* @class AgentPoolAgent
|
|
31
|
+
* @extends {AgentCore}
|
|
32
|
+
* @implements {IAgent}
|
|
33
|
+
*/
|
|
34
|
+
export class AgentPoolAgent extends AgentCore {
|
|
35
|
+
/**
|
|
36
|
+
* Constructs an `AgentPoolAgent` instance.
|
|
37
|
+
*
|
|
38
|
+
* @param {AgentPoolAgentConfig} config - The configuration for this agent pool.
|
|
39
|
+
* Must specify `type` as `AgentType.POOL` and include `agentPoolOptions`.
|
|
40
|
+
* @param {IPromptEngine} promptEngine - An instance of the `IPromptEngine`.
|
|
41
|
+
* @param {IProvider} llmProvider - The primary AI model provider for the pool agent's
|
|
42
|
+
* own meta-tasks (e.g., routing, synthesis).
|
|
43
|
+
* @param {IUtilityAI | undefined} utilityAI - Optional. An instance of an `IUtilityAI` service.
|
|
44
|
+
* @param {IAgentFactory} agentFactory - The `IAgentFactory` instance, which is **required**
|
|
45
|
+
* for the `AgentPoolAgent` to load and instantiate its sub-agents.
|
|
46
|
+
* @throws {AgentCoreError} If the configuration is invalid (e.g., missing `agentPoolOptions`)
|
|
47
|
+
* or if the `agentFactory` dependency is not provided.
|
|
48
|
+
*/
|
|
49
|
+
constructor(config, promptEngine, llmProvider, utilityAI, agentFactory // Made mandatory for AgentPoolAgent
|
|
50
|
+
) {
|
|
51
|
+
super(config, promptEngine, llmProvider, utilityAI, agentFactory);
|
|
52
|
+
/**
|
|
53
|
+
* A map storing the instantiated sub-agent instances, keyed by their agent IDs.
|
|
54
|
+
* @private
|
|
55
|
+
* @type {Map<string, IAgent>}
|
|
56
|
+
*/
|
|
57
|
+
this.subAgents = new Map();
|
|
58
|
+
/**
|
|
59
|
+
* Stores tools that are available to the pool agent itself. These might be
|
|
60
|
+
* different from tools available to individual sub-agents.
|
|
61
|
+
* @private
|
|
62
|
+
* @type {Tool[]}
|
|
63
|
+
*/
|
|
64
|
+
this.availablePoolTools = [];
|
|
65
|
+
if (config.type !== AgentType.POOL || !config.agentPoolOptions) {
|
|
66
|
+
throw new AgentCoreError("AgentPoolAgent: Invalid configuration. 'type' must be AgentType.POOL and 'agentPoolOptions' must be provided.", 'POOL_AGENT_INVALID_CONFIG', config);
|
|
67
|
+
}
|
|
68
|
+
if (!agentFactory) {
|
|
69
|
+
// This check is technically redundant due to super class constructor already using it,
|
|
70
|
+
// but reinforces that AgentPoolAgent *critically* needs it.
|
|
71
|
+
throw new AgentCoreError("AgentPoolAgent: IAgentFactory dependency is absolutely required for AgentPoolAgent to function.", 'POOL_AGENT_MISSING_FACTORY', config);
|
|
72
|
+
}
|
|
73
|
+
this.poolConfig = config.agentPoolOptions;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Allows the orchestrator/factory to provide the dependency bundle that was used
|
|
77
|
+
* to construct this pool agent so it can reuse them when instantiating sub-agents.
|
|
78
|
+
*/
|
|
79
|
+
setAgentDependencies(dependencies) {
|
|
80
|
+
this.agentDependencies = dependencies;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Initializes the `AgentPoolAgent`. This involves:
|
|
84
|
+
* 1. Calling the base class `initialize` method.
|
|
85
|
+
* 2. Using the injected `IAgentFactory` to load and initialize all sub-agents
|
|
86
|
+
* specified in `this.poolConfig.subAgentIds`.
|
|
87
|
+
*
|
|
88
|
+
* @override
|
|
89
|
+
* @param {Record<string, any>} [configOverrides] - Optional configuration overrides applied during initialization.
|
|
90
|
+
* @returns {Promise<void>}
|
|
91
|
+
* @throws {AgentCoreError} If the `agentFactory` is missing or if any sub-agent fails to load or initialize.
|
|
92
|
+
*/
|
|
93
|
+
async initialize(configOverrides) {
|
|
94
|
+
await super.initialize(configOverrides); // Call base class initialize
|
|
95
|
+
if (!this.agentFactory) {
|
|
96
|
+
// This should ideally be caught by the constructor, but defensive check here.
|
|
97
|
+
throw new AgentCoreError(`AgentPoolAgent '${this.name}': Critical dependency IAgentFactory is missing. Cannot load sub-agents.`, 'POOL_AGENT_INIT_NO_FACTORY');
|
|
98
|
+
}
|
|
99
|
+
// console.log(`AgentPoolAgent '${this.name}' (ID: ${this.id}) initializing sub-agents using factory...`);
|
|
100
|
+
const subAgentLoadPromises = [];
|
|
101
|
+
const loadedSubAgentsMap = new Map();
|
|
102
|
+
const providerManager = this.agentDependencies?.providerManager;
|
|
103
|
+
if (!providerManager) {
|
|
104
|
+
throw new AgentCoreError(`AgentPoolAgent '${this.name}': Missing providerManager dependency. Cannot materialize sub-agents.`, 'POOL_AGENT_MISSING_PROVIDER_MANAGER');
|
|
105
|
+
}
|
|
106
|
+
// Gather dependencies for sub-agents. They re-use the pool's core services.
|
|
107
|
+
const subAgentDeps = {
|
|
108
|
+
promptEngine: this.agentDependencies?.promptEngine ?? this.promptEngine,
|
|
109
|
+
providerManager,
|
|
110
|
+
utilityAI: this.agentDependencies?.utilityAI ?? this.utilityAI,
|
|
111
|
+
agentFactory: this.agentDependencies?.agentFactory ?? this.agentFactory,
|
|
112
|
+
};
|
|
113
|
+
for (const subAgentId of this.poolConfig.subAgentIds) {
|
|
114
|
+
subAgentLoadPromises.push(this.agentFactory.getAgent(subAgentId, subAgentDeps)
|
|
115
|
+
.then(subAgent => {
|
|
116
|
+
if (subAgent) {
|
|
117
|
+
loadedSubAgentsMap.set(subAgentId, subAgent);
|
|
118
|
+
// console.log(`- AgentPoolAgent '${this.name}': Successfully loaded sub-agent: ${subAgent.name} (ID: ${subAgent.id})`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.warn(`- AgentPoolAgent '${this.name}': Failed to load sub-agent with ID '${subAgentId}'. It might not be configured, registered, or an error occurred during its creation.`);
|
|
122
|
+
// Optionally, throw an error here if any sub-agent loading failure is critical
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.catch(error => {
|
|
126
|
+
console.error(`- AgentPoolAgent '${this.name}': Error loading sub-agent '${subAgentId}':`, error);
|
|
127
|
+
// Decide on error handling: continue without this sub-agent, or fail pool initialization?
|
|
128
|
+
// For robustness, let's allow continuing but log a critical warning.
|
|
129
|
+
// throw new AgentCoreError(`Failed to load sub-agent '${subAgentId}' for pool '${this.name}'.`, 'SUB_AGENT_LOAD_FAILED', error);
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
await Promise.all(subAgentLoadPromises);
|
|
133
|
+
this.subAgents = loadedSubAgentsMap;
|
|
134
|
+
if (this.subAgents.size !== this.poolConfig.subAgentIds.length) {
|
|
135
|
+
console.warn(`AgentPoolAgent '${this.name}': Not all configured sub-agents were loaded. Expected ${this.poolConfig.subAgentIds.length}, loaded ${this.subAgents.size}. The pool may not function as intended.`);
|
|
136
|
+
}
|
|
137
|
+
// console.log(`AgentPoolAgent '${this.name}' initialization complete. Loaded ${this.subAgents.size} of ${this.poolConfig.subAgentIds.length} configured sub-agents.`);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Resets the `AgentPoolAgent`'s internal state and propagates the reset call
|
|
141
|
+
* to all its managed sub-agents.
|
|
142
|
+
* @override
|
|
143
|
+
*/
|
|
144
|
+
reset() {
|
|
145
|
+
super.reset(); // Call base class reset
|
|
146
|
+
this.subAgents.forEach(agent => {
|
|
147
|
+
if (typeof agent.reset === 'function') {
|
|
148
|
+
try {
|
|
149
|
+
agent.reset();
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.error(`AgentPoolAgent '${this.name}': Error resetting sub-agent '${agent.id}': ${error.message}`, error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
// console.log(`AgentPoolAgent '${this.name}' (ID: ${this.id}) and its ${this.subAgents.size} sub-agents have been reset.`);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Overrides the `processTurn` method from `AgentCore` to implement the specific
|
|
160
|
+
* orchestration logic of the `AgentPoolAgent` based on its configured strategy.
|
|
161
|
+
* This method will route tasks to, or synthesize results from, its sub-agents.
|
|
162
|
+
*
|
|
163
|
+
* @override
|
|
164
|
+
* @param {string | null} userInput - The latest input from the user.
|
|
165
|
+
* @param {ConversationContext} conversationContext - The current conversation context.
|
|
166
|
+
* @param {Tool[]} [availableTools] - Tools available to the pool agent itself (these might also
|
|
167
|
+
* be passed down to sub-agents depending on the strategy and sub-agent capabilities).
|
|
168
|
+
* @returns {Promise<AgentOutput>} The agent's response and actions, which could be a direct
|
|
169
|
+
* response, a synthesized response from sub-agents, or tool calls.
|
|
170
|
+
* @throws {AgentCoreError} If an unhandled error occurs within the chosen strategy.
|
|
171
|
+
*/
|
|
172
|
+
async processTurn(userInput, conversationContext, availableTools // Tools available to this pool agent
|
|
173
|
+
) {
|
|
174
|
+
this.ensureInitialized(); // Ensure pool agent (and thus sub-agents) are initialized
|
|
175
|
+
this.availablePoolTools = availableTools || [];
|
|
176
|
+
// Optional: Apply unified persona to conversation context if configured for the pool
|
|
177
|
+
if (this.poolConfig.unifiedPersonaId) {
|
|
178
|
+
// This is a conceptual step. How this `unifiedPersonaId` translates to an actionable
|
|
179
|
+
// change in context depends on how personas are managed and applied.
|
|
180
|
+
// It might mean this pool agent's own system prompt (this.agentConfig.systemPrompt)
|
|
181
|
+
// IS the unified persona, or it refers to a separate persona definition to load.
|
|
182
|
+
// For now, we assume the pool agent's own configuration embodies the unified persona.
|
|
183
|
+
conversationContext.setMetadata('activePoolPersonaId', this.poolConfig.unifiedPersonaId);
|
|
184
|
+
conversationContext.setMetadata('controllingAgentId', this.id); // Mark that pool is in control
|
|
185
|
+
}
|
|
186
|
+
// console.log(`AgentPoolAgent '${this.name}' (ID: ${this.id}) processing turn. Strategy: '${this.poolConfig.strategy}'. User input: "${userInput ? userInput.substring(0,50)+'...' : 'N/A'}"`);
|
|
187
|
+
if (this.subAgents.size === 0 && this.poolConfig.subAgentIds.length > 0) {
|
|
188
|
+
const noSubAgentsMsg = `AgentPoolAgent '${this.name}' has no sub-agents loaded or available to handle the request. Please check the pool configuration and sub-agent status.`;
|
|
189
|
+
console.warn(noSubAgentsMsg);
|
|
190
|
+
return this.textOutput("I'm currently unable to process your request as my specialized internal assistants are not available. Please try again later.", true, { error: noSubAgentsMsg });
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
switch (this.poolConfig.strategy) {
|
|
194
|
+
case AgentPoolStrategy.UNIFIED_PERSONA_ROUTING:
|
|
195
|
+
return await this.handleUnifiedPersonaRouting(userInput, conversationContext);
|
|
196
|
+
case AgentPoolStrategy.MIXTURE_OF_EXPERTS_SYNTHESIS:
|
|
197
|
+
return await this.handleMixtureOfExpertsSynthesis(userInput, conversationContext);
|
|
198
|
+
case AgentPoolStrategy.DIRECT_DELEGATION:
|
|
199
|
+
return await this.handleDirectDelegation(userInput, conversationContext);
|
|
200
|
+
case AgentPoolStrategy.EXPLORATORY_GENERATION:
|
|
201
|
+
return await this.handleExploratoryGeneration(userInput, conversationContext);
|
|
202
|
+
default: {
|
|
203
|
+
const errorMsg = `AgentPoolAgent '${this.name}': Unhandled or unknown strategy '${this.poolConfig.strategy}'.`;
|
|
204
|
+
console.error(errorMsg);
|
|
205
|
+
// Use the inherited error handler to explain this to the user via LLM
|
|
206
|
+
return await this.handleInternalAgentError(new AgentCoreError(errorMsg, 'POOL_UNKNOWN_STRATEGY'), conversationContext, true // This is fatal for the turn
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
const strategyErrorMsg = `Error executing strategy '${this.poolConfig.strategy}' in AgentPoolAgent '${this.name}': ${error.message}`;
|
|
213
|
+
console.error(strategyErrorMsg, error);
|
|
214
|
+
return await this.handleInternalAgentError(new AgentCoreError(strategyErrorMsg, 'POOL_STRATEGY_EXECUTION_FAILED', error), conversationContext, true);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Implements the `UNIFIED_PERSONA_ROUTING` strategy.
|
|
219
|
+
* This involves using an LLM (the pool agent's own) to select the most appropriate sub-agent
|
|
220
|
+
* based on the user input and sub-agent descriptions. The selected sub-agent's output
|
|
221
|
+
* is then rephrased by the pool agent to maintain a consistent unified persona.
|
|
222
|
+
*
|
|
223
|
+
* @private
|
|
224
|
+
* @param {string | null} userInput - The user's input.
|
|
225
|
+
* @param {ConversationContext} conversationContext - The current conversation context.
|
|
226
|
+
* @returns {Promise<AgentOutput>} The synthesized and persona-aligned output.
|
|
227
|
+
*/
|
|
228
|
+
async handleUnifiedPersonaRouting(userInput, conversationContext) {
|
|
229
|
+
const availableSubAgents = Array.from(this.subAgents.values());
|
|
230
|
+
if (availableSubAgents.length === 0) {
|
|
231
|
+
return this.textOutput("I apologize, but I don't have any specialist agents available to help with that specific request right now.", true);
|
|
232
|
+
}
|
|
233
|
+
// 1. Generate a prompt for the pool's LLM to choose a sub-agent.
|
|
234
|
+
const routingPromptComponents = this.generateRoutingPrompt(userInput, conversationContext, availableSubAgents);
|
|
235
|
+
let chosenAgentId;
|
|
236
|
+
let routingLlmResponse;
|
|
237
|
+
try {
|
|
238
|
+
routingLlmResponse = await this.callLLM(this.llmProvider, // Pool agent's LLM
|
|
239
|
+
routingPromptComponents, {
|
|
240
|
+
temperature: 0.1,
|
|
241
|
+
maxTokens: 150,
|
|
242
|
+
...(this.poolConfig.routingConfig?.selectionCompletionOptions || {}),
|
|
243
|
+
});
|
|
244
|
+
chosenAgentId = this.parseLLMResponseForRouting(routingLlmResponse, availableSubAgents.map(a => a.id));
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
console.error(`AgentPoolAgent '${this.name}': LLM call for routing failed: ${error.message}`, error);
|
|
248
|
+
return this.handleInternalAgentError(new AgentCoreError(`Failed to determine the best sub-agent for your request due to an internal routing error.`, 'POOL_ROUTING_LLM_ERROR', error), conversationContext, true);
|
|
249
|
+
}
|
|
250
|
+
if (!chosenAgentId) {
|
|
251
|
+
console.warn(`AgentPoolAgent '${this.name}': LLM failed to choose a sub-agent for routing. Input: "${userInput}". LLM response: ${routingLlmResponse.choices[0]?.message.content}`);
|
|
252
|
+
// Fallback: could try a default agent or ask user for more clarification.
|
|
253
|
+
return this.textOutput("I'm having a bit of trouble determining the best way to handle your request. Could you please provide more specific details or rephrase your query?", false);
|
|
254
|
+
}
|
|
255
|
+
const chosenAgent = this.subAgents.get(chosenAgentId);
|
|
256
|
+
if (!chosenAgent) {
|
|
257
|
+
const routingErrorMsg = `LLM chose sub-agent ID '${chosenAgentId}', but this agent is not found or not loaded in the pool '${this.name}'.`;
|
|
258
|
+
console.error(`AgentPoolAgent '${this.name}': ${routingErrorMsg}`);
|
|
259
|
+
return this.handleInternalAgentError(new AgentCoreError(routingErrorMsg, 'POOL_ROUTED_AGENT_NOT_FOUND'), conversationContext, true);
|
|
260
|
+
}
|
|
261
|
+
// console.log(`AgentPoolAgent '${this.name}': Routing to sub-agent: ${chosenAgent.name} (ID: ${chosenAgent.id}).`);
|
|
262
|
+
// 2. Call the chosen sub-agent's processTurn.
|
|
263
|
+
// Provide tools available to the pool, sub-agent will filter based on its own config.
|
|
264
|
+
let subAgentResponse;
|
|
265
|
+
try {
|
|
266
|
+
subAgentResponse = await chosenAgent.processTurn(userInput, conversationContext, this.availablePoolTools);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
const subAgentErrorMsg = `Sub-agent '${chosenAgent.name}' (ID: ${chosenAgent.id}) failed to process the turn: ${error.message}`;
|
|
270
|
+
console.error(`AgentPoolAgent '${this.name}': ${subAgentErrorMsg}`, error);
|
|
271
|
+
return this.handleInternalAgentError(new AgentCoreError(subAgentErrorMsg, 'SUB_AGENT_TURN_PROCESSING_FAILED', error), conversationContext, true);
|
|
272
|
+
}
|
|
273
|
+
// 3. Synthesize/rephrase the sub-agent's response to align with the pool's unified persona.
|
|
274
|
+
return await this.synthesizeAndFinalizeOutput(subAgentResponse, chosenAgent, conversationContext, "Routed to expert, rephrased for unified voice.");
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Implements the `MIXTURE_OF_EXPERTS_SYNTHESIS` strategy.
|
|
278
|
+
* Consults multiple (or all) sub-agents and then uses the pool's LLM to synthesize
|
|
279
|
+
* their contributions into a single, coherent response.
|
|
280
|
+
*
|
|
281
|
+
* @private
|
|
282
|
+
* @param {string | null} userInput - The user's input.
|
|
283
|
+
* @param {ConversationContext} conversationContext - The current conversation context.
|
|
284
|
+
* @returns {Promise<AgentOutput>} The synthesized output from the mixture of experts.
|
|
285
|
+
*/
|
|
286
|
+
async handleMixtureOfExpertsSynthesis(userInput, conversationContext) {
|
|
287
|
+
const activeSubAgents = Array.from(this.subAgents.values());
|
|
288
|
+
if (activeSubAgents.length === 0) {
|
|
289
|
+
return this.textOutput("I apologize, but I don't have any expert agents available to consult for this request at the moment.", true);
|
|
290
|
+
}
|
|
291
|
+
// console.log(`AgentPoolAgent '${this.name}': Consulting ${activeSubAgents.length} experts for input: "${userInput ? userInput.substring(0,50)+'...' : 'N/A'}".`);
|
|
292
|
+
// 1. Concurrently call processTurn on all (or a selection of) sub-agents.
|
|
293
|
+
const expertOutputPromises = activeSubAgents.map(async (subAgent) => {
|
|
294
|
+
try {
|
|
295
|
+
const output = await subAgent.processTurn(userInput, conversationContext, this.availablePoolTools);
|
|
296
|
+
// console.log(`- AgentPoolAgent '${this.name}': Expert '${subAgent.name}' responded.`);
|
|
297
|
+
return { agentId: subAgent.id, agentName: subAgent.name, agentDescription: subAgent.description, output };
|
|
298
|
+
}
|
|
299
|
+
catch (e) {
|
|
300
|
+
console.error(`- AgentPoolAgent '${this.name}': Expert '${subAgent.name}' (ID: ${subAgent.id}) failed to respond: ${e.message}`, e);
|
|
301
|
+
return {
|
|
302
|
+
agentId: subAgent.id,
|
|
303
|
+
agentName: subAgent.name,
|
|
304
|
+
agentDescription: subAgent.description,
|
|
305
|
+
output: {
|
|
306
|
+
responseText: `Error: Specialist '${subAgent.name}' encountered an issue and could not contribute.`,
|
|
307
|
+
isComplete: true, // This expert's contribution is complete (with an error)
|
|
308
|
+
error: new AgentCoreError(`Sub-agent ${subAgent.name} failed.`, 'SUB_AGENT_FAILURE_IN_MOE', e),
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
const expertResults = await Promise.all(expertOutputPromises);
|
|
314
|
+
// Filter out results that are purely errors or have no text, unless all are errors.
|
|
315
|
+
const validExpertOutputs = expertResults.filter(res => res.output.responseText || res.output.toolCalls);
|
|
316
|
+
if (validExpertOutputs.length === 0 && expertResults.length > 0) {
|
|
317
|
+
// All experts failed or returned nothing. Concatenate error messages if any.
|
|
318
|
+
const combinedErrorMessages = expertResults.map(res => res.output.error ? `${res.agentName}: ${res.output.error.message || res.output.error}` : `${res.agentName} provided no usable output.`).join('\n');
|
|
319
|
+
return this.textOutput(`I consulted my team of experts, but unfortunately, they were unable to provide a consolidated response at this time. Details:\n${combinedErrorMessages}`, true, { allExpertsFailed: true });
|
|
320
|
+
}
|
|
321
|
+
// 2. Generate a prompt for the pool's LLM to synthesize these expert outputs.
|
|
322
|
+
const synthesisPromptComponents = this.generateSynthesisPrompt(userInput, conversationContext, validExpertOutputs);
|
|
323
|
+
// 3. Call the pool's LLM for synthesis.
|
|
324
|
+
let synthesizedResponse;
|
|
325
|
+
try {
|
|
326
|
+
const synthesisLlmResponse = await this.callLLM(this.llmProvider, synthesisPromptComponents, {
|
|
327
|
+
temperature: 0.4,
|
|
328
|
+
maxTokens: 1500,
|
|
329
|
+
...(this.poolConfig.synthesisConfig?.synthesisCompletionOptions || {}),
|
|
330
|
+
});
|
|
331
|
+
// The synthesis LLM might itself request tools or provide complex output.
|
|
332
|
+
const parsed = this.parseLLMResponse(synthesisLlmResponse);
|
|
333
|
+
synthesizedResponse = {
|
|
334
|
+
responseText: parsed.responseText ?? undefined,
|
|
335
|
+
toolCalls: parsed.toolCalls,
|
|
336
|
+
isComplete: !parsed.toolCalls || parsed.toolCalls.length === 0,
|
|
337
|
+
rawModelResponse: parsed.rawResponseMessage,
|
|
338
|
+
metadata: { synthesizedByPool: true },
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
console.error(`AgentPoolAgent '${this.name}': LLM call for expert synthesis failed: ${error.message}`, error);
|
|
343
|
+
return this.handleInternalAgentError(new AgentCoreError(`Failed to synthesize expert opinions due to an internal processing error.`, 'POOL_SYNTHESIS_LLM_ERROR', error), conversationContext, true);
|
|
344
|
+
}
|
|
345
|
+
return await this.synthesizeAndFinalizeOutput(synthesizedResponse, this, conversationContext, "Synthesized from multiple experts.");
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Implements the `DIRECT_DELEGATION` strategy.
|
|
349
|
+
* Selects a single sub-agent (e.g., based on simple routing logic or configuration)
|
|
350
|
+
* and directly forwards its response without significant modification by the pool agent.
|
|
351
|
+
*
|
|
352
|
+
* @private
|
|
353
|
+
* @param {string | null} userInput - The user's input.
|
|
354
|
+
* @param {ConversationContext} conversationContext - The current conversation context.
|
|
355
|
+
* @returns {Promise<AgentOutput>} The output from the delegated sub-agent.
|
|
356
|
+
*/
|
|
357
|
+
async handleDirectDelegation(userInput, conversationContext) {
|
|
358
|
+
const availableSubAgents = Array.from(this.subAgents.values());
|
|
359
|
+
if (availableSubAgents.length === 0) {
|
|
360
|
+
return this.textOutput("I don't have any specialist agents available to delegate this task to at the moment.", true);
|
|
361
|
+
}
|
|
362
|
+
// Simple delegation: use routing prompt to pick one, or pick first if routing fails/not configured.
|
|
363
|
+
// More complex delegation might involve specific rules in poolConfig.routingConfig.
|
|
364
|
+
let delegatedAgent = availableSubAgents[0]; // Fallback to first
|
|
365
|
+
if (availableSubAgents.length > 1 && (this.poolConfig.routingConfig || this.poolConfig.poolSystemPrompt)) {
|
|
366
|
+
// Attempt to use routing LLM if configured for it.
|
|
367
|
+
const routingPromptComponents = this.generateRoutingPrompt(userInput, conversationContext, availableSubAgents);
|
|
368
|
+
try {
|
|
369
|
+
const routingLlmResponse = await this.callLLM(this.llmProvider, routingPromptComponents, {
|
|
370
|
+
temperature: 0.1,
|
|
371
|
+
maxTokens: 150,
|
|
372
|
+
...(this.poolConfig.routingConfig?.selectionCompletionOptions || {}),
|
|
373
|
+
});
|
|
374
|
+
const chosenAgentId = this.parseLLMResponseForRouting(routingLlmResponse, availableSubAgents.map(a => a.id));
|
|
375
|
+
if (chosenAgentId) {
|
|
376
|
+
delegatedAgent = this.subAgents.get(chosenAgentId) || delegatedAgent;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
console.warn(`AgentPoolAgent '${this.name}' (DirectDelegation): LLM routing failed to select an agent. Defaulting to agent '${delegatedAgent?.id}'.`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
console.warn(`AgentPoolAgent '${this.name}' (DirectDelegation): LLM routing call failed: ${error.message}. Defaulting to agent '${delegatedAgent?.id}'.`, error);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (!delegatedAgent) { // Should not happen if availableSubAgents is not empty, but defensive check.
|
|
387
|
+
return this.handleInternalAgentError(new AgentCoreError("Could not select a sub-agent for direct delegation.", 'POOL_DELEGATION_NO_AGENT_SELECTED'), conversationContext, true);
|
|
388
|
+
}
|
|
389
|
+
// console.log(`AgentPoolAgent '${this.name}': Directly delegating task to sub-agent: ${delegatedAgent.name} (ID: ${delegatedAgent.id}).`);
|
|
390
|
+
try {
|
|
391
|
+
const subAgentResponse = await delegatedAgent.processTurn(userInput, conversationContext, this.availablePoolTools);
|
|
392
|
+
// For "direct" delegation, we might do minimal or no synthesis.
|
|
393
|
+
// However, if a unifiedPersonaId is set, a light rephrasing might still be desired.
|
|
394
|
+
return await this.synthesizeAndFinalizeOutput(subAgentResponse, delegatedAgent, conversationContext, "Directly delegated to expert.", true); // Pass `isDirectDelegation = true`
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
const subAgentErrorMsg = `Sub-agent '${delegatedAgent.name}' (ID: ${delegatedAgent.id}) failed during direct delegation: ${error.message}`;
|
|
398
|
+
console.error(`AgentPoolAgent '${this.name}': ${subAgentErrorMsg}`, error);
|
|
399
|
+
return this.handleInternalAgentError(new AgentCoreError(subAgentErrorMsg, 'SUB_AGENT_DELEGATION_FAILED', error), conversationContext, true);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Implements the `EXPLORATORY_GENERATION` strategy. (Placeholder - complex to fully implement here)
|
|
404
|
+
* Spawns sub-agents to explore different approaches for a problem, then evaluates
|
|
405
|
+
* and synthesizes their outputs. This is a more advanced strategy.
|
|
406
|
+
*
|
|
407
|
+
* @private
|
|
408
|
+
* @param {string | null} userInput - The user's input.
|
|
409
|
+
* @param {ConversationContext} conversationContext - The current conversation context.
|
|
410
|
+
* @returns {Promise<AgentOutput>} The synthesized result of the exploratory generation.
|
|
411
|
+
*/
|
|
412
|
+
async handleExploratoryGeneration(userInput, conversationContext) {
|
|
413
|
+
// console.log(`AgentPoolAgent '${this.name}': Exploratory Generation strategy selected. This is a complex strategy and this implementation is a simplified placeholder.`);
|
|
414
|
+
// Simplified: Behaves like Mixture of Experts for now.
|
|
415
|
+
// A true exploratory generation would involve:
|
|
416
|
+
// 1. Defining diverse sub-tasks or perspectives based on userInput.
|
|
417
|
+
// 2. Assigning these to sub-agents (possibly with modified prompts for each).
|
|
418
|
+
// 3. Collecting all exploratory outputs.
|
|
419
|
+
// 4. Using an evaluation mechanism (LLM or heuristic) to rank/select/combine results.
|
|
420
|
+
// 5. Synthesizing a final response.
|
|
421
|
+
if (this.subAgents.size < 1) { // Needs at least one "explorer"
|
|
422
|
+
return this.textOutput("I need at least one specialist agent to conduct an exploration, but none are available.", true);
|
|
423
|
+
}
|
|
424
|
+
return this.handleMixtureOfExpertsSynthesis(userInput, conversationContext); // Fallback to MoE
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Generates a prompt for the pool agent's internal LLM to perform routing to a sub-agent.
|
|
428
|
+
* The prompt includes descriptions of available sub-agents and the user's query.
|
|
429
|
+
*
|
|
430
|
+
* @private
|
|
431
|
+
* @param {string | null} userInput - The user's current input.
|
|
432
|
+
* @param {ConversationContext} conversationContext - For history and broader context.
|
|
433
|
+
* @param {IAgent[]} subAgents - The list of available sub-agents to choose from.
|
|
434
|
+
* @returns {Partial<PromptComponents>} The components for constructing the routing prompt.
|
|
435
|
+
*/
|
|
436
|
+
generateRoutingPrompt(userInput, conversationContext, subAgents) {
|
|
437
|
+
const agentDescriptions = subAgents
|
|
438
|
+
.map(agent => `- Agent ID: "${agent.id}", Name: "${agent.name}", Description: "${agent.description.substring(0, 150)}..."`)
|
|
439
|
+
.join('\n');
|
|
440
|
+
const systemPromptContent = this.poolConfig.poolSystemPrompt ||
|
|
441
|
+
`You are an intelligent request router for a team of specialized AI agents. Your task is to analyze the user's request and the ongoing conversation, then select the most suitable agent from the provided list to handle the request.
|
|
442
|
+
Respond with ONLY the Agent ID of your chosen agent. If no agent is suitable, respond with "NONE". Do not add any other text or explanation.`;
|
|
443
|
+
const fullQueryContext = `
|
|
444
|
+
User's latest input: "${userInput || "No explicit new input from user, consider the conversation history."}"
|
|
445
|
+
|
|
446
|
+
Conversation History (last few turns):
|
|
447
|
+
${conversationContext.getHistory(5).map(msg => `${msg.role}: ${typeof msg.content === 'string' ? msg.content : '[multimodal_content]'}`).join('\n')}
|
|
448
|
+
|
|
449
|
+
Available Specialist Agents:
|
|
450
|
+
${agentDescriptions}
|
|
451
|
+
|
|
452
|
+
Based on the user's input and conversation history, which agent (by Agent ID) is best suited to handle this request?
|
|
453
|
+
Respond with only the Agent ID. If unsure or no agent is a good fit, respond with "NONE".`;
|
|
454
|
+
return {
|
|
455
|
+
systemPrompts: [{ content: systemPromptContent, priority: 0 }],
|
|
456
|
+
userInput: fullQueryContext, // The task for the routing LLM
|
|
457
|
+
// No conversation history for the routing LLM itself, it's embedded in the userInput.
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Parses the LLM's response when it was tasked with routing, expecting just an agent ID or "NONE".
|
|
462
|
+
*
|
|
463
|
+
* @private
|
|
464
|
+
* @param {ModelCompletionResponse} llmResponse - The response from the routing LLM call.
|
|
465
|
+
* @param {string[]} validAgentIds - An array of valid sub-agent IDs for validation.
|
|
466
|
+
* @returns {string | null} The chosen agent ID, or `null` if parsing fails or "NONE" is returned.
|
|
467
|
+
*/
|
|
468
|
+
parseLLMResponseForRouting(llmResponse, validAgentIds) {
|
|
469
|
+
const choice = llmResponse.choices?.[0];
|
|
470
|
+
const textContent = this.extractTextFromMessageContent(choice?.message?.content) || choice?.text?.trim();
|
|
471
|
+
if (textContent) {
|
|
472
|
+
// Remove potential quotes or markdown code blocks around the ID
|
|
473
|
+
const cleanedText = textContent.replace(/^[`"']|[`"']$/g, '').replace(/^`{3}.*?`{3}$/s, '').trim();
|
|
474
|
+
if (cleanedText.toUpperCase() === "NONE") {
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
if (validAgentIds.includes(cleanedText)) {
|
|
478
|
+
return cleanedText;
|
|
479
|
+
}
|
|
480
|
+
// Try to find if the response *contains* a valid ID among other text (less ideal LLM behavior)
|
|
481
|
+
for (const id of validAgentIds) {
|
|
482
|
+
if (cleanedText.includes(id))
|
|
483
|
+
return id;
|
|
484
|
+
}
|
|
485
|
+
console.warn(`AgentPoolAgent '${this.name}': Routing LLM returned text ('${textContent}') that is not a valid agent ID and not "NONE".`);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
console.warn(`AgentPoolAgent '${this.name}': Routing LLM returned no parsable text content.`);
|
|
489
|
+
}
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Generates a prompt for the pool agent's internal LLM to synthesize outputs from multiple expert sub-agents.
|
|
494
|
+
*
|
|
495
|
+
* @private
|
|
496
|
+
* @param {string | null} originalUserInput - The initial user input that led to expert consultation.
|
|
497
|
+
* @param {ConversationContext} conversationContext - For overall context.
|
|
498
|
+
* @param {Array<{ agentId: string; agentName: string; agentDescription: string; output: AgentOutput; }>} expertResults - The outputs from consulted sub-agents.
|
|
499
|
+
* @returns {Partial<PromptComponents>} The components for constructing the synthesis prompt.
|
|
500
|
+
*/
|
|
501
|
+
generateSynthesisPrompt(originalUserInput, conversationContext, expertResults) {
|
|
502
|
+
const expertContributionsText = expertResults
|
|
503
|
+
.map(res => {
|
|
504
|
+
let contribution = `Expert: ${res.agentName} (Specialty: ${res.agentDescription.substring(0, 100)}...)\n`;
|
|
505
|
+
if (res.output.responseText) {
|
|
506
|
+
contribution += `Response:\n${res.output.responseText}\n`;
|
|
507
|
+
}
|
|
508
|
+
if (res.output.toolCalls && res.output.toolCalls.length > 0) {
|
|
509
|
+
contribution += `Proposed Tool Calls:\n${res.output.toolCalls.map(tc => `- ${tc.toolId}(${JSON.stringify(tc.arguments)})`).join('\n')}\n`;
|
|
510
|
+
}
|
|
511
|
+
if (res.output.error) {
|
|
512
|
+
contribution += `Note: This expert encountered an issue: ${typeof res.output.error === 'string' ? res.output.error : res.output.error.message}\n`;
|
|
513
|
+
}
|
|
514
|
+
return contribution;
|
|
515
|
+
})
|
|
516
|
+
.join('---\n');
|
|
517
|
+
const systemPromptContent = this.poolConfig.synthesisConfig?.synthesisPrompt || this.poolConfig.poolSystemPrompt ||
|
|
518
|
+
`You are a master synthesizer AI. Your role is to consolidate findings from a team of specialist AI agents into a single, coherent, and comprehensive response or plan of action.
|
|
519
|
+
The user's original request was: "${originalUserInput || "Not specified, refer to conversation history."}"
|
|
520
|
+
You have received the following contributions from your specialist team. Review them carefully, identify key insights, resolve any contradictions, and formulate a unified output.
|
|
521
|
+
If the experts propose tool calls, decide if they are necessary and include the most relevant ones in your final plan.
|
|
522
|
+
Your final response should be directly address the user's request and be presented as if you are the sole, highly knowledgeable AI.`;
|
|
523
|
+
const synthesisTaskPrompt = `
|
|
524
|
+
Conversation History (last few turns for context):
|
|
525
|
+
${conversationContext.getHistory(3).map(msg => `${msg.role}: ${typeof msg.content === 'string' ? msg.content : '[multimodal_content]'}`).join('\n')}
|
|
526
|
+
|
|
527
|
+
Original User Request: "${originalUserInput || "Refer to history."}"
|
|
528
|
+
|
|
529
|
+
Contributions from Specialist Agents:
|
|
530
|
+
${expertContributionsText}
|
|
531
|
+
|
|
532
|
+
---
|
|
533
|
+
Task: Based on all the above, generate a single, synthesized response to the user. If tool calls are appropriate, include them.
|
|
534
|
+
The response should be comprehensive and directly address the user's original request.`;
|
|
535
|
+
return {
|
|
536
|
+
systemPrompts: [{ content: systemPromptContent, priority: 0 }],
|
|
537
|
+
userInput: synthesisTaskPrompt,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* A helper method to potentially rephrase or wrap a sub-agent's output to align
|
|
542
|
+
* with the pool's unified persona, if one is configured. Also finalizes metadata.
|
|
543
|
+
*
|
|
544
|
+
* @private
|
|
545
|
+
* @param {AgentOutput} subAgentOutput - The output from the sub-agent.
|
|
546
|
+
* @param {IAgent} sourceAgent - The sub-agent that produced the output.
|
|
547
|
+
* @param {ConversationContext} conversationContext - For context if rephrasing LLM call is needed.
|
|
548
|
+
* @param {string} internalActionDescription - Description of the pool's internal action (e.g., "Routed to expert").
|
|
549
|
+
* @param {boolean} [isDirectDelegation=false] - If true, rephrasing might be lighter or skipped.
|
|
550
|
+
* @returns {Promise<AgentOutput>} The finalized (potentially rephrased) `AgentOutput`.
|
|
551
|
+
*/
|
|
552
|
+
async synthesizeAndFinalizeOutput(subAgentOutput, sourceAgent, conversationContext, internalActionDescription, isDirectDelegation = false) {
|
|
553
|
+
const finalOutput = { ...subAgentOutput }; // Start with a copy
|
|
554
|
+
// Add metadata about the source of this output
|
|
555
|
+
finalOutput.metadata = {
|
|
556
|
+
...finalOutput.metadata,
|
|
557
|
+
sourceAgentId: sourceAgent.id,
|
|
558
|
+
sourceAgentName: sourceAgent.name,
|
|
559
|
+
poolAction: internalActionDescription,
|
|
560
|
+
controllingAgentId: this.id,
|
|
561
|
+
};
|
|
562
|
+
// If a unified persona is defined and this isn't a direct delegation where original voice is preferred,
|
|
563
|
+
// and there's text to rephrase, then attempt rephrasing.
|
|
564
|
+
if (this.poolConfig.unifiedPersonaId && !isDirectDelegation && finalOutput.responseText) {
|
|
565
|
+
const unifiedPersonaSystemPrompt = this.agentConfig.systemPrompt; // Pool agent's own system prompt defines unified voice
|
|
566
|
+
const rephrasePromptComponents = {
|
|
567
|
+
systemPrompts: Array.isArray(unifiedPersonaSystemPrompt) ? unifiedPersonaSystemPrompt : [{ content: unifiedPersonaSystemPrompt, priority: 0 }],
|
|
568
|
+
userInput: `An internal specialist agent (${sourceAgent.name}) provided the following information:
|
|
569
|
+
---
|
|
570
|
+
${finalOutput.responseText}
|
|
571
|
+
---
|
|
572
|
+
Your task is to rephrase this information to perfectly match YOUR persona and tone (as defined by the system prompt).
|
|
573
|
+
Present it as if you generated it directly. Ensure consistency with your overall voice and the ongoing conversation.
|
|
574
|
+
If the specialist proposed tool calls, and you agree with them, include them in your rephrased response's tool_calls section.`,
|
|
575
|
+
conversationHistory: [...conversationContext.getHistory(2)], // Brief recent history
|
|
576
|
+
// Pass through tool schemas if rephrasing LLM might also decide on tools
|
|
577
|
+
toolSchemas: finalOutput.toolCalls ? (await this.getAvailableToolDefinitions(finalOutput.toolCalls.map(tc => tc.toolId))) : undefined,
|
|
578
|
+
};
|
|
579
|
+
try {
|
|
580
|
+
const rephraseLlmResponse = await this.callLLM(this.llmProvider, rephrasePromptComponents, {
|
|
581
|
+
temperature: 0.3, // Low temperature for faithful rephrasing
|
|
582
|
+
maxTokens: (finalOutput.responseText.length * 2) + 500, // Generous allowance
|
|
583
|
+
});
|
|
584
|
+
const parsedRephrased = this.parseLLMResponse(rephraseLlmResponse);
|
|
585
|
+
if (parsedRephrased.responseText) {
|
|
586
|
+
finalOutput.responseText = parsedRephrased.responseText;
|
|
587
|
+
finalOutput.metadata = {
|
|
588
|
+
...finalOutput.metadata,
|
|
589
|
+
rephrasedByPool: true,
|
|
590
|
+
};
|
|
591
|
+
// If rephrasing LLM makes its own tool decisions, use them
|
|
592
|
+
if (parsedRephrased.toolCalls) {
|
|
593
|
+
finalOutput.toolCalls = parsedRephrased.toolCalls;
|
|
594
|
+
finalOutput.isComplete = false; // Now has tool calls
|
|
595
|
+
}
|
|
596
|
+
else if (subAgentOutput.toolCalls && !finalOutput.toolCalls) {
|
|
597
|
+
// If original had tool calls but rephrased didn't explicitly include them,
|
|
598
|
+
// decide if they should be carried over or if the rephrasing implies they are handled.
|
|
599
|
+
// For safety, let's assume if rephrasing LLM doesn't re-request tools, they are not needed from this step.
|
|
600
|
+
// This might need more nuanced logic based on the rephrasing prompt.
|
|
601
|
+
// A clearer prompt would ask the rephrasing LLM to explicitly state if original tool calls are still valid.
|
|
602
|
+
// For now, if rephrasing occurs and new tool calls are not part of rephrased output, old tool calls are dropped.
|
|
603
|
+
if (finalOutput.toolCalls) {
|
|
604
|
+
// console.log(`AgentPoolAgent '${this.name}': Rephrasing LLM suggested new tool calls, overriding sub-agent's original calls.`);
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
// console.log(`AgentPoolAgent '${this.name}': Rephrasing occurred. Original sub-agent tool calls are not automatically carried over unless re-stated by rephrasing LLM.`);
|
|
608
|
+
// This means if the rephrasing integrates the information such that tools are no longer needed, that's the new state.
|
|
609
|
+
finalOutput.toolCalls = undefined; // Explicitly clear if not re-requested.
|
|
610
|
+
finalOutput.isComplete = true; // Since no more tool calls from this unified output.
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
console.warn(`AgentPoolAgent '${this.name}': Failed to rephrase sub-agent output for unified persona. Using original text from '${sourceAgent.name}'. Error: ${error.message}`, error);
|
|
617
|
+
// Fallback to original text, but metadata still indicates source.
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
else if (isDirectDelegation && this.poolConfig.unifiedPersonaId && finalOutput.responseText) {
|
|
621
|
+
// Light touch for direct delegation if unified persona is active: just prepend a small attribution.
|
|
622
|
+
// finalOutput.responseText = `My specialist, ${sourceAgent.name}, reports: "${finalOutput.responseText}"`;
|
|
623
|
+
// This kind of modification should be optional or configurable. For true direct delegation, no modification.
|
|
624
|
+
}
|
|
625
|
+
return finalOutput;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Overrides `handleToolResult` from `AgentCore`.
|
|
629
|
+
* This method is called when a tool initiated by the `AgentPoolAgent` itself completes.
|
|
630
|
+
* (Tools initiated by sub-agents are handled by their respective `handleToolResult` methods,
|
|
631
|
+
* and the orchestrator delivers the result to that sub-agent).
|
|
632
|
+
*
|
|
633
|
+
* The `AgentPoolAgent` might use tools for its meta-tasks, like a "SubAgentSelectionTool"
|
|
634
|
+
* or a "ContentAnalysisTool" to help in routing or synthesis.
|
|
635
|
+
*
|
|
636
|
+
* @override
|
|
637
|
+
* @param {string} toolCallId - The ID of the tool call this result pertains to.
|
|
638
|
+
* @param {any} toolOutput - The output from the tool execution.
|
|
639
|
+
* @param {string} toolName - The name of the tool that was called.
|
|
640
|
+
* @param {ConversationContext} conversationContext - The current conversation context.
|
|
641
|
+
* @returns {Promise<AgentOutput>} The pool agent's subsequent output after processing its own tool's result.
|
|
642
|
+
*/
|
|
643
|
+
async handleToolResult(toolCallId, toolOutput, toolName, conversationContext) {
|
|
644
|
+
this.ensureInitialized();
|
|
645
|
+
// console.log(`AgentPoolAgent '${this.name}' (ID: ${this.id}) is handling its OWN tool result for tool '${toolName}' (Call ID: ${toolCallId}).`);
|
|
646
|
+
// First, add the tool result to the conversation context, as per standard practice.
|
|
647
|
+
try {
|
|
648
|
+
conversationContext.addMessage({
|
|
649
|
+
role: MessageRole.TOOL,
|
|
650
|
+
content: typeof toolOutput === 'string' ? toolOutput : JSON.stringify(toolOutput, null, 2),
|
|
651
|
+
tool_call_id: toolCallId,
|
|
652
|
+
name: toolName,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
catch (error) {
|
|
656
|
+
const contextErrorMsg = `Failed to add AgentPoolAgent's own tool result ('${toolName}') to context: ${error.message}`;
|
|
657
|
+
console.error(`AgentPoolAgent '${this.name}': ${contextErrorMsg}`, error);
|
|
658
|
+
return this.handleInternalAgentError(new AgentCoreError(contextErrorMsg, 'POOL_TOOL_RESULT_CONTEXT_ERROR', error), conversationContext, true);
|
|
659
|
+
}
|
|
660
|
+
// Now, the AgentPoolAgent needs to decide what to do with this tool's output.
|
|
661
|
+
// This typically involves another LLM call to interpret the tool's output in the context
|
|
662
|
+
// of its ongoing meta-task (e.g., routing, synthesis).
|
|
663
|
+
// This logic mirrors the base AgentCore's handleToolResult but is specific to the pool's context.
|
|
664
|
+
const metaSystemPrompt = this.agentConfig.metaSystemPromptForUnexpectedSituations || this.poolConfig.poolSystemPrompt ||
|
|
665
|
+
`You are the Agent Pool Manager. You just used a tool called '${toolName}' to assist with your orchestration tasks.
|
|
666
|
+
The tool's output is: "${typeof toolOutput === 'string' ? toolOutput.substring(0, 200) : JSON.stringify(toolOutput).substring(0, 200)}...".
|
|
667
|
+
Based on this output and the overall goal (e.g., routing a user request, synthesizing information), decide the next step in your pool management process.
|
|
668
|
+
This might involve selecting a sub-agent, formulating a synthesis plan, or directly responding if the tool provided a final answer.`;
|
|
669
|
+
try {
|
|
670
|
+
const promptComponents = {
|
|
671
|
+
systemPrompts: [{ content: metaSystemPrompt, priority: 0 }],
|
|
672
|
+
conversationHistory: [...conversationContext.getHistory()], // Full history now includes the pool's tool result
|
|
673
|
+
// The "userInput" for this LLM call is effectively the context of needing to process its own tool's output.
|
|
674
|
+
userInput: `The tool '${toolName}' (which I, the Pool Manager, called) has provided its output. Now, how should I proceed with managing my sub-agents or responding to the original user query based on this new information?`,
|
|
675
|
+
};
|
|
676
|
+
// The pool agent might itself call other tools after processing this one.
|
|
677
|
+
const llmResponse = await this.callLLM(this.llmProvider, promptComponents, {
|
|
678
|
+
// Tools available to the pool agent for its meta-tasks
|
|
679
|
+
tools: this.availablePoolTools.length > 0 ? this.availablePoolTools.map(t => t.definition) : undefined
|
|
680
|
+
});
|
|
681
|
+
const parsedResponse = this.parseLLMResponse(llmResponse);
|
|
682
|
+
return {
|
|
683
|
+
responseText: parsedResponse.responseText ?? undefined,
|
|
684
|
+
toolCalls: parsedResponse.toolCalls,
|
|
685
|
+
isComplete: !parsedResponse.toolCalls || parsedResponse.toolCalls.length === 0,
|
|
686
|
+
rawModelResponse: parsedResponse.rawResponseMessage,
|
|
687
|
+
metadata: { processedPoolToolResult: toolName, toolCallId },
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
catch (llmError) {
|
|
691
|
+
const errorMsg = `AgentPoolAgent '${this.name}' failed to process its own tool result for '${toolName}' using LLM: ${llmError.message}`;
|
|
692
|
+
console.error(errorMsg, llmError);
|
|
693
|
+
return this.handleInternalAgentError(new AgentCoreError(errorMsg, 'POOL_SELF_TOOL_RESULT_LLM_ERROR', llmError), conversationContext, true);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
//# sourceMappingURL=AgentPoolAgent.js.map
|