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.
Files changed (442) hide show
  1. package/AGENTS.md +4 -0
  2. package/CLAUDE.md +4 -0
  3. package/README.md +141 -167
  4. package/ai-instructions/claude-code/SKILL.md +11 -0
  5. package/ai-instructions/setup.sh +0 -0
  6. package/dist/adapters/llm/BrowserOpenAIProvider.js +1 -1
  7. package/dist/adapters/llm/MockProvider.js +2 -1
  8. package/dist/adapters/llm/MockProvider.js.map +1 -1
  9. package/dist/core/agent/buildAgentChart.js +2 -1
  10. package/dist/core/agent/buildAgentChart.js.map +1 -1
  11. package/dist/core/agent/buildDynamicAgentChart.js +3 -1
  12. package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
  13. package/dist/core/agent/stages/pickEntry.js +3 -1
  14. package/dist/core/agent/stages/pickEntry.js.map +1 -1
  15. package/dist/debug/finders.js +29 -0
  16. package/dist/debug/finders.js.map +1 -0
  17. package/dist/debug.js +134 -0
  18. package/dist/debug.js.map +1 -0
  19. package/dist/esm/adapters/identity/agentcore.d.ts +100 -0
  20. package/dist/esm/adapters/llm/AnthropicProvider.d.ts +130 -0
  21. package/dist/esm/adapters/llm/BedrockProvider.d.ts +100 -0
  22. package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +41 -0
  23. package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +95 -0
  24. package/dist/esm/adapters/llm/BrowserOpenAIProvider.js +1 -1
  25. package/dist/esm/adapters/llm/MockProvider.d.ts +154 -0
  26. package/dist/esm/adapters/llm/MockProvider.js +2 -1
  27. package/dist/esm/adapters/llm/MockProvider.js.map +1 -1
  28. package/dist/esm/adapters/llm/OpenAIProvider.d.ts +220 -0
  29. package/dist/esm/adapters/llm/createProvider.d.ts +85 -0
  30. package/dist/esm/adapters/memory/agentcore.d.ts +146 -0
  31. package/dist/esm/adapters/memory/bedrockAgentMemory.d.ts +95 -0
  32. package/dist/esm/adapters/memory/redis.d.ts +127 -0
  33. package/dist/esm/adapters/observability/agentcore.d.ts +67 -0
  34. package/dist/esm/adapters/observability/audit.d.ts +254 -0
  35. package/dist/esm/adapters/observability/cloudwatch.d.ts +96 -0
  36. package/dist/esm/adapters/observability/otel.d.ts +237 -0
  37. package/dist/esm/adapters/observability/xray.d.ts +88 -0
  38. package/dist/esm/adapters/types.d.ts +378 -0
  39. package/dist/esm/bridge/eventMeta.d.ts +59 -0
  40. package/dist/esm/cache/CacheDecisionSubflow.d.ts +85 -0
  41. package/dist/esm/cache/CacheGateDecider.d.ts +127 -0
  42. package/dist/esm/cache/applyCachePolicy.d.ts +37 -0
  43. package/dist/esm/cache/cacheRecorder.d.ts +85 -0
  44. package/dist/esm/cache/index.d.ts +33 -0
  45. package/dist/esm/cache/strategies/AnthropicCacheStrategy.d.ts +38 -0
  46. package/dist/esm/cache/strategies/BedrockCacheStrategy.d.ts +33 -0
  47. package/dist/esm/cache/strategies/NoOpCacheStrategy.d.ts +29 -0
  48. package/dist/esm/cache/strategies/OpenAICacheStrategy.d.ts +36 -0
  49. package/dist/esm/cache/strategyRegistry.d.ts +45 -0
  50. package/dist/esm/cache/types.d.ts +243 -0
  51. package/dist/esm/conventions.d.ts +203 -0
  52. package/dist/esm/core/Agent.d.ts +355 -0
  53. package/dist/esm/core/LLMCall.d.ts +139 -0
  54. package/dist/esm/core/RunnerBase.d.ts +267 -0
  55. package/dist/esm/core/agent/AgentBuilder.d.ts +565 -0
  56. package/dist/esm/core/agent/buildAgentChart.d.ts +109 -0
  57. package/dist/esm/core/agent/buildAgentChart.js +2 -1
  58. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  59. package/dist/esm/core/agent/buildAgentMessageApiChart.d.ts +40 -0
  60. package/dist/esm/core/agent/buildCacheSubflow.d.ts +35 -0
  61. package/dist/esm/core/agent/buildDynamicAgentChart.d.ts +56 -0
  62. package/dist/esm/core/agent/buildDynamicAgentChart.js +3 -1
  63. package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
  64. package/dist/esm/core/agent/buildMessageApiChart.d.ts +47 -0
  65. package/dist/esm/core/agent/buildToolRegistry.d.ts +61 -0
  66. package/dist/esm/core/agent/memoryRecallInjections.d.ts +8 -0
  67. package/dist/esm/core/agent/stages/breakFinal.d.ts +22 -0
  68. package/dist/esm/core/agent/stages/callLLM.d.ts +74 -0
  69. package/dist/esm/core/agent/stages/pickEntry.d.ts +19 -0
  70. package/dist/esm/core/agent/stages/pickEntry.js +3 -1
  71. package/dist/esm/core/agent/stages/pickEntry.js.map +1 -1
  72. package/dist/esm/core/agent/stages/prepareFinal.d.ts +19 -0
  73. package/dist/esm/core/agent/stages/reliabilityExecution.d.ts +135 -0
  74. package/dist/esm/core/agent/stages/route.d.ts +18 -0
  75. package/dist/esm/core/agent/stages/seed.d.ts +53 -0
  76. package/dist/esm/core/agent/stages/toolCalls.d.ts +76 -0
  77. package/dist/esm/core/agent/toolArgsValidation.d.ts +62 -0
  78. package/dist/esm/core/agent/types.d.ts +382 -0
  79. package/dist/esm/core/agent/validators.d.ts +52 -0
  80. package/dist/esm/core/cost.d.ts +38 -0
  81. package/dist/esm/core/flowchartAsTool.d.ts +200 -0
  82. package/dist/esm/core/humanizeLLMError.d.ts +23 -0
  83. package/dist/esm/core/outputFallback.d.ts +139 -0
  84. package/dist/esm/core/outputSchema.d.ts +127 -0
  85. package/dist/esm/core/pause.d.ts +74 -0
  86. package/dist/esm/core/runCheckpoint.d.ts +179 -0
  87. package/dist/esm/core/runner.d.ts +203 -0
  88. package/dist/esm/core/slots/buildMessagesSlot.d.ts +40 -0
  89. package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +41 -0
  90. package/dist/esm/core/slots/buildThinkingSubflow.d.ts +40 -0
  91. package/dist/esm/core/slots/buildToolsSlot.d.ts +60 -0
  92. package/dist/esm/core/slots/helpers.d.ts +27 -0
  93. package/dist/esm/core/toolContract.d.ts +43 -0
  94. package/dist/esm/core/tools.d.ts +90 -0
  95. package/dist/esm/core/translator.d.ts +94 -0
  96. package/dist/esm/core-flow/Conditional.d.ts +119 -0
  97. package/dist/esm/core-flow/Loop.d.ts +160 -0
  98. package/dist/esm/core-flow/Parallel.d.ts +360 -0
  99. package/dist/esm/core-flow/Sequence.d.ts +133 -0
  100. package/dist/esm/debug/finders.d.ts +12 -0
  101. package/dist/esm/debug/finders.js +13 -0
  102. package/dist/esm/debug/finders.js.map +1 -0
  103. package/dist/esm/debug.d.ts +25 -0
  104. package/dist/esm/debug.js +54 -0
  105. package/dist/esm/debug.js.map +1 -0
  106. package/dist/esm/events/dispatcher.d.ts +134 -0
  107. package/dist/esm/events/payloads.d.ts +761 -0
  108. package/dist/esm/events/registry.d.ts +198 -0
  109. package/dist/esm/events/types.d.ts +70 -0
  110. package/dist/esm/events.d.ts +18 -0
  111. package/dist/esm/events.js +22 -0
  112. package/dist/esm/events.js.map +1 -0
  113. package/dist/esm/identity/kinds.d.ts +36 -0
  114. package/dist/esm/identity/staticTokens.d.ts +28 -0
  115. package/dist/esm/identity/types.d.ts +113 -0
  116. package/dist/esm/identity/withCredentialRetry.d.ts +64 -0
  117. package/dist/esm/identity.d.ts +31 -0
  118. package/dist/esm/index.d.ts +44 -0
  119. package/dist/esm/index.js +7 -52
  120. package/dist/esm/index.js.map +1 -1
  121. package/dist/esm/injection-engine.d.ts +4 -0
  122. package/dist/esm/lib/canonicalJson.d.ts +56 -0
  123. package/dist/esm/lib/context-bisect/ablation.d.ts +109 -0
  124. package/dist/esm/lib/context-bisect/bisect.d.ts +75 -0
  125. package/dist/esm/lib/context-bisect/cost.d.ts +37 -0
  126. package/dist/esm/lib/context-bisect/index.d.ts +31 -0
  127. package/dist/esm/lib/context-bisect/index.js +3 -0
  128. package/dist/esm/lib/context-bisect/index.js.map +1 -1
  129. package/dist/esm/lib/context-bisect/llmEdgeWeigher.d.ts +124 -0
  130. package/dist/esm/lib/context-bisect/localize.d.ts +152 -0
  131. package/dist/esm/lib/context-bisect/localize.js +2 -0
  132. package/dist/esm/lib/context-bisect/localize.js.map +1 -1
  133. package/dist/esm/lib/context-bisect/loop-recall.d.ts +97 -0
  134. package/dist/esm/lib/context-bisect/missingContext.d.ts +71 -0
  135. package/dist/esm/lib/context-bisect/restoration.d.ts +39 -0
  136. package/dist/esm/lib/context-bisect/toBacktrackTrace.d.ts +138 -0
  137. package/dist/esm/lib/context-bisect/trajectory.d.ts +168 -0
  138. package/dist/esm/lib/context-bisect/types.d.ts +448 -0
  139. package/dist/esm/lib/context-bisect/walk-to-root.d.ts +103 -0
  140. package/dist/esm/lib/influence-core/attributability.d.ts +72 -0
  141. package/dist/esm/lib/influence-core/cache.d.ts +94 -0
  142. package/dist/esm/lib/influence-core/contrastive.d.ts +26 -0
  143. package/dist/esm/lib/influence-core/index.d.ts +34 -0
  144. package/dist/esm/lib/influence-core/margin.d.ts +33 -0
  145. package/dist/esm/lib/influence-core/signals.d.ts +128 -0
  146. package/dist/esm/lib/influence-core/similarity.d.ts +25 -0
  147. package/dist/esm/lib/influence-core/types.d.ts +252 -0
  148. package/dist/esm/lib/injection-engine/SkillRegistry.d.ts +147 -0
  149. package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.d.ts +110 -0
  150. package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
  151. package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
  152. package/dist/esm/lib/injection-engine/entryScorer.d.ts +93 -0
  153. package/dist/esm/lib/injection-engine/entryScorer.js +172 -0
  154. package/dist/esm/lib/injection-engine/entryScorer.js.map +1 -0
  155. package/dist/esm/lib/injection-engine/evaluator.d.ts +24 -0
  156. package/dist/esm/lib/injection-engine/factories/defineFact.d.ts +60 -0
  157. package/dist/esm/lib/injection-engine/factories/defineInjection.d.ts +41 -0
  158. package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +78 -0
  159. package/dist/esm/lib/injection-engine/factories/defineRelevanceHint.d.ts +26 -0
  160. package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +160 -0
  161. package/dist/esm/lib/injection-engine/factories/defineSteering.d.ts +39 -0
  162. package/dist/esm/lib/injection-engine/index.d.ts +22 -0
  163. package/dist/esm/lib/injection-engine/index.js +2 -1
  164. package/dist/esm/lib/injection-engine/index.js.map +1 -1
  165. package/dist/esm/lib/injection-engine/skillContract.d.ts +29 -0
  166. package/dist/esm/lib/injection-engine/skillGraph.d.ts +290 -0
  167. package/dist/esm/lib/injection-engine/skillGraph.js +38 -43
  168. package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
  169. package/dist/esm/lib/injection-engine/skillGraphCheckup.d.ts +49 -0
  170. package/dist/esm/lib/injection-engine/skillTools.d.ts +72 -0
  171. package/dist/esm/lib/injection-engine/softmax.d.ts +11 -0
  172. package/dist/esm/lib/injection-engine/types.d.ts +229 -0
  173. package/dist/esm/lib/injection-engine/types.js.map +1 -1
  174. package/dist/esm/lib/lazyRequire.d.ts +29 -0
  175. package/dist/esm/lib/mcp/index.d.ts +9 -0
  176. package/dist/esm/lib/mcp/mcpClient.d.ts +46 -0
  177. package/dist/esm/lib/mcp/mockMcpClient.d.ts +65 -0
  178. package/dist/esm/lib/mcp/types.d.ts +133 -0
  179. package/dist/esm/lib/rag/defineRAG.d.ts +139 -0
  180. package/dist/esm/lib/rag/defineRAG.js +3 -3
  181. package/dist/esm/lib/rag/index.d.ts +7 -0
  182. package/dist/esm/lib/rag/indexDocuments.d.ts +106 -0
  183. package/dist/esm/lib/rag/indexDocuments.js +2 -1
  184. package/dist/esm/lib/rag/indexDocuments.js.map +1 -1
  185. package/dist/esm/lib/tool-lint/analyze.d.ts +83 -0
  186. package/dist/esm/lib/tool-lint/cli.d.ts +43 -0
  187. package/dist/esm/lib/tool-lint/format.d.ts +18 -0
  188. package/dist/esm/lib/tool-lint/index.d.ts +23 -0
  189. package/dist/esm/lib/tool-lint/rules.d.ts +85 -0
  190. package/dist/esm/lib/tool-lint/types.d.ts +155 -0
  191. package/dist/esm/lib/trace-toolpack/bounded.d.ts +47 -0
  192. package/dist/esm/lib/trace-toolpack/debugPrompt.d.ts +19 -0
  193. package/dist/esm/lib/trace-toolpack/index.d.ts +20 -0
  194. package/dist/esm/lib/trace-toolpack/lazyToolpack.d.ts +35 -0
  195. package/dist/esm/lib/trace-toolpack/selfExplain.d.ts +100 -0
  196. package/dist/esm/lib/trace-toolpack/traceDebugAgent.d.ts +42 -0
  197. package/dist/esm/lib/trace-toolpack/traceToolpack.d.ts +69 -0
  198. package/dist/esm/lib/trace-toolpack/types.d.ts +59 -0
  199. package/dist/esm/llm-providers.d.ts +26 -0
  200. package/dist/esm/locales/index.d.ts +141 -0
  201. package/dist/esm/locales/index.js +7 -0
  202. package/dist/esm/locales/index.js.map +1 -1
  203. package/dist/esm/memory/beats/extractBeats.d.ts +61 -0
  204. package/dist/esm/memory/beats/extractor.d.ts +47 -0
  205. package/dist/esm/memory/beats/formatAsNarrative.d.ts +62 -0
  206. package/dist/esm/memory/beats/heuristicExtractor.d.ts +37 -0
  207. package/dist/esm/memory/beats/index.d.ts +12 -0
  208. package/dist/esm/memory/beats/llmExtractor.d.ts +56 -0
  209. package/dist/esm/memory/beats/types.d.ts +60 -0
  210. package/dist/esm/memory/beats/writeBeats.d.ts +22 -0
  211. package/dist/esm/memory/causal/evidenceRecorder.d.ts +66 -0
  212. package/dist/esm/memory/causal/index.d.ts +6 -0
  213. package/dist/esm/memory/causal/loadSnapshot.d.ts +51 -0
  214. package/dist/esm/memory/causal/snapshotPipeline.d.ts +35 -0
  215. package/dist/esm/memory/causal/types.d.ts +134 -0
  216. package/dist/esm/memory/causal/types.js.map +1 -1
  217. package/dist/esm/memory/causal/writeSnapshot.d.ts +73 -0
  218. package/dist/esm/memory/define.d.ts +63 -0
  219. package/dist/esm/memory/define.types.d.ts +278 -0
  220. package/dist/esm/memory/define.types.js +6 -4
  221. package/dist/esm/memory/define.types.js.map +1 -1
  222. package/dist/esm/memory/embedding/cosine.d.ts +18 -0
  223. package/dist/esm/memory/embedding/embedMessages.d.ts +58 -0
  224. package/dist/esm/memory/embedding/index.d.ts +8 -0
  225. package/dist/esm/memory/embedding/loadRelevant.d.ts +51 -0
  226. package/dist/esm/memory/embedding/mockEmbedder.d.ts +22 -0
  227. package/dist/esm/memory/embedding/types.d.ts +46 -0
  228. package/dist/esm/memory/entry/decay.d.ts +36 -0
  229. package/dist/esm/memory/entry/index.d.ts +2 -0
  230. package/dist/esm/memory/entry/types.d.ts +140 -0
  231. package/dist/esm/memory/facts/extractFacts.d.ts +50 -0
  232. package/dist/esm/memory/facts/extractor.d.ts +33 -0
  233. package/dist/esm/memory/facts/formatFacts.d.ts +60 -0
  234. package/dist/esm/memory/facts/index.d.ts +14 -0
  235. package/dist/esm/memory/facts/llmFactExtractor.d.ts +64 -0
  236. package/dist/esm/memory/facts/loadFacts.d.ts +43 -0
  237. package/dist/esm/memory/facts/patternFactExtractor.d.ts +2 -0
  238. package/dist/esm/memory/facts/types.d.ts +68 -0
  239. package/dist/esm/memory/facts/writeFacts.d.ts +19 -0
  240. package/dist/esm/memory/identity/index.d.ts +2 -0
  241. package/dist/esm/memory/identity/types.d.ts +49 -0
  242. package/dist/esm/memory/index.d.ts +19 -0
  243. package/dist/esm/memory/pipeline/auto.d.ts +59 -0
  244. package/dist/esm/memory/pipeline/default.d.ts +49 -0
  245. package/dist/esm/memory/pipeline/ephemeral.d.ts +28 -0
  246. package/dist/esm/memory/pipeline/fact.d.ts +26 -0
  247. package/dist/esm/memory/pipeline/index.d.ts +13 -0
  248. package/dist/esm/memory/pipeline/narrative.d.ts +35 -0
  249. package/dist/esm/memory/pipeline/semantic.d.ts +37 -0
  250. package/dist/esm/memory/pipeline/types.d.ts +31 -0
  251. package/dist/esm/memory/stages/formatDefault.d.ts +64 -0
  252. package/dist/esm/memory/stages/index.d.ts +13 -0
  253. package/dist/esm/memory/stages/loadRecent.d.ts +49 -0
  254. package/dist/esm/memory/stages/pickByBudget.d.ts +63 -0
  255. package/dist/esm/memory/stages/summarize.d.ts +87 -0
  256. package/dist/esm/memory/stages/tokenize.d.ts +43 -0
  257. package/dist/esm/memory/stages/types.d.ts +75 -0
  258. package/dist/esm/memory/stages/writeMessages.d.ts +71 -0
  259. package/dist/esm/memory/store/InMemoryStore.d.ts +62 -0
  260. package/dist/esm/memory/store/index.d.ts +2 -0
  261. package/dist/esm/memory/store/types.d.ts +223 -0
  262. package/dist/esm/memory/wire/index.d.ts +2 -0
  263. package/dist/esm/memory/wire/mountMemoryPipeline.d.ts +108 -0
  264. package/dist/esm/memory-providers.d.ts +37 -0
  265. package/dist/esm/observability/contextError/finders/compareFinders.d.ts +19 -0
  266. package/dist/esm/observability/contextError/finders/index.d.ts +22 -0
  267. package/dist/esm/observability/contextError/finders/rankSuspects.d.ts +2 -0
  268. package/dist/esm/observability/contextError/finders/removeAndRetry.d.ts +11 -0
  269. package/dist/esm/observability/contextError/finders/shrinkToCause.d.ts +11 -0
  270. package/dist/esm/observability/contextError/finders/testManyCombos.d.ts +11 -0
  271. package/dist/esm/observability/contextError/finders/traceSteps.d.ts +2 -0
  272. package/dist/esm/observability/contextError/finders/types.d.ts +88 -0
  273. package/dist/esm/observability-providers.d.ts +46 -0
  274. package/dist/esm/observe.d.ts +57 -0
  275. package/dist/esm/observe.js +7 -36
  276. package/dist/esm/observe.js.map +1 -1
  277. package/dist/esm/patterns/Debate.d.ts +39 -0
  278. package/dist/esm/patterns/MapReduce.d.ts +66 -0
  279. package/dist/esm/patterns/Reflection.d.ts +51 -0
  280. package/dist/esm/patterns/SelfConsistency.d.ts +43 -0
  281. package/dist/esm/patterns/Swarm.d.ts +60 -0
  282. package/dist/esm/patterns/ToT.d.ts +53 -0
  283. package/dist/esm/patterns/index.d.ts +22 -0
  284. package/dist/esm/providers.d.ts +33 -0
  285. package/dist/esm/providers.js +1 -1
  286. package/dist/esm/providers.js.map +1 -1
  287. package/dist/esm/recorders/core/AgentRecorder.d.ts +15 -0
  288. package/dist/esm/recorders/core/CompositionRecorder.d.ts +17 -0
  289. package/dist/esm/recorders/core/ContextEvaluatedRecorder.d.ts +23 -0
  290. package/dist/esm/recorders/core/ContextRecorder.d.ts +47 -0
  291. package/dist/esm/recorders/core/CostRecorder.d.ts +14 -0
  292. package/dist/esm/recorders/core/EmitBridge.d.ts +30 -0
  293. package/dist/esm/recorders/core/ErrorBridge.d.ts +38 -0
  294. package/dist/esm/recorders/core/EvalRecorder.d.ts +16 -0
  295. package/dist/esm/recorders/core/MemoryRecorder.d.ts +17 -0
  296. package/dist/esm/recorders/core/PermissionRecorder.d.ts +16 -0
  297. package/dist/esm/recorders/core/ReliabilityRecorder.d.ts +24 -0
  298. package/dist/esm/recorders/core/SkillRecorder.d.ts +14 -0
  299. package/dist/esm/recorders/core/StreamRecorder.d.ts +15 -0
  300. package/dist/esm/recorders/core/ToolsRecorder.d.ts +18 -0
  301. package/dist/esm/recorders/core/ValidationRecorder.d.ts +16 -0
  302. package/dist/esm/recorders/core/contextEngineering.d.ts +136 -0
  303. package/dist/esm/recorders/core/typedEmit.d.ts +34 -0
  304. package/dist/esm/recorders/core/types.d.ts +97 -0
  305. package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.d.ts +117 -0
  306. package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +546 -0
  307. package/dist/esm/recorders/observability/FlowchartRecorder.d.ts +220 -0
  308. package/dist/esm/recorders/observability/LiveStateRecorder.d.ts +250 -0
  309. package/dist/esm/recorders/observability/LoggingRecorder.d.ts +91 -0
  310. package/dist/esm/recorders/observability/RouteRecorder.d.ts +83 -0
  311. package/dist/esm/recorders/observability/RunStepRecorder.d.ts +231 -0
  312. package/dist/esm/recorders/observability/StatusRecorder.d.ts +36 -0
  313. package/dist/esm/recorders/observability/ToolChoiceRecorder.d.ts +164 -0
  314. package/dist/esm/recorders/observability/ToolLineageRecorder.d.ts +71 -0
  315. package/dist/esm/recorders/observability/commentary/commentaryTemplates.d.ts +105 -0
  316. package/dist/esm/recorders/observability/internal/ActorArrowClassifier.d.ts +25 -0
  317. package/dist/esm/recorders/observability/internal/CandidateAnswerBuffer.d.ts +28 -0
  318. package/dist/esm/recorders/observability/internal/ForkTracker.d.ts +60 -0
  319. package/dist/esm/recorders/observability/internal/RootInferrer.d.ts +51 -0
  320. package/dist/esm/recorders/observability/internal/SequenceSiblingTracker.d.ts +24 -0
  321. package/dist/esm/recorders/observability/localObservability.d.ts +48 -0
  322. package/dist/esm/recorders/observability/observeRunId.d.ts +36 -0
  323. package/dist/esm/recorders/observability/status/statusTemplates.d.ts +106 -0
  324. package/dist/esm/recorders/observability/trace.d.ts +119 -0
  325. package/dist/esm/reliability/CircuitBreaker.d.ts +75 -0
  326. package/dist/esm/reliability/buildReliabilityGateChart.d.ts +53 -0
  327. package/dist/esm/reliability/classifyError.d.ts +28 -0
  328. package/dist/esm/reliability/index.d.ts +35 -0
  329. package/dist/esm/reliability/types.d.ts +327 -0
  330. package/dist/esm/resilience/fallbackProvider.d.ts +33 -0
  331. package/dist/esm/resilience/index.d.ts +21 -0
  332. package/dist/esm/resilience/withCircuitBreaker.d.ts +129 -0
  333. package/dist/esm/resilience/withFallback.d.ts +45 -0
  334. package/dist/esm/resilience/withRetry.d.ts +71 -0
  335. package/dist/esm/security/PermissionPolicy.d.ts +124 -0
  336. package/dist/esm/security/PolicyHaltError.d.ts +72 -0
  337. package/dist/esm/security/extractSequence.d.ts +46 -0
  338. package/dist/esm/security/index.d.ts +44 -0
  339. package/dist/esm/security/thinkingRedaction.d.ts +50 -0
  340. package/dist/esm/status.d.ts +54 -0
  341. package/dist/esm/status.js +13 -4
  342. package/dist/esm/status.js.map +1 -1
  343. package/dist/esm/strategies/attach.d.ts +47 -0
  344. package/dist/esm/strategies/compose.d.ts +48 -0
  345. package/dist/esm/strategies/defaults/chatBubbleLiveStatus.d.ts +36 -0
  346. package/dist/esm/strategies/defaults/consoleObservability.d.ts +42 -0
  347. package/dist/esm/strategies/defaults/inMemorySinkCost.d.ts +50 -0
  348. package/dist/esm/strategies/defaults/index.d.ts +30 -0
  349. package/dist/esm/strategies/defaults/noopLens.d.ts +28 -0
  350. package/dist/esm/strategies/index.d.ts +36 -0
  351. package/dist/esm/strategies/registry.d.ts +70 -0
  352. package/dist/esm/strategies/types.d.ts +303 -0
  353. package/dist/esm/stream.d.ts +82 -0
  354. package/dist/esm/thinking/AnthropicThinkingHandler.d.ts +42 -0
  355. package/dist/esm/thinking/MockThinkingHandler.d.ts +50 -0
  356. package/dist/esm/thinking/OpenAIThinkingHandler.d.ts +37 -0
  357. package/dist/esm/thinking/index.d.ts +51 -0
  358. package/dist/esm/thinking/registry.d.ts +33 -0
  359. package/dist/esm/thinking/types.d.ts +162 -0
  360. package/dist/esm/tool-providers/gatedTools.d.ts +36 -0
  361. package/dist/esm/tool-providers/index.d.ts +41 -0
  362. package/dist/esm/tool-providers/skillScopedTools.d.ts +45 -0
  363. package/dist/esm/tool-providers/staticTools.d.ts +21 -0
  364. package/dist/esm/tool-providers/types.d.ts +138 -0
  365. package/dist/events.js +42 -0
  366. package/dist/events.js.map +1 -0
  367. package/dist/index.js +7 -117
  368. package/dist/index.js.map +1 -1
  369. package/dist/lib/context-bisect/index.js +3 -0
  370. package/dist/lib/context-bisect/index.js.map +1 -1
  371. package/dist/lib/context-bisect/localize.js +2 -0
  372. package/dist/lib/context-bisect/localize.js.map +1 -1
  373. package/dist/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
  374. package/dist/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
  375. package/dist/lib/injection-engine/entryScorer.js +178 -0
  376. package/dist/lib/injection-engine/entryScorer.js.map +1 -0
  377. package/dist/lib/injection-engine/index.js +6 -2
  378. package/dist/lib/injection-engine/index.js.map +1 -1
  379. package/dist/lib/injection-engine/skillGraph.js +40 -45
  380. package/dist/lib/injection-engine/skillGraph.js.map +1 -1
  381. package/dist/lib/injection-engine/types.js.map +1 -1
  382. package/dist/lib/rag/defineRAG.js +3 -3
  383. package/dist/lib/rag/indexDocuments.js +2 -1
  384. package/dist/lib/rag/indexDocuments.js.map +1 -1
  385. package/dist/locales/index.js +2 -1
  386. package/dist/locales/index.js.map +1 -1
  387. package/dist/memory/causal/types.js.map +1 -1
  388. package/dist/memory/define.types.js +6 -4
  389. package/dist/memory/define.types.js.map +1 -1
  390. package/dist/observe.js +22 -115
  391. package/dist/observe.js.map +1 -1
  392. package/dist/providers.js +3 -1
  393. package/dist/providers.js.map +1 -1
  394. package/dist/status.js +13 -5
  395. package/dist/status.js.map +1 -1
  396. package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts +1 -1
  397. package/dist/types/adapters/llm/MockProvider.d.ts +2 -1
  398. package/dist/types/adapters/llm/MockProvider.d.ts.map +1 -1
  399. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  400. package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
  401. package/dist/types/core/agent/stages/pickEntry.d.ts.map +1 -1
  402. package/dist/types/core/agent/types.d.ts +8 -4
  403. package/dist/types/core/agent/types.d.ts.map +1 -1
  404. package/dist/types/debug/finders.d.ts +13 -0
  405. package/dist/types/debug/finders.d.ts.map +1 -0
  406. package/dist/types/debug.d.ts +26 -0
  407. package/dist/types/debug.d.ts.map +1 -0
  408. package/dist/types/events.d.ts +19 -0
  409. package/dist/types/events.d.ts.map +1 -0
  410. package/dist/types/index.d.ts +4 -24
  411. package/dist/types/index.d.ts.map +1 -1
  412. package/dist/types/lib/context-bisect/index.d.ts +3 -0
  413. package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
  414. package/dist/types/lib/context-bisect/localize.d.ts +2 -0
  415. package/dist/types/lib/context-bisect/localize.d.ts.map +1 -1
  416. package/dist/types/lib/injection-engine/buildInjectionEngineSubflow.d.ts.map +1 -1
  417. package/dist/types/lib/injection-engine/entryScorer.d.ts +94 -0
  418. package/dist/types/lib/injection-engine/entryScorer.d.ts.map +1 -0
  419. package/dist/types/lib/injection-engine/index.d.ts +2 -1
  420. package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
  421. package/dist/types/lib/injection-engine/skillGraph.d.ts +24 -26
  422. package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
  423. package/dist/types/lib/injection-engine/types.d.ts +9 -4
  424. package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
  425. package/dist/types/lib/rag/defineRAG.d.ts +3 -3
  426. package/dist/types/lib/rag/indexDocuments.d.ts +2 -1
  427. package/dist/types/lib/rag/indexDocuments.d.ts.map +1 -1
  428. package/dist/types/locales/index.d.ts +9 -0
  429. package/dist/types/locales/index.d.ts.map +1 -1
  430. package/dist/types/memory/causal/types.d.ts +13 -9
  431. package/dist/types/memory/causal/types.d.ts.map +1 -1
  432. package/dist/types/memory/define.types.d.ts +6 -4
  433. package/dist/types/memory/define.types.d.ts.map +1 -1
  434. package/dist/types/observe.d.ts +1 -6
  435. package/dist/types/observe.d.ts.map +1 -1
  436. package/dist/types/providers.d.ts +2 -2
  437. package/dist/types/providers.d.ts.map +1 -1
  438. package/dist/types/status.d.ts +10 -4
  439. package/dist/types/status.d.ts.map +1 -1
  440. package/dist/types/tool-providers/index.d.ts +1 -1
  441. package/dist/types/tool-providers/index.d.ts.map +1 -1
  442. package/package.json +261 -57
