agentfootprint 6.44.0 → 7.0.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/AGENTS.md +4 -0
- package/CLAUDE.md +4 -0
- package/README.md +141 -167
- package/ai-instructions/claude-code/SKILL.md +11 -0
- package/ai-instructions/setup.sh +0 -0
- package/dist/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/adapters/llm/MockProvider.js +2 -1
- package/dist/adapters/llm/MockProvider.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +2 -1
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/stages/pickEntry.js +3 -1
- package/dist/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/debug/finders.js +29 -0
- package/dist/debug/finders.js.map +1 -0
- package/dist/debug.js +134 -0
- package/dist/debug.js.map +1 -0
- package/dist/esm/adapters/identity/agentcore.d.ts +100 -0
- package/dist/esm/adapters/llm/AnthropicProvider.d.ts +130 -0
- package/dist/esm/adapters/llm/BedrockProvider.d.ts +100 -0
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +41 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +95 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/esm/adapters/llm/MockProvider.d.ts +154 -0
- package/dist/esm/adapters/llm/MockProvider.js +2 -1
- package/dist/esm/adapters/llm/MockProvider.js.map +1 -1
- package/dist/esm/adapters/llm/OpenAIProvider.d.ts +220 -0
- package/dist/esm/adapters/llm/createProvider.d.ts +85 -0
- package/dist/esm/adapters/memory/agentcore.d.ts +146 -0
- package/dist/esm/adapters/memory/bedrockAgentMemory.d.ts +95 -0
- package/dist/esm/adapters/memory/redis.d.ts +127 -0
- package/dist/esm/adapters/observability/agentcore.d.ts +67 -0
- package/dist/esm/adapters/observability/audit.d.ts +254 -0
- package/dist/esm/adapters/observability/cloudwatch.d.ts +96 -0
- package/dist/esm/adapters/observability/otel.d.ts +237 -0
- package/dist/esm/adapters/observability/xray.d.ts +88 -0
- package/dist/esm/adapters/types.d.ts +378 -0
- package/dist/esm/bridge/eventMeta.d.ts +59 -0
- package/dist/esm/cache/CacheDecisionSubflow.d.ts +85 -0
- package/dist/esm/cache/CacheGateDecider.d.ts +127 -0
- package/dist/esm/cache/applyCachePolicy.d.ts +37 -0
- package/dist/esm/cache/cacheRecorder.d.ts +85 -0
- package/dist/esm/cache/index.d.ts +33 -0
- package/dist/esm/cache/strategies/AnthropicCacheStrategy.d.ts +38 -0
- package/dist/esm/cache/strategies/BedrockCacheStrategy.d.ts +33 -0
- package/dist/esm/cache/strategies/NoOpCacheStrategy.d.ts +29 -0
- package/dist/esm/cache/strategies/OpenAICacheStrategy.d.ts +36 -0
- package/dist/esm/cache/strategyRegistry.d.ts +45 -0
- package/dist/esm/cache/types.d.ts +243 -0
- package/dist/esm/conventions.d.ts +203 -0
- package/dist/esm/core/Agent.d.ts +355 -0
- package/dist/esm/core/LLMCall.d.ts +139 -0
- package/dist/esm/core/RunnerBase.d.ts +267 -0
- package/dist/esm/core/agent/AgentBuilder.d.ts +565 -0
- package/dist/esm/core/agent/buildAgentChart.d.ts +109 -0
- package/dist/esm/core/agent/buildAgentChart.js +2 -1
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildAgentMessageApiChart.d.ts +40 -0
- package/dist/esm/core/agent/buildCacheSubflow.d.ts +35 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.d.ts +56 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildMessageApiChart.d.ts +47 -0
- package/dist/esm/core/agent/buildToolRegistry.d.ts +61 -0
- package/dist/esm/core/agent/memoryRecallInjections.d.ts +8 -0
- package/dist/esm/core/agent/stages/breakFinal.d.ts +22 -0
- package/dist/esm/core/agent/stages/callLLM.d.ts +74 -0
- package/dist/esm/core/agent/stages/pickEntry.d.ts +19 -0
- package/dist/esm/core/agent/stages/pickEntry.js +3 -1
- package/dist/esm/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/esm/core/agent/stages/prepareFinal.d.ts +19 -0
- package/dist/esm/core/agent/stages/reliabilityExecution.d.ts +135 -0
- package/dist/esm/core/agent/stages/route.d.ts +18 -0
- package/dist/esm/core/agent/stages/seed.d.ts +53 -0
- package/dist/esm/core/agent/stages/toolCalls.d.ts +76 -0
- package/dist/esm/core/agent/toolArgsValidation.d.ts +62 -0
- package/dist/esm/core/agent/types.d.ts +382 -0
- package/dist/esm/core/agent/validators.d.ts +52 -0
- package/dist/esm/core/cost.d.ts +38 -0
- package/dist/esm/core/flowchartAsTool.d.ts +200 -0
- package/dist/esm/core/humanizeLLMError.d.ts +23 -0
- package/dist/esm/core/outputFallback.d.ts +139 -0
- package/dist/esm/core/outputSchema.d.ts +127 -0
- package/dist/esm/core/pause.d.ts +74 -0
- package/dist/esm/core/runCheckpoint.d.ts +179 -0
- package/dist/esm/core/runner.d.ts +203 -0
- package/dist/esm/core/slots/buildMessagesSlot.d.ts +40 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +41 -0
- package/dist/esm/core/slots/buildThinkingSubflow.d.ts +40 -0
- package/dist/esm/core/slots/buildToolsSlot.d.ts +60 -0
- package/dist/esm/core/slots/helpers.d.ts +27 -0
- package/dist/esm/core/toolContract.d.ts +43 -0
- package/dist/esm/core/tools.d.ts +90 -0
- package/dist/esm/core/translator.d.ts +94 -0
- package/dist/esm/core-flow/Conditional.d.ts +119 -0
- package/dist/esm/core-flow/Loop.d.ts +160 -0
- package/dist/esm/core-flow/Parallel.d.ts +360 -0
- package/dist/esm/core-flow/Sequence.d.ts +133 -0
- package/dist/esm/debug/finders.d.ts +12 -0
- package/dist/esm/debug/finders.js +13 -0
- package/dist/esm/debug/finders.js.map +1 -0
- package/dist/esm/debug.d.ts +25 -0
- package/dist/esm/debug.js +54 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/events/dispatcher.d.ts +134 -0
- package/dist/esm/events/payloads.d.ts +761 -0
- package/dist/esm/events/registry.d.ts +198 -0
- package/dist/esm/events/types.d.ts +70 -0
- package/dist/esm/events.d.ts +18 -0
- package/dist/esm/events.js +22 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/identity/kinds.d.ts +36 -0
- package/dist/esm/identity/staticTokens.d.ts +28 -0
- package/dist/esm/identity/types.d.ts +113 -0
- package/dist/esm/identity/withCredentialRetry.d.ts +64 -0
- package/dist/esm/identity.d.ts +31 -0
- package/dist/esm/index.d.ts +44 -0
- package/dist/esm/index.js +7 -52
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/injection-engine.d.ts +4 -0
- package/dist/esm/lib/canonicalJson.d.ts +56 -0
- package/dist/esm/lib/context-bisect/ablation.d.ts +109 -0
- package/dist/esm/lib/context-bisect/bisect.d.ts +75 -0
- package/dist/esm/lib/context-bisect/cost.d.ts +37 -0
- package/dist/esm/lib/context-bisect/index.d.ts +31 -0
- package/dist/esm/lib/context-bisect/index.js +3 -0
- package/dist/esm/lib/context-bisect/index.js.map +1 -1
- package/dist/esm/lib/context-bisect/llmEdgeWeigher.d.ts +124 -0
- package/dist/esm/lib/context-bisect/localize.d.ts +152 -0
- package/dist/esm/lib/context-bisect/localize.js +2 -0
- package/dist/esm/lib/context-bisect/localize.js.map +1 -1
- package/dist/esm/lib/context-bisect/loop-recall.d.ts +97 -0
- package/dist/esm/lib/context-bisect/missingContext.d.ts +71 -0
- package/dist/esm/lib/context-bisect/restoration.d.ts +39 -0
- package/dist/esm/lib/context-bisect/toBacktrackTrace.d.ts +138 -0
- package/dist/esm/lib/context-bisect/trajectory.d.ts +168 -0
- package/dist/esm/lib/context-bisect/types.d.ts +448 -0
- package/dist/esm/lib/context-bisect/walk-to-root.d.ts +103 -0
- package/dist/esm/lib/influence-core/attributability.d.ts +72 -0
- package/dist/esm/lib/influence-core/cache.d.ts +94 -0
- package/dist/esm/lib/influence-core/contrastive.d.ts +26 -0
- package/dist/esm/lib/influence-core/index.d.ts +34 -0
- package/dist/esm/lib/influence-core/margin.d.ts +33 -0
- package/dist/esm/lib/influence-core/signals.d.ts +128 -0
- package/dist/esm/lib/influence-core/similarity.d.ts +25 -0
- package/dist/esm/lib/influence-core/types.d.ts +252 -0
- package/dist/esm/lib/injection-engine/SkillRegistry.d.ts +147 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.d.ts +110 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/esm/lib/injection-engine/entryScorer.d.ts +93 -0
- package/dist/esm/lib/injection-engine/entryScorer.js +172 -0
- package/dist/esm/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/esm/lib/injection-engine/evaluator.d.ts +24 -0
- package/dist/esm/lib/injection-engine/factories/defineFact.d.ts +60 -0
- package/dist/esm/lib/injection-engine/factories/defineInjection.d.ts +41 -0
- package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +78 -0
- package/dist/esm/lib/injection-engine/factories/defineRelevanceHint.d.ts +26 -0
- package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +160 -0
- package/dist/esm/lib/injection-engine/factories/defineSteering.d.ts +39 -0
- package/dist/esm/lib/injection-engine/index.d.ts +22 -0
- package/dist/esm/lib/injection-engine/index.js +2 -1
- package/dist/esm/lib/injection-engine/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillContract.d.ts +29 -0
- package/dist/esm/lib/injection-engine/skillGraph.d.ts +290 -0
- package/dist/esm/lib/injection-engine/skillGraph.js +38 -43
- package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillGraphCheckup.d.ts +49 -0
- package/dist/esm/lib/injection-engine/skillTools.d.ts +72 -0
- package/dist/esm/lib/injection-engine/softmax.d.ts +11 -0
- package/dist/esm/lib/injection-engine/types.d.ts +229 -0
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/lib/lazyRequire.d.ts +29 -0
- package/dist/esm/lib/mcp/index.d.ts +9 -0
- package/dist/esm/lib/mcp/mcpClient.d.ts +46 -0
- package/dist/esm/lib/mcp/mockMcpClient.d.ts +65 -0
- package/dist/esm/lib/mcp/types.d.ts +133 -0
- package/dist/esm/lib/rag/defineRAG.d.ts +139 -0
- package/dist/esm/lib/rag/defineRAG.js +3 -3
- package/dist/esm/lib/rag/index.d.ts +7 -0
- package/dist/esm/lib/rag/indexDocuments.d.ts +106 -0
- package/dist/esm/lib/rag/indexDocuments.js +2 -1
- package/dist/esm/lib/rag/indexDocuments.js.map +1 -1
- package/dist/esm/lib/tool-lint/analyze.d.ts +83 -0
- package/dist/esm/lib/tool-lint/cli.d.ts +43 -0
- package/dist/esm/lib/tool-lint/format.d.ts +18 -0
- package/dist/esm/lib/tool-lint/index.d.ts +23 -0
- package/dist/esm/lib/tool-lint/rules.d.ts +85 -0
- package/dist/esm/lib/tool-lint/types.d.ts +155 -0
- package/dist/esm/lib/trace-toolpack/bounded.d.ts +47 -0
- package/dist/esm/lib/trace-toolpack/debugPrompt.d.ts +19 -0
- package/dist/esm/lib/trace-toolpack/index.d.ts +20 -0
- package/dist/esm/lib/trace-toolpack/lazyToolpack.d.ts +35 -0
- package/dist/esm/lib/trace-toolpack/selfExplain.d.ts +100 -0
- package/dist/esm/lib/trace-toolpack/traceDebugAgent.d.ts +42 -0
- package/dist/esm/lib/trace-toolpack/traceToolpack.d.ts +69 -0
- package/dist/esm/lib/trace-toolpack/types.d.ts +59 -0
- package/dist/esm/llm-providers.d.ts +26 -0
- package/dist/esm/locales/index.d.ts +141 -0
- package/dist/esm/locales/index.js +7 -0
- package/dist/esm/locales/index.js.map +1 -1
- package/dist/esm/memory/beats/extractBeats.d.ts +61 -0
- package/dist/esm/memory/beats/extractor.d.ts +47 -0
- package/dist/esm/memory/beats/formatAsNarrative.d.ts +62 -0
- package/dist/esm/memory/beats/heuristicExtractor.d.ts +37 -0
- package/dist/esm/memory/beats/index.d.ts +12 -0
- package/dist/esm/memory/beats/llmExtractor.d.ts +56 -0
- package/dist/esm/memory/beats/types.d.ts +60 -0
- package/dist/esm/memory/beats/writeBeats.d.ts +22 -0
- package/dist/esm/memory/causal/evidenceRecorder.d.ts +66 -0
- package/dist/esm/memory/causal/index.d.ts +6 -0
- package/dist/esm/memory/causal/loadSnapshot.d.ts +51 -0
- package/dist/esm/memory/causal/snapshotPipeline.d.ts +35 -0
- package/dist/esm/memory/causal/types.d.ts +134 -0
- package/dist/esm/memory/causal/types.js.map +1 -1
- package/dist/esm/memory/causal/writeSnapshot.d.ts +73 -0
- package/dist/esm/memory/define.d.ts +63 -0
- package/dist/esm/memory/define.types.d.ts +278 -0
- package/dist/esm/memory/define.types.js +6 -4
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/embedding/cosine.d.ts +18 -0
- package/dist/esm/memory/embedding/embedMessages.d.ts +58 -0
- package/dist/esm/memory/embedding/index.d.ts +8 -0
- package/dist/esm/memory/embedding/loadRelevant.d.ts +51 -0
- package/dist/esm/memory/embedding/mockEmbedder.d.ts +22 -0
- package/dist/esm/memory/embedding/types.d.ts +46 -0
- package/dist/esm/memory/entry/decay.d.ts +36 -0
- package/dist/esm/memory/entry/index.d.ts +2 -0
- package/dist/esm/memory/entry/types.d.ts +140 -0
- package/dist/esm/memory/facts/extractFacts.d.ts +50 -0
- package/dist/esm/memory/facts/extractor.d.ts +33 -0
- package/dist/esm/memory/facts/formatFacts.d.ts +60 -0
- package/dist/esm/memory/facts/index.d.ts +14 -0
- package/dist/esm/memory/facts/llmFactExtractor.d.ts +64 -0
- package/dist/esm/memory/facts/loadFacts.d.ts +43 -0
- package/dist/esm/memory/facts/patternFactExtractor.d.ts +2 -0
- package/dist/esm/memory/facts/types.d.ts +68 -0
- package/dist/esm/memory/facts/writeFacts.d.ts +19 -0
- package/dist/esm/memory/identity/index.d.ts +2 -0
- package/dist/esm/memory/identity/types.d.ts +49 -0
- package/dist/esm/memory/index.d.ts +19 -0
- package/dist/esm/memory/pipeline/auto.d.ts +59 -0
- package/dist/esm/memory/pipeline/default.d.ts +49 -0
- package/dist/esm/memory/pipeline/ephemeral.d.ts +28 -0
- package/dist/esm/memory/pipeline/fact.d.ts +26 -0
- package/dist/esm/memory/pipeline/index.d.ts +13 -0
- package/dist/esm/memory/pipeline/narrative.d.ts +35 -0
- package/dist/esm/memory/pipeline/semantic.d.ts +37 -0
- package/dist/esm/memory/pipeline/types.d.ts +31 -0
- package/dist/esm/memory/stages/formatDefault.d.ts +64 -0
- package/dist/esm/memory/stages/index.d.ts +13 -0
- package/dist/esm/memory/stages/loadRecent.d.ts +49 -0
- package/dist/esm/memory/stages/pickByBudget.d.ts +63 -0
- package/dist/esm/memory/stages/summarize.d.ts +87 -0
- package/dist/esm/memory/stages/tokenize.d.ts +43 -0
- package/dist/esm/memory/stages/types.d.ts +75 -0
- package/dist/esm/memory/stages/writeMessages.d.ts +71 -0
- package/dist/esm/memory/store/InMemoryStore.d.ts +62 -0
- package/dist/esm/memory/store/index.d.ts +2 -0
- package/dist/esm/memory/store/types.d.ts +223 -0
- package/dist/esm/memory/wire/index.d.ts +2 -0
- package/dist/esm/memory/wire/mountMemoryPipeline.d.ts +108 -0
- package/dist/esm/memory-providers.d.ts +37 -0
- package/dist/esm/observability/contextError/finders/compareFinders.d.ts +19 -0
- package/dist/esm/observability/contextError/finders/index.d.ts +22 -0
- package/dist/esm/observability/contextError/finders/rankSuspects.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/removeAndRetry.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/shrinkToCause.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/testManyCombos.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/traceSteps.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/types.d.ts +88 -0
- package/dist/esm/observability-providers.d.ts +46 -0
- package/dist/esm/observe.d.ts +57 -0
- package/dist/esm/observe.js +7 -36
- package/dist/esm/observe.js.map +1 -1
- package/dist/esm/patterns/Debate.d.ts +39 -0
- package/dist/esm/patterns/MapReduce.d.ts +66 -0
- package/dist/esm/patterns/Reflection.d.ts +51 -0
- package/dist/esm/patterns/SelfConsistency.d.ts +43 -0
- package/dist/esm/patterns/Swarm.d.ts +60 -0
- package/dist/esm/patterns/ToT.d.ts +53 -0
- package/dist/esm/patterns/index.d.ts +22 -0
- package/dist/esm/providers.d.ts +33 -0
- package/dist/esm/providers.js +1 -1
- package/dist/esm/providers.js.map +1 -1
- package/dist/esm/recorders/core/AgentRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/CompositionRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/ContextEvaluatedRecorder.d.ts +23 -0
- package/dist/esm/recorders/core/ContextRecorder.d.ts +47 -0
- package/dist/esm/recorders/core/CostRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/EmitBridge.d.ts +30 -0
- package/dist/esm/recorders/core/ErrorBridge.d.ts +38 -0
- package/dist/esm/recorders/core/EvalRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/MemoryRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/PermissionRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/ReliabilityRecorder.d.ts +24 -0
- package/dist/esm/recorders/core/SkillRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/StreamRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/ToolsRecorder.d.ts +18 -0
- package/dist/esm/recorders/core/ValidationRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/contextEngineering.d.ts +136 -0
- package/dist/esm/recorders/core/typedEmit.d.ts +34 -0
- package/dist/esm/recorders/core/types.d.ts +97 -0
- package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.d.ts +117 -0
- package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +546 -0
- package/dist/esm/recorders/observability/FlowchartRecorder.d.ts +220 -0
- package/dist/esm/recorders/observability/LiveStateRecorder.d.ts +250 -0
- package/dist/esm/recorders/observability/LoggingRecorder.d.ts +91 -0
- package/dist/esm/recorders/observability/RouteRecorder.d.ts +83 -0
- package/dist/esm/recorders/observability/RunStepRecorder.d.ts +231 -0
- package/dist/esm/recorders/observability/StatusRecorder.d.ts +36 -0
- package/dist/esm/recorders/observability/ToolChoiceRecorder.d.ts +164 -0
- package/dist/esm/recorders/observability/ToolLineageRecorder.d.ts +71 -0
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.d.ts +105 -0
- package/dist/esm/recorders/observability/internal/ActorArrowClassifier.d.ts +25 -0
- package/dist/esm/recorders/observability/internal/CandidateAnswerBuffer.d.ts +28 -0
- package/dist/esm/recorders/observability/internal/ForkTracker.d.ts +60 -0
- package/dist/esm/recorders/observability/internal/RootInferrer.d.ts +51 -0
- package/dist/esm/recorders/observability/internal/SequenceSiblingTracker.d.ts +24 -0
- package/dist/esm/recorders/observability/localObservability.d.ts +48 -0
- package/dist/esm/recorders/observability/observeRunId.d.ts +36 -0
- package/dist/esm/recorders/observability/status/statusTemplates.d.ts +106 -0
- package/dist/esm/recorders/observability/trace.d.ts +119 -0
- package/dist/esm/reliability/CircuitBreaker.d.ts +75 -0
- package/dist/esm/reliability/buildReliabilityGateChart.d.ts +53 -0
- package/dist/esm/reliability/classifyError.d.ts +28 -0
- package/dist/esm/reliability/index.d.ts +35 -0
- package/dist/esm/reliability/types.d.ts +327 -0
- package/dist/esm/resilience/fallbackProvider.d.ts +33 -0
- package/dist/esm/resilience/index.d.ts +21 -0
- package/dist/esm/resilience/withCircuitBreaker.d.ts +129 -0
- package/dist/esm/resilience/withFallback.d.ts +45 -0
- package/dist/esm/resilience/withRetry.d.ts +71 -0
- package/dist/esm/security/PermissionPolicy.d.ts +124 -0
- package/dist/esm/security/PolicyHaltError.d.ts +72 -0
- package/dist/esm/security/extractSequence.d.ts +46 -0
- package/dist/esm/security/index.d.ts +44 -0
- package/dist/esm/security/thinkingRedaction.d.ts +50 -0
- package/dist/esm/status.d.ts +54 -0
- package/dist/esm/status.js +13 -4
- package/dist/esm/status.js.map +1 -1
- package/dist/esm/strategies/attach.d.ts +47 -0
- package/dist/esm/strategies/compose.d.ts +48 -0
- package/dist/esm/strategies/defaults/chatBubbleLiveStatus.d.ts +36 -0
- package/dist/esm/strategies/defaults/consoleObservability.d.ts +42 -0
- package/dist/esm/strategies/defaults/inMemorySinkCost.d.ts +50 -0
- package/dist/esm/strategies/defaults/index.d.ts +30 -0
- package/dist/esm/strategies/defaults/noopLens.d.ts +28 -0
- package/dist/esm/strategies/index.d.ts +36 -0
- package/dist/esm/strategies/registry.d.ts +70 -0
- package/dist/esm/strategies/types.d.ts +303 -0
- package/dist/esm/stream.d.ts +82 -0
- package/dist/esm/thinking/AnthropicThinkingHandler.d.ts +42 -0
- package/dist/esm/thinking/MockThinkingHandler.d.ts +50 -0
- package/dist/esm/thinking/OpenAIThinkingHandler.d.ts +37 -0
- package/dist/esm/thinking/index.d.ts +51 -0
- package/dist/esm/thinking/registry.d.ts +33 -0
- package/dist/esm/thinking/types.d.ts +162 -0
- package/dist/esm/tool-providers/gatedTools.d.ts +36 -0
- package/dist/esm/tool-providers/index.d.ts +41 -0
- package/dist/esm/tool-providers/skillScopedTools.d.ts +45 -0
- package/dist/esm/tool-providers/staticTools.d.ts +21 -0
- package/dist/esm/tool-providers/types.d.ts +138 -0
- package/dist/events.js +42 -0
- package/dist/events.js.map +1 -0
- package/dist/index.js +7 -117
- package/dist/index.js.map +1 -1
- package/dist/lib/context-bisect/index.js +3 -0
- package/dist/lib/context-bisect/index.js.map +1 -1
- package/dist/lib/context-bisect/localize.js +2 -0
- package/dist/lib/context-bisect/localize.js.map +1 -1
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/lib/injection-engine/entryScorer.js +178 -0
- package/dist/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/lib/injection-engine/index.js +6 -2
- package/dist/lib/injection-engine/index.js.map +1 -1
- package/dist/lib/injection-engine/skillGraph.js +40 -45
- package/dist/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/lib/rag/defineRAG.js +3 -3
- package/dist/lib/rag/indexDocuments.js +2 -1
- package/dist/lib/rag/indexDocuments.js.map +1 -1
- package/dist/locales/index.js +2 -1
- package/dist/locales/index.js.map +1 -1
- package/dist/memory/causal/types.js.map +1 -1
- package/dist/memory/define.types.js +6 -4
- package/dist/memory/define.types.js.map +1 -1
- package/dist/observe.js +22 -115
- package/dist/observe.js.map +1 -1
- package/dist/providers.js +3 -1
- package/dist/providers.js.map +1 -1
- package/dist/status.js +13 -5
- package/dist/status.js.map +1 -1
- package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts +1 -1
- package/dist/types/adapters/llm/MockProvider.d.ts +2 -1
- package/dist/types/adapters/llm/MockProvider.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/stages/pickEntry.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +8 -4
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/debug/finders.d.ts +13 -0
- package/dist/types/debug/finders.d.ts.map +1 -0
- package/dist/types/debug.d.ts +26 -0
- package/dist/types/debug.d.ts.map +1 -0
- package/dist/types/events.d.ts +19 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -24
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/index.d.ts +3 -0
- package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/localize.d.ts +2 -0
- package/dist/types/lib/context-bisect/localize.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/buildInjectionEngineSubflow.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/entryScorer.d.ts +94 -0
- package/dist/types/lib/injection-engine/entryScorer.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/index.d.ts +2 -1
- package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillGraph.d.ts +24 -26
- package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/types.d.ts +9 -4
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/lib/rag/defineRAG.d.ts +3 -3
- package/dist/types/lib/rag/indexDocuments.d.ts +2 -1
- package/dist/types/lib/rag/indexDocuments.d.ts.map +1 -1
- package/dist/types/locales/index.d.ts +9 -0
- package/dist/types/locales/index.d.ts.map +1 -1
- package/dist/types/memory/causal/types.d.ts +13 -9
- package/dist/types/memory/causal/types.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +6 -4
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/observe.d.ts +1 -6
- package/dist/types/observe.d.ts.map +1 -1
- package/dist/types/providers.d.ts +2 -2
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/status.d.ts +10 -4
- package/dist/types/status.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +1 -1
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/package.json +261 -57
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* embedMessages — write-side stage that attaches an embedding vector
|
|
3
|
+
* to each `MemoryEntry` in `scope.newMessages` before persistence.
|
|
4
|
+
*
|
|
5
|
+
* Reads from scope: `newMessages` (Message[]) — same input as writeMessages
|
|
6
|
+
* Writes to scope: `newMessages` (with entries pre-wrapped — see note)
|
|
7
|
+
*
|
|
8
|
+
* Note on composition:
|
|
9
|
+
* Unlike the `extractBeats → writeBeats` pair (which produces fully
|
|
10
|
+
* wrapped `MemoryEntry<NarrativeBeat>[]`), `embedMessages` runs
|
|
11
|
+
* AFTER a packaging step and BEFORE `writeMessages`. The simplest
|
|
12
|
+
* shape is: stage writes `scope.newMessageEmbeddings: number[][]`
|
|
13
|
+
* — one vector per message — and `writeMessages` merges it into the
|
|
14
|
+
* entries it builds.
|
|
15
|
+
*
|
|
16
|
+
* We take the cleaner path: embed here, write the embeddings to
|
|
17
|
+
* scope as a parallel array keyed by message index, and extend
|
|
18
|
+
* `writeMessages` to pick them up. No reshuffle of the existing
|
|
19
|
+
* write stage's contract.
|
|
20
|
+
*/
|
|
21
|
+
import type { TypedScope } from 'footprintjs';
|
|
22
|
+
import type { Embedder } from './types.js';
|
|
23
|
+
import type { LLMMessage as Message } from '../../adapters/types.js';
|
|
24
|
+
import type { MemoryState } from '../stages/index.js';
|
|
25
|
+
/** Extend MemoryState to carry per-message embeddings for writeMessages. */
|
|
26
|
+
export interface EmbedMessagesState extends MemoryState {
|
|
27
|
+
/**
|
|
28
|
+
* Per-message embedding vectors, indexed by position in `newMessages`.
|
|
29
|
+
* Produced by `embedMessages`; consumed by `writeMessages` when the
|
|
30
|
+
* pipeline is a semantic one.
|
|
31
|
+
*/
|
|
32
|
+
newMessageEmbeddings?: readonly (readonly number[])[];
|
|
33
|
+
/** Identifier of the embedder — carried onto entries for model-mismatch guards. */
|
|
34
|
+
newMessageEmbeddingModel?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface EmbedMessagesConfig {
|
|
37
|
+
/** The embedder to call. Typically OpenAI / Voyage / Cohere / custom. */
|
|
38
|
+
readonly embedder: Embedder;
|
|
39
|
+
/**
|
|
40
|
+
* Identifier for the embedder — stored on each entry's
|
|
41
|
+
* `embeddingModel` so `store.search({ embedderId })` can guard
|
|
42
|
+
* against cross-model pollution. Use a stable string like
|
|
43
|
+
* `"openai-text-embedding-3-small"`.
|
|
44
|
+
*/
|
|
45
|
+
readonly embedderId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Pull the text to embed from a message. Default: extracts the
|
|
48
|
+
* message content as a string (supports both `string` content and
|
|
49
|
+
* `[{ type: 'text', text: ... }]` block arrays).
|
|
50
|
+
*/
|
|
51
|
+
readonly textFrom?: (message: Message) => string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build the `embedMessages` stage. Prefers `embedBatch()` when the
|
|
55
|
+
* embedder implements it (one round-trip for the whole turn), otherwise
|
|
56
|
+
* falls back to N sequential `embed()` calls.
|
|
57
|
+
*/
|
|
58
|
+
export declare function embedMessages(config: EmbedMessagesConfig): (scope: TypedScope<EmbedMessagesState>) => Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Embedder, EmbedArgs, EmbedBatchArgs } from './types.js';
|
|
2
|
+
export { cosineSimilarity } from './cosine.js';
|
|
3
|
+
export { mockEmbedder } from './mockEmbedder.js';
|
|
4
|
+
export type { MockEmbedderOptions } from './mockEmbedder.js';
|
|
5
|
+
export { embedMessages } from './embedMessages.js';
|
|
6
|
+
export type { EmbedMessagesConfig, EmbedMessagesState } from './embedMessages.js';
|
|
7
|
+
export { loadRelevant } from './loadRelevant.js';
|
|
8
|
+
export type { LoadRelevantConfig } from './loadRelevant.js';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loadRelevant — read-side stage that embeds a query and fetches the
|
|
3
|
+
* top-k most similar entries from a vector-capable `MemoryStore`.
|
|
4
|
+
*
|
|
5
|
+
* Reads from scope: `identity`, `newMessages` (or custom queryFrom)
|
|
6
|
+
* Writes to scope: `loaded` (MemoryEntry[], ordered best-first — to be
|
|
7
|
+
* narrowed by `pickByBudget` downstream)
|
|
8
|
+
*
|
|
9
|
+
* Query derivation:
|
|
10
|
+
* Default: the last user message in `newMessages`. That's the natural
|
|
11
|
+
* "what is the user asking about?" signal. Override with `queryFrom`
|
|
12
|
+
* for custom retrieval (e.g., compose user + assistant content,
|
|
13
|
+
* pull a summary, etc.).
|
|
14
|
+
*
|
|
15
|
+
* Empty behavior:
|
|
16
|
+
* No query text → no search → `loaded = []`. Downstream
|
|
17
|
+
* `pickByBudget` picks nothing and the formatter emits nothing — safe.
|
|
18
|
+
*
|
|
19
|
+
* Feature detection:
|
|
20
|
+
* Throws at stage build time if the store doesn't implement
|
|
21
|
+
* `search()`. Fail-loud — a semantic pipeline configured against a
|
|
22
|
+
* non-vector store is a config bug, not a runtime condition.
|
|
23
|
+
*/
|
|
24
|
+
import type { TypedScope } from 'footprintjs';
|
|
25
|
+
import type { MemoryStore } from '../store/index.js';
|
|
26
|
+
import type { MemoryState } from '../stages/index.js';
|
|
27
|
+
import type { Embedder } from './types.js';
|
|
28
|
+
export interface LoadRelevantConfig {
|
|
29
|
+
/** The vector-capable store. Must implement `search()`. */
|
|
30
|
+
readonly store: MemoryStore;
|
|
31
|
+
/** Embedder used to turn the query text into a vector. */
|
|
32
|
+
readonly embedder: Embedder;
|
|
33
|
+
/**
|
|
34
|
+
* Identifier for the embedder. When set, the search filters entries
|
|
35
|
+
* to those produced by the same embedder (prevents cross-model
|
|
36
|
+
* similarity pollution).
|
|
37
|
+
*/
|
|
38
|
+
readonly embedderId?: string;
|
|
39
|
+
/** Top-k to retrieve. Default 20 — picker will narrow further by budget. */
|
|
40
|
+
readonly k?: number;
|
|
41
|
+
/** Minimum cosine score [-1, 1] to consider a match. Default: none. */
|
|
42
|
+
readonly minScore?: number;
|
|
43
|
+
/** Filter results by tier. */
|
|
44
|
+
readonly tiers?: ReadonlyArray<'hot' | 'warm' | 'cold'>;
|
|
45
|
+
/**
|
|
46
|
+
* Extract the query text from scope. Default: the last user message
|
|
47
|
+
* in `newMessages`. Override for custom retrieval signals.
|
|
48
|
+
*/
|
|
49
|
+
readonly queryFrom?: (scope: TypedScope<MemoryState>) => string;
|
|
50
|
+
}
|
|
51
|
+
export declare function loadRelevant(config: LoadRelevantConfig): (scope: TypedScope<MemoryState>) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mockEmbedder — deterministic character-frequency embedder for tests.
|
|
3
|
+
*
|
|
4
|
+
* Produces a vector of length `dimensions` (default 32) where each
|
|
5
|
+
* coordinate is the count of characters whose code-point modulo
|
|
6
|
+
* `dimensions` lands on that index. Same text → same vector always,
|
|
7
|
+
* and texts that share characters have elevated cosine similarity.
|
|
8
|
+
*
|
|
9
|
+
* This is good enough for testing pipeline plumbing and basic
|
|
10
|
+
* retrieval semantics (e.g. "dogs" retrieves beats mentioning "dog"
|
|
11
|
+
* over beats mentioning "car"). It is NOT a real embedder — do not
|
|
12
|
+
* use for anything consumer-facing.
|
|
13
|
+
*/
|
|
14
|
+
import type { Embedder } from './types.js';
|
|
15
|
+
export interface MockEmbedderOptions {
|
|
16
|
+
readonly dimensions?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build a deterministic mock embedder. Same text always yields the
|
|
20
|
+
* same vector; texts sharing characters share cosine similarity.
|
|
21
|
+
*/
|
|
22
|
+
export declare function mockEmbedder(options?: MockEmbedderOptions): Embedder;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedder — text-to-vector abstraction.
|
|
3
|
+
*
|
|
4
|
+
* Pluggable interface: consumers bring their own embedding backend
|
|
5
|
+
* (OpenAI, Voyage, Cohere, Sentence Transformers, a local model, a
|
|
6
|
+
* custom rules-based hashing scheme, etc.). The library ships
|
|
7
|
+
* `mockEmbedder()` for tests — no default real embedder, since LLM
|
|
8
|
+
* providers' embedding APIs are not uniform (Anthropic doesn't
|
|
9
|
+
* publish one at all).
|
|
10
|
+
*
|
|
11
|
+
* An embedder is configured once (model + api key + dims) and reused
|
|
12
|
+
* across many turns. `dimensions` is a constant per instance — mixing
|
|
13
|
+
* embedders of different dims within the same `MemoryStore` breaks
|
|
14
|
+
* cosine similarity, so adapters should reject mismatched sizes.
|
|
15
|
+
*/
|
|
16
|
+
export interface EmbedArgs {
|
|
17
|
+
/** The text to embed. */
|
|
18
|
+
readonly text: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional abort signal — embedders making network calls should
|
|
21
|
+
* thread this through to respect run-level timeouts.
|
|
22
|
+
*/
|
|
23
|
+
readonly signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
export interface EmbedBatchArgs {
|
|
26
|
+
readonly texts: readonly string[];
|
|
27
|
+
readonly signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An Embedder turns text into a dense vector of constant dimensionality.
|
|
31
|
+
* Implement `embedBatch` for backends that support one-call multi-embed
|
|
32
|
+
* (OpenAI / Voyage / etc.) — without it, batch callers fall back to
|
|
33
|
+
* N sequential `embed()` calls.
|
|
34
|
+
*/
|
|
35
|
+
export interface Embedder {
|
|
36
|
+
/** Vector length. Constant per embedder instance. */
|
|
37
|
+
readonly dimensions: number;
|
|
38
|
+
/** Embed a single text into a vector of length `dimensions`. */
|
|
39
|
+
embed(args: EmbedArgs): Promise<number[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Optional batch API. When present, pipeline stages can avoid N
|
|
42
|
+
* sequential round-trips for turn-level indexing. Adapter SHOULD
|
|
43
|
+
* implement when the backend supports it.
|
|
44
|
+
*/
|
|
45
|
+
embedBatch?(args: EmbedBatchArgs): Promise<number[][]>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decay computation — pure function.
|
|
3
|
+
*
|
|
4
|
+
* Applied by retrieval stages to compute an entry's effective relevance at
|
|
5
|
+
* read time. Never mutates the entry; only returns a scaling factor in
|
|
6
|
+
* `[0, +∞)` that stages apply to their existing score.
|
|
7
|
+
*
|
|
8
|
+
* Model:
|
|
9
|
+
* factor = exp(-ln2 · Δt / halfLife) · min(accessBoost^accessCount, MAX_BOOST)
|
|
10
|
+
*
|
|
11
|
+
* The time term is exponential decay (half after one half-life). The access
|
|
12
|
+
* term is multiplicative — each read of an entry boosts its future
|
|
13
|
+
* relevance. `MAX_BOOST_MULTIPLIER` caps runaway boosting so a frequently-
|
|
14
|
+
* read but old entry doesn't crowd out newer relevant entries indefinitely.
|
|
15
|
+
*/
|
|
16
|
+
import type { DecayPolicy, MemoryEntry } from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Compute the decay factor for an entry at a given moment.
|
|
19
|
+
*
|
|
20
|
+
* @param entry The memory entry to score. Must have `lastAccessedAt` and
|
|
21
|
+
* `accessCount` set (storage adapters populate these).
|
|
22
|
+
* @param now The reference time (unix ms). Defaults to `Date.now()`.
|
|
23
|
+
* @param policy Optional override — when omitted, uses `entry.decayPolicy`.
|
|
24
|
+
* Stages can pass a stage-wide default so entries without a
|
|
25
|
+
* per-entry policy still decay consistently. If neither is
|
|
26
|
+
* set, returns 1.0 (no decay applied).
|
|
27
|
+
*
|
|
28
|
+
* @returns Scaling factor in `[0, MAX_BOOST_MULTIPLIER]` — stages multiply
|
|
29
|
+
* this against their existing relevance score.
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeDecayFactor(entry: Pick<MemoryEntry, 'lastAccessedAt' | 'accessCount' | 'decayPolicy'>, now?: number, policy?: DecayPolicy): number;
|
|
32
|
+
/**
|
|
33
|
+
* Compute decay for multiple entries in one call. Order-preserving; returns
|
|
34
|
+
* one factor per entry. Convenience for stages that rank whole batches.
|
|
35
|
+
*/
|
|
36
|
+
export declare function computeDecayFactors(entries: readonly Pick<MemoryEntry, 'lastAccessedAt' | 'accessCount' | 'decayPolicy'>[], now?: number, policy?: DecayPolicy): number[];
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { MemoryIdentity } from '../identity/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* MemoryEntry — a single stored item with decay-, version-, and source-aware
|
|
4
|
+
* metadata.
|
|
5
|
+
*
|
|
6
|
+
* Entry shape is generic over `T` so stores can hold messages, facts,
|
|
7
|
+
* narrative traces, or anything else JSON-serializable. The metadata fields
|
|
8
|
+
* around `value` are what make entries first-class objects instead of raw
|
|
9
|
+
* blobs:
|
|
10
|
+
*
|
|
11
|
+
* - `version` — optimistic concurrency (`putIfVersion`) + migration
|
|
12
|
+
* - `tier` — MemGPT-style hot/warm/cold classification
|
|
13
|
+
* - `source` — provenance — "where did this memory come from?"
|
|
14
|
+
* - `lastAccessedAt` / `accessCount` — decay signals
|
|
15
|
+
* - `ttl` — absolute expiry at the storage layer
|
|
16
|
+
* - `embeddingModel`— compatibility check for semantic search
|
|
17
|
+
*
|
|
18
|
+
* Entries are **immutable in spirit** — a "mutation" is a new entry with the
|
|
19
|
+
* same `id` and an incremented `version`. Storage adapters may implement
|
|
20
|
+
* this as an in-place update or an append-only log, but the library treats
|
|
21
|
+
* entries as values.
|
|
22
|
+
*
|
|
23
|
+
* NOTE: `readonly` modifiers are a TypeScript compile-time hint only. At
|
|
24
|
+
* runtime, nothing prevents a consumer from mutating an entry they received.
|
|
25
|
+
* The library's internal code never mutates entries; adapters that wish to
|
|
26
|
+
* enforce this at runtime may `Object.freeze(entry)` before returning.
|
|
27
|
+
*/
|
|
28
|
+
export interface MemoryEntry<T = unknown> {
|
|
29
|
+
/** Stable id within the identity namespace. */
|
|
30
|
+
readonly id: string;
|
|
31
|
+
/** The actual stored payload. JSON-serializable. */
|
|
32
|
+
readonly value: T;
|
|
33
|
+
/**
|
|
34
|
+
* Free-form metadata — tags, labels, user-supplied annotations. Kept
|
|
35
|
+
* separate from the decay / version fields so those stay typed.
|
|
36
|
+
*/
|
|
37
|
+
readonly metadata?: Record<string, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Monotonic version number. Stores use this for `putIfVersion` optimistic
|
|
40
|
+
* concurrency — write only if the entry is still at the version the
|
|
41
|
+
* writer expected. Defaults to 1 on first write; callers increment.
|
|
42
|
+
*/
|
|
43
|
+
readonly version: number;
|
|
44
|
+
/** Unix ms. */
|
|
45
|
+
readonly createdAt: number;
|
|
46
|
+
/** Unix ms. Equal to createdAt on first write. */
|
|
47
|
+
readonly updatedAt: number;
|
|
48
|
+
/** Unix ms. Updated by `store.get` / retrieval stages. Decay input. */
|
|
49
|
+
readonly lastAccessedAt: number;
|
|
50
|
+
/** Number of times this entry has been read. Decay input. */
|
|
51
|
+
readonly accessCount: number;
|
|
52
|
+
/**
|
|
53
|
+
* Optional absolute expiry (unix ms). Storage adapters MUST refuse to
|
|
54
|
+
* return entries past their ttl. Implementations: InMemory filters on
|
|
55
|
+
* read, Redis uses native EXPIRE, DynamoDB uses TTL attribute.
|
|
56
|
+
*/
|
|
57
|
+
readonly ttl?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Optional decay policy applied at retrieval time. When present, stages
|
|
60
|
+
* that rank entries (picker, reranker) decrease relevance for entries
|
|
61
|
+
* whose `lastAccessedAt` is far in the past. See `decay.ts`.
|
|
62
|
+
*/
|
|
63
|
+
readonly decayPolicy?: DecayPolicy;
|
|
64
|
+
/**
|
|
65
|
+
* Tier classification — enables MemGPT-style page-in/page-out policies.
|
|
66
|
+
* Stages can filter by tier (e.g. "load hot entries first, consult cold
|
|
67
|
+
* only under pressure"). Omitting the field means "untiered."
|
|
68
|
+
*/
|
|
69
|
+
readonly tier?: 'hot' | 'warm' | 'cold';
|
|
70
|
+
/**
|
|
71
|
+
* Provenance — which turn / runtime stage / message produced this entry.
|
|
72
|
+
* Lets retrieval cite sources ("remembered from turn 5") and lets
|
|
73
|
+
* `causalChain` cross session boundaries.
|
|
74
|
+
*/
|
|
75
|
+
readonly source?: MemorySource;
|
|
76
|
+
/**
|
|
77
|
+
* Optional dense vector embedding of this entry's value. Populated
|
|
78
|
+
* by semantic-memory pipelines (see `embedMessages` / `embedBeats`
|
|
79
|
+
* stages) when an `Embedder` is configured. Stores that support
|
|
80
|
+
* vector search index on this field; stores that don't ignore it.
|
|
81
|
+
*
|
|
82
|
+
* Vector length MUST match the configured embedder's `dimensions`.
|
|
83
|
+
* Mixing embedders of different sizes within the same identity
|
|
84
|
+
* namespace will break cosine similarity — `store.search()` uses
|
|
85
|
+
* `cosineSimilarity()` which throws on length mismatch.
|
|
86
|
+
*/
|
|
87
|
+
readonly embedding?: readonly number[];
|
|
88
|
+
/**
|
|
89
|
+
* Identifier of the embedder that produced `embedding`. Search
|
|
90
|
+
* stages compare this against the active embedder's id before
|
|
91
|
+
* trusting distance scores — prevents silent retrieval corruption
|
|
92
|
+
* when an embedding model is swapped but old entries are still
|
|
93
|
+
* indexed with the previous vector space.
|
|
94
|
+
*/
|
|
95
|
+
readonly embeddingModel?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Where a memory entry came from. The library populates this automatically
|
|
99
|
+
* when entries are written from inside a memory stage (writeMessages,
|
|
100
|
+
* extractFacts, etc.); consumers can populate it when writing programmatically.
|
|
101
|
+
*
|
|
102
|
+
* When searching across sessions ("did we learn this in a previous session?"),
|
|
103
|
+
* `identity` + `turn` + `runtimeStageId` form a globally-unique causal coordinate
|
|
104
|
+
* — you can replay exactly what the agent was doing when the entry was born.
|
|
105
|
+
*/
|
|
106
|
+
export interface MemorySource {
|
|
107
|
+
/** Run-local turn counter. */
|
|
108
|
+
readonly turn?: number;
|
|
109
|
+
/** footprintjs runtime stage id (`stageId#executionIndex`). */
|
|
110
|
+
readonly runtimeStageId?: string;
|
|
111
|
+
/** Originating message id, if the entry came from a conversation turn. */
|
|
112
|
+
readonly messageId?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Cross-session provenance — the `MemoryIdentity` that produced this entry.
|
|
115
|
+
* Lets retrieval stages show "remembered from session X, user Y, turn 5"
|
|
116
|
+
* instead of anonymous citation. Storage adapters MUST preserve this field
|
|
117
|
+
* verbatim on every read/write.
|
|
118
|
+
*/
|
|
119
|
+
readonly identity?: MemoryIdentity;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Natural-forgetting policy. Decay applies at retrieval time: the entry's
|
|
123
|
+
* stored value is never mutated; only its computed "relevance" is adjusted.
|
|
124
|
+
*
|
|
125
|
+
* Consumers choose half-life + access boost to match their domain:
|
|
126
|
+
* - Fast-moving (news, tickets) — halfLifeMs ≈ 1 day, accessBoost ≈ 1.5
|
|
127
|
+
* - Stable (user profile, facts)— halfLifeMs ≈ 30 days, accessBoost ≈ 1.1
|
|
128
|
+
*/
|
|
129
|
+
export interface DecayPolicy {
|
|
130
|
+
/**
|
|
131
|
+
* How long for relevance to halve when never accessed. Milliseconds.
|
|
132
|
+
*/
|
|
133
|
+
readonly halfLifeMs: number;
|
|
134
|
+
/**
|
|
135
|
+
* Multiplier applied per access (clamped to a reasonable ceiling inside
|
|
136
|
+
* `applyDecay`). Values > 1.0 boost frequently-used entries; values in
|
|
137
|
+
* (0, 1.0) would *reduce* relevance with use (rarely desired).
|
|
138
|
+
*/
|
|
139
|
+
readonly accessBoost: number;
|
|
140
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* extractFacts — write-side stage that distills `scope.newMessages` into
|
|
3
|
+
* `Fact`s via a pluggable `FactExtractor`.
|
|
4
|
+
*
|
|
5
|
+
* Reads from scope: `newMessages`, `turnNumber`, optional `loadedFacts`
|
|
6
|
+
* Writes to scope: `newFacts` (MemoryEntry<Fact>[], ready for writeFacts)
|
|
7
|
+
*
|
|
8
|
+
* The extractor is called ONCE per turn on the turn's new messages. If
|
|
9
|
+
* `scope.loadedFacts` is populated (the write subflow ran `loadFacts`
|
|
10
|
+
* first), existing facts are passed to the extractor so LLM-based
|
|
11
|
+
* extractors can update rather than duplicate.
|
|
12
|
+
*
|
|
13
|
+
* **Stable ids**: each produced entry gets id `fact:${fact.key}`. When
|
|
14
|
+
* the same key is written again in a future turn, the storage layer
|
|
15
|
+
* overwrites in place — no duplicate accumulation. This is the core
|
|
16
|
+
* property that makes facts different from beats (append-only) and
|
|
17
|
+
* messages (append-only).
|
|
18
|
+
*
|
|
19
|
+
* Empty-extraction behavior: `newFacts = []`. Downstream `writeFacts`
|
|
20
|
+
* short-circuits on empty — no store round-trip.
|
|
21
|
+
*/
|
|
22
|
+
import type { TypedScope } from 'footprintjs';
|
|
23
|
+
import type { MemoryEntry } from '../entry/index.js';
|
|
24
|
+
import type { MemoryState } from '../stages/index.js';
|
|
25
|
+
import type { FactExtractor } from './extractor.js';
|
|
26
|
+
import type { Fact } from './types.js';
|
|
27
|
+
export interface ExtractFactsConfig {
|
|
28
|
+
/** The extractor to call. See `patternFactExtractor` / `llmFactExtractor`. */
|
|
29
|
+
readonly extractor: FactExtractor;
|
|
30
|
+
/**
|
|
31
|
+
* Optional tier for the persisted facts. Typical pattern: `'hot'` for
|
|
32
|
+
* current identity / preferences, `'warm'` for older commitments.
|
|
33
|
+
* Omit for no tier.
|
|
34
|
+
*/
|
|
35
|
+
readonly tier?: 'hot' | 'warm' | 'cold';
|
|
36
|
+
/**
|
|
37
|
+
* Optional TTL in ms from `Date.now()` applied to persisted fact
|
|
38
|
+
* entries. Useful for facts that should decay (task statuses,
|
|
39
|
+
* short-term preferences). Identity facts typically have no TTL.
|
|
40
|
+
*/
|
|
41
|
+
readonly ttlMs?: number;
|
|
42
|
+
}
|
|
43
|
+
/** State added to `MemoryState` by the fact pipeline stages. */
|
|
44
|
+
export interface FactPipelineState extends MemoryState {
|
|
45
|
+
/** Produced by `extractFacts`, consumed by `writeFacts`. */
|
|
46
|
+
newFacts?: readonly MemoryEntry<Fact>[];
|
|
47
|
+
/** Produced by `loadFacts`, consumed by `formatFacts` and `extractFacts`. */
|
|
48
|
+
loadedFacts?: readonly MemoryEntry<Fact>[];
|
|
49
|
+
}
|
|
50
|
+
export declare function extractFacts(config: ExtractFactsConfig): (scope: TypedScope<FactPipelineState>) => Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FactExtractor — interface for distilling stable claims out of a turn.
|
|
3
|
+
*
|
|
4
|
+
* Complements `BeatExtractor`: a beat summarizes what happened, a
|
|
5
|
+
* fact captures what's *currently true*. Different extractors produce
|
|
6
|
+
* different levels of structure (pattern-based for quick identity /
|
|
7
|
+
* contact info; LLM-based for rich open-ended extraction).
|
|
8
|
+
*
|
|
9
|
+
* Built-in extractors:
|
|
10
|
+
* - `patternFactExtractor()` — zero-dep regex heuristics for
|
|
11
|
+
* common identity / location / contact patterns.
|
|
12
|
+
* - `llmFactExtractor({ provider })` — one LLM call per turn for
|
|
13
|
+
* open-ended extraction. Opt-in.
|
|
14
|
+
*/
|
|
15
|
+
import type { LLMMessage as Message } from '../../adapters/types.js';
|
|
16
|
+
import type { Fact } from './types.js';
|
|
17
|
+
export interface FactExtractArgs {
|
|
18
|
+
/** New-turn messages. */
|
|
19
|
+
readonly messages: readonly Message[];
|
|
20
|
+
/** Current turn number. Useful for extractors that want it in a source tag. */
|
|
21
|
+
readonly turnNumber: number;
|
|
22
|
+
/**
|
|
23
|
+
* Facts already in the store (if caller has a cheap way to fetch).
|
|
24
|
+
* Passed to extractors that merge / dedupe at extraction time.
|
|
25
|
+
* May be empty even when facts exist — not every pipeline pre-loads.
|
|
26
|
+
*/
|
|
27
|
+
readonly existing?: readonly Fact[];
|
|
28
|
+
/** Optional abort signal for LLM-based extractors. */
|
|
29
|
+
readonly signal?: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
export interface FactExtractor {
|
|
32
|
+
extract(args: FactExtractArgs): Promise<readonly Fact[]>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* formatFacts — render loaded `Fact` entries into a single system
|
|
3
|
+
* message for prompt injection.
|
|
4
|
+
*
|
|
5
|
+
* Reads from scope: `loadedFacts`
|
|
6
|
+
* Writes to scope: `formatted` (Message[] — one system message, or empty)
|
|
7
|
+
*
|
|
8
|
+
* Facts are tiny and semantically distinct from beats/messages, so they
|
|
9
|
+
* render as a compact key/value block rather than a narrative paragraph
|
|
10
|
+
* or per-entry `<memory>` tags. The default shape:
|
|
11
|
+
*
|
|
12
|
+
* Known facts about the user:
|
|
13
|
+
*
|
|
14
|
+
* - user.name: Alice
|
|
15
|
+
* - user.email: alice@example.com
|
|
16
|
+
* - user.preferences.color: blue
|
|
17
|
+
*
|
|
18
|
+
* Why one block, not one message per fact?
|
|
19
|
+
* LLMs parse key/value lists efficiently; splitting would waste
|
|
20
|
+
* tokens on per-message system overhead and break up the list's
|
|
21
|
+
* visual grouping.
|
|
22
|
+
*
|
|
23
|
+
* Why NOT run facts through `pickByBudget`?
|
|
24
|
+
* Facts are typically 10-50 items, each a handful of tokens. Picking
|
|
25
|
+
* subsets is rarely useful — the user either knows your name or
|
|
26
|
+
* they don't. Consumers who *do* want budget-based fact pruning can
|
|
27
|
+
* copy-paste this stage and wrap it with a picker.
|
|
28
|
+
*/
|
|
29
|
+
import type { TypedScope } from 'footprintjs';
|
|
30
|
+
import type { MemoryEntry } from '../entry/index.js';
|
|
31
|
+
import type { Fact } from './types.js';
|
|
32
|
+
import type { FactPipelineState } from './extractFacts.js';
|
|
33
|
+
export interface FormatFactsConfig {
|
|
34
|
+
/**
|
|
35
|
+
* Header prepended to the injected message. Explains to the LLM what
|
|
36
|
+
* follows and what it's for. Override if your app has specific
|
|
37
|
+
* phrasing guidance.
|
|
38
|
+
*/
|
|
39
|
+
readonly header?: string;
|
|
40
|
+
/** Footer appended after the fact list. Empty by default. */
|
|
41
|
+
readonly footer?: string;
|
|
42
|
+
/**
|
|
43
|
+
* When `true`, appends `(conf 0.xx)` after each fact's value. Off by
|
|
44
|
+
* default — confidence is usually noise for the LLM and only useful
|
|
45
|
+
* in audit / debug flows.
|
|
46
|
+
*/
|
|
47
|
+
readonly showConfidence?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Custom per-fact renderer. Receives the entry; returns the block
|
|
50
|
+
* string (without the leading `- ` bullet). Use for app-specific
|
|
51
|
+
* formatting: custom attribution, hiding category info, etc.
|
|
52
|
+
*/
|
|
53
|
+
readonly renderFact?: (entry: MemoryEntry<Fact>) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Inject the message even when `loadedFacts` is empty. Usually
|
|
56
|
+
* undesired — an empty list is noise. Off by default.
|
|
57
|
+
*/
|
|
58
|
+
readonly emitWhenEmpty?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export declare function formatFacts(config?: FormatFactsConfig): (scope: TypedScope<FactPipelineState>) => Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { Fact } from './types.js';
|
|
2
|
+
export { factId, isFactId, isFact, asConfidence } from './types.js';
|
|
3
|
+
export type { FactExtractor, FactExtractArgs } from './extractor.js';
|
|
4
|
+
export { patternFactExtractor } from './patternFactExtractor.js';
|
|
5
|
+
export { llmFactExtractor } from './llmFactExtractor.js';
|
|
6
|
+
export type { LLMFactExtractorConfig } from './llmFactExtractor.js';
|
|
7
|
+
export { extractFacts } from './extractFacts.js';
|
|
8
|
+
export type { ExtractFactsConfig, FactPipelineState } from './extractFacts.js';
|
|
9
|
+
export { writeFacts } from './writeFacts.js';
|
|
10
|
+
export type { WriteFactsConfig } from './writeFacts.js';
|
|
11
|
+
export { loadFacts } from './loadFacts.js';
|
|
12
|
+
export type { LoadFactsConfig } from './loadFacts.js';
|
|
13
|
+
export { formatFacts } from './formatFacts.js';
|
|
14
|
+
export type { FormatFactsConfig } from './formatFacts.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* llmFactExtractor — LLM-backed fact extractor.
|
|
3
|
+
*
|
|
4
|
+
* Uses an LLMProvider (typically a cheap model like Claude Haiku or
|
|
5
|
+
* GPT-4o-mini) to pull stable, timeless claims out of a conversation
|
|
6
|
+
* turn. Complements `patternFactExtractor` — regex catches the obvious
|
|
7
|
+
* self-disclosures, the LLM catches the open-ended ones.
|
|
8
|
+
*
|
|
9
|
+
* The extractor asks the LLM for a JSON response in this shape:
|
|
10
|
+
*
|
|
11
|
+
* ```json
|
|
12
|
+
* {
|
|
13
|
+
* "facts": [
|
|
14
|
+
* {
|
|
15
|
+
* "key": "user.name",
|
|
16
|
+
* "value": "Alice",
|
|
17
|
+
* "confidence": 0.95,
|
|
18
|
+
* "category": "identity",
|
|
19
|
+
* "refs": ["msg-1-0"]
|
|
20
|
+
* }
|
|
21
|
+
* ]
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* The extractor parses, clamps confidence via `asConfidence()`, dedups
|
|
26
|
+
* by `key` (last occurrence wins, matching `patternFactExtractor`),
|
|
27
|
+
* and returns the facts. Malformed responses fall back to `[]` — a bad
|
|
28
|
+
* extraction should not break the agent turn.
|
|
29
|
+
*
|
|
30
|
+
* Usage:
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { anthropic } from 'agentfootprint';
|
|
33
|
+
* import { llmFactExtractor, factPipeline, InMemoryStore } from 'agentfootprint/memory';
|
|
34
|
+
*
|
|
35
|
+
* const pipeline = factPipeline({
|
|
36
|
+
* store: new InMemoryStore(),
|
|
37
|
+
* extractor: llmFactExtractor({ provider: yourLLMProvider }),
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
import type { LLMProvider } from '../../adapters/types.js';
|
|
42
|
+
import type { FactExtractor } from './extractor.js';
|
|
43
|
+
export interface LLMFactExtractorConfig {
|
|
44
|
+
/** The provider used for extraction. Typically a cheap/fast model. */
|
|
45
|
+
readonly provider: LLMProvider;
|
|
46
|
+
/**
|
|
47
|
+
* Override the system prompt. Defaults to a one-paragraph instruction
|
|
48
|
+
* that elicits the JSON shape described in the module docs.
|
|
49
|
+
*/
|
|
50
|
+
readonly systemPrompt?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Dev-mode logger invoked when the LLM response fails to parse.
|
|
53
|
+
* Defaults to `console.warn` — production consumers can route the
|
|
54
|
+
* signal to their telemetry pipeline.
|
|
55
|
+
*/
|
|
56
|
+
readonly onParseError?: (error: unknown, rawContent: string) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Include up to this many existing facts in the user prompt so the
|
|
59
|
+
* model can update / refine rather than duplicate. Set to `0` to
|
|
60
|
+
* skip — cheaper but loses update awareness. Default `16`.
|
|
61
|
+
*/
|
|
62
|
+
readonly includeExistingLimit?: number;
|
|
63
|
+
}
|
|
64
|
+
export declare function llmFactExtractor(config: LLMFactExtractorConfig): FactExtractor;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loadFacts — read-side stage that loads stored `Fact` entries into
|
|
3
|
+
* `scope.loadedFacts`.
|
|
4
|
+
*
|
|
5
|
+
* Reads from scope: `identity`
|
|
6
|
+
* Writes to scope: `loadedFacts` (appends — does not replace)
|
|
7
|
+
*
|
|
8
|
+
* Unlike `loadRecent` (which returns ALL entries and lets downstream
|
|
9
|
+
* stages filter), `loadFacts` queries the store and keeps only entries
|
|
10
|
+
* whose id matches the `fact:` prefix. Facts are typically few dozen
|
|
11
|
+
* at most per identity — a linear scan after a bounded `list` call is
|
|
12
|
+
* cheap.
|
|
13
|
+
*
|
|
14
|
+
* Why append, not replace?
|
|
15
|
+
* Same contract as `loadRecent` — pipelines may combine multiple
|
|
16
|
+
* load stages (e.g. facts + recent messages + beats). Appending lets
|
|
17
|
+
* each contribute without coordination.
|
|
18
|
+
*
|
|
19
|
+
* Note: this stage writes `loadedFacts` (a separate field from
|
|
20
|
+
* `loaded`) because fact entries have a different payload type
|
|
21
|
+
* (`MemoryEntry<Fact>`) than message entries (`MemoryEntry<Message>`).
|
|
22
|
+
* Keeping them separate prevents format stages from misrouting entries.
|
|
23
|
+
*/
|
|
24
|
+
import type { TypedScope } from 'footprintjs';
|
|
25
|
+
import type { MemoryStore } from '../store/index.js';
|
|
26
|
+
import type { FactPipelineState } from './extractFacts.js';
|
|
27
|
+
export interface LoadFactsConfig {
|
|
28
|
+
/** The store to read from. */
|
|
29
|
+
readonly store: MemoryStore;
|
|
30
|
+
/**
|
|
31
|
+
* Upper bound on the `list` call's page size. Adapters may cap this
|
|
32
|
+
* lower. Defaults to 100 — enough for typical identity/preference
|
|
33
|
+
* inventories. Fact pipelines that accumulate task statuses or
|
|
34
|
+
* commitments should raise this.
|
|
35
|
+
*/
|
|
36
|
+
readonly limit?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Optional tier filter. When set, only loads facts tagged with one
|
|
39
|
+
* of these tiers. Matches the `loadRecent` / `loadRelevant` API.
|
|
40
|
+
*/
|
|
41
|
+
readonly tiers?: ReadonlyArray<'hot' | 'warm' | 'cold'>;
|
|
42
|
+
}
|
|
43
|
+
export declare function loadFacts(config: LoadFactsConfig): (scope: TypedScope<FactPipelineState>) => Promise<void>;
|