@framers/agentos 0.1.112 → 0.1.114
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/README.md +39 -5
- package/dist/api/AgentOS.d.ts +45 -12
- package/dist/api/AgentOS.d.ts.map +1 -1
- package/dist/api/AgentOS.js +225 -78
- package/dist/api/AgentOS.js.map +1 -1
- package/dist/api/AgentOSOrchestrator.d.ts +8 -0
- package/dist/api/AgentOSOrchestrator.d.ts.map +1 -1
- package/dist/api/AgentOSOrchestrator.js +350 -59
- package/dist/api/AgentOSOrchestrator.js.map +1 -1
- package/dist/api/StreamChunkEmitter.d.ts.map +1 -1
- package/dist/api/StreamChunkEmitter.js +2 -0
- package/dist/api/StreamChunkEmitter.js.map +1 -1
- package/dist/api/agency.d.ts.map +1 -1
- package/dist/api/agency.js +47 -1
- package/dist/api/agency.js.map +1 -1
- package/dist/api/agent.d.ts +18 -5
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +48 -9
- package/dist/api/agent.js.map +1 -1
- package/dist/api/agentExport.d.ts +202 -0
- package/dist/api/agentExport.d.ts.map +1 -0
- package/dist/api/agentExport.js +323 -0
- package/dist/api/agentExport.js.map +1 -0
- package/dist/api/editImage.d.ts +119 -0
- package/dist/api/editImage.d.ts.map +1 -0
- package/dist/api/editImage.js +150 -0
- package/dist/api/editImage.js.map +1 -0
- package/dist/api/embedText.d.ts +137 -0
- package/dist/api/embedText.d.ts.map +1 -0
- package/dist/api/embedText.js +229 -0
- package/dist/api/embedText.js.map +1 -0
- package/dist/api/externalToolRegistry.d.ts +44 -0
- package/dist/api/externalToolRegistry.d.ts.map +1 -0
- package/dist/api/externalToolRegistry.js +245 -0
- package/dist/api/externalToolRegistry.js.map +1 -0
- package/dist/api/generateImage.d.ts +1 -1
- package/dist/api/generateImage.d.ts.map +1 -1
- package/dist/api/generateImage.js +17 -13
- package/dist/api/generateImage.js.map +1 -1
- package/dist/api/generateObject.d.ts +185 -0
- package/dist/api/generateObject.d.ts.map +1 -0
- package/dist/api/generateObject.js +249 -0
- package/dist/api/generateObject.js.map +1 -0
- package/dist/api/generateText.d.ts +13 -3
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js +20 -5
- package/dist/api/generateText.js.map +1 -1
- package/dist/api/interfaces/IAgentOS.d.ts +29 -1
- package/dist/api/interfaces/IAgentOS.d.ts.map +1 -1
- package/dist/api/model.d.ts +7 -7
- package/dist/api/model.d.ts.map +1 -1
- package/dist/api/model.js +22 -16
- package/dist/api/model.js.map +1 -1
- package/dist/api/processRequestWithExternalTools.d.ts +26 -0
- package/dist/api/processRequestWithExternalTools.d.ts.map +1 -0
- package/dist/api/processRequestWithExternalTools.js +52 -0
- package/dist/api/processRequestWithExternalTools.js.map +1 -0
- package/dist/api/processRequestWithRegisteredTools.d.ts +56 -0
- package/dist/api/processRequestWithRegisteredTools.d.ts.map +1 -0
- package/dist/api/processRequestWithRegisteredTools.js +125 -0
- package/dist/api/processRequestWithRegisteredTools.js.map +1 -0
- package/dist/api/provider-defaults.d.ts.map +1 -1
- package/dist/api/provider-defaults.js +28 -0
- package/dist/api/provider-defaults.js.map +1 -1
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.d.ts +71 -0
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.d.ts.map +1 -0
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.js +159 -0
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.js.map +1 -0
- package/dist/api/strategies/agentGraphBuilder.d.ts +170 -0
- package/dist/api/strategies/agentGraphBuilder.d.ts.map +1 -0
- package/dist/api/strategies/agentGraphBuilder.js +299 -0
- package/dist/api/strategies/agentGraphBuilder.js.map +1 -0
- package/dist/api/strategies/debate.d.ts +12 -1
- package/dist/api/strategies/debate.d.ts.map +1 -1
- package/dist/api/strategies/debate.js +41 -5
- package/dist/api/strategies/debate.js.map +1 -1
- package/dist/api/strategies/graphCompiler.d.ts +84 -0
- package/dist/api/strategies/graphCompiler.d.ts.map +1 -0
- package/dist/api/strategies/graphCompiler.js +617 -0
- package/dist/api/strategies/graphCompiler.js.map +1 -0
- package/dist/api/strategies/hierarchical.d.ts +15 -1
- package/dist/api/strategies/hierarchical.d.ts.map +1 -1
- package/dist/api/strategies/hierarchical.js +53 -8
- package/dist/api/strategies/hierarchical.js.map +1 -1
- package/dist/api/strategies/index.d.ts +29 -4
- package/dist/api/strategies/index.d.ts.map +1 -1
- package/dist/api/strategies/index.js +28 -4
- package/dist/api/strategies/index.js.map +1 -1
- package/dist/api/strategies/parallel.d.ts +15 -4
- package/dist/api/strategies/parallel.d.ts.map +1 -1
- package/dist/api/strategies/parallel.js +53 -16
- package/dist/api/strategies/parallel.js.map +1 -1
- package/dist/api/strategies/review-loop.d.ts +15 -1
- package/dist/api/strategies/review-loop.d.ts.map +1 -1
- package/dist/api/strategies/review-loop.js +36 -10
- package/dist/api/strategies/review-loop.js.map +1 -1
- package/dist/api/strategies/sequential.d.ts +11 -1
- package/dist/api/strategies/sequential.d.ts.map +1 -1
- package/dist/api/strategies/sequential.js +39 -8
- package/dist/api/strategies/sequential.js.map +1 -1
- package/dist/api/strategies/shared.d.ts +72 -8
- package/dist/api/strategies/shared.d.ts.map +1 -1
- package/dist/api/strategies/shared.js +92 -12
- package/dist/api/strategies/shared.js.map +1 -1
- package/dist/api/streamObject.d.ts +166 -0
- package/dist/api/streamObject.d.ts.map +1 -0
- package/dist/api/streamObject.js +268 -0
- package/dist/api/streamObject.js.map +1 -0
- package/dist/api/streamText.d.ts +1 -1
- package/dist/api/streamText.d.ts.map +1 -1
- package/dist/api/streamText.js +26 -8
- package/dist/api/streamText.js.map +1 -1
- package/dist/api/toolAdapter.d.ts +44 -8
- package/dist/api/toolAdapter.d.ts.map +1 -1
- package/dist/api/toolAdapter.js +224 -45
- package/dist/api/toolAdapter.js.map +1 -1
- package/dist/api/types/AgentOSExternalToolRequest.d.ts +35 -0
- package/dist/api/types/AgentOSExternalToolRequest.d.ts.map +1 -0
- package/dist/api/types/AgentOSExternalToolRequest.js +2 -0
- package/dist/api/types/AgentOSExternalToolRequest.js.map +1 -0
- package/dist/api/types/AgentOSResponse.d.ts +25 -0
- package/dist/api/types/AgentOSResponse.d.ts.map +1 -1
- package/dist/api/types/AgentOSResponse.js +20 -0
- package/dist/api/types/AgentOSResponse.js.map +1 -1
- package/dist/api/types/AgentOSToolResult.d.ts +11 -0
- package/dist/api/types/AgentOSToolResult.d.ts.map +1 -0
- package/dist/api/types/AgentOSToolResult.js +2 -0
- package/dist/api/types/AgentOSToolResult.js.map +1 -0
- package/dist/api/types.d.ts +81 -4
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/api/upscaleImage.d.ts +92 -0
- package/dist/api/upscaleImage.d.ts.map +1 -0
- package/dist/api/upscaleImage.js +133 -0
- package/dist/api/upscaleImage.js.map +1 -0
- package/dist/api/variateImage.d.ts +102 -0
- package/dist/api/variateImage.d.ts.map +1 -0
- package/dist/api/variateImage.js +154 -0
- package/dist/api/variateImage.js.map +1 -0
- package/dist/cognitive_substrate/GMI.d.ts +16 -2
- package/dist/cognitive_substrate/GMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/GMI.js +188 -56
- package/dist/cognitive_substrate/GMI.js.map +1 -1
- package/dist/cognitive_substrate/IGMI.d.ts +10 -0
- package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/IGMI.js.map +1 -1
- package/dist/config/AgentOSConfig.d.ts +19 -2
- package/dist/config/AgentOSConfig.d.ts.map +1 -1
- package/dist/config/AgentOSConfig.js +46 -29
- package/dist/config/AgentOSConfig.js.map +1 -1
- package/dist/core/guardrails/IGuardrailService.d.ts +1 -1
- package/dist/core/images/IImageProvider.d.ts +93 -0
- package/dist/core/images/IImageProvider.d.ts.map +1 -1
- package/dist/core/images/IImageProvider.js.map +1 -1
- package/dist/core/images/ImageOperationError.d.ts +52 -0
- package/dist/core/images/ImageOperationError.d.ts.map +1 -0
- package/dist/core/images/ImageOperationError.js +58 -0
- package/dist/core/images/ImageOperationError.js.map +1 -0
- package/dist/core/images/imageToBuffer.d.ts +41 -0
- package/dist/core/images/imageToBuffer.d.ts.map +1 -0
- package/dist/core/images/imageToBuffer.js +95 -0
- package/dist/core/images/imageToBuffer.js.map +1 -0
- package/dist/core/images/index.d.ts +4 -0
- package/dist/core/images/index.d.ts.map +1 -1
- package/dist/core/images/index.js +8 -0
- package/dist/core/images/index.js.map +1 -1
- package/dist/core/images/providers/FalImageProvider.d.ts +208 -0
- package/dist/core/images/providers/FalImageProvider.d.ts.map +1 -0
- package/dist/core/images/providers/FalImageProvider.js +301 -0
- package/dist/core/images/providers/FalImageProvider.js.map +1 -0
- package/dist/core/images/providers/FluxImageProvider.d.ts +197 -0
- package/dist/core/images/providers/FluxImageProvider.d.ts.map +1 -0
- package/dist/core/images/providers/FluxImageProvider.js +271 -0
- package/dist/core/images/providers/FluxImageProvider.js.map +1 -0
- package/dist/core/images/providers/OpenAIImageProvider.d.ts +33 -1
- package/dist/core/images/providers/OpenAIImageProvider.d.ts.map +1 -1
- package/dist/core/images/providers/OpenAIImageProvider.js +125 -0
- package/dist/core/images/providers/OpenAIImageProvider.js.map +1 -1
- package/dist/core/images/providers/ReplicateImageProvider.d.ts +26 -1
- package/dist/core/images/providers/ReplicateImageProvider.d.ts.map +1 -1
- package/dist/core/images/providers/ReplicateImageProvider.js +118 -0
- package/dist/core/images/providers/ReplicateImageProvider.js.map +1 -1
- package/dist/core/images/providers/StabilityImageProvider.d.ts +41 -1
- package/dist/core/images/providers/StabilityImageProvider.d.ts.map +1 -1
- package/dist/core/images/providers/StabilityImageProvider.js +180 -7
- package/dist/core/images/providers/StabilityImageProvider.js.map +1 -1
- package/dist/core/images/providers/StableDiffusionLocalProvider.d.ts +29 -1
- package/dist/core/images/providers/StableDiffusionLocalProvider.d.ts.map +1 -1
- package/dist/core/images/providers/StableDiffusionLocalProvider.js +124 -0
- package/dist/core/images/providers/StableDiffusionLocalProvider.js.map +1 -1
- package/dist/core/llm/IPromptEngine.d.ts +2 -2
- package/dist/core/llm/IPromptEngine.d.ts.map +1 -1
- package/dist/core/llm/IPromptEngine.js +2 -2
- package/dist/core/llm/IPromptEngine.js.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.d.ts +7 -1
- package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.js +24 -0
- package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -1
- package/dist/core/llm/providers/errors/AnthropicProviderError.d.ts +42 -0
- package/dist/core/llm/providers/errors/AnthropicProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/AnthropicProviderError.js +45 -0
- package/dist/core/llm/providers/errors/AnthropicProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.d.ts +45 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.js +46 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts +1 -1
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts.map +1 -1
- package/dist/core/llm/providers/errors/OllamaProviderError.js +1 -1
- package/dist/core/llm/providers/errors/OllamaProviderError.js.map +1 -1
- package/dist/core/llm/providers/errors/OpenAIProviderError.d.ts +1 -1
- package/dist/core/llm/providers/errors/OpenAIProviderError.js +1 -1
- package/dist/core/llm/providers/errors/OpenRouterProviderError.d.ts +1 -1
- package/dist/core/llm/providers/errors/OpenRouterProviderError.js +1 -1
- package/dist/core/llm/providers/implementations/AnthropicProvider.d.ts +340 -0
- package/dist/core/llm/providers/implementations/AnthropicProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/AnthropicProvider.js +959 -0
- package/dist/core/llm/providers/implementations/AnthropicProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.d.ts +339 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.js +1004 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/GroqProvider.d.ts +105 -0
- package/dist/core/llm/providers/implementations/GroqProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/GroqProvider.js +134 -0
- package/dist/core/llm/providers/implementations/GroqProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/MistralProvider.d.ts +105 -0
- package/dist/core/llm/providers/implementations/MistralProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/MistralProvider.js +146 -0
- package/dist/core/llm/providers/implementations/MistralProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.d.ts +107 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.js +138 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/XAIProvider.d.ts +102 -0
- package/dist/core/llm/providers/implementations/XAIProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/XAIProvider.js +123 -0
- package/dist/core/llm/providers/implementations/XAIProvider.js.map +1 -0
- package/dist/core/orchestration/AgentOrchestrator.d.ts.map +1 -1
- package/dist/core/orchestration/AgentOrchestrator.js +26 -5
- package/dist/core/orchestration/AgentOrchestrator.js.map +1 -1
- package/dist/core/tools/IToolOrchestrator.d.ts +2 -2
- package/dist/core/tools/IToolOrchestrator.d.ts.map +1 -1
- package/dist/core/tools/ToolExecutor.d.ts +3 -0
- package/dist/core/tools/ToolExecutor.d.ts.map +1 -1
- package/dist/core/tools/ToolExecutor.js +2 -1
- package/dist/core/tools/ToolExecutor.js.map +1 -1
- package/dist/core/tools/ToolOrchestrator.d.ts +7 -7
- package/dist/core/tools/ToolOrchestrator.d.ts.map +1 -1
- package/dist/core/tools/ToolOrchestrator.js +135 -36
- package/dist/core/tools/ToolOrchestrator.js.map +1 -1
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts +6 -5
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts.map +1 -1
- package/dist/core/tools/permissions/ToolPermissionManager.js +47 -21
- package/dist/core/tools/permissions/ToolPermissionManager.js.map +1 -1
- package/dist/core/vision/VisionPipeline.d.ts +437 -0
- package/dist/core/vision/VisionPipeline.d.ts.map +1 -0
- package/dist/core/vision/VisionPipeline.js +1113 -0
- package/dist/core/vision/VisionPipeline.js.map +1 -0
- package/dist/core/vision/index.d.ts +97 -0
- package/dist/core/vision/index.d.ts.map +1 -0
- package/dist/core/vision/index.js +182 -0
- package/dist/core/vision/index.js.map +1 -0
- package/dist/core/vision/providers/LLMVisionProvider.d.ts +135 -0
- package/dist/core/vision/providers/LLMVisionProvider.d.ts.map +1 -0
- package/dist/core/vision/providers/LLMVisionProvider.js +136 -0
- package/dist/core/vision/providers/LLMVisionProvider.js.map +1 -0
- package/dist/core/vision/providers/PipelineVisionProvider.d.ts +154 -0
- package/dist/core/vision/providers/PipelineVisionProvider.d.ts.map +1 -0
- package/dist/core/vision/providers/PipelineVisionProvider.js +160 -0
- package/dist/core/vision/providers/PipelineVisionProvider.js.map +1 -0
- package/dist/core/vision/types.d.ts +286 -0
- package/dist/core/vision/types.d.ts.map +1 -0
- package/dist/core/vision/types.js +24 -0
- package/dist/core/vision/types.js.map +1 -0
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts +1 -1
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts.map +1 -1
- package/dist/discovery/CapabilityDiscoveryEngine.js +1 -1
- package/dist/discovery/CapabilityDiscoveryEngine.js.map +1 -1
- package/dist/emergent/ComposableToolBuilder.d.ts +15 -4
- package/dist/emergent/ComposableToolBuilder.d.ts.map +1 -1
- package/dist/emergent/ComposableToolBuilder.js +29 -14
- package/dist/emergent/ComposableToolBuilder.js.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.d.ts +3 -3
- package/dist/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.js +15 -12
- package/dist/emergent/EmergentCapabilityEngine.js.map +1 -1
- package/dist/emergent/EmergentJudge.d.ts +20 -0
- package/dist/emergent/EmergentJudge.d.ts.map +1 -1
- package/dist/emergent/EmergentJudge.js +121 -26
- package/dist/emergent/EmergentJudge.js.map +1 -1
- package/dist/emergent/EmergentToolRegistry.d.ts +17 -0
- package/dist/emergent/EmergentToolRegistry.d.ts.map +1 -1
- package/dist/emergent/EmergentToolRegistry.js +26 -0
- package/dist/emergent/EmergentToolRegistry.js.map +1 -1
- package/dist/emergent/ForgeToolMetaTool.d.ts +1 -1
- package/dist/emergent/ForgeToolMetaTool.d.ts.map +1 -1
- package/dist/emergent/ForgeToolMetaTool.js +15 -2
- package/dist/emergent/ForgeToolMetaTool.js.map +1 -1
- package/dist/emergent/SandboxedToolForge.d.ts +2 -2
- package/dist/emergent/SandboxedToolForge.d.ts.map +1 -1
- package/dist/emergent/SandboxedToolForge.js +13 -23
- package/dist/emergent/SandboxedToolForge.js.map +1 -1
- package/dist/emergent/SkillExporter.d.ts +119 -0
- package/dist/emergent/SkillExporter.d.ts.map +1 -0
- package/dist/emergent/SkillExporter.js +344 -0
- package/dist/emergent/SkillExporter.js.map +1 -0
- package/dist/emergent/index.d.ts +1 -0
- package/dist/emergent/index.d.ts.map +1 -1
- package/dist/emergent/index.js +1 -0
- package/dist/emergent/index.js.map +1 -1
- package/dist/emergent/types.d.ts +4 -4
- package/dist/index.d.ts +30 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/memory/facade/Memory.d.ts.map +1 -1
- package/dist/memory/facade/Memory.js +8 -0
- package/dist/memory/facade/Memory.js.map +1 -1
- package/dist/memory/facade/types.d.ts +10 -0
- package/dist/memory/facade/types.d.ts.map +1 -1
- package/dist/memory/index.d.ts +15 -7
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +7 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/ingestion/DoclingLoader.d.ts +3 -3
- package/dist/memory/ingestion/DoclingLoader.d.ts.map +1 -1
- package/dist/memory/ingestion/DoclingLoader.js +12 -8
- package/dist/memory/ingestion/DoclingLoader.js.map +1 -1
- package/dist/memory/ingestion/FolderScanner.d.ts +7 -7
- package/dist/memory/ingestion/FolderScanner.d.ts.map +1 -1
- package/dist/memory/ingestion/FolderScanner.js +6 -6
- package/dist/memory/ingestion/FolderScanner.js.map +1 -1
- package/dist/memory/ingestion/LoaderRegistry.d.ts +8 -8
- package/dist/memory/ingestion/LoaderRegistry.d.ts.map +1 -1
- package/dist/memory/ingestion/LoaderRegistry.js +9 -11
- package/dist/memory/ingestion/LoaderRegistry.js.map +1 -1
- package/dist/memory/ingestion/MultimodalAggregator.d.ts +1 -1
- package/dist/memory/ingestion/MultimodalAggregator.js +1 -1
- package/dist/memory/ingestion/OcrPdfLoader.d.ts +2 -2
- package/dist/memory/ingestion/OcrPdfLoader.d.ts.map +1 -1
- package/dist/memory/ingestion/OcrPdfLoader.js +12 -8
- package/dist/memory/ingestion/OcrPdfLoader.js.map +1 -1
- package/dist/memory/ingestion/PdfLoader.d.ts +8 -8
- package/dist/memory/ingestion/PdfLoader.d.ts.map +1 -1
- package/dist/memory/ingestion/PdfLoader.js +13 -10
- package/dist/memory/ingestion/PdfLoader.js.map +1 -1
- package/dist/memory/io/MarkdownExporter.d.ts +1 -1
- package/dist/memory/io/MarkdownExporter.d.ts.map +1 -1
- package/dist/memory/io/MarkdownExporter.js +1 -1
- package/dist/memory/io/MarkdownExporter.js.map +1 -1
- package/dist/memory/observation/MemoryObserver.d.ts +63 -1
- package/dist/memory/observation/MemoryObserver.d.ts.map +1 -1
- package/dist/memory/observation/MemoryObserver.js +115 -4
- package/dist/memory/observation/MemoryObserver.js.map +1 -1
- package/dist/memory/observation/ObservationCompressor.d.ts +88 -0
- package/dist/memory/observation/ObservationCompressor.d.ts.map +1 -0
- package/dist/memory/observation/ObservationCompressor.js +207 -0
- package/dist/memory/observation/ObservationCompressor.js.map +1 -0
- package/dist/memory/observation/ObservationReflector.d.ts +82 -0
- package/dist/memory/observation/ObservationReflector.d.ts.map +1 -0
- package/dist/memory/observation/ObservationReflector.js +212 -0
- package/dist/memory/observation/ObservationReflector.js.map +1 -0
- package/dist/memory/observation/temporal.d.ts +54 -0
- package/dist/memory/observation/temporal.d.ts.map +1 -0
- package/dist/memory/observation/temporal.js +115 -0
- package/dist/memory/observation/temporal.js.map +1 -0
- package/dist/memory/tools/MemoryAddTool.d.ts +2 -2
- package/dist/memory/tools/MemoryAddTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryAddTool.js +8 -3
- package/dist/memory/tools/MemoryAddTool.js.map +1 -1
- package/dist/memory/tools/MemorySearchTool.d.ts +3 -3
- package/dist/memory/tools/MemorySearchTool.d.ts.map +1 -1
- package/dist/memory/tools/MemorySearchTool.js +11 -9
- package/dist/memory/tools/MemorySearchTool.js.map +1 -1
- package/dist/memory/tools/scopeContext.d.ts +11 -0
- package/dist/memory/tools/scopeContext.d.ts.map +1 -0
- package/dist/memory/tools/scopeContext.js +46 -0
- package/dist/memory/tools/scopeContext.js.map +1 -0
- package/dist/orchestration/builders/AgentGraph.d.ts +12 -11
- package/dist/orchestration/builders/AgentGraph.d.ts.map +1 -1
- package/dist/orchestration/builders/AgentGraph.js +12 -11
- package/dist/orchestration/builders/AgentGraph.js.map +1 -1
- package/dist/orchestration/builders/VoiceNodeBuilder.d.ts +82 -25
- package/dist/orchestration/builders/VoiceNodeBuilder.d.ts.map +1 -1
- package/dist/orchestration/builders/VoiceNodeBuilder.js +86 -26
- package/dist/orchestration/builders/VoiceNodeBuilder.js.map +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.d.ts +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.d.ts.map +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.js +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.js.map +1 -1
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.d.ts +7 -54
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.d.ts.map +1 -1
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.js +8 -56
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.js.map +1 -1
- package/dist/orchestration/events/GraphEvent.d.ts +67 -5
- package/dist/orchestration/events/GraphEvent.d.ts.map +1 -1
- package/dist/orchestration/events/GraphEvent.js.map +1 -1
- package/dist/orchestration/runtime/GraphRuntime.d.ts.map +1 -1
- package/dist/orchestration/runtime/GraphRuntime.js +151 -1
- package/dist/orchestration/runtime/GraphRuntime.js.map +1 -1
- package/dist/orchestration/runtime/LoopController.d.ts +3 -3
- package/dist/orchestration/runtime/LoopController.d.ts.map +1 -1
- package/dist/orchestration/runtime/LoopController.js.map +1 -1
- package/dist/orchestration/runtime/StateManager.d.ts +3 -3
- package/dist/orchestration/runtime/StateManager.js +3 -3
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts +103 -26
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts.map +1 -1
- package/dist/orchestration/runtime/VoiceNodeExecutor.js +155 -43
- package/dist/orchestration/runtime/VoiceNodeExecutor.js.map +1 -1
- package/dist/orchestration/runtime/VoiceTransportAdapter.d.ts +95 -33
- package/dist/orchestration/runtime/VoiceTransportAdapter.d.ts.map +1 -1
- package/dist/orchestration/runtime/VoiceTransportAdapter.js +83 -29
- package/dist/orchestration/runtime/VoiceTransportAdapter.js.map +1 -1
- package/dist/orchestration/runtime/VoiceTurnCollector.d.ts +73 -20
- package/dist/orchestration/runtime/VoiceTurnCollector.d.ts.map +1 -1
- package/dist/orchestration/runtime/VoiceTurnCollector.js +84 -23
- package/dist/orchestration/runtime/VoiceTurnCollector.js.map +1 -1
- package/dist/query-router/KeywordFallback.d.ts +70 -0
- package/dist/query-router/KeywordFallback.d.ts.map +1 -0
- package/dist/query-router/KeywordFallback.js +132 -0
- package/dist/query-router/KeywordFallback.js.map +1 -0
- package/dist/query-router/QueryClassifier.d.ts +140 -0
- package/dist/query-router/QueryClassifier.d.ts.map +1 -0
- package/dist/query-router/QueryClassifier.js +223 -0
- package/dist/query-router/QueryClassifier.js.map +1 -0
- package/dist/query-router/QueryDispatcher.d.ts +139 -0
- package/dist/query-router/QueryDispatcher.d.ts.map +1 -0
- package/dist/query-router/QueryDispatcher.js +297 -0
- package/dist/query-router/QueryDispatcher.js.map +1 -0
- package/dist/query-router/QueryGenerator.d.ts +184 -0
- package/dist/query-router/QueryGenerator.d.ts.map +1 -0
- package/dist/query-router/QueryGenerator.js +241 -0
- package/dist/query-router/QueryGenerator.js.map +1 -0
- package/dist/query-router/QueryRouter.d.ts +292 -0
- package/dist/query-router/QueryRouter.d.ts.map +1 -0
- package/dist/query-router/QueryRouter.js +803 -0
- package/dist/query-router/QueryRouter.js.map +1 -0
- package/dist/query-router/TopicExtractor.d.ts +73 -0
- package/dist/query-router/TopicExtractor.d.ts.map +1 -0
- package/dist/query-router/TopicExtractor.js +95 -0
- package/dist/query-router/TopicExtractor.js.map +1 -0
- package/dist/query-router/index.d.ts +40 -0
- package/dist/query-router/index.d.ts.map +1 -0
- package/dist/query-router/index.js +46 -0
- package/dist/query-router/index.js.map +1 -0
- package/dist/query-router/types.d.ts +508 -0
- package/dist/query-router/types.d.ts.map +1 -0
- package/dist/query-router/types.js +39 -0
- package/dist/query-router/types.js.map +1 -0
- package/dist/rag/index.d.ts +5 -0
- package/dist/rag/index.d.ts.map +1 -1
- package/dist/rag/index.js +7 -0
- package/dist/rag/index.js.map +1 -1
- package/dist/rag/multimodal/LLMVisionAdapter.d.ts +43 -0
- package/dist/rag/multimodal/LLMVisionAdapter.d.ts.map +1 -0
- package/dist/rag/multimodal/LLMVisionAdapter.js +46 -0
- package/dist/rag/multimodal/LLMVisionAdapter.js.map +1 -0
- package/dist/rag/multimodal/MultimodalIndexer.d.ts +244 -0
- package/dist/rag/multimodal/MultimodalIndexer.d.ts.map +1 -0
- package/dist/rag/multimodal/MultimodalIndexer.js +411 -0
- package/dist/rag/multimodal/MultimodalIndexer.js.map +1 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.d.ts +448 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.d.ts.map +1 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.js +941 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.js.map +1 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.d.ts +139 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.d.ts.map +1 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.js +143 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.js.map +1 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.d.ts +172 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.d.ts.map +1 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.js +152 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.js.map +1 -0
- package/dist/rag/multimodal/index.d.ts +44 -0
- package/dist/rag/multimodal/index.d.ts.map +1 -0
- package/dist/rag/multimodal/index.js +42 -0
- package/dist/rag/multimodal/index.js.map +1 -0
- package/dist/rag/multimodal/types.d.ts +276 -0
- package/dist/rag/multimodal/types.d.ts.map +1 -0
- package/dist/rag/multimodal/types.js +26 -0
- package/dist/rag/multimodal/types.js.map +1 -0
- package/dist/social-posting/SocialPostManager.d.ts +3 -3
- package/dist/social-posting/SocialPostManager.d.ts.map +1 -1
- package/dist/social-posting/SocialPostManager.js +3 -5
- package/dist/social-posting/SocialPostManager.js.map +1 -1
- package/dist/speech/FallbackProxy.d.ts +6 -6
- package/dist/speech/FallbackProxy.d.ts.map +1 -1
- package/dist/speech/FallbackProxy.js +3 -3
- package/dist/speech/FallbackProxy.js.map +1 -1
- package/dist/speech/SpeechProviderResolver.d.ts +8 -8
- package/dist/speech/SpeechProviderResolver.d.ts.map +1 -1
- package/dist/speech/SpeechProviderResolver.js +22 -11
- package/dist/speech/SpeechProviderResolver.js.map +1 -1
- package/dist/speech/SpeechRuntime.d.ts +1 -5
- package/dist/speech/SpeechRuntime.d.ts.map +1 -1
- package/dist/speech/SpeechRuntime.js +17 -9
- package/dist/speech/SpeechRuntime.js.map +1 -1
- package/dist/speech/providers/AssemblyAISTTProvider.d.ts +4 -4
- package/dist/speech/providers/AssemblyAISTTProvider.js +4 -4
- package/dist/speech/providers/AzureSpeechTTSProvider.d.ts +3 -3
- package/dist/speech/providers/AzureSpeechTTSProvider.js +2 -2
- package/dist/speech/providers/AzureSpeechTTSProvider.js.map +1 -1
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts +9 -9
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts.map +1 -1
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.js +5 -5
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.js.map +1 -1
- package/dist/speech/providers/DeepgramBatchSTTProvider.d.ts +2 -2
- package/dist/speech/providers/DeepgramBatchSTTProvider.js +2 -2
- package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts +3 -3
- package/dist/speech/providers/OpenAITextToSpeechProvider.js +2 -2
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts +1 -1
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts.map +1 -1
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js +1 -1
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js.map +1 -1
- package/dist/voice/TelephonyStreamTransport.d.ts +6 -6
- package/dist/voice/TelephonyStreamTransport.d.ts.map +1 -1
- package/dist/voice/TelephonyStreamTransport.js +5 -5
- package/dist/voice/TelephonyStreamTransport.js.map +1 -1
- package/dist/voice-pipeline/AcousticEndpointDetector.d.ts +4 -4
- package/dist/voice-pipeline/AcousticEndpointDetector.d.ts.map +1 -1
- package/dist/voice-pipeline/AcousticEndpointDetector.js +4 -4
- package/dist/voice-pipeline/AcousticEndpointDetector.js.map +1 -1
- package/dist/voice-pipeline/HardCutBargeinHandler.d.ts +3 -3
- package/dist/voice-pipeline/HardCutBargeinHandler.js +3 -3
- package/dist/voice-pipeline/HeuristicEndpointDetector.d.ts +3 -3
- package/dist/voice-pipeline/HeuristicEndpointDetector.d.ts.map +1 -1
- package/dist/voice-pipeline/HeuristicEndpointDetector.js +3 -3
- package/dist/voice-pipeline/HeuristicEndpointDetector.js.map +1 -1
- package/dist/voice-pipeline/SoftFadeBargeinHandler.d.ts +5 -5
- package/dist/voice-pipeline/SoftFadeBargeinHandler.js +1 -1
- package/dist/voice-pipeline/VoiceInterruptError.d.ts +6 -6
- package/dist/voice-pipeline/VoiceInterruptError.d.ts.map +1 -1
- package/dist/voice-pipeline/VoiceInterruptError.js +4 -4
- package/dist/voice-pipeline/VoiceInterruptError.js.map +1 -1
- package/dist/voice-pipeline/VoicePipelineOrchestrator.d.ts +9 -9
- package/dist/voice-pipeline/VoicePipelineOrchestrator.d.ts.map +1 -1
- package/dist/voice-pipeline/VoicePipelineOrchestrator.js +8 -8
- package/dist/voice-pipeline/VoicePipelineOrchestrator.js.map +1 -1
- package/dist/voice-pipeline/WebRTCStreamTransport.d.ts +421 -0
- package/dist/voice-pipeline/WebRTCStreamTransport.d.ts.map +1 -0
- package/dist/voice-pipeline/WebRTCStreamTransport.js +573 -0
- package/dist/voice-pipeline/WebRTCStreamTransport.js.map +1 -0
- package/dist/voice-pipeline/WebSocketStreamTransport.d.ts +8 -8
- package/dist/voice-pipeline/WebSocketStreamTransport.js +5 -5
- package/dist/voice-pipeline/index.d.ts +1 -0
- package/dist/voice-pipeline/index.d.ts.map +1 -1
- package/dist/voice-pipeline/index.js +2 -0
- package/dist/voice-pipeline/index.js.map +1 -1
- package/dist/voice-pipeline/types.d.ts +43 -43
- package/dist/voice-pipeline/types.d.ts.map +1 -1
- package/package.json +19 -1
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Memory Observer — personality-biased background note extraction
|
|
2
|
+
* @fileoverview Memory Observer — personality-biased background note extraction
|
|
3
|
+
* with LLM-based compression and reflection tiers.
|
|
3
4
|
*
|
|
4
5
|
* Monitors accumulated conversation tokens via ObservationBuffer.
|
|
5
6
|
* When the threshold is reached, extracts concise observation notes
|
|
6
7
|
* via a persona-configured LLM (defaults to cheap model).
|
|
7
8
|
*
|
|
9
|
+
* Three-tier agentic memory pipeline (Mastra-style):
|
|
10
|
+
* 1. Raw notes — extracted per-turn when token threshold is reached.
|
|
11
|
+
* 2. Compressed observations — produced by ObservationCompressor when
|
|
12
|
+
* accumulated notes exceed the compression threshold (default: 50 notes).
|
|
13
|
+
* 3. Reflections — produced by ObservationReflector when compressed
|
|
14
|
+
* observations exceed the reflection token threshold (default: 40,000 tokens).
|
|
15
|
+
*
|
|
8
16
|
* Personality bias:
|
|
9
17
|
* - High emotionality → notes emotional shifts
|
|
10
18
|
* - High conscientiousness → notes commitments/deadlines
|
|
@@ -15,6 +23,9 @@
|
|
|
15
23
|
* @module agentos/memory/observation/MemoryObserver
|
|
16
24
|
*/
|
|
17
25
|
import { ObservationBuffer } from './ObservationBuffer.js';
|
|
26
|
+
import { ObservationCompressor } from './ObservationCompressor.js';
|
|
27
|
+
import { ObservationReflector } from './ObservationReflector.js';
|
|
28
|
+
import { relativeTimeLabel } from './temporal.js';
|
|
18
29
|
// ---------------------------------------------------------------------------
|
|
19
30
|
// Personality-aware system prompt builder
|
|
20
31
|
// ---------------------------------------------------------------------------
|
|
@@ -48,8 +59,17 @@ Output ONLY valid JSON objects, one per line. No markdown, no explanation.${emph
|
|
|
48
59
|
// MemoryObserver
|
|
49
60
|
// ---------------------------------------------------------------------------
|
|
50
61
|
let noteIdCounter = 0;
|
|
62
|
+
/** Default number of accumulated notes before compression triggers. */
|
|
63
|
+
const DEFAULT_COMPRESSION_THRESHOLD = 50;
|
|
64
|
+
/** Default token count of compressed observations before reflection triggers. */
|
|
65
|
+
const DEFAULT_REFLECTION_THRESHOLD_TOKENS = 40000;
|
|
51
66
|
export class MemoryObserver {
|
|
52
67
|
constructor(traits, config) {
|
|
68
|
+
// --- Compression / reflection tier state ---
|
|
69
|
+
this.accumulatedNotes = [];
|
|
70
|
+
this.accumulatedCompressed = [];
|
|
71
|
+
this.compressor = null;
|
|
72
|
+
this.reflector = null;
|
|
53
73
|
this.traits = traits;
|
|
54
74
|
this.config = {
|
|
55
75
|
activationThresholdTokens: config?.activationThresholdTokens ?? 30000,
|
|
@@ -60,6 +80,14 @@ export class MemoryObserver {
|
|
|
60
80
|
this.buffer = new ObservationBuffer({
|
|
61
81
|
activationThresholdTokens: this.config.activationThresholdTokens,
|
|
62
82
|
});
|
|
83
|
+
// Default thresholds for compression and reflection tiers.
|
|
84
|
+
this.compressionThreshold = DEFAULT_COMPRESSION_THRESHOLD;
|
|
85
|
+
this.reflectionThresholdTokens = DEFAULT_REFLECTION_THRESHOLD_TOKENS;
|
|
86
|
+
// Initialize compressor and reflector if LLM invoker is provided.
|
|
87
|
+
if (this.llmInvoker) {
|
|
88
|
+
this.compressor = new ObservationCompressor(this.llmInvoker, this.traits);
|
|
89
|
+
this.reflector = new ObservationReflector(this.llmInvoker);
|
|
90
|
+
}
|
|
63
91
|
}
|
|
64
92
|
/**
|
|
65
93
|
* Feed a message into the observation buffer.
|
|
@@ -89,12 +117,55 @@ export class MemoryObserver {
|
|
|
89
117
|
const systemPrompt = buildObserverSystemPrompt(this.traits);
|
|
90
118
|
try {
|
|
91
119
|
const response = await this.llmInvoker(systemPrompt, conversationText);
|
|
92
|
-
|
|
120
|
+
const notes = this.parseNotes(response, mood, messages);
|
|
121
|
+
// Accumulate notes for the compression tier.
|
|
122
|
+
this.accumulatedNotes.push(...notes);
|
|
123
|
+
return notes;
|
|
93
124
|
}
|
|
94
125
|
catch {
|
|
95
126
|
return [];
|
|
96
127
|
}
|
|
97
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Run compression if accumulated notes exceed the compression threshold.
|
|
131
|
+
*
|
|
132
|
+
* When the number of accumulated raw notes exceeds the configured threshold
|
|
133
|
+
* (default: 50), the ObservationCompressor is invoked to produce denser
|
|
134
|
+
* compressed observations. The raw notes are then cleared.
|
|
135
|
+
*
|
|
136
|
+
* @returns Compressed observations if threshold was met, null otherwise.
|
|
137
|
+
*/
|
|
138
|
+
async compressIfNeeded() {
|
|
139
|
+
if (!this.compressor)
|
|
140
|
+
return null;
|
|
141
|
+
if (this.accumulatedNotes.length < this.compressionThreshold)
|
|
142
|
+
return null;
|
|
143
|
+
const compressed = await this.compressor.compress(this.accumulatedNotes);
|
|
144
|
+
// Clear consumed notes and accumulate compressed observations.
|
|
145
|
+
this.accumulatedNotes = [];
|
|
146
|
+
this.accumulatedCompressed.push(...compressed);
|
|
147
|
+
return compressed;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Run reflection if accumulated compressed observations exceed the token threshold.
|
|
151
|
+
*
|
|
152
|
+
* When the total estimated tokens of accumulated compressed observations
|
|
153
|
+
* exceeds the configured threshold (default: 40,000 tokens), the
|
|
154
|
+
* ObservationReflector is invoked to extract higher-level patterns.
|
|
155
|
+
*
|
|
156
|
+
* @returns Reflections if threshold was met, null otherwise.
|
|
157
|
+
*/
|
|
158
|
+
async reflectIfNeeded() {
|
|
159
|
+
if (!this.reflector)
|
|
160
|
+
return null;
|
|
161
|
+
const totalTokens = this.accumulatedCompressed.reduce((sum, o) => sum + Math.ceil(o.summary.length / 4), 0);
|
|
162
|
+
if (totalTokens < this.reflectionThresholdTokens)
|
|
163
|
+
return null;
|
|
164
|
+
const reflections = await this.reflector.reflect(this.accumulatedCompressed);
|
|
165
|
+
// Clear consumed compressed observations.
|
|
166
|
+
this.accumulatedCompressed = [];
|
|
167
|
+
return reflections;
|
|
168
|
+
}
|
|
98
169
|
/** Get the underlying buffer for inspection. */
|
|
99
170
|
getBuffer() {
|
|
100
171
|
return this.buffer;
|
|
@@ -103,18 +174,53 @@ export class MemoryObserver {
|
|
|
103
174
|
shouldActivate() {
|
|
104
175
|
return this.buffer.shouldActivate();
|
|
105
176
|
}
|
|
177
|
+
/** Get the count of accumulated raw notes awaiting compression. */
|
|
178
|
+
getAccumulatedNoteCount() {
|
|
179
|
+
return this.accumulatedNotes.length;
|
|
180
|
+
}
|
|
181
|
+
/** Get the count of accumulated compressed observations awaiting reflection. */
|
|
182
|
+
getAccumulatedCompressedCount() {
|
|
183
|
+
return this.accumulatedCompressed.length;
|
|
184
|
+
}
|
|
185
|
+
/** Get the accumulated compressed observations (read-only snapshot). */
|
|
186
|
+
getAccumulatedCompressed() {
|
|
187
|
+
return this.accumulatedCompressed;
|
|
188
|
+
}
|
|
189
|
+
/** Set the compression threshold (number of notes before compression triggers). */
|
|
190
|
+
setCompressionThreshold(threshold) {
|
|
191
|
+
this.compressionThreshold = threshold;
|
|
192
|
+
}
|
|
193
|
+
/** Set the reflection token threshold (estimated tokens before reflection triggers). */
|
|
194
|
+
setReflectionThresholdTokens(threshold) {
|
|
195
|
+
this.reflectionThresholdTokens = threshold;
|
|
196
|
+
}
|
|
106
197
|
/** Reset the observer. */
|
|
107
198
|
clear() {
|
|
108
199
|
this.buffer.clear();
|
|
200
|
+
this.accumulatedNotes = [];
|
|
201
|
+
this.accumulatedCompressed = [];
|
|
109
202
|
}
|
|
110
203
|
// --- Internal ---
|
|
111
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Parse LLM response into ObservationNote objects.
|
|
206
|
+
*
|
|
207
|
+
* Attaches three-date temporal metadata from conversation message timestamps
|
|
208
|
+
* when available, using the earliest message timestamp as `referencedAt`
|
|
209
|
+
* and the current time as `observedAt`.
|
|
210
|
+
*/
|
|
211
|
+
parseNotes(llmResponse, mood, messages) {
|
|
112
212
|
const notes = [];
|
|
113
213
|
const lines = llmResponse.split('\n').filter((l) => l.trim());
|
|
214
|
+
// Determine the earliest message timestamp for the referencedAt field.
|
|
215
|
+
const earliestMessageTime = messages && messages.length > 0
|
|
216
|
+
? Math.min(...messages.map((m) => m.timestamp))
|
|
217
|
+
: undefined;
|
|
114
218
|
for (const line of lines) {
|
|
115
219
|
try {
|
|
116
220
|
const parsed = JSON.parse(line.trim());
|
|
117
221
|
if (parsed.type && parsed.content) {
|
|
222
|
+
const now = Date.now();
|
|
223
|
+
const referencedAt = earliestMessageTime ?? now;
|
|
118
224
|
notes.push({
|
|
119
225
|
id: `obs_${Date.now()}_${++noteIdCounter}`,
|
|
120
226
|
type: parsed.type,
|
|
@@ -122,7 +228,12 @@ export class MemoryObserver {
|
|
|
122
228
|
importance: typeof parsed.importance === 'number' ? parsed.importance : 0.5,
|
|
123
229
|
entities: Array.isArray(parsed.entities) ? parsed.entities : [],
|
|
124
230
|
emotionalContext: mood ? { valence: mood.valence, arousal: mood.arousal } : undefined,
|
|
125
|
-
timestamp:
|
|
231
|
+
timestamp: now,
|
|
232
|
+
temporal: {
|
|
233
|
+
observedAt: now,
|
|
234
|
+
referencedAt,
|
|
235
|
+
relativeLabel: relativeTimeLabel(referencedAt, now),
|
|
236
|
+
},
|
|
126
237
|
});
|
|
127
238
|
}
|
|
128
239
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryObserver.js","sourceRoot":"","sources":["../../../src/memory/observation/MemoryObserver.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MemoryObserver.js","sourceRoot":"","sources":["../../../src/memory/observation/MemoryObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,iBAAiB,EAAwB,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAA8B,MAAM,4BAA4B,CAAC;AAC/F,OAAO,EAAE,oBAAoB,EAAmB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA8BlD,8EAA8E;AAC9E,0CAA0C;AAC1C,8EAA8E;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vB,MAAM,YAAY,GAAG,mBAAmB,IAAI,GAAG,CAAC;oBAEhD,KAAK,CAAC,IAAI,CAAC;wBACT,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE;wBAC1C,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,UAAU,EAAE,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG;wBAC3E,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;wBAC/D,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;wBACrF,SAAS,EAAE,GAAG;wBACd,QAAQ,EAAE;4BACR,UAAU,EAAE,GAAG;4BACf,YAAY;4BACZ,aAAa,EAAE,iBAAiB,CAAC,YAAY,EAAE,GAAG,CAAC;yBACpD;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,uBAAuB;YACzB,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview LLM-based observational memory compressor.
|
|
3
|
+
*
|
|
4
|
+
* Takes a batch of {@link ObservationNote} objects and compresses them into
|
|
5
|
+
* denser {@link CompressedObservation} summaries via an LLM call. This is the
|
|
6
|
+
* "Observer" agent in Mastra's agentic memory model — it groups related
|
|
7
|
+
* observations by topic/entity overlap, produces a 1-3 sentence summary per
|
|
8
|
+
* group, assigns a priority level, and attaches three-date temporal metadata.
|
|
9
|
+
*
|
|
10
|
+
* Typical compression: 3-10x (many individual notes become fewer dense
|
|
11
|
+
* summaries while preserving all critical facts).
|
|
12
|
+
*
|
|
13
|
+
* Personality bias: when HEXACO traits are provided, the system prompt
|
|
14
|
+
* is tuned to emphasise observation categories that align with the agent's
|
|
15
|
+
* personality (e.g. high conscientiousness → emphasise commitments).
|
|
16
|
+
*
|
|
17
|
+
* @module agentos/memory/observation/ObservationCompressor
|
|
18
|
+
*/
|
|
19
|
+
import type { HexacoTraits } from '../config.js';
|
|
20
|
+
import type { ObservationNote } from './MemoryObserver.js';
|
|
21
|
+
/** Priority level for a compressed observation. */
|
|
22
|
+
export type CompressionPriority = 'critical' | 'important' | 'informational';
|
|
23
|
+
/**
|
|
24
|
+
* A compressed observation produced by merging multiple raw
|
|
25
|
+
* {@link ObservationNote} objects into a single dense summary.
|
|
26
|
+
*/
|
|
27
|
+
export interface CompressedObservation {
|
|
28
|
+
/** Unique identifier for this compressed observation. */
|
|
29
|
+
id: string;
|
|
30
|
+
/** Dense summary of multiple observations (1-3 sentences). */
|
|
31
|
+
summary: string;
|
|
32
|
+
/** Triage priority. */
|
|
33
|
+
priority: CompressionPriority;
|
|
34
|
+
/** Three-date temporal metadata. */
|
|
35
|
+
temporal: {
|
|
36
|
+
/** When this compression was performed (Unix ms). */
|
|
37
|
+
observedAt: number;
|
|
38
|
+
/** Earliest event timestamp across all source observations (Unix ms). */
|
|
39
|
+
referencedAt: number;
|
|
40
|
+
/** Human-friendly relative time label for `referencedAt`. */
|
|
41
|
+
relativeLabel: string;
|
|
42
|
+
};
|
|
43
|
+
/** IDs of the source {@link ObservationNote} objects that were compressed. */
|
|
44
|
+
sourceIds: string[];
|
|
45
|
+
/** Union of key entities across all source observations. */
|
|
46
|
+
entities: string[];
|
|
47
|
+
/** Average importance score of the source observations (0-1). */
|
|
48
|
+
importance: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* LLM-based compressor that takes a batch of {@link ObservationNote} objects
|
|
52
|
+
* and produces denser {@link CompressedObservation} summaries.
|
|
53
|
+
*
|
|
54
|
+
* Achieves 3-10x compression while preserving key facts, entities, and
|
|
55
|
+
* temporal context. Each compressed observation carries three-date temporal
|
|
56
|
+
* metadata: when the compression happened, the earliest referenced event,
|
|
57
|
+
* and a human-friendly relative time label.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ObservationCompressor {
|
|
60
|
+
private llmInvoker;
|
|
61
|
+
private traits?;
|
|
62
|
+
/**
|
|
63
|
+
* @param llmInvoker - Function that calls an LLM with (system, user) prompts.
|
|
64
|
+
* @param traits - Optional HEXACO personality traits for bias-aware compression.
|
|
65
|
+
*/
|
|
66
|
+
constructor(llmInvoker: (system: string, user: string) => Promise<string>, traits?: HexacoTraits | undefined);
|
|
67
|
+
/**
|
|
68
|
+
* Compress a batch of observation notes into denser summaries.
|
|
69
|
+
*
|
|
70
|
+
* The method:
|
|
71
|
+
* 1. Formats the notes as a numbered list for the LLM.
|
|
72
|
+
* 2. Sends the batch to the LLM with a compression prompt.
|
|
73
|
+
* 3. Parses the JSON array response into {@link CompressedObservation} objects.
|
|
74
|
+
* 4. Attaches three-date temporal metadata (observedAt, referencedAt, relativeLabel).
|
|
75
|
+
*
|
|
76
|
+
* @param notes - Batch of observation notes to compress.
|
|
77
|
+
* @returns Array of compressed observations. Returns empty array on LLM failure.
|
|
78
|
+
*/
|
|
79
|
+
compress(notes: ObservationNote[]): Promise<CompressedObservation[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Parse the LLM response into CompressedObservation objects.
|
|
82
|
+
*
|
|
83
|
+
* Tries to parse the response as a JSON array. Falls back to extracting
|
|
84
|
+
* individual JSON objects from lines if the array parse fails.
|
|
85
|
+
*/
|
|
86
|
+
private parseCompressed;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=ObservationCompressor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservationCompressor.d.ts","sourceRoot":"","sources":["../../../src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|
+
* @fileoverview LLM-based observational memory compressor.
|
|
3
|
+
*
|
|
4
|
+
* Takes a batch of {@link ObservationNote} objects and compresses them into
|
|
5
|
+
* denser {@link CompressedObservation} summaries via an LLM call. This is the
|
|
6
|
+
* "Observer" agent in Mastra's agentic memory model — it groups related
|
|
7
|
+
* observations by topic/entity overlap, produces a 1-3 sentence summary per
|
|
8
|
+
* group, assigns a priority level, and attaches three-date temporal metadata.
|
|
9
|
+
*
|
|
10
|
+
* Typical compression: 3-10x (many individual notes become fewer dense
|
|
11
|
+
* summaries while preserving all critical facts).
|
|
12
|
+
*
|
|
13
|
+
* Personality bias: when HEXACO traits are provided, the system prompt
|
|
14
|
+
* is tuned to emphasise observation categories that align with the agent's
|
|
15
|
+
* personality (e.g. high conscientiousness → emphasise commitments).
|
|
16
|
+
*
|
|
17
|
+
* @module agentos/memory/observation/ObservationCompressor
|
|
18
|
+
*/
|
|
19
|
+
import { relativeTimeLabel } from './temporal.js';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// System prompt builder
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/**
|
|
24
|
+
* Build the LLM system prompt for observation compression.
|
|
25
|
+
* Personality traits modulate which observation categories receive emphasis.
|
|
26
|
+
*/
|
|
27
|
+
function buildCompressorSystemPrompt(traits) {
|
|
28
|
+
const emphases = [];
|
|
29
|
+
if (traits) {
|
|
30
|
+
const c = (v) => v == null ? 0.5 : Math.max(0, Math.min(1, v));
|
|
31
|
+
if (c(traits.emotionality) > 0.6)
|
|
32
|
+
emphases.push('Preserve emotional context and sentiment shifts.');
|
|
33
|
+
if (c(traits.conscientiousness) > 0.6)
|
|
34
|
+
emphases.push('Preserve commitments, deadlines, and action items.');
|
|
35
|
+
if (c(traits.openness) > 0.6)
|
|
36
|
+
emphases.push('Preserve creative ideas and exploratory tangents.');
|
|
37
|
+
if (c(traits.agreeableness) > 0.6)
|
|
38
|
+
emphases.push('Preserve rapport cues and user preferences.');
|
|
39
|
+
if (c(traits.honesty) > 0.6)
|
|
40
|
+
emphases.push('Preserve corrections, retractions, and factual updates.');
|
|
41
|
+
}
|
|
42
|
+
const emphasisBlock = emphases.length > 0
|
|
43
|
+
? `\n\nPersonality emphasis:\n${emphases.map((e) => `- ${e}`).join('\n')}`
|
|
44
|
+
: '';
|
|
45
|
+
return `You are a memory compressor. Your task is to compress a batch of observation notes into denser summary groups.
|
|
46
|
+
|
|
47
|
+
Rules:
|
|
48
|
+
1. Group related observations by topic overlap or entity overlap.
|
|
49
|
+
2. For each group, produce ONE dense summary of 1-3 sentences that captures all key facts.
|
|
50
|
+
3. Assign a priority: "critical" (security, safety, urgent deadlines), "important" (user preferences, key decisions, commitments), or "informational" (context, background, trivia).
|
|
51
|
+
4. Include the IDs of all source observations in each group.
|
|
52
|
+
5. Merge entity lists from all grouped observations.
|
|
53
|
+
6. Target 3-10x compression while preserving ALL critical facts.
|
|
54
|
+
|
|
55
|
+
Output a JSON array of objects, each with:
|
|
56
|
+
{
|
|
57
|
+
"summary": "dense summary text",
|
|
58
|
+
"priority": "critical|important|informational",
|
|
59
|
+
"sourceIds": ["obs_id_1", "obs_id_2"],
|
|
60
|
+
"entities": ["entity1", "entity2"]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Output ONLY a valid JSON array. No markdown, no explanation.${emphasisBlock}`;
|
|
64
|
+
}
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Counter for unique IDs
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
let compressedIdCounter = 0;
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// ObservationCompressor
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
/**
|
|
73
|
+
* LLM-based compressor that takes a batch of {@link ObservationNote} objects
|
|
74
|
+
* and produces denser {@link CompressedObservation} summaries.
|
|
75
|
+
*
|
|
76
|
+
* Achieves 3-10x compression while preserving key facts, entities, and
|
|
77
|
+
* temporal context. Each compressed observation carries three-date temporal
|
|
78
|
+
* metadata: when the compression happened, the earliest referenced event,
|
|
79
|
+
* and a human-friendly relative time label.
|
|
80
|
+
*/
|
|
81
|
+
export class ObservationCompressor {
|
|
82
|
+
/**
|
|
83
|
+
* @param llmInvoker - Function that calls an LLM with (system, user) prompts.
|
|
84
|
+
* @param traits - Optional HEXACO personality traits for bias-aware compression.
|
|
85
|
+
*/
|
|
86
|
+
constructor(llmInvoker, traits) {
|
|
87
|
+
this.llmInvoker = llmInvoker;
|
|
88
|
+
this.traits = traits;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Compress a batch of observation notes into denser summaries.
|
|
92
|
+
*
|
|
93
|
+
* The method:
|
|
94
|
+
* 1. Formats the notes as a numbered list for the LLM.
|
|
95
|
+
* 2. Sends the batch to the LLM with a compression prompt.
|
|
96
|
+
* 3. Parses the JSON array response into {@link CompressedObservation} objects.
|
|
97
|
+
* 4. Attaches three-date temporal metadata (observedAt, referencedAt, relativeLabel).
|
|
98
|
+
*
|
|
99
|
+
* @param notes - Batch of observation notes to compress.
|
|
100
|
+
* @returns Array of compressed observations. Returns empty array on LLM failure.
|
|
101
|
+
*/
|
|
102
|
+
async compress(notes) {
|
|
103
|
+
if (notes.length === 0)
|
|
104
|
+
return [];
|
|
105
|
+
const systemPrompt = buildCompressorSystemPrompt(this.traits);
|
|
106
|
+
// Format notes as a numbered list with IDs, types, importance, and content.
|
|
107
|
+
const userPrompt = notes
|
|
108
|
+
.map((n) => `[${n.id}] (${n.type}, importance=${n.importance.toFixed(2)}, entities=[${n.entities.join(', ')}]) ${n.content}`)
|
|
109
|
+
.join('\n');
|
|
110
|
+
try {
|
|
111
|
+
const response = await this.llmInvoker(systemPrompt, userPrompt);
|
|
112
|
+
return this.parseCompressed(response, notes);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// -------------------------------------------------------------------------
|
|
119
|
+
// Internal parsing
|
|
120
|
+
// -------------------------------------------------------------------------
|
|
121
|
+
/**
|
|
122
|
+
* Parse the LLM response into CompressedObservation objects.
|
|
123
|
+
*
|
|
124
|
+
* Tries to parse the response as a JSON array. Falls back to extracting
|
|
125
|
+
* individual JSON objects from lines if the array parse fails.
|
|
126
|
+
*/
|
|
127
|
+
parseCompressed(llmResponse, sourceNotes) {
|
|
128
|
+
const now = Date.now();
|
|
129
|
+
const noteMap = new Map(sourceNotes.map((n) => [n.id, n]));
|
|
130
|
+
const results = [];
|
|
131
|
+
// Try parsing as a JSON array first.
|
|
132
|
+
let parsed;
|
|
133
|
+
try {
|
|
134
|
+
// Strip markdown fences if present.
|
|
135
|
+
const cleaned = llmResponse
|
|
136
|
+
.replace(/^```json\s*/i, '')
|
|
137
|
+
.replace(/```\s*$/, '')
|
|
138
|
+
.trim();
|
|
139
|
+
parsed = JSON.parse(cleaned);
|
|
140
|
+
if (!Array.isArray(parsed)) {
|
|
141
|
+
parsed = [parsed];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// Fallback: try parsing line by line.
|
|
146
|
+
parsed = [];
|
|
147
|
+
for (const line of llmResponse.split('\n')) {
|
|
148
|
+
const trimmed = line.trim();
|
|
149
|
+
if (!trimmed || trimmed === '[' || trimmed === ']')
|
|
150
|
+
continue;
|
|
151
|
+
try {
|
|
152
|
+
// Strip trailing comma for JSON-lines style.
|
|
153
|
+
const clean = trimmed.endsWith(',') ? trimmed.slice(0, -1) : trimmed;
|
|
154
|
+
parsed.push(JSON.parse(clean));
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// Skip malformed lines.
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (const item of parsed) {
|
|
162
|
+
if (typeof item !== 'object' || item === null)
|
|
163
|
+
continue;
|
|
164
|
+
const obj = item;
|
|
165
|
+
if (typeof obj.summary !== 'string' || !obj.summary)
|
|
166
|
+
continue;
|
|
167
|
+
const sourceIds = Array.isArray(obj.sourceIds)
|
|
168
|
+
? obj.sourceIds.filter((id) => typeof id === 'string')
|
|
169
|
+
: [];
|
|
170
|
+
const entities = Array.isArray(obj.entities)
|
|
171
|
+
? obj.entities.filter((e) => typeof e === 'string')
|
|
172
|
+
: [];
|
|
173
|
+
const priority = (['critical', 'important', 'informational'].includes(obj.priority)
|
|
174
|
+
? obj.priority
|
|
175
|
+
: 'informational');
|
|
176
|
+
// Compute temporal metadata from source notes.
|
|
177
|
+
const sourceTimes = sourceIds
|
|
178
|
+
.map((id) => noteMap.get(id)?.timestamp)
|
|
179
|
+
.filter((t) => t != null);
|
|
180
|
+
const earliestRef = sourceTimes.length > 0
|
|
181
|
+
? Math.min(...sourceTimes)
|
|
182
|
+
: now;
|
|
183
|
+
// Compute average importance from source notes.
|
|
184
|
+
const sourceImportances = sourceIds
|
|
185
|
+
.map((id) => noteMap.get(id)?.importance)
|
|
186
|
+
.filter((i) => i != null);
|
|
187
|
+
const avgImportance = sourceImportances.length > 0
|
|
188
|
+
? sourceImportances.reduce((a, b) => a + b, 0) / sourceImportances.length
|
|
189
|
+
: 0.5;
|
|
190
|
+
results.push({
|
|
191
|
+
id: `cobs_${Date.now()}_${++compressedIdCounter}`,
|
|
192
|
+
summary: obj.summary,
|
|
193
|
+
priority,
|
|
194
|
+
temporal: {
|
|
195
|
+
observedAt: now,
|
|
196
|
+
referencedAt: earliestRef,
|
|
197
|
+
relativeLabel: relativeTimeLabel(earliestRef, now),
|
|
198
|
+
},
|
|
199
|
+
sourceIds,
|
|
200
|
+
entities,
|
|
201
|
+
importance: avgImportance,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return results;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=ObservationCompressor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservationCompressor.js","sourceRoot":"","sources":["../../../src/memory/observation/ObservationCompressor.ts"],"names":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AI,CAAC,CAAC;YACzC,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC;gBACxC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;gBAC1B,CAAC,CAAC,GAAG,CAAC;YAER,gDAAgD;YAChD,MAAM,iBAAiB,GAAG,SAAS;iBAChC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC;iBACxC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;YACzC,MAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC;gBAChD,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAC,MAAM;gBACzE,CAAC,CAAC,GAAG,CAAC;YAER,OAAO,CAAC,IAAI,CAAC;gBACX,EAAE,EAAE,QAAQ,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,mBAAmB,EAAE;gBACjD,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,QAAQ;gBACR,QAAQ,EAAE;oBACR,UAAU,EAAE,GAAG;oBACf,YAAY,EAAE,WAAW;oBACzB,aAAa,EAAE,iBAAiB,CAAC,WAAW,EAAE,GAAG,CAAC;iBACnD;gBACD,SAAS;gBACT,QAAQ;gBACR,UAAU,EAAE,aAAa;aAC1B,CAAC,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Higher-level reflector that condenses compressed observations
|
|
3
|
+
* into reflections — long-lived insights about user patterns, preferences,
|
|
4
|
+
* capabilities, relationships, and goals.
|
|
5
|
+
*
|
|
6
|
+
* This is the "Reflector" agent in Mastra's agentic memory model. It runs
|
|
7
|
+
* when compressed observations exceed a configurable token threshold
|
|
8
|
+
* (default: 40,000 tokens) and extracts higher-level patterns that transcend
|
|
9
|
+
* individual conversation turns.
|
|
10
|
+
*
|
|
11
|
+
* Each {@link Reflection} carries a pattern type classifier, confidence score,
|
|
12
|
+
* source provenance, and temporal span metadata.
|
|
13
|
+
*
|
|
14
|
+
* @module agentos/memory/observation/ObservationReflector
|
|
15
|
+
*/
|
|
16
|
+
import type { CompressedObservation } from './ObservationCompressor.js';
|
|
17
|
+
/** The kind of pattern identified by the reflector. */
|
|
18
|
+
export type ReflectionPatternType = 'preference' | 'behavior' | 'capability' | 'relationship' | 'goal';
|
|
19
|
+
/**
|
|
20
|
+
* A high-level insight derived from multiple compressed observations.
|
|
21
|
+
* Reflections are the highest tier in the observation hierarchy:
|
|
22
|
+
* raw notes → compressed observations → reflections.
|
|
23
|
+
*/
|
|
24
|
+
export interface Reflection {
|
|
25
|
+
/** Unique identifier for this reflection. */
|
|
26
|
+
id: string;
|
|
27
|
+
/** High-level insight text (1-3 sentences). */
|
|
28
|
+
insight: string;
|
|
29
|
+
/** Pattern type classifier. */
|
|
30
|
+
patternType: ReflectionPatternType;
|
|
31
|
+
/** Confidence in this reflection (0-1). */
|
|
32
|
+
confidence: number;
|
|
33
|
+
/** IDs of the source compressed observations. */
|
|
34
|
+
sourceIds: string[];
|
|
35
|
+
/** Temporal span covered by this reflection. */
|
|
36
|
+
temporal: {
|
|
37
|
+
/** When this reflection was produced (Unix ms). */
|
|
38
|
+
reflectedAt: number;
|
|
39
|
+
/** Earliest source timestamp in the compressed observations (Unix ms). */
|
|
40
|
+
spanStart: number;
|
|
41
|
+
/** Latest source timestamp in the compressed observations (Unix ms). */
|
|
42
|
+
spanEnd: number;
|
|
43
|
+
/** Human-friendly label for the temporal span. */
|
|
44
|
+
relativeLabel: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Condenses compressed observations into higher-level reflections.
|
|
49
|
+
*
|
|
50
|
+
* Runs when accumulated compressed observations exceed 40,000 tokens
|
|
51
|
+
* (configurable). Each reflection captures a long-lived pattern such as
|
|
52
|
+
* a user preference, behavioral habit, capability, relationship dynamic,
|
|
53
|
+
* or goal.
|
|
54
|
+
*/
|
|
55
|
+
export declare class ObservationReflector {
|
|
56
|
+
private llmInvoker;
|
|
57
|
+
/**
|
|
58
|
+
* @param llmInvoker - Function that calls an LLM with (system, user) prompts.
|
|
59
|
+
*/
|
|
60
|
+
constructor(llmInvoker: (system: string, user: string) => Promise<string>);
|
|
61
|
+
/**
|
|
62
|
+
* Reflect on compressed observations to extract higher-level patterns.
|
|
63
|
+
*
|
|
64
|
+
* @param observations - Compressed observations to reflect on.
|
|
65
|
+
* @returns Array of reflections. Returns empty array on LLM failure.
|
|
66
|
+
*/
|
|
67
|
+
reflect(observations: CompressedObservation[]): Promise<Reflection[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Parse the LLM response into Reflection objects.
|
|
70
|
+
*/
|
|
71
|
+
private parseReflections;
|
|
72
|
+
/**
|
|
73
|
+
* Build a human-friendly label describing a temporal span.
|
|
74
|
+
*
|
|
75
|
+
* @param start - Earliest timestamp in the span (Unix ms).
|
|
76
|
+
* @param end - Latest timestamp in the span (Unix ms).
|
|
77
|
+
* @param now - Current reference time (Unix ms).
|
|
78
|
+
* @returns Label such as "over the past week" or "over the past 3 days".
|
|
79
|
+
*/
|
|
80
|
+
private buildSpanLabel;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=ObservationReflector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservationReflector.d.ts","sourceRoot":"","sources":["../../../src/memory/observation/ObservationReflector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAOxE,uDAAuD;AACvD,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,UAAU,GACV,YAAY,GACZ,cAAc,GACd,MAAM,CAAC;AAEX;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,WAAW,EAAE,qBAAqB,CAAC;IACnC,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,gDAAgD;IAChD,QAAQ,EAAE;QACR,mDAAmD;QACnD,WAAW,EAAE,MAAM,CAAC;QACpB,0EAA0E;QAC1E,SAAS,EAAE,MAAM,CAAC;QAClB,wEAAwE;QACxE,OAAO,EAAE,MAAM,CAAC;QAChB,kDAAkD;QAClD,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAsCD;;;;;;;GAOG;AACH,qBAAa,oBAAoB;IAK7B,OAAO,CAAC,UAAU;IAJpB;;OAEG;gBAEO,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC;IAGvE;;;;;OAKG;IACG,OAAO,CAAC,YAAY,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAwB3E;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgGxB;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;CA2BvB"}
|