agentic-qe 2.3.5 → 2.5.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/.claude/agents/qe-a11y-ally.md +751 -0
- package/.claude/agents/qx-partner.md +120 -4
- package/.claude/skills/testability-scoring/SKILL.md +107 -6
- package/CHANGELOG.md +133 -0
- package/README.md +7 -6
- package/dist/agents/AccessibilityAllyAgent.d.ts +168 -0
- package/dist/agents/AccessibilityAllyAgent.d.ts.map +1 -0
- package/dist/agents/AccessibilityAllyAgent.js +462 -0
- package/dist/agents/AccessibilityAllyAgent.js.map +1 -0
- package/dist/agents/BaseAgent.d.ts +56 -49
- package/dist/agents/BaseAgent.d.ts.map +1 -1
- package/dist/agents/BaseAgent.js +208 -604
- package/dist/agents/BaseAgent.js.map +1 -1
- package/dist/agents/FlakyTestHunterAgent.d.ts +2 -2
- package/dist/agents/FlakyTestHunterAgent.d.ts.map +1 -1
- package/dist/agents/FlakyTestHunterAgent.js +8 -104
- package/dist/agents/FlakyTestHunterAgent.js.map +1 -1
- package/dist/agents/SONAIntegration.d.ts +109 -0
- package/dist/agents/SONAIntegration.d.ts.map +1 -0
- package/dist/agents/SONAIntegration.js +167 -0
- package/dist/agents/SONAIntegration.js.map +1 -0
- package/dist/agents/TestExecutorAgent.d.ts +1 -1
- package/dist/agents/TestExecutorAgent.d.ts.map +1 -1
- package/dist/agents/TestExecutorAgent.js +4 -46
- package/dist/agents/TestExecutorAgent.js.map +1 -1
- package/dist/agents/TestGeneratorAgent.d.ts.map +1 -1
- package/dist/agents/TestGeneratorAgent.js +15 -35
- package/dist/agents/TestGeneratorAgent.js.map +1 -1
- package/dist/agents/adapters/CoordinatorAdapter.d.ts +47 -0
- package/dist/agents/adapters/CoordinatorAdapter.d.ts.map +1 -0
- package/dist/agents/adapters/CoordinatorAdapter.js +266 -0
- package/dist/agents/adapters/CoordinatorAdapter.js.map +1 -0
- package/dist/agents/adapters/LearningEngineAdapter.d.ts +45 -0
- package/dist/agents/adapters/LearningEngineAdapter.d.ts.map +1 -0
- package/dist/agents/adapters/LearningEngineAdapter.js +279 -0
- package/dist/agents/adapters/LearningEngineAdapter.js.map +1 -0
- package/dist/agents/adapters/LifecycleManagerAdapter.d.ts +45 -0
- package/dist/agents/adapters/LifecycleManagerAdapter.d.ts.map +1 -0
- package/dist/agents/adapters/LifecycleManagerAdapter.js +128 -0
- package/dist/agents/adapters/LifecycleManagerAdapter.js.map +1 -0
- package/dist/agents/adapters/MemoryServiceAdapter.d.ts +96 -0
- package/dist/agents/adapters/MemoryServiceAdapter.d.ts.map +1 -0
- package/dist/agents/adapters/MemoryServiceAdapter.js +266 -0
- package/dist/agents/adapters/MemoryServiceAdapter.js.map +1 -0
- package/dist/agents/adapters/index.d.ts +14 -0
- package/dist/agents/adapters/index.d.ts.map +1 -0
- package/dist/agents/adapters/index.js +25 -0
- package/dist/agents/adapters/index.js.map +1 -0
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +93 -2
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lifecycle/AgentLifecycleManager.d.ts.map +1 -1
- package/dist/agents/lifecycle/AgentLifecycleManager.js +12 -6
- package/dist/agents/lifecycle/AgentLifecycleManager.js.map +1 -1
- package/dist/cli/init/agents.js +1 -1
- package/dist/cli/init/claude-config.js +2 -2
- package/dist/cli/init/database-init.js +1 -1
- package/dist/core/cache/BinaryCacheBuilder.d.ts +84 -0
- package/dist/core/cache/BinaryCacheBuilder.d.ts.map +1 -0
- package/dist/core/cache/BinaryCacheBuilder.js +225 -0
- package/dist/core/cache/BinaryCacheBuilder.js.map +1 -0
- package/dist/core/cache/BinaryCacheImpl.d.ts +161 -0
- package/dist/core/cache/BinaryCacheImpl.d.ts.map +1 -0
- package/dist/core/cache/BinaryCacheImpl.js +685 -0
- package/dist/core/cache/BinaryCacheImpl.js.map +1 -0
- package/dist/core/cache/BinaryCacheManager.d.ts +142 -0
- package/dist/core/cache/BinaryCacheManager.d.ts.map +1 -0
- package/dist/core/cache/BinaryCacheManager.js +354 -0
- package/dist/core/cache/BinaryCacheManager.js.map +1 -0
- package/dist/core/cache/BinaryCacheReader.d.ts +129 -0
- package/dist/core/cache/BinaryCacheReader.d.ts.map +1 -0
- package/dist/core/cache/BinaryCacheReader.js +243 -0
- package/dist/core/cache/BinaryCacheReader.js.map +1 -0
- package/dist/core/cache/BinaryMetadataCache.d.ts +777 -0
- package/dist/core/cache/BinaryMetadataCache.d.ts.map +1 -0
- package/dist/core/cache/BinaryMetadataCache.js +204 -0
- package/dist/core/cache/BinaryMetadataCache.js.map +1 -0
- package/dist/core/cache/CacheInvalidator.d.ts +103 -0
- package/dist/core/cache/CacheInvalidator.d.ts.map +1 -0
- package/dist/core/cache/CacheInvalidator.js +152 -0
- package/dist/core/cache/CacheInvalidator.js.map +1 -0
- package/dist/core/cache/CacheValidator.d.ts +69 -0
- package/dist/core/cache/CacheValidator.d.ts.map +1 -0
- package/dist/core/cache/CacheValidator.js +189 -0
- package/dist/core/cache/CacheValidator.js.map +1 -0
- package/dist/core/cache/MessagePackSerializer.d.ts +163 -0
- package/dist/core/cache/MessagePackSerializer.d.ts.map +1 -0
- package/dist/core/cache/MessagePackSerializer.js +274 -0
- package/dist/core/cache/MessagePackSerializer.js.map +1 -0
- package/dist/core/cache/index.d.ts +59 -0
- package/dist/core/cache/index.d.ts.map +1 -0
- package/dist/core/cache/index.js +111 -0
- package/dist/core/cache/index.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +18 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/memory/AgentDBService.d.ts +30 -4
- package/dist/core/memory/AgentDBService.d.ts.map +1 -1
- package/dist/core/memory/AgentDBService.js +122 -12
- package/dist/core/memory/AgentDBService.js.map +1 -1
- package/dist/core/memory/CachedHNSWVectorMemory.d.ts +153 -0
- package/dist/core/memory/CachedHNSWVectorMemory.d.ts.map +1 -0
- package/dist/core/memory/CachedHNSWVectorMemory.js +329 -0
- package/dist/core/memory/CachedHNSWVectorMemory.js.map +1 -0
- package/dist/core/memory/HNSWVectorMemory.js +1 -1
- package/dist/core/memory/PatternStoreFactory.d.ts +28 -0
- package/dist/core/memory/PatternStoreFactory.d.ts.map +1 -1
- package/dist/core/memory/PatternStoreFactory.js +68 -3
- package/dist/core/memory/PatternStoreFactory.js.map +1 -1
- package/dist/core/memory/RuVectorPatternStore.d.ts.map +1 -1
- package/dist/core/memory/RuVectorPatternStore.js +8 -2
- package/dist/core/memory/RuVectorPatternStore.js.map +1 -1
- package/dist/core/memory/UnifiedMemoryCoordinator.d.ts +50 -0
- package/dist/core/memory/UnifiedMemoryCoordinator.d.ts.map +1 -1
- package/dist/core/memory/UnifiedMemoryCoordinator.js +206 -0
- package/dist/core/memory/UnifiedMemoryCoordinator.js.map +1 -1
- package/dist/core/memory/index.d.ts +2 -0
- package/dist/core/memory/index.d.ts.map +1 -1
- package/dist/core/memory/index.js +8 -1
- package/dist/core/memory/index.js.map +1 -1
- package/dist/core/optimization/RecursiveOptimizer.d.ts +233 -0
- package/dist/core/optimization/RecursiveOptimizer.d.ts.map +1 -0
- package/dist/core/optimization/RecursiveOptimizer.js +509 -0
- package/dist/core/optimization/RecursiveOptimizer.js.map +1 -0
- package/dist/core/platform/FileOperations.d.ts +124 -0
- package/dist/core/platform/FileOperations.d.ts.map +1 -0
- package/dist/core/platform/FileOperations.js +371 -0
- package/dist/core/platform/FileOperations.js.map +1 -0
- package/dist/core/platform/PlatformDetector.d.ts +53 -0
- package/dist/core/platform/PlatformDetector.d.ts.map +1 -0
- package/dist/core/platform/PlatformDetector.js +251 -0
- package/dist/core/platform/PlatformDetector.js.map +1 -0
- package/dist/core/platform/index.d.ts +12 -0
- package/dist/core/platform/index.d.ts.map +1 -0
- package/dist/core/platform/index.js +28 -0
- package/dist/core/platform/index.js.map +1 -0
- package/dist/core/strategies/AcceleratedLearningStrategy.d.ts +74 -0
- package/dist/core/strategies/AcceleratedLearningStrategy.d.ts.map +1 -0
- package/dist/core/strategies/AcceleratedLearningStrategy.js +200 -0
- package/dist/core/strategies/AcceleratedLearningStrategy.js.map +1 -0
- package/dist/core/strategies/AgentCoordinationStrategy.d.ts +157 -0
- package/dist/core/strategies/AgentCoordinationStrategy.d.ts.map +1 -0
- package/dist/core/strategies/AgentCoordinationStrategy.js +12 -0
- package/dist/core/strategies/AgentCoordinationStrategy.js.map +1 -0
- package/dist/core/strategies/AgentLearningStrategy.d.ts +200 -0
- package/dist/core/strategies/AgentLearningStrategy.d.ts.map +1 -0
- package/dist/core/strategies/AgentLearningStrategy.js +13 -0
- package/dist/core/strategies/AgentLearningStrategy.js.map +1 -0
- package/dist/core/strategies/AgentLifecycleStrategy.d.ts +116 -0
- package/dist/core/strategies/AgentLifecycleStrategy.d.ts.map +1 -0
- package/dist/core/strategies/AgentLifecycleStrategy.js +12 -0
- package/dist/core/strategies/AgentLifecycleStrategy.js.map +1 -0
- package/dist/core/strategies/AgentMemoryStrategy.d.ts +154 -0
- package/dist/core/strategies/AgentMemoryStrategy.d.ts.map +1 -0
- package/dist/core/strategies/AgentMemoryStrategy.js +13 -0
- package/dist/core/strategies/AgentMemoryStrategy.js.map +1 -0
- package/dist/core/strategies/DefaultCoordinationStrategy.d.ts +105 -0
- package/dist/core/strategies/DefaultCoordinationStrategy.d.ts.map +1 -0
- package/dist/core/strategies/DefaultCoordinationStrategy.js +332 -0
- package/dist/core/strategies/DefaultCoordinationStrategy.js.map +1 -0
- package/dist/core/strategies/DefaultLearningStrategy.d.ts +120 -0
- package/dist/core/strategies/DefaultLearningStrategy.d.ts.map +1 -0
- package/dist/core/strategies/DefaultLearningStrategy.js +365 -0
- package/dist/core/strategies/DefaultLearningStrategy.js.map +1 -0
- package/dist/core/strategies/DefaultLifecycleStrategy.d.ts +129 -0
- package/dist/core/strategies/DefaultLifecycleStrategy.d.ts.map +1 -0
- package/dist/core/strategies/DefaultLifecycleStrategy.js +297 -0
- package/dist/core/strategies/DefaultLifecycleStrategy.js.map +1 -0
- package/dist/core/strategies/DefaultMemoryStrategy.d.ts +91 -0
- package/dist/core/strategies/DefaultMemoryStrategy.d.ts.map +1 -0
- package/dist/core/strategies/DefaultMemoryStrategy.js +257 -0
- package/dist/core/strategies/DefaultMemoryStrategy.js.map +1 -0
- package/dist/core/strategies/DistributedMemoryStrategy.d.ts +85 -0
- package/dist/core/strategies/DistributedMemoryStrategy.d.ts.map +1 -0
- package/dist/core/strategies/DistributedMemoryStrategy.js +126 -0
- package/dist/core/strategies/DistributedMemoryStrategy.js.map +1 -0
- package/dist/core/strategies/SONALearningStrategy.d.ts +115 -0
- package/dist/core/strategies/SONALearningStrategy.d.ts.map +1 -0
- package/dist/core/strategies/SONALearningStrategy.js +656 -0
- package/dist/core/strategies/SONALearningStrategy.js.map +1 -0
- package/dist/core/strategies/TRMLearningStrategy.d.ts +162 -0
- package/dist/core/strategies/TRMLearningStrategy.d.ts.map +1 -0
- package/dist/core/strategies/TRMLearningStrategy.js +670 -0
- package/dist/core/strategies/TRMLearningStrategy.js.map +1 -0
- package/dist/core/strategies/index.d.ts +104 -0
- package/dist/core/strategies/index.d.ts.map +1 -0
- package/dist/core/strategies/index.js +68 -0
- package/dist/core/strategies/index.js.map +1 -0
- package/dist/learning/PerformanceOptimizer.js +2 -2
- package/dist/learning/PerformanceOptimizer.js.map +1 -1
- package/dist/learning/SONAFeedbackLoop.d.ts +168 -0
- package/dist/learning/SONAFeedbackLoop.d.ts.map +1 -0
- package/dist/learning/SONAFeedbackLoop.js +344 -0
- package/dist/learning/SONAFeedbackLoop.js.map +1 -0
- package/dist/learning/baselines/BaselineCollector.d.ts +1 -1
- package/dist/learning/baselines/BaselineCollector.js +1 -1
- package/dist/learning/baselines/StandardTaskSuite.d.ts +1 -1
- package/dist/learning/baselines/StandardTaskSuite.js +1 -1
- package/dist/learning/index.d.ts +2 -0
- package/dist/learning/index.d.ts.map +1 -1
- package/dist/learning/index.js +6 -1
- package/dist/learning/index.js.map +1 -1
- package/dist/mcp/handlers/base-handler.d.ts +28 -1
- package/dist/mcp/handlers/base-handler.d.ts.map +1 -1
- package/dist/mcp/handlers/base-handler.js +41 -0
- package/dist/mcp/handlers/base-handler.js.map +1 -1
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.js +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +23 -16
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/services/AgentRegistry.d.ts.map +1 -1
- package/dist/mcp/services/AgentRegistry.js +6 -1
- package/dist/mcp/services/AgentRegistry.js.map +1 -1
- package/dist/mcp/tools/qe/accessibility/accname-computation.d.ts +114 -0
- package/dist/mcp/tools/qe/accessibility/accname-computation.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/accname-computation.js +566 -0
- package/dist/mcp/tools/qe/accessibility/accname-computation.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/apg-patterns.d.ts +103 -0
- package/dist/mcp/tools/qe/accessibility/apg-patterns.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/apg-patterns.js +1028 -0
- package/dist/mcp/tools/qe/accessibility/apg-patterns.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/en-301-549-mapping.d.ts +48 -0
- package/dist/mcp/tools/qe/accessibility/en-301-549-mapping.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/en-301-549-mapping.js +565 -0
- package/dist/mcp/tools/qe/accessibility/en-301-549-mapping.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/eu-accessibility-act.d.ts +117 -0
- package/dist/mcp/tools/qe/accessibility/eu-accessibility-act.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/eu-accessibility-act.js +571 -0
- package/dist/mcp/tools/qe/accessibility/eu-accessibility-act.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/html-report-generator.d.ts +23 -0
- package/dist/mcp/tools/qe/accessibility/html-report-generator.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/html-report-generator.js +1152 -0
- package/dist/mcp/tools/qe/accessibility/html-report-generator.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/index.d.ts +22 -0
- package/dist/mcp/tools/qe/accessibility/index.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/index.js +38 -0
- package/dist/mcp/tools/qe/accessibility/index.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/markdown-report-generator.d.ts +18 -0
- package/dist/mcp/tools/qe/accessibility/markdown-report-generator.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/markdown-report-generator.js +549 -0
- package/dist/mcp/tools/qe/accessibility/markdown-report-generator.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/remediation-code-generator.d.ts +139 -0
- package/dist/mcp/tools/qe/accessibility/remediation-code-generator.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/remediation-code-generator.js +1300 -0
- package/dist/mcp/tools/qe/accessibility/remediation-code-generator.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/scan-comprehensive.d.ts +138 -0
- package/dist/mcp/tools/qe/accessibility/scan-comprehensive.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/scan-comprehensive.js +1326 -0
- package/dist/mcp/tools/qe/accessibility/scan-comprehensive.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/video-vision-analyzer.d.ts +50 -0
- package/dist/mcp/tools/qe/accessibility/video-vision-analyzer.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/video-vision-analyzer.js +469 -0
- package/dist/mcp/tools/qe/accessibility/video-vision-analyzer.js.map +1 -0
- package/dist/mcp/tools/qe/accessibility/webvtt-generator.d.ts +193 -0
- package/dist/mcp/tools/qe/accessibility/webvtt-generator.d.ts.map +1 -0
- package/dist/mcp/tools/qe/accessibility/webvtt-generator.js +511 -0
- package/dist/mcp/tools/qe/accessibility/webvtt-generator.js.map +1 -0
- package/dist/mcp/tools.d.ts +1 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +61 -0
- package/dist/mcp/tools.js.map +1 -1
- package/dist/output/AIActionSuggester.d.ts +98 -0
- package/dist/output/AIActionSuggester.d.ts.map +1 -0
- package/dist/output/AIActionSuggester.js +499 -0
- package/dist/output/AIActionSuggester.js.map +1 -0
- package/dist/output/CLIOutputHelper.d.ts +169 -0
- package/dist/output/CLIOutputHelper.d.ts.map +1 -0
- package/dist/output/CLIOutputHelper.js +320 -0
- package/dist/output/CLIOutputHelper.js.map +1 -0
- package/dist/output/OutputFormatter.d.ts +764 -0
- package/dist/output/OutputFormatter.d.ts.map +1 -0
- package/dist/output/OutputFormatter.js +125 -0
- package/dist/output/OutputFormatter.js.map +1 -0
- package/dist/output/OutputFormatterImpl.d.ts +131 -0
- package/dist/output/OutputFormatterImpl.d.ts.map +1 -0
- package/dist/output/OutputFormatterImpl.js +556 -0
- package/dist/output/OutputFormatterImpl.js.map +1 -0
- package/dist/output/examples.d.ts +38 -0
- package/dist/output/examples.d.ts.map +1 -0
- package/dist/output/examples.js +503 -0
- package/dist/output/examples.js.map +1 -0
- package/dist/output/index.d.ts +16 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +58 -0
- package/dist/output/index.js.map +1 -0
- package/dist/providers/HybridRouter.d.ts +34 -3
- package/dist/providers/HybridRouter.d.ts.map +1 -1
- package/dist/providers/HybridRouter.js +69 -4
- package/dist/providers/HybridRouter.js.map +1 -1
- package/dist/providers/LLMProviderFactory.d.ts +68 -1
- package/dist/providers/LLMProviderFactory.d.ts.map +1 -1
- package/dist/providers/LLMProviderFactory.js +173 -6
- package/dist/providers/LLMProviderFactory.js.map +1 -1
- package/dist/providers/OpenRouterProvider.d.ts +150 -0
- package/dist/providers/OpenRouterProvider.d.ts.map +1 -0
- package/dist/providers/OpenRouterProvider.js +545 -0
- package/dist/providers/OpenRouterProvider.js.map +1 -0
- package/dist/providers/RuvllmProvider.d.ts +130 -16
- package/dist/providers/RuvllmProvider.d.ts.map +1 -1
- package/dist/providers/RuvllmProvider.js +399 -83
- package/dist/providers/RuvllmProvider.js.map +1 -1
- package/dist/providers/index.d.ts +33 -4
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +72 -21
- package/dist/providers/index.js.map +1 -1
- package/dist/telemetry/instrumentation/agent.d.ts +1 -1
- package/dist/telemetry/instrumentation/agent.js +1 -1
- package/dist/telemetry/instrumentation/index.d.ts +1 -1
- package/dist/telemetry/instrumentation/index.js +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/ruvllm.d.ts +97 -0
- package/dist/types/ruvllm.d.ts.map +1 -0
- package/dist/types/ruvllm.js +46 -0
- package/dist/types/ruvllm.js.map +1 -0
- package/dist/utils/ruvllm-loader.d.ts +94 -0
- package/dist/utils/ruvllm-loader.d.ts.map +1 -0
- package/dist/utils/ruvllm-loader.js +87 -0
- package/dist/utils/ruvllm-loader.js.map +1 -0
- package/docs/reference/agents.md +36 -1
- package/package.json +7 -2
package/dist/agents/BaseAgent.js
CHANGED
|
@@ -8,84 +8,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.BaseAgentFactory = exports.BaseAgent = void 0;
|
|
9
9
|
const events_1 = require("events");
|
|
10
10
|
const SecureRandom_js_1 = require("../utils/SecureRandom.js");
|
|
11
|
-
const EmbeddingGenerator_js_1 = require("../utils/EmbeddingGenerator.js");
|
|
12
11
|
const types_1 = require("../types");
|
|
13
12
|
const hooks_1 = require("../core/hooks");
|
|
14
13
|
const MemoryStoreAdapter_1 = require("../adapters/MemoryStoreAdapter");
|
|
15
14
|
const PerformanceTracker_1 = require("../learning/PerformanceTracker");
|
|
16
15
|
const SwarmMemoryManager_1 = require("../core/memory/SwarmMemoryManager");
|
|
17
16
|
const LearningEngine_1 = require("../learning/LearningEngine");
|
|
18
|
-
const AgentDBManager_1 = require("../core/memory/AgentDBManager");
|
|
19
17
|
const AgentLifecycleManager_1 = require("./lifecycle/AgentLifecycleManager");
|
|
20
18
|
const AgentCoordinator_1 = require("./coordination/AgentCoordinator");
|
|
21
19
|
const AgentMemoryService_1 = require("./memory/AgentMemoryService");
|
|
22
|
-
const
|
|
20
|
+
const adapters_1 = require("./adapters");
|
|
23
21
|
class BaseAgent extends events_1.EventEmitter {
|
|
24
22
|
constructor(config) {
|
|
25
23
|
super();
|
|
26
|
-
this.performanceMetrics = {
|
|
27
|
-
|
|
28
|
-
averageExecutionTime: 0,
|
|
29
|
-
errorCount: 0,
|
|
30
|
-
lastActivity: new Date()
|
|
31
|
-
};
|
|
32
|
-
this.agentId = {
|
|
33
|
-
id: config.id || this.generateAgentId(config.type),
|
|
34
|
-
type: config.type,
|
|
35
|
-
created: new Date()
|
|
36
|
-
};
|
|
24
|
+
this.performanceMetrics = { tasksCompleted: 0, averageExecutionTime: 0, errorCount: 0, lastActivity: new Date() };
|
|
25
|
+
this.agentId = { id: config.id || this.generateAgentId(config.type), type: config.type, created: new Date() };
|
|
37
26
|
this.capabilities = new Map(config.capabilities.map(cap => [cap.name, cap]));
|
|
38
27
|
this.context = config.context;
|
|
39
28
|
this.memoryStore = config.memoryStore;
|
|
40
29
|
this.eventBus = config.eventBus;
|
|
41
|
-
this.enableLearning = config.enableLearning ?? true;
|
|
30
|
+
this.enableLearning = config.enableLearning ?? true;
|
|
42
31
|
this.learningConfig = config.learningConfig;
|
|
43
|
-
//
|
|
44
|
-
// All persistence now goes through SwarmMemoryManager to .agentic-qe/memory.db
|
|
45
|
-
// AgentDB is kept for backward compatibility but should NOT be used for new code.
|
|
46
|
-
// LearningEngine handles all learning/pattern storage via memoryStore.
|
|
47
|
-
if (config.agentDBConfig) {
|
|
48
|
-
console.warn(`[${config.type}] AgentDB is DEPRECATED. All persistence should use SwarmMemoryManager (memory.db). ` +
|
|
49
|
-
`AgentDB will be removed in v3.0.0.`);
|
|
50
|
-
this.agentDBConfig = config.agentDBConfig;
|
|
51
|
-
}
|
|
52
|
-
else if (config.agentDBPath || config.enableQUICSync) {
|
|
53
|
-
console.warn(`[${config.type}] AgentDB paths are DEPRECATED. All persistence now uses memory.db via SwarmMemoryManager.`);
|
|
54
|
-
// Do NOT create agentDBConfig by default - let memoryStore handle everything
|
|
55
|
-
// Only create if explicitly requested with a custom path
|
|
56
|
-
if (config.agentDBPath) {
|
|
57
|
-
this.agentDBConfig = {
|
|
58
|
-
dbPath: config.agentDBPath, // Use explicit path only, no default
|
|
59
|
-
enableQUICSync: config.enableQUICSync || false,
|
|
60
|
-
syncPort: config.syncPort || 4433,
|
|
61
|
-
syncPeers: config.syncPeers || [],
|
|
62
|
-
enableLearning: config.enableLearning || false,
|
|
63
|
-
enableReasoning: true,
|
|
64
|
-
cacheSize: 1000,
|
|
65
|
-
quantizationType: config.quantizationType || 'scalar',
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Initialize verification hook manager with type-safe adapter
|
|
70
|
-
// MemoryStoreAdapter bridges MemoryStore interface to SwarmMemoryManager
|
|
71
|
-
// Provides runtime validation and clear error messages for incompatible implementations
|
|
32
|
+
// Initialize service classes
|
|
72
33
|
const memoryAdapter = new MemoryStoreAdapter_1.MemoryStoreAdapter(this.memoryStore);
|
|
73
34
|
this.hookManager = new hooks_1.VerificationHookManager(memoryAdapter);
|
|
74
|
-
// Initialize integrated service classes
|
|
75
35
|
this.lifecycleManager = new AgentLifecycleManager_1.AgentLifecycleManager(this.agentId);
|
|
76
|
-
this.coordinator = new AgentCoordinator_1.AgentCoordinator({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
this.lifecycleManager.setStatusChangeCallback((status) => {
|
|
87
|
-
this.emitStatusChange(status);
|
|
88
|
-
});
|
|
36
|
+
this.coordinator = new AgentCoordinator_1.AgentCoordinator({ agentId: this.agentId, eventBus: this.eventBus, memoryStore: this.memoryStore });
|
|
37
|
+
this.memoryService = new AgentMemoryService_1.AgentMemoryService({ agentId: this.agentId, memoryStore: this.memoryStore });
|
|
38
|
+
// Initialize strategies (B1.2)
|
|
39
|
+
this.strategies = {
|
|
40
|
+
lifecycle: config.lifecycleStrategy ?? (0, adapters_1.createLifecycleAdapter)(this.lifecycleManager),
|
|
41
|
+
memory: config.memoryStrategy ?? (0, adapters_1.createMemoryAdapter)(this.memoryService, this.memoryStore, this.agentId),
|
|
42
|
+
learning: config.learningStrategy,
|
|
43
|
+
coordination: config.coordinationStrategy ?? (0, adapters_1.createCoordinationAdapter)(this.eventBus, this.agentId),
|
|
44
|
+
};
|
|
45
|
+
this.lifecycleManager.setStatusChangeCallback((status) => this.emitStatusChange(status));
|
|
89
46
|
this.setupEventHandlers();
|
|
90
47
|
this.setupLifecycleHooks();
|
|
91
48
|
}
|
|
@@ -101,6 +58,11 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
101
58
|
if (this.initializationMutex) {
|
|
102
59
|
console.info(`[${this.agentId.id}] Initialization already in progress, waiting for completion`);
|
|
103
60
|
await this.initializationMutex;
|
|
61
|
+
// Check if initialization succeeded or failed
|
|
62
|
+
const statusAfterWait = this.lifecycleManager.getStatus();
|
|
63
|
+
if (statusAfterWait === types_1.AgentStatus.ERROR) {
|
|
64
|
+
throw new Error(`Initialization failed (status: ${statusAfterWait})`);
|
|
65
|
+
}
|
|
104
66
|
return;
|
|
105
67
|
}
|
|
106
68
|
// Guard: Skip if already initialized (ACTIVE or IDLE)
|
|
@@ -142,16 +104,17 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
142
104
|
// No direct database dependency - memoryStore handles all coordination
|
|
143
105
|
this.learningEngine = new LearningEngine_1.LearningEngine(this.agentId.id, this.memoryStore, this.learningConfig);
|
|
144
106
|
await this.learningEngine.initialize();
|
|
107
|
+
// Phase 2 (B1.2): Create learning strategy adapter
|
|
108
|
+
// Only set if not already injected via config
|
|
109
|
+
if (!this.strategies.learning) {
|
|
110
|
+
this.strategies.learning = (0, adapters_1.createLearningAdapter)(this.learningEngine);
|
|
111
|
+
}
|
|
145
112
|
}
|
|
146
113
|
else if (this.enableLearning && !(this.memoryStore instanceof SwarmMemoryManager_1.SwarmMemoryManager)) {
|
|
147
114
|
// Runtime check: Warn if learning is enabled but memoryStore doesn't support it
|
|
148
115
|
console.warn(`[${this.agentId.id}] Learning enabled but memoryStore is not SwarmMemoryManager. ` +
|
|
149
116
|
`Learning features will be disabled. Expected SwarmMemoryManager, got ${this.memoryStore.constructor.name}`);
|
|
150
117
|
}
|
|
151
|
-
// Initialize AgentDB if configured
|
|
152
|
-
if (this.agentDBConfig) {
|
|
153
|
-
await this.initializeAgentDB(this.agentDBConfig);
|
|
154
|
-
}
|
|
155
118
|
// Initialize agent-specific components
|
|
156
119
|
await this.initializeComponents();
|
|
157
120
|
// Execute post-initialization hooks
|
|
@@ -182,7 +145,8 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
182
145
|
// Validate task assignment
|
|
183
146
|
this.validateTaskAssignment(assignment);
|
|
184
147
|
this.currentTask = assignment;
|
|
185
|
-
|
|
148
|
+
// Phase 2 (B1.2): Use lifecycle strategy for status transitions
|
|
149
|
+
await this.strategies.lifecycle.transitionTo(types_1.AgentStatus.ACTIVE);
|
|
186
150
|
// Execute pre-task hooks with verification
|
|
187
151
|
const preTaskData = { assignment };
|
|
188
152
|
await this.onPreTask(preTaskData);
|
|
@@ -195,41 +159,19 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
195
159
|
const postTaskData = { assignment, result };
|
|
196
160
|
await this.onPostTask(postTaskData);
|
|
197
161
|
await this.executeHook('post-task', postTaskData);
|
|
198
|
-
// Update performance metrics
|
|
199
|
-
const duration = Date.now() - startTime;
|
|
162
|
+
// Update performance metrics and store result
|
|
200
163
|
this.updatePerformanceMetrics(startTime, true);
|
|
201
|
-
// Capture experience for learning (Nightly-Learner integration)
|
|
202
|
-
await this.captureExperience({
|
|
203
|
-
taskId: assignment.id,
|
|
204
|
-
taskType: assignment.task.type || 'general',
|
|
205
|
-
input: assignment.task.payload || {},
|
|
206
|
-
output: result,
|
|
207
|
-
duration,
|
|
208
|
-
success: true,
|
|
209
|
-
metrics: this.extractTaskMetrics(result),
|
|
210
|
-
});
|
|
211
|
-
// Store task completion in memory
|
|
212
164
|
await this.memoryService.storeTaskResult(assignment.id, result);
|
|
213
165
|
this.currentTask = undefined;
|
|
214
|
-
|
|
166
|
+
// Phase 2 (B1.2): Use lifecycle strategy for status transitions
|
|
167
|
+
await this.strategies.lifecycle.transitionTo(types_1.AgentStatus.IDLE);
|
|
215
168
|
return result;
|
|
216
169
|
}
|
|
217
170
|
catch (error) {
|
|
218
|
-
const duration = Date.now() - startTime;
|
|
219
171
|
this.updatePerformanceMetrics(startTime, false);
|
|
220
|
-
// Capture failed experience for learning
|
|
221
|
-
await this.captureExperience({
|
|
222
|
-
taskId: assignment.id,
|
|
223
|
-
taskType: assignment.task.type || 'general',
|
|
224
|
-
input: assignment.task.payload || {},
|
|
225
|
-
output: {},
|
|
226
|
-
duration,
|
|
227
|
-
success: false,
|
|
228
|
-
error: error,
|
|
229
|
-
metrics: {},
|
|
230
|
-
});
|
|
231
172
|
this.currentTask = undefined;
|
|
232
|
-
|
|
173
|
+
// Phase 2 (B1.2): Use lifecycle strategy for error transition
|
|
174
|
+
await this.strategies.lifecycle.transitionTo(types_1.AgentStatus.ERROR, `Task execution failed: ${error}`);
|
|
233
175
|
// Execute error hooks
|
|
234
176
|
const errorData = {
|
|
235
177
|
assignment,
|
|
@@ -245,49 +187,39 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
245
187
|
*/
|
|
246
188
|
async terminate() {
|
|
247
189
|
try {
|
|
248
|
-
// Use lifecycle manager's terminate method instead of manual status setting
|
|
249
190
|
await this.lifecycleManager.terminate({
|
|
250
191
|
onPreTermination: async () => {
|
|
251
192
|
await this.executeHook('pre-termination');
|
|
252
|
-
// Flush learning data before termination
|
|
253
|
-
if (this.learningEngine && this.learningEngine.isEnabled()) {
|
|
254
|
-
// ARCHITECTURE (v2.2.0): LearningEngine persists to unified memory.db
|
|
255
|
-
// All data goes through SwarmMemoryManager to .agentic-qe/memory.db
|
|
256
|
-
// No explicit flush needed - memoryStore handles persistence automatically
|
|
257
|
-
console.info(`[${this.agentId.id}] Learning data persisted via SwarmMemoryManager (memory.db)`);
|
|
258
|
-
}
|
|
259
|
-
// Close AgentDB if enabled
|
|
260
|
-
if (this.agentDB) {
|
|
261
|
-
await this.agentDB.close();
|
|
262
|
-
this.agentDB = undefined;
|
|
263
|
-
}
|
|
264
|
-
// Save current state
|
|
265
193
|
await this.saveState();
|
|
266
|
-
// Clean up agent-specific resources
|
|
267
194
|
await this.cleanup();
|
|
268
|
-
// Remove all event handlers from EventBus using coordinator
|
|
269
195
|
this.coordinator.clearAllHandlers();
|
|
270
196
|
},
|
|
271
197
|
onPostTermination: async () => {
|
|
272
198
|
await this.executeHook('post-termination');
|
|
273
199
|
this.emitEvent('agent.terminated', { agentId: this.agentId });
|
|
274
|
-
// Remove all listeners from this agent (EventEmitter)
|
|
275
200
|
this.removeAllListeners();
|
|
276
201
|
}
|
|
277
202
|
});
|
|
278
203
|
}
|
|
279
204
|
catch (error) {
|
|
280
|
-
this.
|
|
205
|
+
await this.strategies.lifecycle.transitionTo(types_1.AgentStatus.ERROR, `Termination failed: ${error}`);
|
|
281
206
|
throw error;
|
|
282
207
|
}
|
|
283
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Get agent ID
|
|
211
|
+
*/
|
|
212
|
+
getAgentId() {
|
|
213
|
+
return this.agentId;
|
|
214
|
+
}
|
|
284
215
|
/**
|
|
285
216
|
* Get current agent status and metrics
|
|
286
217
|
*/
|
|
287
218
|
getStatus() {
|
|
219
|
+
// Phase 2 (B1.2): Use lifecycle strategy instead of direct manager call
|
|
288
220
|
return {
|
|
289
221
|
agentId: this.agentId,
|
|
290
|
-
status: this.
|
|
222
|
+
status: this.strategies.lifecycle.getStatus(),
|
|
291
223
|
currentTask: this.currentTask?.id,
|
|
292
224
|
capabilities: Array.from(this.capabilities.keys()),
|
|
293
225
|
performanceMetrics: { ...this.performanceMetrics }
|
|
@@ -302,9 +234,15 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
302
234
|
* Use: await agent.waitForStatus('ready')
|
|
303
235
|
*/
|
|
304
236
|
async waitForStatus(status, timeout = 10000) {
|
|
237
|
+
// Phase 2 (B1.2): Use lifecycle strategy for status waiting
|
|
238
|
+
// Strategy provides waitForStatus implementation
|
|
239
|
+
if (typeof this.strategies.lifecycle.waitForStatus === 'function') {
|
|
240
|
+
return this.strategies.lifecycle.waitForStatus(status, timeout);
|
|
241
|
+
}
|
|
242
|
+
// Fallback to event-based implementation
|
|
305
243
|
return new Promise((resolve, reject) => {
|
|
306
244
|
// Already at target status
|
|
307
|
-
if (this.
|
|
245
|
+
if (this.strategies.lifecycle.getStatus() === status) {
|
|
308
246
|
return resolve();
|
|
309
247
|
}
|
|
310
248
|
const timer = setTimeout(() => {
|
|
@@ -327,7 +265,13 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
327
265
|
* Use: await agent.waitForReady()
|
|
328
266
|
*/
|
|
329
267
|
async waitForReady(timeout = 10000) {
|
|
330
|
-
|
|
268
|
+
// Phase 2 (B1.2): Use lifecycle strategy
|
|
269
|
+
// Strategy provides waitForReady implementation
|
|
270
|
+
if (typeof this.strategies.lifecycle.waitForReady === 'function') {
|
|
271
|
+
return this.strategies.lifecycle.waitForReady(timeout);
|
|
272
|
+
}
|
|
273
|
+
// Fallback to waitForStatus-based implementation
|
|
274
|
+
const currentStatus = this.strategies.lifecycle.getStatus();
|
|
331
275
|
if (currentStatus === types_1.AgentStatus.IDLE || currentStatus === types_1.AgentStatus.ACTIVE) {
|
|
332
276
|
return; // Already ready
|
|
333
277
|
}
|
|
@@ -381,6 +325,37 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
381
325
|
getCapabilities() {
|
|
382
326
|
return Array.from(this.capabilities.values());
|
|
383
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Get strategies (Phase 2 B1.2)
|
|
330
|
+
* Lifecycle and memory strategies are always available (adapter or custom)
|
|
331
|
+
*/
|
|
332
|
+
getStrategies() {
|
|
333
|
+
return this.strategies;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Get the lifecycle strategy
|
|
337
|
+
*/
|
|
338
|
+
getLifecycleStrategy() {
|
|
339
|
+
return this.strategies.lifecycle;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Get the memory strategy
|
|
343
|
+
*/
|
|
344
|
+
getMemoryStrategy() {
|
|
345
|
+
return this.strategies.memory;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Get the learning strategy (if enabled)
|
|
349
|
+
*/
|
|
350
|
+
getLearningStrategy() {
|
|
351
|
+
return this.strategies.learning;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Get the coordination strategy
|
|
355
|
+
*/
|
|
356
|
+
getCoordinationStrategy() {
|
|
357
|
+
return this.strategies.coordination;
|
|
358
|
+
}
|
|
384
359
|
/**
|
|
385
360
|
* Register a new capability dynamically
|
|
386
361
|
*/
|
|
@@ -436,74 +411,23 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
436
411
|
};
|
|
437
412
|
}
|
|
438
413
|
/**
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
* @deprecated v2.2.0 - AgentDB is deprecated. All persistence now goes through
|
|
442
|
-
* SwarmMemoryManager to the unified .agentic-qe/memory.db database.
|
|
443
|
-
* Use memoryStore methods instead. This method will be removed in v3.0.0.
|
|
444
|
-
*
|
|
445
|
-
* @param config AgentDB configuration
|
|
414
|
+
* @deprecated v2.2.0 - AgentDB is deprecated. Use SwarmMemoryManager instead.
|
|
415
|
+
* Stub method for backward compatibility - will be removed in v3.0.0.
|
|
446
416
|
*/
|
|
447
|
-
async initializeAgentDB(
|
|
448
|
-
|
|
449
|
-
console.warn(`[${this.agentId.id}] AgentDB already initialized`);
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
try {
|
|
453
|
-
this.agentDB = (0, AgentDBManager_1.createAgentDBManager)(config);
|
|
454
|
-
await this.agentDB.initialize();
|
|
455
|
-
this.emitEvent('agent.agentdb.enabled', {
|
|
456
|
-
agentId: this.agentId,
|
|
457
|
-
config,
|
|
458
|
-
});
|
|
459
|
-
console.info(`[${this.agentId.id}] AgentDB integration enabled`, {
|
|
460
|
-
quicSync: config.enableQUICSync || false,
|
|
461
|
-
learning: config.enableLearning || false,
|
|
462
|
-
reasoning: config.enableReasoning || false,
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
catch (error) {
|
|
466
|
-
console.error(`[${this.agentId.id}] Failed to initialize AgentDB:`, error);
|
|
467
|
-
throw error;
|
|
468
|
-
}
|
|
417
|
+
async initializeAgentDB(_config) {
|
|
418
|
+
console.warn(`[${this.agentId.id}] AgentDB is DEPRECATED and will be removed in v3.0.0`);
|
|
469
419
|
}
|
|
470
420
|
/**
|
|
471
|
-
*
|
|
421
|
+
* @deprecated v2.2.0 - Use learning strategy instead.
|
|
472
422
|
*/
|
|
473
423
|
async getAgentDBStatus() {
|
|
474
|
-
|
|
475
|
-
return null;
|
|
476
|
-
try {
|
|
477
|
-
const stats = await this.agentDB.getStats();
|
|
478
|
-
return {
|
|
479
|
-
enabled: true,
|
|
480
|
-
stats,
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
catch (error) {
|
|
484
|
-
return {
|
|
485
|
-
enabled: true,
|
|
486
|
-
error: error instanceof Error ? error.message : 'Unknown error',
|
|
487
|
-
};
|
|
488
|
-
}
|
|
424
|
+
return null;
|
|
489
425
|
}
|
|
490
426
|
/**
|
|
491
|
-
*
|
|
427
|
+
* @deprecated v2.2.0 - Returns false, AgentDB removed.
|
|
492
428
|
*/
|
|
493
429
|
hasAgentDB() {
|
|
494
|
-
return
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Check if AgentDB is using a real adapter (vs mock)
|
|
498
|
-
* @returns true if using real AgentDB, false if mock
|
|
499
|
-
*/
|
|
500
|
-
isRealAgentDB() {
|
|
501
|
-
if (!this.agentDB)
|
|
502
|
-
return false;
|
|
503
|
-
// Check adapter type or test mode flags
|
|
504
|
-
const isTestMode = process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID !== undefined;
|
|
505
|
-
const useMock = process.env.AQE_USE_MOCK_AGENTDB === 'true';
|
|
506
|
-
return !isTestMode && !useMock;
|
|
430
|
+
return false;
|
|
507
431
|
}
|
|
508
432
|
/**
|
|
509
433
|
* Start the agent (idempotent - safe to call multiple times)
|
|
@@ -580,407 +504,159 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
580
504
|
this.eventBus.emit('agent.message', message);
|
|
581
505
|
}
|
|
582
506
|
// ============================================================================
|
|
583
|
-
// Memory Operations
|
|
507
|
+
// Memory Operations (Phase 2 B1.2 - delegated to strategy)
|
|
584
508
|
// ============================================================================
|
|
585
509
|
/**
|
|
586
510
|
* Store data in memory with automatic namespacing
|
|
511
|
+
* Phase 2 (B1.2): Delegates to memory strategy with aqe/{agentType}/{key} namespace
|
|
587
512
|
*/
|
|
588
513
|
async storeMemory(key, value, ttl) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
514
|
+
// Phase 2 (B1.2): Use memory strategy with local namespace
|
|
515
|
+
const memoryStrategy = this.strategies.memory;
|
|
516
|
+
if (memoryStrategy instanceof adapters_1.MemoryServiceAdapter) {
|
|
517
|
+
await memoryStrategy.storeLocal(key, value, ttl);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
// Fallback for custom strategies
|
|
521
|
+
await memoryStrategy.store(key, value, { ttl, namespace: this.agentId.type });
|
|
592
522
|
}
|
|
593
|
-
// Standardized namespace: aqe/{agentType}/{key}
|
|
594
|
-
const namespacedKey = `aqe/${this.agentId.type}/${key}`;
|
|
595
|
-
await this.memoryStore.store(namespacedKey, value, ttl);
|
|
596
523
|
}
|
|
597
524
|
/**
|
|
598
525
|
* Retrieve data from memory
|
|
526
|
+
* Phase 2 (B1.2): Delegates to memory strategy with aqe/{agentType}/{key} namespace
|
|
599
527
|
*/
|
|
600
528
|
async retrieveMemory(key) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
529
|
+
// Phase 2 (B1.2): Use memory strategy with local namespace
|
|
530
|
+
const memoryStrategy = this.strategies.memory;
|
|
531
|
+
if (memoryStrategy instanceof adapters_1.MemoryServiceAdapter) {
|
|
532
|
+
return await memoryStrategy.retrieveLocal(key);
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
// Fallback for custom strategies - must handle namespace manually
|
|
536
|
+
return await memoryStrategy.retrieve(`aqe/${this.agentId.type}/${key}`);
|
|
604
537
|
}
|
|
605
|
-
// Standardized namespace: aqe/{agentType}/{key}
|
|
606
|
-
const namespacedKey = `aqe/${this.agentId.type}/${key}`;
|
|
607
|
-
return await this.memoryStore.retrieve(namespacedKey);
|
|
608
538
|
}
|
|
609
539
|
/**
|
|
610
540
|
* Store shared data accessible by other agents
|
|
541
|
+
* Phase 2 (B1.2): Delegates to memory strategy with aqe/shared/{agentType}/{key} namespace
|
|
611
542
|
*/
|
|
612
543
|
async storeSharedMemory(key, value, ttl) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
544
|
+
// Phase 2 (B1.2): Use memory strategy with shared namespace
|
|
545
|
+
const memoryStrategy = this.strategies.memory;
|
|
546
|
+
if (memoryStrategy instanceof adapters_1.MemoryServiceAdapter) {
|
|
547
|
+
await memoryStrategy.storeSharedLocal(key, value, ttl);
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
// Fallback for custom strategies
|
|
551
|
+
await memoryStrategy.storeShared(this.agentId.type, key, value, { ttl });
|
|
616
552
|
}
|
|
617
|
-
// Standardized namespace: aqe/shared/{agentType}/{key}
|
|
618
|
-
const sharedKey = `aqe/shared/${this.agentId.type}/${key}`;
|
|
619
|
-
await this.memoryStore.store(sharedKey, value, ttl);
|
|
620
553
|
}
|
|
621
554
|
/**
|
|
622
555
|
* Retrieve shared data from other agents
|
|
556
|
+
* Phase 2 (B1.2): Delegates to memory strategy with aqe/shared/{agentType}/{key} namespace
|
|
623
557
|
*/
|
|
624
558
|
async retrieveSharedMemory(agentType, key) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
return null;
|
|
628
|
-
}
|
|
629
|
-
// Standardized namespace: aqe/shared/{agentType}/{key}
|
|
630
|
-
const sharedKey = `aqe/shared/${agentType}/${key}`;
|
|
631
|
-
return await this.memoryStore.retrieve(sharedKey);
|
|
559
|
+
// Phase 2 (B1.2): Use memory strategy for shared retrieval
|
|
560
|
+
return await this.strategies.memory.retrieveShared(agentType, key);
|
|
632
561
|
}
|
|
633
562
|
// ============================================================================
|
|
634
563
|
// Lifecycle Hooks
|
|
635
564
|
// ============================================================================
|
|
636
565
|
/**
|
|
637
566
|
* Pre-task hook - called before task execution
|
|
638
|
-
*
|
|
639
|
-
* Integrates AgentDB for context loading via vector search
|
|
640
|
-
* @param data Pre-task hook data including task assignment
|
|
567
|
+
* Delegates to lifecycle strategy for pre-task processing
|
|
641
568
|
*/
|
|
642
569
|
async onPreTask(data) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
// Generate embedding using consolidated utility
|
|
657
|
-
const queryEmbedding = (0, EmbeddingGenerator_js_1.generateEmbedding)(taskQuery);
|
|
658
|
-
// Retrieve relevant context from AgentDB
|
|
659
|
-
const retrievalResult = await this.agentDB.retrieve(queryEmbedding, {
|
|
660
|
-
domain: `agent:${this.agentId.type}:tasks`,
|
|
661
|
-
k: 5,
|
|
662
|
-
useMMR: true,
|
|
663
|
-
synthesizeContext: true,
|
|
664
|
-
minConfidence: 0.6,
|
|
665
|
-
metric: 'cosine'
|
|
666
|
-
});
|
|
667
|
-
const searchTime = Date.now() - searchStart;
|
|
668
|
-
const isReal = this.isRealAgentDB();
|
|
669
|
-
const adapterType = isReal ? 'real AgentDB' : 'mock adapter';
|
|
670
|
-
// Enrich context with retrieved patterns
|
|
671
|
-
if (retrievalResult.memories.length > 0) {
|
|
672
|
-
const enrichedContext = {
|
|
673
|
-
...data.context,
|
|
674
|
-
agentDBContext: retrievalResult.context,
|
|
675
|
-
relevantPatterns: retrievalResult.patterns || [],
|
|
676
|
-
similarTasks: retrievalResult.memories.map((m) => {
|
|
677
|
-
const patternData = JSON.parse(m.pattern_data);
|
|
678
|
-
return {
|
|
679
|
-
taskType: patternData.taskType,
|
|
680
|
-
success: patternData.success,
|
|
681
|
-
accuracy: patternData.accuracy,
|
|
682
|
-
executionTime: patternData.executionTime,
|
|
683
|
-
similarity: m.similarity,
|
|
684
|
-
confidence: m.confidence
|
|
685
|
-
};
|
|
686
|
-
})
|
|
687
|
-
};
|
|
688
|
-
data.context = enrichedContext;
|
|
689
|
-
console.info(`[${this.agentId.id}] Loaded ${retrievalResult.memories.length} patterns from ${adapterType} ` +
|
|
690
|
-
`(${searchTime}ms, ${retrievalResult.metadata.cacheHit ? 'cache hit' : 'cache miss'})`);
|
|
691
|
-
// Log top similar task
|
|
692
|
-
if (retrievalResult.memories.length > 0 && isReal) {
|
|
693
|
-
const topMatch = retrievalResult.memories[0];
|
|
694
|
-
console.info(`[${this.agentId.id}] 🎯 Top match: similarity=${topMatch.similarity.toFixed(3)}, ` +
|
|
695
|
-
`confidence=${topMatch.confidence.toFixed(3)}`);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
console.info(`[${this.agentId.id}] No relevant patterns found in ${adapterType} (${searchTime}ms)`);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
catch (agentDBError) {
|
|
703
|
-
console.warn(`[${this.agentId.id}] AgentDB retrieval failed:`, agentDBError);
|
|
704
|
-
// Don't fail task if AgentDB retrieval fails
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
const verificationResult = await this.hookManager.executePreTaskVerification({
|
|
708
|
-
task: data.assignment.task.type,
|
|
709
|
-
context: data.context
|
|
710
|
-
});
|
|
711
|
-
if (!verificationResult.passed) {
|
|
712
|
-
throw new Error(`Pre-task verification failed with score ${verificationResult.score}. ` +
|
|
713
|
-
`Checks: ${verificationResult.checks.join(', ')}`);
|
|
714
|
-
}
|
|
715
|
-
this.emitEvent('hook.pre-task.completed', {
|
|
716
|
-
agentId: this.agentId,
|
|
717
|
-
result: verificationResult
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
catch (error) {
|
|
721
|
-
console.error(`Pre-task hook failed for agent ${this.agentId.id}:`, error);
|
|
722
|
-
throw error;
|
|
570
|
+
this.taskStartTime = Date.now();
|
|
571
|
+
// Delegate to lifecycle strategy if available
|
|
572
|
+
if (this.strategies.lifecycle.onPreTask) {
|
|
573
|
+
await this.strategies.lifecycle.onPreTask(data);
|
|
574
|
+
}
|
|
575
|
+
// Run verification checks
|
|
576
|
+
const verificationResult = await this.hookManager.executePreTaskVerification({
|
|
577
|
+
task: data.assignment.task.type,
|
|
578
|
+
context: data.context
|
|
579
|
+
});
|
|
580
|
+
if (!verificationResult.passed) {
|
|
581
|
+
throw new Error(`Pre-task verification failed with score ${verificationResult.score}. ` +
|
|
582
|
+
`Checks: ${verificationResult.checks.join(', ')}`);
|
|
723
583
|
}
|
|
584
|
+
this.emitEvent('hook.pre-task.completed', {
|
|
585
|
+
agentId: this.agentId,
|
|
586
|
+
result: verificationResult
|
|
587
|
+
});
|
|
724
588
|
}
|
|
725
589
|
/**
|
|
726
590
|
* Post-task hook - called after task execution
|
|
727
|
-
*
|
|
728
|
-
* Integrates AgentDB for pattern storage and neural training
|
|
729
|
-
* @param data Post-task hook data including result
|
|
591
|
+
* Delegates to lifecycle and learning strategies
|
|
730
592
|
*/
|
|
731
593
|
async onPostTask(data) {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
validations: validationResult.validations
|
|
755
|
-
},
|
|
756
|
-
context: data.assignment.task.context || {},
|
|
757
|
-
timestamp: Date.now()
|
|
758
|
-
};
|
|
759
|
-
// Generate embedding using consolidated utility
|
|
760
|
-
const embedding = (0, EmbeddingGenerator_js_1.generateEmbedding)(JSON.stringify(patternData));
|
|
761
|
-
// Store pattern in AgentDB
|
|
762
|
-
const pattern = {
|
|
763
|
-
id: `${this.agentId.id}-task-${data.assignment.id}`,
|
|
764
|
-
type: 'experience',
|
|
765
|
-
domain: `agent:${this.agentId.type}:tasks`,
|
|
766
|
-
pattern_data: JSON.stringify({
|
|
767
|
-
taskType: patternData.taskType,
|
|
768
|
-
taskDescription: patternData.taskDescription,
|
|
769
|
-
success: patternData.result.success,
|
|
770
|
-
accuracy: patternData.result.accuracy,
|
|
771
|
-
executionTime: patternData.result.executionTime,
|
|
772
|
-
timestamp: patternData.timestamp
|
|
773
|
-
}),
|
|
774
|
-
confidence: validationResult.valid ? validationResult.accuracy : 0.5,
|
|
775
|
-
usage_count: 1,
|
|
776
|
-
success_count: validationResult.valid ? 1 : 0,
|
|
777
|
-
created_at: Date.now(),
|
|
778
|
-
last_used: Date.now()
|
|
779
|
-
};
|
|
780
|
-
const patternId = await this.agentDB.store(pattern);
|
|
781
|
-
const storeTime = Date.now() - startTime;
|
|
782
|
-
const isReal = this.isRealAgentDB();
|
|
783
|
-
const adapterType = isReal ? 'AgentDB' : 'mock adapter';
|
|
784
|
-
console.info(`[${this.agentId.id}] Stored pattern in ${adapterType}: ${patternId} (${storeTime}ms)`);
|
|
785
|
-
// ACTUAL Neural training integration if learning is enabled
|
|
786
|
-
if (this.agentDBConfig?.enableLearning) {
|
|
787
|
-
try {
|
|
788
|
-
// Trigger incremental training every N patterns
|
|
789
|
-
const stats = await this.agentDB.getStats();
|
|
790
|
-
if (stats.totalPatterns && stats.totalPatterns % 100 === 0) {
|
|
791
|
-
console.info(`[${this.agentId.id}] 🧠 Triggering ACTUAL neural training (${stats.totalPatterns} patterns)`);
|
|
792
|
-
const trainingStart = Date.now();
|
|
793
|
-
const trainingMetrics = await this.agentDB.train({
|
|
794
|
-
epochs: 10,
|
|
795
|
-
batchSize: 32,
|
|
796
|
-
validationSplit: 0.2
|
|
797
|
-
});
|
|
798
|
-
const trainingTime = Date.now() - trainingStart;
|
|
799
|
-
console.info(`[${this.agentId.id}] ✅ Neural training COMPLETE: ` +
|
|
800
|
-
`loss=${trainingMetrics.loss.toFixed(4)}, ` +
|
|
801
|
-
`duration=${trainingTime}ms (${trainingMetrics.epochs} epochs)`);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
catch (trainingError) {
|
|
805
|
-
console.warn(`[${this.agentId.id}] Neural training failed:`, trainingError);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
// ACTUAL QUIC sync if enabled (automatic via AgentDB)
|
|
809
|
-
if (this.agentDBConfig?.enableQUICSync) {
|
|
810
|
-
console.info(`[${this.agentId.id}] 🚀 QUIC sync active (<1ms to ${this.agentDBConfig.syncPeers?.length || 0} peers)`);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
catch (agentDBError) {
|
|
814
|
-
console.warn(`[${this.agentId.id}] AgentDB operation failed:`, agentDBError);
|
|
815
|
-
// Don't fail task if AgentDB operations fail
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
// Q-learning integration: Learn from task execution
|
|
819
|
-
if (this.learningEngine && this.learningEngine.isEnabled()) {
|
|
820
|
-
try {
|
|
821
|
-
const learningOutcome = await this.learningEngine.learnFromExecution(data.assignment.task, data.result);
|
|
822
|
-
// Log learning progress
|
|
823
|
-
if (learningOutcome.improved) {
|
|
824
|
-
console.info(`[Learning] Agent ${this.agentId.id} improved by ${learningOutcome.improvementRate.toFixed(2)}%`);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
catch (learningError) {
|
|
828
|
-
console.error(`Learning engine error:`, learningError);
|
|
829
|
-
// Don't fail task due to learning errors
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
// Record performance snapshot if PerformanceTracker is enabled
|
|
833
|
-
if (this.performanceTracker && this.taskStartTime) {
|
|
834
|
-
const executionTime = Date.now() - this.taskStartTime;
|
|
835
|
-
const successRate = this.performanceMetrics.tasksCompleted /
|
|
836
|
-
Math.max(1, this.performanceMetrics.tasksCompleted + this.performanceMetrics.errorCount);
|
|
837
|
-
await this.performanceTracker.recordSnapshot({
|
|
838
|
-
metrics: {
|
|
839
|
-
tasksCompleted: this.performanceMetrics.tasksCompleted,
|
|
840
|
-
successRate: Math.min(1.0, Math.max(0.0, successRate || 1.0)),
|
|
841
|
-
averageExecutionTime: this.performanceMetrics.averageExecutionTime,
|
|
842
|
-
errorRate: this.performanceMetrics.errorCount /
|
|
843
|
-
Math.max(1, this.performanceMetrics.tasksCompleted + this.performanceMetrics.errorCount),
|
|
844
|
-
userSatisfaction: validationResult.valid ? 0.9 : 0.5,
|
|
845
|
-
resourceEfficiency: executionTime < 10000 ? 0.9 : 0.7 // Simple heuristic
|
|
846
|
-
},
|
|
847
|
-
trends: [] // Empty trends array for new snapshot
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
// Capture experience for Dream Engine (Nightly-Learner Phase 2)
|
|
851
|
-
// This enables real agent execution data to flow into the concept graph
|
|
852
|
-
try {
|
|
853
|
-
const executionTime = this.taskStartTime ? Date.now() - this.taskStartTime : 0;
|
|
854
|
-
const experienceCapture = await ExperienceCapture_1.ExperienceCapture.getSharedInstance();
|
|
855
|
-
const executionEvent = {
|
|
856
|
-
agentId: this.agentId.id,
|
|
857
|
-
agentType: this.agentId.type,
|
|
594
|
+
const executionTime = this.taskStartTime ? Date.now() - this.taskStartTime : 0;
|
|
595
|
+
// Run validation checks
|
|
596
|
+
const validationResult = await this.hookManager.executePostTaskValidation({
|
|
597
|
+
task: data.assignment.task.type,
|
|
598
|
+
result: data.result
|
|
599
|
+
});
|
|
600
|
+
if (!validationResult.valid) {
|
|
601
|
+
console.warn(`Post-task validation warning with accuracy ${validationResult.accuracy}. ` +
|
|
602
|
+
`Validations: ${validationResult.validations.join(', ')}`);
|
|
603
|
+
}
|
|
604
|
+
// Delegate to lifecycle strategy
|
|
605
|
+
if (this.strategies.lifecycle.onPostTask) {
|
|
606
|
+
await this.strategies.lifecycle.onPostTask(data);
|
|
607
|
+
}
|
|
608
|
+
// Delegate learning to learning strategy (handles Q-learning, performance tracking)
|
|
609
|
+
if (this.strategies.learning?.recordExecution) {
|
|
610
|
+
await this.strategies.learning.recordExecution({
|
|
611
|
+
task: data.assignment.task,
|
|
612
|
+
result: data.result,
|
|
613
|
+
success: validationResult.valid,
|
|
614
|
+
duration: executionTime,
|
|
615
|
+
metadata: {
|
|
858
616
|
taskId: data.assignment.id,
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
duration: executionTime,
|
|
863
|
-
success: validationResult.valid,
|
|
864
|
-
metrics: {
|
|
865
|
-
quality_score: validationResult.valid ? 0.85 : 0.3,
|
|
866
|
-
coverage_delta: 0, // Can be enhanced with actual coverage data
|
|
867
|
-
},
|
|
868
|
-
timestamp: new Date(),
|
|
869
|
-
};
|
|
870
|
-
await experienceCapture.captureExecution(executionEvent);
|
|
871
|
-
}
|
|
872
|
-
catch (captureError) {
|
|
873
|
-
// Don't fail task due to experience capture errors
|
|
874
|
-
console.warn(`[${this.agentId.id}] Experience capture failed:`, captureError);
|
|
875
|
-
}
|
|
876
|
-
this.emitEvent('hook.post-task.completed', {
|
|
877
|
-
agentId: this.agentId,
|
|
878
|
-
result: validationResult
|
|
617
|
+
accuracy: validationResult.accuracy,
|
|
618
|
+
metrics: this.extractTaskMetrics(data.result)
|
|
619
|
+
}
|
|
879
620
|
});
|
|
880
621
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
}
|
|
622
|
+
this.emitEvent('hook.post-task.completed', {
|
|
623
|
+
agentId: this.agentId,
|
|
624
|
+
result: validationResult
|
|
625
|
+
});
|
|
885
626
|
}
|
|
886
627
|
/**
|
|
887
628
|
* Task error hook - called when task execution fails
|
|
888
|
-
*
|
|
889
|
-
* Integrates AgentDB for error pattern analysis
|
|
890
|
-
* @param data Error hook data including error details
|
|
629
|
+
* Delegates to lifecycle and learning strategies
|
|
891
630
|
*/
|
|
892
631
|
async onTaskError(data) {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
});
|
|
915
|
-
// ACTUAL AgentDB Integration: Store error patterns for failure analysis
|
|
916
|
-
if (this.agentDB) {
|
|
917
|
-
try {
|
|
918
|
-
const storeStart = Date.now();
|
|
919
|
-
const errorPattern = {
|
|
920
|
-
taskType: data.assignment.task.type,
|
|
921
|
-
errorType: data.error.name,
|
|
922
|
-
errorMessage: data.error.message,
|
|
923
|
-
errorStack: data.error.stack?.split('\n').slice(0, 5).join('\n'), // Truncate stack
|
|
924
|
-
context: data.assignment.task.context || {},
|
|
925
|
-
timestamp: Date.now()
|
|
926
|
-
};
|
|
927
|
-
// Generate embedding for error pattern
|
|
928
|
-
const embedding = (0, EmbeddingGenerator_js_1.generateEmbedding)(JSON.stringify(errorPattern));
|
|
929
|
-
// Store error pattern in AgentDB for failure analysis
|
|
930
|
-
const pattern = {
|
|
931
|
-
id: `${this.agentId.id}-error-${data.assignment.id}`,
|
|
932
|
-
type: 'error',
|
|
933
|
-
domain: `agent:${this.agentId.type}:errors`,
|
|
934
|
-
pattern_data: JSON.stringify({
|
|
935
|
-
taskType: errorPattern.taskType,
|
|
936
|
-
errorType: errorPattern.errorType,
|
|
937
|
-
errorMessage: errorPattern.errorMessage,
|
|
938
|
-
timestamp: errorPattern.timestamp
|
|
939
|
-
}),
|
|
940
|
-
confidence: 0.8, // Errors are high-confidence negative patterns
|
|
941
|
-
usage_count: 1,
|
|
942
|
-
success_count: 0, // Errors are failures
|
|
943
|
-
created_at: Date.now(),
|
|
944
|
-
last_used: Date.now()
|
|
945
|
-
};
|
|
946
|
-
const errorPatternId = await this.agentDB.store(pattern);
|
|
947
|
-
const storeTime = Date.now() - storeStart;
|
|
948
|
-
const isReal = this.isRealAgentDB();
|
|
949
|
-
const adapterType = isReal ? 'AgentDB' : 'mock adapter';
|
|
950
|
-
console.info(`[${this.agentId.id}] Stored error pattern in ${adapterType}: ${errorPatternId} ` +
|
|
951
|
-
`(${storeTime}ms, for failure analysis)`);
|
|
952
|
-
}
|
|
953
|
-
catch (agentDBError) {
|
|
954
|
-
console.warn(`[${this.agentId.id}] AgentDB error storage failed:`, agentDBError);
|
|
632
|
+
const executionTime = this.taskStartTime ? Date.now() - this.taskStartTime : 0;
|
|
633
|
+
// Store error in memory for analysis
|
|
634
|
+
await this.storeMemory(`error:${data.assignment.id}`, {
|
|
635
|
+
error: { message: data.error.message, name: data.error.name },
|
|
636
|
+
assignment: { id: data.assignment.id, taskType: data.assignment.task.type },
|
|
637
|
+
timestamp: new Date(),
|
|
638
|
+
agentId: this.agentId.id
|
|
639
|
+
});
|
|
640
|
+
// Delegate to lifecycle strategy
|
|
641
|
+
if (this.strategies.lifecycle.onTaskError) {
|
|
642
|
+
await this.strategies.lifecycle.onTaskError(data);
|
|
643
|
+
}
|
|
644
|
+
// Delegate error recording to learning strategy
|
|
645
|
+
if (this.strategies.learning?.recordExecution) {
|
|
646
|
+
await this.strategies.learning.recordExecution({
|
|
647
|
+
task: data.assignment.task,
|
|
648
|
+
error: data.error,
|
|
649
|
+
success: false,
|
|
650
|
+
duration: executionTime,
|
|
651
|
+
metadata: {
|
|
652
|
+
taskId: data.assignment.id
|
|
955
653
|
}
|
|
956
|
-
}
|
|
957
|
-
// Record failure in PerformanceTracker if enabled
|
|
958
|
-
if (this.performanceTracker && this.taskStartTime) {
|
|
959
|
-
const _executionTime = Date.now() - this.taskStartTime;
|
|
960
|
-
const successRate = this.performanceMetrics.tasksCompleted /
|
|
961
|
-
Math.max(1, this.performanceMetrics.tasksCompleted + this.performanceMetrics.errorCount);
|
|
962
|
-
await this.performanceTracker.recordSnapshot({
|
|
963
|
-
metrics: {
|
|
964
|
-
tasksCompleted: this.performanceMetrics.tasksCompleted,
|
|
965
|
-
successRate: Math.min(1.0, Math.max(0.0, successRate)),
|
|
966
|
-
averageExecutionTime: this.performanceMetrics.averageExecutionTime,
|
|
967
|
-
errorRate: (this.performanceMetrics.errorCount + 1) /
|
|
968
|
-
Math.max(1, this.performanceMetrics.tasksCompleted + this.performanceMetrics.errorCount + 1),
|
|
969
|
-
userSatisfaction: 0.3, // Low satisfaction on error
|
|
970
|
-
resourceEfficiency: 0.5
|
|
971
|
-
},
|
|
972
|
-
trends: [] // Empty trends array for error snapshot
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
this.emitEvent('hook.task-error.completed', {
|
|
976
|
-
agentId: this.agentId,
|
|
977
|
-
error: data.error
|
|
978
|
-
}, 'high');
|
|
979
|
-
}
|
|
980
|
-
catch (error) {
|
|
981
|
-
console.error(`Task error hook failed for agent ${this.agentId.id}:`, error);
|
|
982
|
-
// Swallow this error to prevent recursive error handling
|
|
654
|
+
});
|
|
983
655
|
}
|
|
656
|
+
this.emitEvent('hook.task-error.completed', {
|
|
657
|
+
agentId: this.agentId,
|
|
658
|
+
error: data.error
|
|
659
|
+
}, 'high');
|
|
984
660
|
}
|
|
985
661
|
async executeHook(hookName, data) {
|
|
986
662
|
try {
|
|
@@ -1015,8 +691,9 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
1015
691
|
}
|
|
1016
692
|
setupLifecycleHooks() {
|
|
1017
693
|
// Setup default lifecycle behavior
|
|
1018
|
-
|
|
1019
|
-
|
|
694
|
+
// Phase 2 (B1.2): Use lifecycle strategy for error transition
|
|
695
|
+
this.on('error', async (error) => {
|
|
696
|
+
await this.strategies.lifecycle.transitionTo(types_1.AgentStatus.ERROR, `Error event: ${error}`);
|
|
1020
697
|
this.emitEvent('agent.error', { agentId: this.agentId, error });
|
|
1021
698
|
});
|
|
1022
699
|
}
|
|
@@ -1045,43 +722,6 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
1045
722
|
}
|
|
1046
723
|
this.performanceMetrics.lastActivity = new Date();
|
|
1047
724
|
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Capture execution experience for Nightly-Learner system
|
|
1050
|
-
* Automatically sends task execution data to ExperienceCapture singleton
|
|
1051
|
-
*/
|
|
1052
|
-
async captureExperience(data) {
|
|
1053
|
-
try {
|
|
1054
|
-
// Get the shared ExperienceCapture instance
|
|
1055
|
-
const capture = await ExperienceCapture_1.ExperienceCapture.getSharedInstance();
|
|
1056
|
-
// Build the execution event
|
|
1057
|
-
const event = {
|
|
1058
|
-
agentId: this.agentId.id,
|
|
1059
|
-
agentType: this.agentId.type,
|
|
1060
|
-
taskId: data.taskId,
|
|
1061
|
-
taskType: data.taskType,
|
|
1062
|
-
input: data.input,
|
|
1063
|
-
output: data.output,
|
|
1064
|
-
duration: data.duration,
|
|
1065
|
-
success: data.success,
|
|
1066
|
-
error: data.error,
|
|
1067
|
-
metrics: data.metrics,
|
|
1068
|
-
timestamp: new Date(),
|
|
1069
|
-
};
|
|
1070
|
-
// Capture the execution
|
|
1071
|
-
await capture.captureExecution(event);
|
|
1072
|
-
// Emit event for monitoring
|
|
1073
|
-
this.emit('experience:captured', {
|
|
1074
|
-
agentId: this.agentId.id,
|
|
1075
|
-
taskId: data.taskId,
|
|
1076
|
-
success: data.success,
|
|
1077
|
-
duration: data.duration,
|
|
1078
|
-
});
|
|
1079
|
-
}
|
|
1080
|
-
catch (error) {
|
|
1081
|
-
// Don't let capture failures affect task execution
|
|
1082
|
-
console.warn(`[${this.agentId.id}] Failed to capture experience:`, error);
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
725
|
/**
|
|
1086
726
|
* Extract metrics from task result for learning
|
|
1087
727
|
* Override in subclasses to provide agent-specific metrics
|
|
@@ -1108,48 +748,12 @@ class BaseAgent extends events_1.EventEmitter {
|
|
|
1108
748
|
}
|
|
1109
749
|
return metrics;
|
|
1110
750
|
}
|
|
1111
|
-
|
|
1112
|
-
await this.storeMemory(`task:${taskId}:result`, {
|
|
1113
|
-
result,
|
|
1114
|
-
timestamp: new Date(),
|
|
1115
|
-
agentId: this.agentId.id
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
async restoreState() {
|
|
1119
|
-
try {
|
|
1120
|
-
const state = await this.retrieveMemory('state');
|
|
1121
|
-
if (state) {
|
|
1122
|
-
this.performanceMetrics = { ...this.performanceMetrics, ...state.performanceMetrics };
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
catch (error) {
|
|
1126
|
-
// State restoration is optional
|
|
1127
|
-
console.warn(`Could not restore state for agent ${this.agentId.id}:`, error);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
751
|
+
// State management delegated to memoryService (used in initialize/terminate)
|
|
1130
752
|
async saveState() {
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
catch (error) {
|
|
1138
|
-
console.error(`Could not save state for agent ${this.agentId.id}:`, error);
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
async reportStatus(status) {
|
|
1142
|
-
try {
|
|
1143
|
-
await this.storeSharedMemory('status', {
|
|
1144
|
-
agentId: this.agentId.id,
|
|
1145
|
-
status,
|
|
1146
|
-
timestamp: new Date(),
|
|
1147
|
-
metrics: this.performanceMetrics
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
catch (error) {
|
|
1151
|
-
console.warn(`Could not report status for agent ${this.agentId.id}:`, error);
|
|
1152
|
-
}
|
|
753
|
+
await this.memoryService.saveState({
|
|
754
|
+
performanceMetrics: this.performanceMetrics,
|
|
755
|
+
timestamp: new Date()
|
|
756
|
+
});
|
|
1153
757
|
}
|
|
1154
758
|
generateAgentId(type) {
|
|
1155
759
|
return `${type}-${Date.now()}-${SecureRandom_js_1.SecureRandom.generateId(5)}`;
|