@@ -0,0 +1,35 @@
1
+ /**
2
+ * snapshotPipeline — composes `loadSnapshot` + `writeSnapshot` into a
3
+ * `MemoryPipeline` ready to be mounted by `defineMemory({ type: CAUSAL })`.
4
+ *
5
+ * READ : LoadSnapshot — embed query → search → project → format
6
+ * WRITE : WriteSnapshot — embed query → store as MemoryEntry<SnapshotEntry>
7
+ *
8
+ * The pipeline emits the same `agentfootprint.context.injected` event
9
+ * (with `source: 'memory'`) as every other memory flavor, so Lens
10
+ * shows Causal injections as memory chips alongside Episodic /
11
+ * Semantic / Narrative without special UI.
12
+ */
13
+ import type { MemoryStore } from '../store/index.js';
14
+ import type { Embedder } from '../embedding/index.js';
15
+ import type { MemoryPipeline } from '../pipeline/types.js';
16
+ import type { SnapshotProjection } from '../define.types.js';
17
+ export interface SnapshotPipelineConfig {
18
+ /** Vector-capable store for the snapshots. Must implement `search()`. */
19
+ readonly store: MemoryStore;
20
+ /** Embedder used for both write-side indexing and read-side query. */
21
+ readonly embedder: Embedder;
22
+ /** Stable id of the embedder — prevents cross-model similarity pollution. */
23
+ readonly embedderId?: string;
24
+ /** Top-k past snapshots to consider on read. Default 1. */
25
+ readonly topK?: number;
26
+ /** Cosine threshold below which matches are dropped. Default 0.7. */
27
+ readonly minScore?: number;
28
+ /** Slice of the snapshot to inject. Default `'decisions'`. */
29
+ readonly projection?: SnapshotProjection;
30
+ /** Optional TTL for snapshots in ms. Useful for compliance windows. */
31
+ readonly ttlMs?: number;
32
+ /** Optional tier tag for written snapshots. */
33
+ readonly tier?: 'hot' | 'warm' | 'cold';
34
+ }
35
+ export declare function snapshotPipeline(config: SnapshotPipelineConfig): MemoryPipeline;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Causal memory — types.
3
+ *
4
+ * A `SnapshotEntry` is the value stored in a Causal `MemoryStore`. It
5
+ * captures one agent run's "what happened and why" so future turns can
6
+ * answer follow-up questions ("why did you reject this?") with EXACT
7
+ * past facts instead of LLM reconstruction.
8
+ *
9
+ * Differentiator: footprintjs's `decide()`/`select()` already capture
10
+ * decision evidence as first-class events during traversal — we just
11
+ * persist them. Other libraries can't do this without rebuilding their
12
+ * core to surface decision evidence.
13
+ *
14
+ * Stored as `MemoryEntry<SnapshotEntry>` so the existing store layer
15
+ * (`MemoryStore`, `InMemoryStore`, future Redis/Dynamo/Postgres
16
+ * adapters) handles persistence + identity isolation + TTL + vector
17
+ * search out of the box.
18
+ */
19
+ import type { LLMMessage } from '../../adapters/types.js';
20
+ /**
21
+ * One stored agent run — the unit of causal memory.
22
+ *
23
+ * Decisions, tool calls, iterations, and token usage are harvested DURING the run
24
+ * by `causalEvidenceRecorder` (the evidence bridge) and persisted here — the Agent
25
+ * attaches it automatically whenever a CAUSAL memory is mounted. Still deferred: the
26
+ * FULL `commitLog` + narrative entries with depth/path, which land only when an
27
+ * out-of-band recorder integrates `executor.getSnapshot()` directly. Consequence: a
28
+ * persisted snapshot answers "why?" from the recorded DOMAIN evidence (decisions /
29
+ * tool calls), but cannot yet rehydrate the trace-toolpack tools for cross-restart
30
+ * step-by-step navigation — use `.selfExplain()` for in-conversation deep traces.
31
+ */
32
+ export interface SnapshotEntry {
33
+ /**
34
+ * The user's message at the time of the run. THIS IS WHAT GETS
35
+ * EMBEDDED for retrieval — new queries are matched by cosine
36
+ * similarity against past queries.
37
+ */
38
+ readonly query: string;
39
+ /**
40
+ * The agent's final answer for the run. Pairs with `query` to form
41
+ * the (prompt, completion) pair RL/SFT exports project on.
42
+ */
43
+ readonly finalContent: string;
44
+ /**
45
+ * Iteration count — how many ReAct loop turns the agent used to
46
+ * produce `finalContent`. Useful for ranking "decisive" runs vs
47
+ * "thrashy" ones.
48
+ */
49
+ readonly iterations: number;
50
+ /**
51
+ * Decision records collected via `decide()`/`select()` (and skill-graph routing)
52
+ * during the run — harvested live by `causalEvidenceRecorder` (the evidence
53
+ * bridge) and persisted here. Empty only when the run used no decision primitives.
54
+ * THE killer field (by design): each entry carries the rule that matched + the
55
+ * evidence values that satisfied it.
56
+ */
57
+ readonly decisions: ReadonlyArray<DecisionRecord>;
58
+ /**
59
+ * Tool calls made during the run. Each entry: tool name, args,
60
+ * result (truncated). Surfaces the agent's tool-use trajectory for
61
+ * RL training of tool-use policies.
62
+ */
63
+ readonly toolCalls: ReadonlyArray<ToolCallRecord>;
64
+ /**
65
+ * Optional rendered narrative — when an out-of-band recorder
66
+ * captures `executor.getNarrative()` at write time, the full
67
+ * human-readable trace lands here.
68
+ */
69
+ readonly narrative?: string;
70
+ /**
71
+ * Wall-clock duration of the run in milliseconds.
72
+ */
73
+ readonly durationMs: number;
74
+ /**
75
+ * Cumulative token usage at end of run. Used to skip expensive
76
+ * snapshots from training-data exports under cost caps.
77
+ */
78
+ readonly tokenUsage: {
79
+ readonly input: number;
80
+ readonly output: number;
81
+ };
82
+ /**
83
+ * Optional eval score attached by an `evalRecorder`. When present,
84
+ * exports can filter to high-quality runs for SFT or rank for DPO.
85
+ */
86
+ readonly evalScore?: number;
87
+ }
88
+ export interface DecisionRecord {
89
+ /** Stage id where the decision happened (`'classify-risk'`). */
90
+ readonly stageId: string;
91
+ /** Branch chosen (`'rejected'`, `'manual-review'`). */
92
+ readonly chosen: string;
93
+ /** Optional human label of the rule that matched. */
94
+ readonly rule?: string;
95
+ /** Evidence values that led to the choice (key→value). */
96
+ readonly evidence?: Readonly<Record<string, unknown>>;
97
+ }
98
+ export interface ToolCallRecord {
99
+ /** Tool name as registered on the agent. */
100
+ readonly name: string;
101
+ /** Arguments passed to the tool. */
102
+ readonly args: Readonly<Record<string, unknown>>;
103
+ /** Result returned by the tool — TRUNCATED to keep snapshots small. */
104
+ readonly resultPreview: string;
105
+ /** True when the tool threw and the result is the error message. */
106
+ readonly errored: boolean;
107
+ }
108
+ /**
109
+ * Default truncation when serializing tool results into the snapshot.
110
+ * Keeps snapshot entries small enough to fit many in context during
111
+ * retrieval. Override per-call via `writeSnapshot` config.
112
+ */
113
+ export declare const DEFAULT_TOOL_RESULT_PREVIEW_LEN = 500;
114
+ /**
115
+ * What `loadSnapshot` returns to the formatter — the projection slice
116
+ * the consumer asked for via `defineMemory({ projection })`. Each
117
+ * projection produces a different `LLMMessage` content layout.
118
+ */
119
+ export interface ProjectedSnapshot {
120
+ readonly query: string;
121
+ readonly content: string;
122
+ readonly source: {
123
+ readonly entryId: string;
124
+ readonly score: number;
125
+ };
126
+ }
127
+ /**
128
+ * The shape of a single message produced from a projected snapshot.
129
+ * Always `system` role so the LLM treats it as authoritative context
130
+ * about a past run.
131
+ */
132
+ export type SnapshotMessage = LLMMessage & {
133
+ readonly role: 'system';
134
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/memory/causal/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAmGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/memory/causal/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAuGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * writeSnapshot — write-side stage for Causal memory.
3
+ *
4
+ * Captures the current run's `(query, finalContent)` pair from
5
+ * `scope.newMessages` (populated by the Agent's PrepareFinal stage),
6
+ * embeds the query for retrieval, and persists a `SnapshotEntry` to
7
+ * the store. Future turns can match new questions against past
8
+ * queries via cosine similarity to replay decision evidence.
9
+ *
10
+ * Reads from scope: `identity`, `turnNumber`, `newMessages`
11
+ * Writes to store: one `SnapshotEntry` per call, id = `snap-{turn}`
12
+ *
13
+ * Why per-turn (not per-iteration)?
14
+ * Causal memory captures TURN outcomes — "user asked X, agent said Y."
15
+ * Mid-iteration state isn't useful for cross-run replay.
16
+ *
17
+ * Turn derivation — collisions are impossible by construction:
18
+ * The effective turn is `max(scope.turnNumber, maxStoredTurn + 1)` where
19
+ * `maxStoredTurn` is the highest `snap-{n}` already live in THIS
20
+ * conversation's namespace (`identityNamespace(identity)` — the durable
21
+ * conversation anchor across `run()` calls, Agent instances, and
22
+ * processes). Rationale:
23
+ * - Hosts that track `turnNumber` correctly keep their numbering
24
+ * (`turnNumber: 5` → `snap-5`, gaps preserved).
25
+ * - Hosts with a stale counter (the Agent seeds `turnNumber = 1` on
26
+ * every run) still get a fresh, ordered id — turn 2 of the same
27
+ * conversation lands `snap-2` instead of silently replacing
28
+ * `snap-1`.
29
+ * Causal snapshots are decision evidence (audit/replay data): when
30
+ * "stale counter" and "deliberate same-turn rewrite" are
31
+ * indistinguishable, never destroying a prior turn's evidence wins.
32
+ * TTL-expired snapshots are ignored by the scan (same as every read).
33
+ *
34
+ * Empty-newMessages handling:
35
+ * When `newMessages` is empty (no final answer produced — e.g.
36
+ * pause-resume mid-flight), the stage no-ops. Re-runs after resume
37
+ * capture the snapshot then.
38
+ *
39
+ * @see ./types.ts for the SnapshotEntry shape this writes
40
+ * @see ./loadSnapshot.ts for the read-side counterpart
41
+ */
42
+ import type { TypedScope } from 'footprintjs';
43
+ import type { MemoryStore } from '../store/index.js';
44
+ import type { Embedder } from '../embedding/index.js';
45
+ import type { MemoryState } from '../stages/index.js';
46
+ export interface WriteSnapshotConfig {
47
+ /** The store to persist the snapshot to. */
48
+ readonly store: MemoryStore;
49
+ /**
50
+ * Embedder used to vectorize the query for later cosine-search.
51
+ * Required — Causal memory's value comes from semantic retrieval
52
+ * across past runs.
53
+ */
54
+ readonly embedder: Embedder;
55
+ /**
56
+ * Stable id for the embedder. Stored on the entry so a later
57
+ * embedder swap doesn't cross-pollute similarity scores.
58
+ * Default: `'unknown-embedder'` — pass an explicit id when you
59
+ * may swap embedder instances over time.
60
+ */
61
+ readonly embedderId?: string;
62
+ /**
63
+ * TTL in milliseconds — drop snapshots after this duration. Useful
64
+ * for compliance ("delete causal trace after 30 days").
65
+ */
66
+ readonly ttlMs?: number;
67
+ /**
68
+ * Tier to tag the snapshot with — typical: `'hot'` for current,
69
+ * `'warm'`/`'cold'` for archived. Read stages can filter by tier.
70
+ */
71
+ readonly tier?: 'hot' | 'warm' | 'cold';
72
+ }
73
+ export declare function writeSnapshot(config: WriteSnapshotConfig): (scope: TypedScope<MemoryState>) => Promise<void>;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * defineMemory — the single factory the consumer uses to register a
3
+ * memory subsystem on an Agent.
4
+ *
5
+ * defineMemory({ id, type, strategy, store }) → MemoryDefinition
6
+ *
7
+ * The factory's job:
8
+ * 1. Switch on `type` (Episodic / Semantic / Narrative / Causal)
9
+ * to pick the right family of pipelines.
10
+ * 2. Switch on `strategy.kind` within that family to wire stage
11
+ * configs (loadCount / topK / threshold / extractor / ...).
12
+ * 3. Return an opaque `MemoryDefinition` that step-4's
13
+ * `Agent.memory()` builder method consumes.
14
+ *
15
+ * Pattern: Factory + Strategy (GoF). One factory, N strategies, four
16
+ * types — all reduce to two compiled FlowCharts (`read`,
17
+ * `write?`) that mount as subflows.
18
+ *
19
+ * Role: Layer-2 of the memory stack. Sits between the const-objects
20
+ * contract (Layer 1) and the Agent builder method (Layer 4).
21
+ *
22
+ * Emits: Indirectly — the compiled subflows emit
23
+ * `agentfootprint.context.injected` with `source: 'memory'`
24
+ * when their formatter writes to the messages slot.
25
+ *
26
+ * @see ./define.types.ts for the const-objects + types
27
+ * @see ./pipeline/*.ts for the existing pipeline factories this dispatches to
28
+ */
29
+ import { type DefineMemoryOptions } from './define.types.js';
30
+ import type { MemoryDefinition, ReadonlyMemoryFlowChart } from './define.types.js';
31
+ /**
32
+ * Build a `MemoryDefinition` from a high-level `{ type, strategy, store }`
33
+ * config. Internally dispatches to one of the existing pipeline factories
34
+ * (defaultPipeline / semanticPipeline / factPipeline / narrativePipeline /
35
+ * autoPipeline / ephemeralPipeline) and wires the compiled flowcharts
36
+ * into the opaque definition that `Agent.memory()` consumes.
37
+ *
38
+ * Supported combinations:
39
+ *
40
+ * | type | strategy.kind | underlying pipeline |
41
+ * | --------- | ------------- | ------------------------ |
42
+ * | EPISODIC | WINDOW | defaultPipeline |
43
+ * | EPISODIC | BUDGET | defaultPipeline |
44
+ * | EPISODIC | SUMMARIZE | defaultPipeline + summarize stage |
45
+ * | SEMANTIC | TOP_K | semanticPipeline |
46
+ * | SEMANTIC | EXTRACT | factPipeline |
47
+ * | SEMANTIC | WINDOW | factPipeline (recency-load) |
48
+ * | NARRATIVE | EXTRACT | narrativePipeline |
49
+ * | NARRATIVE | WINDOW | narrativePipeline (recency-load) |
50
+ * | (any) | HYBRID | autoPipeline (when sub-strategies map cleanly) |
51
+ *
52
+ * Unsupported combinations throw with a remediation hint pointing to a
53
+ * working alternative or to the raw `mountMemoryRead`/`mountMemoryWrite`
54
+ * helpers for power users.
55
+ */
56
+ export declare function defineMemory(options: DefineMemoryOptions): MemoryDefinition;
57
+ /**
58
+ * Internal — unwrap the brand. Used by `Agent.memory()` (step 4)
59
+ * to mount the pipeline. NOT exported.
60
+ *
61
+ * @internal
62
+ */
63
+ export declare function unwrapMemoryFlowChart<T>(branded: ReadonlyMemoryFlowChart<T>): unknown;
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Memory subsystem — public type surface.
3
+ *
4
+ * THE 2D mental model the library teaches:
5
+ *
6
+ * MEMORY = TYPE × STRATEGY × STORE
7
+ *
8
+ * TYPE — what shape of memory you're keeping
9
+ * (Episodic messages / Semantic facts / Narrative beats /
10
+ * Causal footprintjs snapshots)
11
+ * STRATEGY — how to fit content into the next LLM call
12
+ * (Window / Budget / Summarize / TopK / Extract / Decay / Hybrid)
13
+ * STORE — where the bytes live
14
+ * (InMemoryStore / Redis / Postgres / DynamoDB / Vector ...)
15
+ *
16
+ * Strategy is universal — same Window works for Episodic and for Causal.
17
+ * That's why examples are organized by strategy (the discipline) not by
18
+ * type (the shape).
19
+ *
20
+ * Pattern: Single-Source-of-Truth const objects + discriminated union.
21
+ * Mirrors `src/conventions.ts` (SUBFLOW_IDS, INJECTION_KEYS).
22
+ * NEVER enums (TS enums emit runtime objects + opacity).
23
+ * Const-as-const erases at compile time, accepts string literals,
24
+ * and gives consumers IDE autocomplete + refactor safety.
25
+ *
26
+ * Role: Layer-1 contract for the memory subsystem. Step 2's
27
+ * `defineMemory()` factory consumes these to build pipelines;
28
+ * Step 4's `Agent.memory()` builder mounts the resulting
29
+ * definitions; Step 5's Causal machinery extends them.
30
+ *
31
+ * Emits: Indirectly — every memory pipeline emits the unified
32
+ * `agentfootprint.context.injected` event with `source: 'memory'`
33
+ * when its read subflow places content into the messages slot.
34
+ *
35
+ * @see ./define.ts for the `defineMemory()` factory itself
36
+ * @see ../../docs-next for guides + the 7 strategy examples
37
+ * @see MEMORY.md for the load-bearing design memory
38
+ */
39
+ import type { LLMProvider } from '../adapters/types.js';
40
+ import type { ContextRole } from '../events/types.js';
41
+ import type { Embedder } from './embedding/index.js';
42
+ import type { MemoryStore } from './store/index.js';
43
+ /**
44
+ * What shape of memory you're keeping.
45
+ *
46
+ * - `EPISODIC` — raw conversation messages, replayed on next turn
47
+ * - `SEMANTIC` — extracted structured facts, deduped on key
48
+ * - `NARRATIVE` — beats / summaries of prior runs (append-only)
49
+ * - `CAUSAL` — footprintjs execution snapshots, the differentiator
50
+ * (replays stored decisions + tool evidence for "why?"
51
+ * follow-ups — harvested automatically per run)
52
+ */
53
+ export declare const MEMORY_TYPES: {
54
+ readonly EPISODIC: "episodic";
55
+ readonly SEMANTIC: "semantic";
56
+ readonly NARRATIVE: "narrative";
57
+ readonly CAUSAL: "causal";
58
+ };
59
+ export type MemoryType = (typeof MEMORY_TYPES)[keyof typeof MEMORY_TYPES];
60
+ /**
61
+ * How content is selected / compressed for the next LLM call.
62
+ *
63
+ * A `WINDOW` strategy on an Episodic store keeps the last N messages; on
64
+ * Semantic / Narrative it keeps the last N facts / beats. NOT universal: the
65
+ * `CAUSAL` type accepts ONLY `TOP_K` — its snapshots are matched semantically
66
+ * against the new query, never by recency, so `buildCausalPipeline` throws on
67
+ * any other strategy kind. Mix and match the non-Causal types.
68
+ */
69
+ export declare const MEMORY_STRATEGIES: {
70
+ readonly WINDOW: "window";
71
+ readonly BUDGET: "budget";
72
+ readonly SUMMARIZE: "summarize";
73
+ readonly TOP_K: "topK";
74
+ readonly EXTRACT: "extract";
75
+ readonly DECAY: "decay";
76
+ readonly HYBRID: "hybrid";
77
+ };
78
+ export type MemoryStrategyKind = (typeof MEMORY_STRATEGIES)[keyof typeof MEMORY_STRATEGIES];
79
+ /**
80
+ * When the memory's READ subflow runs.
81
+ *
82
+ * Default `TURN_START` reads memory once per `agent.run()`. Use
83
+ * `EVERY_ITERATION` only when the strategy is sensitive to in-loop tool
84
+ * results — every-iteration multiplies store-latency by iteration-count.
85
+ */
86
+ export declare const MEMORY_TIMING: {
87
+ readonly EVERY_ITERATION: "every-iteration";
88
+ readonly TURN_START: "turn-start";
89
+ };
90
+ export type MemoryTiming = (typeof MEMORY_TIMING)[keyof typeof MEMORY_TIMING];
91
+ /**
92
+ * For Causal memory only — which slice of a footprintjs snapshot to
93
+ * inject. Snapshots can run 100KB+; projecting prevents context blowup.
94
+ *
95
+ * - `DECISIONS` — `decide()`/`select()` evidence only (the "why" chain)
96
+ * - `COMMITS` — commitLog only (every state write, ordered)
97
+ * - `NARRATIVE` — narrative entries only (human-readable trace)
98
+ * - `FULL` — entire snapshot (use sparingly)
99
+ */
100
+ export declare const SNAPSHOT_PROJECTIONS: {
101
+ readonly DECISIONS: "decisions";
102
+ readonly COMMITS: "commits";
103
+ readonly NARRATIVE: "narrative";
104
+ readonly FULL: "full";
105
+ };
106
+ export type SnapshotProjection = (typeof SNAPSHOT_PROJECTIONS)[keyof typeof SNAPSHOT_PROJECTIONS];
107
+ /** Window — keep the last `size` entries. Pure rule, no LLM, no embedder. */
108
+ export interface WindowStrategy {
109
+ readonly kind: typeof MEMORY_STRATEGIES.WINDOW;
110
+ readonly size: number;
111
+ }
112
+ /**
113
+ * Budget — pick entries that fit within a token budget. Used as a
114
+ * decider stage: skip-if-empty | skip-if-no-budget | pick-by-tokens.
115
+ */
116
+ export interface BudgetStrategy {
117
+ readonly kind: typeof MEMORY_STRATEGIES.BUDGET;
118
+ /** Reserve N tokens for prompt headers / new user message. Default 256. */
119
+ readonly reserveTokens?: number;
120
+ /** Skip injection below this token floor. Default 100. */
121
+ readonly minimumTokens?: number;
122
+ /** Hard cap on entries to inject — guards against "lost-in-the-middle". */
123
+ readonly maxEntries?: number;
124
+ }
125
+ /**
126
+ * Summarize — when the conversation grows long, an LLM compresses older
127
+ * turns into a paragraph; recent N turns stay raw. The standard answer
128
+ * to "long conversations blow context."
129
+ */
130
+ export interface SummarizeStrategy {
131
+ readonly kind: typeof MEMORY_STRATEGIES.SUMMARIZE;
132
+ /** Keep this many most-recent turns uncompressed. */
133
+ readonly recent: number;
134
+ /** LLM that does the compression — recommend a cheap model (haiku). */
135
+ readonly llm: LLMProvider;
136
+ }
137
+ /**
138
+ * Top-K — embed the user's query, retrieve top-K by cosine similarity.
139
+ * STRICT threshold: when no entry meets the threshold, return EMPTY.
140
+ * No fallback — garbage in context is worse than no memory.
141
+ */
142
+ export interface TopKStrategy {
143
+ readonly kind: typeof MEMORY_STRATEGIES.TOP_K;
144
+ readonly topK: number;
145
+ /** Min cosine similarity. Strict — no fallback below this. Default 0.7. */
146
+ readonly threshold?: number;
147
+ readonly embedder: Embedder;
148
+ }
149
+ /**
150
+ * Extract — on WRITE, an LLM (or pattern matcher) distills entries from
151
+ * raw messages into structured shapes (facts/beats). Usually paired with
152
+ * a load-side strategy like TopK or Window for the read direction.
153
+ */
154
+ export interface ExtractStrategy {
155
+ readonly kind: typeof MEMORY_STRATEGIES.EXTRACT;
156
+ /** Pattern-based (regex heuristics, free) or LLM-based (paid). */
157
+ readonly extractor: 'pattern' | 'llm';
158
+ /** Required when `extractor: 'llm'`. */
159
+ readonly llm?: LLMProvider;
160
+ /** Discard extractions below this confidence. Default 0.7. */
161
+ readonly minConfidence?: number;
162
+ /** Cap entries extracted per turn. Default 5. */
163
+ readonly maxPerTurn?: number;
164
+ }
165
+ /**
166
+ * Decay — score entries by `recency × accessCount`, drop below floor.
167
+ * For long-running agents where unused memory should fade.
168
+ */
169
+ export interface DecayStrategy {
170
+ readonly kind: typeof MEMORY_STRATEGIES.DECAY;
171
+ /** Half-life in milliseconds for the recency component. */
172
+ readonly halfLifeMs: number;
173
+ /** Drop entries scoring below this. Default 0.1. */
174
+ readonly minScore?: number;
175
+ }
176
+ /**
177
+ * Hybrid — compose multiple strategies. Each sub-strategy runs as its
178
+ * own selector branch; results are merged in the order listed.
179
+ */
180
+ export interface HybridStrategy {
181
+ readonly kind: typeof MEMORY_STRATEGIES.HYBRID;
182
+ readonly strategies: ReadonlyArray<Exclude<Strategy, HybridStrategy>>;
183
+ }
184
+ /** The full strategy union — discriminated by `kind`. */
185
+ export type Strategy = WindowStrategy | BudgetStrategy | SummarizeStrategy | TopKStrategy | ExtractStrategy | DecayStrategy | HybridStrategy;
186
+ /**
187
+ * Reserved API surface for content redaction before memory writes.
188
+ * Impl is deferred; the field exists now so adding redaction later
189
+ * is non-breaking. Snapshot/episodic writes may carry PII — this is
190
+ * the integration point.
191
+ */
192
+ export interface MemoryRedactionPolicy {
193
+ /** Patterns to mask in stored content. */
194
+ readonly patterns?: readonly RegExp[];
195
+ /** Replacement string. Default `'[REDACTED]'`. */
196
+ readonly replacement?: string;
197
+ }
198
+ /**
199
+ * The opaque value `defineMemory()` returns. `Agent.memory()` consumes
200
+ * one of these per memory the consumer registers; multiple definitions
201
+ * layer cleanly via per-id scope keys (`memoryInjection_${id}`).
202
+ *
203
+ * Generic `T` is the payload shape stored — `Message` for episodic,
204
+ * `Fact` for semantic, `NarrativeBeat` for narrative, `RunSnapshot` for
205
+ * causal. The factory infers `T` from `type`.
206
+ */
207
+ export interface MemoryDefinition<T = unknown> {
208
+ /** Stable identifier. Becomes the scope-key suffix and the Lens label. */
209
+ readonly id: string;
210
+ /** Surfaces in narrative / Lens hover. */
211
+ readonly description?: string;
212
+ /** Which TYPE shape — gates legal STRATEGY combinations. */
213
+ readonly type: MemoryType;
214
+ /** Compiled read subflow (built by the factory from type × strategy). */
215
+ readonly read: ReadonlyMemoryFlowChart<T>;
216
+ /** Compiled write subflow. Optional — `EPHEMERAL`-style configs omit. */
217
+ readonly write?: ReadonlyMemoryFlowChart<T>;
218
+ /** When `read` runs. Default `TURN_START`. */
219
+ readonly timing: MemoryTiming;
220
+ /** Role to use when injecting formatted content into the messages slot. */
221
+ readonly asRole: ContextRole;
222
+ /** Reserved for a future release — patterns to redact before write. */
223
+ readonly redact?: MemoryRedactionPolicy;
224
+ /** Snapshot projection — only meaningful when `type === CAUSAL`. */
225
+ readonly projection?: SnapshotProjection;
226
+ }
227
+ /**
228
+ * Opaque tag for the compiled flowchart the factory hands back.
229
+ * The actual type is `FlowChart<MemoryState>` from footprintjs but we
230
+ * keep it nominal here so consumers can't reach in. The phantom type
231
+ * parameter is preserved so consumers can write `ReadonlyMemoryFlowChart<MyShape>`
232
+ * for documentation, even though the brand erases the parameter at runtime.
233
+ */
234
+ export type ReadonlyMemoryFlowChart<_T> = {
235
+ readonly __brand: 'ReadonlyMemoryFlowChart';
236
+ };
237
+ /**
238
+ * Common options for every memory type. Type-specific options layer on
239
+ * top via discriminated `type` field in the next overload set (Step 2).
240
+ */
241
+ export interface DefineMemoryOptionsBase {
242
+ readonly id: string;
243
+ readonly description?: string;
244
+ readonly store: MemoryStore;
245
+ readonly strategy: Strategy;
246
+ readonly timing?: MemoryTiming;
247
+ readonly asRole?: ContextRole;
248
+ readonly redact?: MemoryRedactionPolicy;
249
+ }
250
+ export interface DefineEpisodicOptions extends DefineMemoryOptionsBase {
251
+ readonly type: typeof MEMORY_TYPES.EPISODIC;
252
+ }
253
+ export interface DefineSemanticOptions extends DefineMemoryOptionsBase {
254
+ readonly type: typeof MEMORY_TYPES.SEMANTIC;
255
+ }
256
+ export interface DefineNarrativeOptions extends DefineMemoryOptionsBase {
257
+ readonly type: typeof MEMORY_TYPES.NARRATIVE;
258
+ }
259
+ export interface DefineCausalOptions extends DefineMemoryOptionsBase {
260
+ readonly type: typeof MEMORY_TYPES.CAUSAL;
261
+ /** Slice of the snapshot to inject. Default `DECISIONS`. */
262
+ readonly projection?: SnapshotProjection;
263
+ }
264
+ /** Discriminated by `type`. The factory uses this to pick the pipeline. */
265
+ export type DefineMemoryOptions = DefineEpisodicOptions | DefineSemanticOptions | DefineNarrativeOptions | DefineCausalOptions;
266
+ export declare function isMemoryType(value: string): value is MemoryType;
267
+ export declare function isMemoryStrategyKind(value: string): value is MemoryStrategyKind;
268
+ export declare function isMemoryTiming(value: string): value is MemoryTiming;
269
+ export declare function isSnapshotProjection(value: string): value is SnapshotProjection;
270
+ /**
271
+ * Scope-key prefix used when mounting multiple `.memory()` definitions
272
+ * on the same Agent. Each memory writes to `memoryInjection_${id}` so
273
+ * registrations never collide. Formatter merges all keys with this
274
+ * prefix in registration order.
275
+ */
276
+ export declare const MEMORY_INJECTION_KEY_PREFIX: "memoryInjection_";
277
+ export declare function memoryInjectionKey(id: string): string;
278
+ export declare function isMemoryInjectionKey(key: string): boolean;
@@ -33,7 +33,7 @@
33
33
  * when its read subflow places content into the messages slot.
34
34
  *
35
35
  * @see ./define.ts for the `defineMemory()` factory itself
36
- * @see ../../docs-site for guides + the 7 strategy examples
36
+ * @see ../../docs-next for guides + the 7 strategy examples
37
37
  * @see MEMORY.md for the load-bearing design memory
38
38
  */
39
39
  // ─── Const-objects (SSOT) ───────────────────────────────────────────
@@ -56,9 +56,11 @@ export const MEMORY_TYPES = {
56
56
  /**
57
57
  * How content is selected / compressed for the next LLM call.
58
58
  *
59
- * Universal across types. A `WINDOW` strategy on an Episodic store keeps
60
- * the last N messages; on a Causal store it keeps the last N snapshots.
61
- * Mix and match.
59
+ * A `WINDOW` strategy on an Episodic store keeps the last N messages; on
60
+ * Semantic / Narrative it keeps the last N facts / beats. NOT universal: the
61
+ * `CAUSAL` type accepts ONLY `TOP_K` — its snapshots are matched semantically
62
+ * against the new query, never by recency, so `buildCausalPipeline` throws on
63
+ * any other strategy kind. Mix and match the non-Causal types.
62
64
  */
63
65
  export const MEMORY_STRATEGIES = {
64
66
  WINDOW: 'window',
@@ -1 +1 @@
1
- {"version":3,"file":"define.types.js","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAOH,uEAAuE;AAEvE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;CACR,CAAC;AAGX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACR,CAAC;AAGX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,eAAe,EAAE,iBAAiB;IAClC,UAAU,EAAE,YAAY;CAChB,CAAC;AAGX;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACJ,CAAC;AA+MX,uEAAuE;AAEvE,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAQ,MAAM,CAAC,MAAM,CAAC,YAAY,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAQ,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAQ,MAAM,CAAC,MAAM,CAAC,aAAa,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAQ,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED,uEAAuE;AAEvE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAA2B,CAAC;AAEvE,MAAM,UAAU,kBAAkB,CAAC,EAAU;IAC3C,OAAO,GAAG,2BAA2B,GAAG,EAAE,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,OAAO,GAAG,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;AACrD,CAAC"}
1
+ {"version":3,"file":"define.types.js","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAOH,uEAAuE;AAEvE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;CACR,CAAC;AAGX;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACR,CAAC;AAGX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,eAAe,EAAE,iBAAiB;IAClC,UAAU,EAAE,YAAY;CAChB,CAAC;AAGX;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACJ,CAAC;AA+MX,uEAAuE;AAEvE,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAQ,MAAM,CAAC,MAAM,CAAC,YAAY,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAQ,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAQ,MAAM,CAAC,MAAM,CAAC,aAAa,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAQ,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED,uEAAuE;AAEvE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAA2B,CAAC;AAEvE,MAAM,UAAU,kBAAkB,CAAC,EAAU;IAC3C,OAAO,GAAG,2BAA2B,GAAG,EAAE,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,OAAO,GAAG,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * cosineSimilarity — the similarity metric used by `store.search()`.
3
+ *
4
+ * cos(a, b) = dot(a, b) / (||a|| * ||b||)
5
+ *
6
+ * Range: [-1, 1]. Equal-direction vectors → 1. Orthogonal → 0.
7
+ * Opposite → -1.
8
+ *
9
+ * Zero-magnitude handling: if either vector is all-zero (or the empty
10
+ * vector), returns 0 — never NaN. NaN in a similarity score would
11
+ * poison downstream picker comparisons (NaN < x is false for all x)
12
+ * and silently demote the entry. Explicit 0 is safer.
13
+ *
14
+ * Length mismatch THROWS: comparing vectors of different dimensions
15
+ * is almost always a bug (different embedders mixed in the same store).
16
+ * Fail loud rather than silently truncate.
17
+ */
18
+ export declare function cosineSimilarity(a: readonly number[], b: readonly number[]): number;