@framers/agentos 0.1.46 → 0.1.48

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 (226) hide show
  1. package/README.md +7 -7
  2. package/dist/cognitive_substrate/IGMI.d.ts +2 -0
  3. package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
  4. package/dist/cognitive_substrate/IGMI.js.map +1 -1
  5. package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts +2 -0
  6. package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts.map +1 -1
  7. package/dist/core/audio/AdaptiveVAD.d.ts +147 -0
  8. package/dist/core/audio/AdaptiveVAD.d.ts.map +1 -0
  9. package/dist/core/audio/AdaptiveVAD.js +239 -0
  10. package/dist/core/audio/AdaptiveVAD.js.map +1 -0
  11. package/dist/core/audio/AudioProcessor.d.ts +121 -0
  12. package/dist/core/audio/AudioProcessor.d.ts.map +1 -0
  13. package/dist/core/audio/AudioProcessor.js +299 -0
  14. package/dist/core/audio/AudioProcessor.js.map +1 -0
  15. package/dist/core/audio/EnvironmentalCalibrator.d.ts +187 -0
  16. package/dist/core/audio/EnvironmentalCalibrator.d.ts.map +1 -0
  17. package/dist/core/audio/EnvironmentalCalibrator.js +360 -0
  18. package/dist/core/audio/EnvironmentalCalibrator.js.map +1 -0
  19. package/dist/core/audio/SilenceDetector.d.ts +111 -0
  20. package/dist/core/audio/SilenceDetector.d.ts.map +1 -0
  21. package/dist/core/audio/SilenceDetector.js +178 -0
  22. package/dist/core/audio/SilenceDetector.js.map +1 -0
  23. package/dist/core/llm/IPromptEngine.d.ts +2 -0
  24. package/dist/core/llm/IPromptEngine.d.ts.map +1 -1
  25. package/dist/core/llm/IPromptEngine.js.map +1 -1
  26. package/dist/core/llm/providers/implementations/OllamaProvider.js +2 -2
  27. package/dist/core/llm/providers/implementations/OllamaProvider.js.map +1 -1
  28. package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -1
  29. package/dist/core/llm/providers/implementations/OpenAIProvider.js +8 -1
  30. package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -1
  31. package/dist/discovery/CapabilityIndex.d.ts.map +1 -1
  32. package/dist/discovery/CapabilityIndex.js +18 -4
  33. package/dist/discovery/CapabilityIndex.js.map +1 -1
  34. package/dist/extensions/ExtensionManager.d.ts.map +1 -1
  35. package/dist/extensions/ExtensionManager.js +9 -1
  36. package/dist/extensions/ExtensionManager.js.map +1 -1
  37. package/dist/extensions/types.d.ts +20 -2
  38. package/dist/extensions/types.d.ts.map +1 -1
  39. package/dist/extensions/types.js +4 -0
  40. package/dist/extensions/types.js.map +1 -1
  41. package/dist/index.d.ts +2 -0
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +4 -0
  44. package/dist/index.js.map +1 -1
  45. package/dist/memory/CognitiveMemoryManager.d.ts +133 -0
  46. package/dist/memory/CognitiveMemoryManager.d.ts.map +1 -0
  47. package/dist/memory/CognitiveMemoryManager.js +519 -0
  48. package/dist/memory/CognitiveMemoryManager.js.map +1 -0
  49. package/dist/memory/config.d.ts +135 -0
  50. package/dist/memory/config.d.ts.map +1 -0
  51. package/dist/memory/config.js +28 -0
  52. package/dist/memory/config.js.map +1 -0
  53. package/dist/memory/consolidation/ConsolidationPipeline.d.ts +70 -0
  54. package/dist/memory/consolidation/ConsolidationPipeline.d.ts.map +1 -0
  55. package/dist/memory/consolidation/ConsolidationPipeline.js +301 -0
  56. package/dist/memory/consolidation/ConsolidationPipeline.js.map +1 -0
  57. package/dist/memory/context/CompactionEngine.d.ts +21 -0
  58. package/dist/memory/context/CompactionEngine.d.ts.map +1 -0
  59. package/dist/memory/context/CompactionEngine.js +35 -0
  60. package/dist/memory/context/CompactionEngine.js.map +1 -0
  61. package/dist/memory/context/CompactionLog.d.ts +50 -0
  62. package/dist/memory/context/CompactionLog.d.ts.map +1 -0
  63. package/dist/memory/context/CompactionLog.js +139 -0
  64. package/dist/memory/context/CompactionLog.js.map +1 -0
  65. package/dist/memory/context/ContextWindowManager.d.ts +114 -0
  66. package/dist/memory/context/ContextWindowManager.d.ts.map +1 -0
  67. package/dist/memory/context/ContextWindowManager.js +225 -0
  68. package/dist/memory/context/ContextWindowManager.js.map +1 -0
  69. package/dist/memory/context/RollingSummaryChain.d.ts +53 -0
  70. package/dist/memory/context/RollingSummaryChain.d.ts.map +1 -0
  71. package/dist/memory/context/RollingSummaryChain.js +193 -0
  72. package/dist/memory/context/RollingSummaryChain.js.map +1 -0
  73. package/dist/memory/context/index.d.ts +15 -0
  74. package/dist/memory/context/index.d.ts.map +1 -0
  75. package/dist/memory/context/index.js +14 -0
  76. package/dist/memory/context/index.js.map +1 -0
  77. package/dist/memory/context/strategies/HierarchicalStrategy.d.ts +25 -0
  78. package/dist/memory/context/strategies/HierarchicalStrategy.d.ts.map +1 -0
  79. package/dist/memory/context/strategies/HierarchicalStrategy.js +240 -0
  80. package/dist/memory/context/strategies/HierarchicalStrategy.js.map +1 -0
  81. package/dist/memory/context/strategies/HybridStrategy.d.ts +26 -0
  82. package/dist/memory/context/strategies/HybridStrategy.d.ts.map +1 -0
  83. package/dist/memory/context/strategies/HybridStrategy.js +245 -0
  84. package/dist/memory/context/strategies/HybridStrategy.js.map +1 -0
  85. package/dist/memory/context/strategies/SlidingSummaryStrategy.d.ts +22 -0
  86. package/dist/memory/context/strategies/SlidingSummaryStrategy.d.ts.map +1 -0
  87. package/dist/memory/context/strategies/SlidingSummaryStrategy.js +203 -0
  88. package/dist/memory/context/strategies/SlidingSummaryStrategy.js.map +1 -0
  89. package/dist/memory/context/types.d.ts +120 -0
  90. package/dist/memory/context/types.d.ts.map +1 -0
  91. package/dist/memory/context/types.js +17 -0
  92. package/dist/memory/context/types.js.map +1 -0
  93. package/dist/memory/decay/DecayModel.d.ts +87 -0
  94. package/dist/memory/decay/DecayModel.d.ts.map +1 -0
  95. package/dist/memory/decay/DecayModel.js +117 -0
  96. package/dist/memory/decay/DecayModel.js.map +1 -0
  97. package/dist/memory/decay/RetrievalPriorityScorer.d.ts +63 -0
  98. package/dist/memory/decay/RetrievalPriorityScorer.d.ts.map +1 -0
  99. package/dist/memory/decay/RetrievalPriorityScorer.js +110 -0
  100. package/dist/memory/decay/RetrievalPriorityScorer.js.map +1 -0
  101. package/dist/memory/encoding/ContentFeatureDetector.d.ts +37 -0
  102. package/dist/memory/encoding/ContentFeatureDetector.d.ts.map +1 -0
  103. package/dist/memory/encoding/ContentFeatureDetector.js +176 -0
  104. package/dist/memory/encoding/ContentFeatureDetector.js.map +1 -0
  105. package/dist/memory/encoding/EncodingModel.d.ts +67 -0
  106. package/dist/memory/encoding/EncodingModel.d.ts.map +1 -0
  107. package/dist/memory/encoding/EncodingModel.js +171 -0
  108. package/dist/memory/encoding/EncodingModel.js.map +1 -0
  109. package/dist/memory/extension/CognitiveMemoryExtension.d.ts +18 -0
  110. package/dist/memory/extension/CognitiveMemoryExtension.d.ts.map +1 -0
  111. package/dist/memory/extension/CognitiveMemoryExtension.js +131 -0
  112. package/dist/memory/extension/CognitiveMemoryExtension.js.map +1 -0
  113. package/dist/memory/graph/GraphologyMemoryGraph.d.ts +29 -0
  114. package/dist/memory/graph/GraphologyMemoryGraph.d.ts.map +1 -0
  115. package/dist/memory/graph/GraphologyMemoryGraph.js +224 -0
  116. package/dist/memory/graph/GraphologyMemoryGraph.js.map +1 -0
  117. package/dist/memory/graph/IMemoryGraph.d.ts +70 -0
  118. package/dist/memory/graph/IMemoryGraph.d.ts.map +1 -0
  119. package/dist/memory/graph/IMemoryGraph.js +15 -0
  120. package/dist/memory/graph/IMemoryGraph.js.map +1 -0
  121. package/dist/memory/graph/KnowledgeGraphMemoryGraph.d.ts +38 -0
  122. package/dist/memory/graph/KnowledgeGraphMemoryGraph.d.ts.map +1 -0
  123. package/dist/memory/graph/KnowledgeGraphMemoryGraph.js +264 -0
  124. package/dist/memory/graph/KnowledgeGraphMemoryGraph.js.map +1 -0
  125. package/dist/memory/graph/SpreadingActivation.d.ts +36 -0
  126. package/dist/memory/graph/SpreadingActivation.d.ts.map +1 -0
  127. package/dist/memory/graph/SpreadingActivation.js +100 -0
  128. package/dist/memory/graph/SpreadingActivation.js.map +1 -0
  129. package/dist/memory/index.d.ts +52 -0
  130. package/dist/memory/index.d.ts.map +1 -0
  131. package/dist/memory/index.js +43 -0
  132. package/dist/memory/index.js.map +1 -0
  133. package/dist/memory/observation/MemoryObserver.d.ts +59 -0
  134. package/dist/memory/observation/MemoryObserver.d.ts.map +1 -0
  135. package/dist/memory/observation/MemoryObserver.js +136 -0
  136. package/dist/memory/observation/MemoryObserver.js.map +1 -0
  137. package/dist/memory/observation/MemoryReflector.d.ts +51 -0
  138. package/dist/memory/observation/MemoryReflector.d.ts.map +1 -0
  139. package/dist/memory/observation/MemoryReflector.js +184 -0
  140. package/dist/memory/observation/MemoryReflector.js.map +1 -0
  141. package/dist/memory/observation/ObservationBuffer.d.ts +51 -0
  142. package/dist/memory/observation/ObservationBuffer.d.ts.map +1 -0
  143. package/dist/memory/observation/ObservationBuffer.js +81 -0
  144. package/dist/memory/observation/ObservationBuffer.js.map +1 -0
  145. package/dist/memory/prompt/MemoryFormatters.d.ts +22 -0
  146. package/dist/memory/prompt/MemoryFormatters.d.ts.map +1 -0
  147. package/dist/memory/prompt/MemoryFormatters.js +113 -0
  148. package/dist/memory/prompt/MemoryFormatters.js.map +1 -0
  149. package/dist/memory/prompt/MemoryPromptAssembler.d.ts +40 -0
  150. package/dist/memory/prompt/MemoryPromptAssembler.d.ts.map +1 -0
  151. package/dist/memory/prompt/MemoryPromptAssembler.js +180 -0
  152. package/dist/memory/prompt/MemoryPromptAssembler.js.map +1 -0
  153. package/dist/memory/prospective/ProspectiveMemoryManager.d.ts +83 -0
  154. package/dist/memory/prospective/ProspectiveMemoryManager.d.ts.map +1 -0
  155. package/dist/memory/prospective/ProspectiveMemoryManager.js +128 -0
  156. package/dist/memory/prospective/ProspectiveMemoryManager.js.map +1 -0
  157. package/dist/memory/store/MemoryStore.d.ts +76 -0
  158. package/dist/memory/store/MemoryStore.d.ts.map +1 -0
  159. package/dist/memory/store/MemoryStore.js +320 -0
  160. package/dist/memory/store/MemoryStore.js.map +1 -0
  161. package/dist/memory/types.d.ts +184 -0
  162. package/dist/memory/types.d.ts.map +1 -0
  163. package/dist/memory/types.js +14 -0
  164. package/dist/memory/types.js.map +1 -0
  165. package/dist/memory/working/CognitiveWorkingMemory.d.ts +87 -0
  166. package/dist/memory/working/CognitiveWorkingMemory.d.ts.map +1 -0
  167. package/dist/memory/working/CognitiveWorkingMemory.js +230 -0
  168. package/dist/memory/working/CognitiveWorkingMemory.js.map +1 -0
  169. package/dist/rag/EmbeddingManager.d.ts.map +1 -1
  170. package/dist/rag/EmbeddingManager.js +8 -1
  171. package/dist/rag/EmbeddingManager.js.map +1 -1
  172. package/dist/rag/HydeRetriever.d.ts +111 -0
  173. package/dist/rag/HydeRetriever.d.ts.map +1 -0
  174. package/dist/rag/HydeRetriever.js +143 -0
  175. package/dist/rag/HydeRetriever.js.map +1 -0
  176. package/dist/rag/IRetrievalAugmentor.d.ts +15 -0
  177. package/dist/rag/IRetrievalAugmentor.d.ts.map +1 -1
  178. package/dist/rag/index.d.ts +1 -0
  179. package/dist/rag/index.d.ts.map +1 -1
  180. package/dist/rag/index.js +2 -0
  181. package/dist/rag/index.js.map +1 -1
  182. package/dist/speech/SpeechProviderRegistry.d.ts +17 -0
  183. package/dist/speech/SpeechProviderRegistry.d.ts.map +1 -0
  184. package/dist/speech/SpeechProviderRegistry.js +47 -0
  185. package/dist/speech/SpeechProviderRegistry.js.map +1 -0
  186. package/dist/speech/SpeechRuntime.d.ts +30 -0
  187. package/dist/speech/SpeechRuntime.d.ts.map +1 -0
  188. package/dist/speech/SpeechRuntime.js +156 -0
  189. package/dist/speech/SpeechRuntime.js.map +1 -0
  190. package/dist/speech/SpeechSession.d.ts +37 -0
  191. package/dist/speech/SpeechSession.d.ts.map +1 -0
  192. package/dist/speech/SpeechSession.js +285 -0
  193. package/dist/speech/SpeechSession.js.map +1 -0
  194. package/dist/speech/audio.d.ts +3 -0
  195. package/dist/speech/audio.d.ts.map +1 -0
  196. package/dist/speech/audio.js +39 -0
  197. package/dist/speech/audio.js.map +1 -0
  198. package/dist/speech/index.d.ts +11 -0
  199. package/dist/speech/index.d.ts.map +1 -0
  200. package/dist/speech/index.js +11 -0
  201. package/dist/speech/index.js.map +1 -0
  202. package/dist/speech/providerCatalog.d.ts +7 -0
  203. package/dist/speech/providerCatalog.d.ts.map +1 -0
  204. package/dist/speech/providerCatalog.js +243 -0
  205. package/dist/speech/providerCatalog.js.map +1 -0
  206. package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts +20 -0
  207. package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts.map +1 -0
  208. package/dist/speech/providers/BuiltInAdaptiveVadProvider.js +29 -0
  209. package/dist/speech/providers/BuiltInAdaptiveVadProvider.js.map +1 -0
  210. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.d.ts +20 -0
  211. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.d.ts.map +1 -0
  212. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.js +95 -0
  213. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.js.map +1 -0
  214. package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts +20 -0
  215. package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts.map +1 -0
  216. package/dist/speech/providers/OpenAITextToSpeechProvider.js +75 -0
  217. package/dist/speech/providers/OpenAITextToSpeechProvider.js.map +1 -0
  218. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts +18 -0
  219. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts.map +1 -0
  220. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js +109 -0
  221. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js.map +1 -0
  222. package/dist/speech/types.d.ts +272 -0
  223. package/dist/speech/types.d.ts.map +1 -0
  224. package/dist/speech/types.js +2 -0
  225. package/dist/speech/types.js.map +1 -0
  226. package/package.json +22 -2
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @fileoverview Barrel exports for the Cognitive Memory System.
3
+ * @module agentos/memory
4
+ */
5
+ export { DEFAULT_ENCODING_CONFIG, DEFAULT_DECAY_CONFIG, DEFAULT_BUDGET_ALLOCATION, } from './config.js';
6
+ // --- Encoding ---
7
+ export { computeEncodingWeights, computeEncodingStrength, computeAttentionMultiplier, yerksDodson, moodCongruenceBoost, isFlashbulbMemory, buildEmotionalContext, } from './encoding/EncodingModel.js';
8
+ export { createFeatureDetector, KeywordFeatureDetector, LlmFeatureDetector, HybridFeatureDetector, } from './encoding/ContentFeatureDetector.js';
9
+ // --- Decay ---
10
+ export { computeCurrentStrength, updateOnRetrieval, computeInterference, findPrunableTraces, } from './decay/DecayModel.js';
11
+ export { scoreAndRankTraces, detectPartiallyRetrieved, computeRecencyBoost, computeEmotionalCongruence, DEFAULT_SCORING_WEIGHTS, } from './decay/RetrievalPriorityScorer.js';
12
+ // --- Working Memory ---
13
+ export { CognitiveWorkingMemory } from './working/CognitiveWorkingMemory.js';
14
+ // --- Store ---
15
+ export { MemoryStore } from './store/MemoryStore.js';
16
+ // --- Prompt Assembly ---
17
+ export { assembleMemoryContext } from './prompt/MemoryPromptAssembler.js';
18
+ export { formatMemoryTrace, formatMemoryTraces } from './prompt/MemoryFormatters.js';
19
+ // --- Orchestrator ---
20
+ export { CognitiveMemoryManager } from './CognitiveMemoryManager.js';
21
+ // --- Extension ---
22
+ export { createCognitiveMemoryDescriptor } from './extension/CognitiveMemoryExtension.js';
23
+ export { GraphologyMemoryGraph } from './graph/GraphologyMemoryGraph.js';
24
+ export { KnowledgeGraphMemoryGraph } from './graph/KnowledgeGraphMemoryGraph.js';
25
+ export { spreadActivation } from './graph/SpreadingActivation.js';
26
+ // --- Observation System (Batch 2) ---
27
+ export { ObservationBuffer } from './observation/ObservationBuffer.js';
28
+ export { MemoryObserver } from './observation/MemoryObserver.js';
29
+ export { MemoryReflector } from './observation/MemoryReflector.js';
30
+ // --- Prospective Memory (Batch 2) ---
31
+ export { ProspectiveMemoryManager } from './prospective/ProspectiveMemoryManager.js';
32
+ // --- Consolidation Pipeline (Batch 2) ---
33
+ export { ConsolidationPipeline } from './consolidation/ConsolidationPipeline.js';
34
+ // --- Infinite Context Window (Batch 3) ---
35
+ export { ContextWindowManager } from './context/ContextWindowManager.js';
36
+ export { CompactionEngine } from './context/CompactionEngine.js';
37
+ export { CompactionLog } from './context/CompactionLog.js';
38
+ export { RollingSummaryChain } from './context/RollingSummaryChain.js';
39
+ export { SlidingSummaryStrategy } from './context/strategies/SlidingSummaryStrategy.js';
40
+ export { HierarchicalStrategy } from './context/strategies/HierarchicalStrategy.js';
41
+ export { HybridStrategy } from './context/strategies/HybridStrategy.js';
42
+ export { DEFAULT_INFINITE_CONTEXT_CONFIG } from './context/types.js';
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoCH,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB,mBAAmB;AACnB,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,sCAAsC,CAAC;AAG9C,gBAAgB;AAChB,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,oCAAoC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O,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAYxE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @fileoverview Memory Observer — personality-biased background note extraction.
3
+ *
4
+ * Monitors accumulated conversation tokens via ObservationBuffer.
5
+ * When the threshold is reached, extracts concise observation notes
6
+ * via a persona-configured LLM (defaults to cheap model).
7
+ *
8
+ * Personality bias:
9
+ * - High emotionality → notes emotional shifts
10
+ * - High conscientiousness → notes commitments/deadlines
11
+ * - High openness → notes creative tangents
12
+ * - High agreeableness → notes user preferences and rapport cues
13
+ * - High honesty → notes corrections and retractions
14
+ *
15
+ * @module agentos/memory/observation/MemoryObserver
16
+ */
17
+ import type { HexacoTraits, PADState, ObserverConfig } from '../config.js';
18
+ import { ObservationBuffer, type BufferedMessage } from './ObservationBuffer.js';
19
+ export interface ObservationNote {
20
+ id: string;
21
+ /** Category of observation. */
22
+ type: 'factual' | 'emotional' | 'commitment' | 'preference' | 'creative' | 'correction';
23
+ /** Short summary of the observation. */
24
+ content: string;
25
+ /** 0-1 importance score. */
26
+ importance: number;
27
+ /** Entities mentioned. */
28
+ entities: string[];
29
+ /** Emotional context at observation time. */
30
+ emotionalContext?: {
31
+ valence: number;
32
+ arousal: number;
33
+ };
34
+ timestamp: number;
35
+ }
36
+ export declare class MemoryObserver {
37
+ private buffer;
38
+ private traits;
39
+ private llmInvoker?;
40
+ private config;
41
+ constructor(traits: HexacoTraits, config?: Partial<ObserverConfig>);
42
+ /**
43
+ * Feed a message into the observation buffer.
44
+ * Returns observation notes if the buffer has reached activation threshold.
45
+ */
46
+ observe(role: BufferedMessage['role'], content: string, mood?: PADState): Promise<ObservationNote[] | null>;
47
+ /**
48
+ * Force extraction of observation notes from buffered messages.
49
+ */
50
+ extractNotes(mood?: PADState): Promise<ObservationNote[]>;
51
+ /** Get the underlying buffer for inspection. */
52
+ getBuffer(): ObservationBuffer;
53
+ /** Check if observation should be triggered. */
54
+ shouldActivate(): boolean;
55
+ /** Reset the observer. */
56
+ clear(): void;
57
+ private parseNotes;
58
+ }
59
+ //# sourceMappingURL=MemoryObserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryObserver.d.ts","sourceRoot":"","sources":["../../../src/memory/observation/MemoryObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAMjF,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,+BAA+B;IAC/B,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,CAAC;IACxF,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,SAAS,EAAE,MAAM,CAAC;CACnB;AAqCD,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAgE;IACnF,OAAO,CAAC,MAAM,CAAiB;gBAG7B,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAclC;;;OAGG;IACG,OAAO,CACX,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,QAAQ,GACd,OAAO,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC;IASpC;;OAEG;IACG,YAAY,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAqB/D,gDAAgD;IAChD,SAAS,IAAI,iBAAiB;IAI9B,gDAAgD;IAChD,cAAc,IAAI,OAAO;IAIzB,0BAA0B;IAC1B,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,UAAU;CAyBnB"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @fileoverview Memory Observer — personality-biased background note extraction.
3
+ *
4
+ * Monitors accumulated conversation tokens via ObservationBuffer.
5
+ * When the threshold is reached, extracts concise observation notes
6
+ * via a persona-configured LLM (defaults to cheap model).
7
+ *
8
+ * Personality bias:
9
+ * - High emotionality → notes emotional shifts
10
+ * - High conscientiousness → notes commitments/deadlines
11
+ * - High openness → notes creative tangents
12
+ * - High agreeableness → notes user preferences and rapport cues
13
+ * - High honesty → notes corrections and retractions
14
+ *
15
+ * @module agentos/memory/observation/MemoryObserver
16
+ */
17
+ import { ObservationBuffer } from './ObservationBuffer.js';
18
+ // ---------------------------------------------------------------------------
19
+ // Personality-aware system prompt builder
20
+ // ---------------------------------------------------------------------------
21
+ function buildObserverSystemPrompt(traits) {
22
+ const clamp = (v) => v == null ? 0.5 : Math.max(0, Math.min(1, v));
23
+ const emphases = [];
24
+ if (clamp(traits.emotionality) > 0.6)
25
+ emphases.push('Pay special attention to emotional shifts, tone changes, and sentiment transitions.');
26
+ if (clamp(traits.conscientiousness) > 0.6)
27
+ emphases.push('Note any commitments, deadlines, action items, or structured plans.');
28
+ if (clamp(traits.openness) > 0.6)
29
+ emphases.push('Capture creative tangents, novel ideas, and exploratory topics.');
30
+ if (clamp(traits.agreeableness) > 0.6)
31
+ emphases.push('Track user preferences, rapport cues, and communication style patterns.');
32
+ if (clamp(traits.honesty) > 0.6)
33
+ emphases.push('Flag any corrections, retractions, or contradictions to prior statements.');
34
+ const emphasisBlock = emphases.length > 0
35
+ ? `\n\nPriority focus areas:\n${emphases.map((e) => `- ${e}`).join('\n')}`
36
+ : '';
37
+ return `You are a memory observer. Extract concise observation notes from the conversation below.
38
+
39
+ For each observation, output a JSON object on its own line with these fields:
40
+ - type: "factual" | "emotional" | "commitment" | "preference" | "creative" | "correction"
41
+ - content: brief summary (1-2 sentences max)
42
+ - importance: 0.0-1.0 (how important is this for future recall?)
43
+ - entities: string[] (key entities mentioned)
44
+
45
+ Output ONLY valid JSON objects, one per line. No markdown, no explanation.${emphasisBlock}`;
46
+ }
47
+ // ---------------------------------------------------------------------------
48
+ // MemoryObserver
49
+ // ---------------------------------------------------------------------------
50
+ let noteIdCounter = 0;
51
+ export class MemoryObserver {
52
+ constructor(traits, config) {
53
+ this.traits = traits;
54
+ this.config = {
55
+ activationThresholdTokens: config?.activationThresholdTokens ?? 30000,
56
+ modelId: config?.modelId,
57
+ llmInvoker: config?.llmInvoker,
58
+ };
59
+ this.llmInvoker = config?.llmInvoker;
60
+ this.buffer = new ObservationBuffer({
61
+ activationThresholdTokens: this.config.activationThresholdTokens,
62
+ });
63
+ }
64
+ /**
65
+ * Feed a message into the observation buffer.
66
+ * Returns observation notes if the buffer has reached activation threshold.
67
+ */
68
+ async observe(role, content, mood) {
69
+ const shouldActivate = this.buffer.push(role, content);
70
+ if (!shouldActivate)
71
+ return null;
72
+ if (!this.llmInvoker)
73
+ return null;
74
+ return this.extractNotes(mood);
75
+ }
76
+ /**
77
+ * Force extraction of observation notes from buffered messages.
78
+ */
79
+ async extractNotes(mood) {
80
+ if (!this.llmInvoker)
81
+ return [];
82
+ const messages = this.buffer.drain();
83
+ if (messages.length === 0)
84
+ return [];
85
+ // Build conversation text for the LLM
86
+ const conversationText = messages
87
+ .map((m) => `[${m.role}] ${m.content}`)
88
+ .join('\n');
89
+ const systemPrompt = buildObserverSystemPrompt(this.traits);
90
+ try {
91
+ const response = await this.llmInvoker(systemPrompt, conversationText);
92
+ return this.parseNotes(response, mood);
93
+ }
94
+ catch {
95
+ return [];
96
+ }
97
+ }
98
+ /** Get the underlying buffer for inspection. */
99
+ getBuffer() {
100
+ return this.buffer;
101
+ }
102
+ /** Check if observation should be triggered. */
103
+ shouldActivate() {
104
+ return this.buffer.shouldActivate();
105
+ }
106
+ /** Reset the observer. */
107
+ clear() {
108
+ this.buffer.clear();
109
+ }
110
+ // --- Internal ---
111
+ parseNotes(llmResponse, mood) {
112
+ const notes = [];
113
+ const lines = llmResponse.split('\n').filter((l) => l.trim());
114
+ for (const line of lines) {
115
+ try {
116
+ const parsed = JSON.parse(line.trim());
117
+ if (parsed.type && parsed.content) {
118
+ notes.push({
119
+ id: `obs_${Date.now()}_${++noteIdCounter}`,
120
+ type: parsed.type,
121
+ content: parsed.content,
122
+ importance: typeof parsed.importance === 'number' ? parsed.importance : 0.5,
123
+ entities: Array.isArray(parsed.entities) ? parsed.entities : [],
124
+ emotionalContext: mood ? { valence: mood.valence, arousal: mood.arousal } : undefined,
125
+ timestamp: Date.now(),
126
+ });
127
+ }
128
+ }
129
+ catch {
130
+ // Skip malformed lines
131
+ }
132
+ }
133
+ return notes;
134
+ }
135
+ }
136
+ //# sourceMappingURL=MemoryObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryObserver.js","sourceRoot":"","sources":["../../../src/memory/observation/MemoryObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,iBAAiB,EAAwB,MAAM,wBAAwB,CAAC;AAqBjF,8EAA8E;AAC9E,0CAA0C;AAC1C,8EAA8E;AAE9E,SAAS,yBAAyB,CAAC,MAAoB;IACrD,MAAM,KAAK,GAAG,CAAC,CAAqB,EAAU,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAE/F,MAAM,QAAQ,GAAa,EA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C,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;wBACrF,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;qBACtB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,uBAAuB;YACzB,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @fileoverview Memory Reflector — consolidates observation notes into long-term traces.
3
+ *
4
+ * Activates when accumulated observation notes exceed a token threshold.
5
+ * Uses a persona-configured LLM to:
6
+ * 1. Merge redundant observations
7
+ * 2. Elevate important facts to long-term memory traces
8
+ * 3. Detect conflicts against existing memories
9
+ * 4. Resolve conflicts based on personality (high honesty → update, high agreeableness → coexist)
10
+ *
11
+ * Target compression: 5-40x (many observations → few traces).
12
+ *
13
+ * @module agentos/memory/observation/MemoryReflector
14
+ */
15
+ import type { MemoryTrace } from '../types.js';
16
+ import type { HexacoTraits, ReflectorConfig } from '../config.js';
17
+ import type { ObservationNote } from './MemoryObserver.js';
18
+ export interface MemoryReflectionResult {
19
+ /** New long-term memory traces to store. */
20
+ traces: Omit<MemoryTrace, 'id' | 'encodingStrength' | 'stability' | 'retrievalCount' | 'lastAccessedAt' | 'accessCount' | 'reinforcementInterval' | 'createdAt' | 'updatedAt'>[];
21
+ /** IDs of existing traces that should be superseded. */
22
+ supersededTraceIds: string[];
23
+ /** IDs of observation notes that were consumed. */
24
+ consumedNoteIds: string[];
25
+ /** Compression ratio achieved. */
26
+ compressionRatio: number;
27
+ }
28
+ export declare class MemoryReflector {
29
+ private pendingNotes;
30
+ private traits;
31
+ private llmInvoker?;
32
+ private config;
33
+ constructor(traits: HexacoTraits, config?: Partial<ReflectorConfig>);
34
+ /**
35
+ * Add observation notes for future reflection.
36
+ * Returns a MemoryReflectionResult if the note threshold is reached.
37
+ */
38
+ addNotes(notes: ObservationNote[]): Promise<MemoryReflectionResult | null>;
39
+ /** Whether accumulated notes exceed the reflection threshold. */
40
+ shouldActivate(): boolean;
41
+ /**
42
+ * Force reflection over all pending notes.
43
+ */
44
+ reflect(existingMemoryContext?: string): Promise<MemoryReflectionResult>;
45
+ /** Get pending note count. */
46
+ getPendingNoteCount(): number;
47
+ /** Clear all pending notes. */
48
+ clear(): void;
49
+ private parseReflection;
50
+ }
51
+ //# sourceMappingURL=MemoryReflector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryReflector.d.ts","sourceRoot":"","sources":["../../../src/memory/observation/MemoryReflector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAY,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAM3D,MAAM,WAAW,sBAAsB;IACrC,4CAA4C;IAC5C,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,kBAAkB,GAAG,WAAW,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,aAAa,GAAG,uBAAuB,GAAG,WAAW,GAAG,WAAW,CAAC,EAAE,CAAC;IACjL,wDAAwD;IACxD,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,mDAAmD;IACnD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,kCAAkC;IAClC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAoDD,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAgE;IACnF,OAAO,CAAC,MAAM,CAAkB;gBAG9B,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IAWnC;;;OAGG;IACG,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC;IAShF,iEAAiE;IACjE,cAAc,IAAI,OAAO;IAQzB;;OAEG;IACG,OAAO,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAkC9E,8BAA8B;IAC9B,mBAAmB,IAAI,MAAM;IAI7B,+BAA+B;IAC/B,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,eAAe;CA+DxB"}
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @fileoverview Memory Reflector — consolidates observation notes into long-term traces.
3
+ *
4
+ * Activates when accumulated observation notes exceed a token threshold.
5
+ * Uses a persona-configured LLM to:
6
+ * 1. Merge redundant observations
7
+ * 2. Elevate important facts to long-term memory traces
8
+ * 3. Detect conflicts against existing memories
9
+ * 4. Resolve conflicts based on personality (high honesty → update, high agreeableness → coexist)
10
+ *
11
+ * Target compression: 5-40x (many observations → few traces).
12
+ *
13
+ * @module agentos/memory/observation/MemoryReflector
14
+ */
15
+ // ---------------------------------------------------------------------------
16
+ // Personality-aware system prompt
17
+ // ---------------------------------------------------------------------------
18
+ function buildReflectorSystemPrompt(traits) {
19
+ const clamp = (v) => v == null ? 0.5 : Math.max(0, Math.min(1, v));
20
+ const conflictStrategy = clamp(traits.honesty) > 0.6
21
+ ? 'When you detect a contradiction with existing knowledge, prefer the newer information and flag the old memory for supersession.'
22
+ : clamp(traits.agreeableness) > 0.6
23
+ ? 'When you detect a contradiction, keep both versions and note the discrepancy.'
24
+ : 'When you detect a contradiction, keep the version with higher confidence.';
25
+ const memoryStyle = clamp(traits.conscientiousness) > 0.6
26
+ ? 'Produce structured, well-organized memory traces with clear categories.'
27
+ : clamp(traits.openness) > 0.6
28
+ ? 'Produce rich, associative memory traces that capture connections and context.'
29
+ : 'Produce concise, factual memory traces focused on key information.';
30
+ return `You are a memory reflector. Your job is to consolidate observation notes into long-term memory traces.
31
+
32
+ Rules:
33
+ 1. Merge redundant or overlapping observations into single traces
34
+ 2. Assign each trace a type: "episodic" (events), "semantic" (facts/knowledge), "procedural" (how-to), or "prospective" (future goals/intentions)
35
+ 3. Assign a scope: "user" (about the user), "thread" (conversation-specific), "persona" (about the agent), or "organization" (shared)
36
+ 4. ${conflictStrategy}
37
+ 5. ${memoryStyle}
38
+ 6. Target 5-40x compression: many notes → few high-quality traces
39
+
40
+ For each trace, output a JSON object on its own line:
41
+ {
42
+ "type": "episodic|semantic|procedural|prospective",
43
+ "scope": "user|thread|persona|organization",
44
+ "scopeId": "relevant_id",
45
+ "content": "consolidated memory content",
46
+ "entities": ["entity1", "entity2"],
47
+ "tags": ["tag1", "tag2"],
48
+ "confidence": 0.0-1.0,
49
+ "sourceType": "observation|reflection",
50
+ "supersedes": ["existing_trace_id_if_contradicted"],
51
+ "consumedNotes": ["note_id1", "note_id2"]
52
+ }
53
+
54
+ Output ONLY valid JSON objects, one per line.`;
55
+ }
56
+ // ---------------------------------------------------------------------------
57
+ // MemoryReflector
58
+ // ---------------------------------------------------------------------------
59
+ export class MemoryReflector {
60
+ constructor(traits, config) {
61
+ this.pendingNotes = [];
62
+ this.traits = traits;
63
+ this.config = {
64
+ activationThresholdTokens: config?.activationThresholdTokens ?? 40000,
65
+ modelId: config?.modelId,
66
+ llmInvoker: config?.llmInvoker,
67
+ };
68
+ this.llmInvoker = config?.llmInvoker;
69
+ }
70
+ /**
71
+ * Add observation notes for future reflection.
72
+ * Returns a MemoryReflectionResult if the note threshold is reached.
73
+ */
74
+ async addNotes(notes) {
75
+ this.pendingNotes.push(...notes);
76
+ if (!this.shouldActivate())
77
+ return null;
78
+ if (!this.llmInvoker)
79
+ return null;
80
+ return this.reflect();
81
+ }
82
+ /** Whether accumulated notes exceed the reflection threshold. */
83
+ shouldActivate() {
84
+ const totalTokens = this.pendingNotes.reduce((sum, note) => sum + Math.ceil(note.content.length / 4), 0);
85
+ return totalTokens >= this.config.activationThresholdTokens;
86
+ }
87
+ /**
88
+ * Force reflection over all pending notes.
89
+ */
90
+ async reflect(existingMemoryContext) {
91
+ if (!this.llmInvoker || this.pendingNotes.length === 0) {
92
+ return { traces: [], supersededTraceIds: [], consumedNoteIds: [], compressionRatio: 1 };
93
+ }
94
+ const notesText = this.pendingNotes
95
+ .map((n) => `[${n.id}] (${n.type}, importance=${n.importance.toFixed(2)}) ${n.content}`)
96
+ .join('\n');
97
+ const userPrompt = existingMemoryContext
98
+ ? `## Existing Memory Context\n${existingMemoryContext}\n\n## New Observation Notes\n${notesText}`
99
+ : `## Observation Notes\n${notesText}`;
100
+ const systemPrompt = buildReflectorSystemPrompt(this.traits);
101
+ try {
102
+ const response = await this.llmInvoker(systemPrompt, userPrompt);
103
+ const result = this.parseReflection(response);
104
+ // Clear consumed notes
105
+ const consumedSet = new Set(result.consumedNoteIds);
106
+ this.pendingNotes = this.pendingNotes.filter((n) => !consumedSet.has(n.id));
107
+ // Compute compression ratio
108
+ const inputTokens = notesText.length / 4;
109
+ const outputTokens = result.traces.reduce((sum, t) => sum + t.content.length / 4, 0);
110
+ result.compressionRatio = outputTokens > 0 ? inputTokens / outputTokens : 1;
111
+ return result;
112
+ }
113
+ catch {
114
+ return { traces: [], supersededTraceIds: [], consumedNoteIds: [], compressionRatio: 1 };
115
+ }
116
+ }
117
+ /** Get pending note count. */
118
+ getPendingNoteCount() {
119
+ return this.pendingNotes.length;
120
+ }
121
+ /** Clear all pending notes. */
122
+ clear() {
123
+ this.pendingNotes = [];
124
+ }
125
+ // --- Internal ---
126
+ parseReflection(llmResponse) {
127
+ const traces = [];
128
+ const supersededTraceIds = [];
129
+ const consumedNoteIds = [];
130
+ const lines = llmResponse.split('\n').filter((l) => l.trim());
131
+ const now = Date.now();
132
+ for (const line of lines) {
133
+ try {
134
+ const parsed = JSON.parse(line.trim());
135
+ if (!parsed.content)
136
+ continue;
137
+ const type = (['episodic', 'semantic', 'procedural', 'prospective'].includes(parsed.type)
138
+ ? parsed.type
139
+ : 'semantic');
140
+ const scope = (['user', 'thread', 'persona', 'organization'].includes(parsed.scope)
141
+ ? parsed.scope
142
+ : 'user');
143
+ traces.push({
144
+ type,
145
+ scope,
146
+ scopeId: parsed.scopeId ?? '',
147
+ content: parsed.content,
148
+ entities: Array.isArray(parsed.entities) ? parsed.entities : [],
149
+ tags: Array.isArray(parsed.tags) ? parsed.tags : [],
150
+ provenance: {
151
+ sourceType: 'reflection',
152
+ confidence: typeof parsed.confidence === 'number' ? parsed.confidence : 0.7,
153
+ verificationCount: 0,
154
+ sourceTimestamp: now,
155
+ },
156
+ emotionalContext: {
157
+ valence: 0,
158
+ arousal: 0,
159
+ dominance: 0,
160
+ intensity: 0,
161
+ gmiMood: '',
162
+ },
163
+ associatedTraceIds: [],
164
+ isActive: true,
165
+ });
166
+ if (Array.isArray(parsed.supersedes)) {
167
+ supersededTraceIds.push(...parsed.supersedes);
168
+ }
169
+ if (Array.isArray(parsed.consumedNotes)) {
170
+ consumedNoteIds.push(...parsed.consumedNotes);
171
+ }
172
+ }
173
+ catch {
174
+ // Skip malformed lines
175
+ }
176
+ }
177
+ // If no specific notes were claimed, consider all pending consumed
178
+ if (consumedNoteIds.length === 0 && traces.length > 0) {
179
+ consumedNoteIds.push(...this.pendingNotes.map((n) => n.id));
180
+ }
181
+ return { traces, supersededTraceIds, consumedNoteIds, compressionRatio: 1 };
182
+ }
183
+ }
184
+ //# sourceMappingURL=MemoryReflector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryReflector.js","sourceRoot":"","sources":["../../../src/memory/observation/MemoryReflector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAqBH,8EAA8E;AAC9E,kCAAkC;AAClC,8EAA8E;AAE9E,SAAS,0BAA0B,CAAC,MAAoB;IACtD,MAAM,KAAK,GAAG,CAAC,CAAqB,EAAU,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,I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
+ *
4
+ * Accumulates conversation messages and tracks approximate token count.
5
+ * When the configured threshold is reached, signals that observation
6
+ * extraction should be triggered.
7
+ *
8
+ * @module agentos/memory/observation/ObservationBuffer
9
+ */
10
+ export interface BufferedMessage {
11
+ role: 'user' | 'assistant' | 'system' | 'tool';
12
+ content: string;
13
+ timestamp: number;
14
+ /** Cached token estimate for this message. */
15
+ tokenEstimate: number;
16
+ }
17
+ export interface ObservationBufferConfig {
18
+ /** Token threshold before observer should be triggered. @default 30_000 */
19
+ activationThresholdTokens: number;
20
+ }
21
+ export declare class ObservationBuffer {
22
+ private messages;
23
+ private totalTokens;
24
+ private config;
25
+ /** Number of tokens that have been drained (consumed by observer). */
26
+ private drainedTokens;
27
+ constructor(config?: Partial<ObservationBufferConfig>);
28
+ /**
29
+ * Add a message to the buffer.
30
+ * Returns true if the buffer has reached activation threshold.
31
+ */
32
+ push(role: BufferedMessage['role'], content: string): boolean;
33
+ /** Whether accumulated tokens since last drain exceed the threshold. */
34
+ shouldActivate(): boolean;
35
+ /**
36
+ * Drain messages since last drain for observation processing.
37
+ * Returns the messages and marks them as consumed.
38
+ */
39
+ drain(): BufferedMessage[];
40
+ /** Index of next unprocessed message. */
41
+ private drainCursor;
42
+ /** Total accumulated tokens. */
43
+ getTotalTokens(): number;
44
+ /** Unprocessed tokens since last drain. */
45
+ getPendingTokens(): number;
46
+ /** Total message count. */
47
+ getMessageCount(): number;
48
+ /** Clear the buffer entirely. */
49
+ clear(): void;
50
+ }
51
+ //# sourceMappingURL=ObservationBuffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservationBuffer.d.ts","sourceRoot":"","sources":["../../../src/memory/observation/ObservationBuffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,2EAA2E;IAC3E,yBAAyB,EAAE,MAAM,CAAC;CACnC;AAeD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,MAAM,CAA0B;IACxC,sEAAsE;IACtE,OAAO,CAAC,aAAa,CAAK;gBAEd,MAAM,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC;IAMrD;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAY7D,wEAAwE;IACxE,cAAc,IAAI,OAAO;IAIzB;;;OAGG;IACH,KAAK,IAAI,eAAe,EAAE;IAO1B,yCAAyC;IACzC,OAAO,CAAC,WAAW,CAAK;IAExB,gCAAgC;IAChC,cAAc,IAAI,MAAM;IAIxB,2CAA2C;IAC3C,gBAAgB,IAAI,MAAM;IAI1B,2BAA2B;IAC3B,eAAe,IAAI,MAAM;IAIzB,iCAAiC;IACjC,KAAK,IAAI,IAAI;CAMd"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @fileoverview Token-counting buffer for the observation system.
3
+ *
4
+ * Accumulates conversation messages and tracks approximate token count.
5
+ * When the configured threshold is reached, signals that observation
6
+ * extraction should be triggered.
7
+ *
8
+ * @module agentos/memory/observation/ObservationBuffer
9
+ */
10
+ // ---------------------------------------------------------------------------
11
+ // Token estimation
12
+ // ---------------------------------------------------------------------------
13
+ /** Rough token estimate: ~4 chars per token for English text. */
14
+ function estimateTokens(text) {
15
+ return Math.ceil(text.length / 4);
16
+ }
17
+ // ---------------------------------------------------------------------------
18
+ // ObservationBuffer
19
+ // ---------------------------------------------------------------------------
20
+ export class ObservationBuffer {
21
+ constructor(config) {
22
+ this.messages = [];
23
+ this.totalTokens = 0;
24
+ /** Number of tokens that have been drained (consumed by observer). */
25
+ this.drainedTokens = 0;
26
+ /** Index of next unprocessed message. */
27
+ this.drainCursor = 0;
28
+ this.config = {
29
+ activationThresholdTokens: config?.activationThresholdTokens ?? 30000,
30
+ };
31
+ }
32
+ /**
33
+ * Add a message to the buffer.
34
+ * Returns true if the buffer has reached activation threshold.
35
+ */
36
+ push(role, content) {
37
+ const tokenEstimate = estimateTokens(content);
38
+ this.messages.push({
39
+ role,
40
+ content,
41
+ timestamp: Date.now(),
42
+ tokenEstimate,
43
+ });
44
+ this.totalTokens += tokenEstimate;
45
+ return this.shouldActivate();
46
+ }
47
+ /** Whether accumulated tokens since last drain exceed the threshold. */
48
+ shouldActivate() {
49
+ return (this.totalTokens - this.drainedTokens) >= this.config.activationThresholdTokens;
50
+ }
51
+ /**
52
+ * Drain messages since last drain for observation processing.
53
+ * Returns the messages and marks them as consumed.
54
+ */
55
+ drain() {
56
+ const unprocessed = this.messages.slice(this.drainCursor);
57
+ this.drainedTokens = this.totalTokens;
58
+ this.drainCursor = this.messages.length;
59
+ return unprocessed;
60
+ }
61
+ /** Total accumulated tokens. */
62
+ getTotalTokens() {
63
+ return this.totalTokens;
64
+ }
65
+ /** Unprocessed tokens since last drain. */
66
+ getPendingTokens() {
67
+ return this.totalTokens - this.drainedTokens;
68
+ }
69
+ /** Total message count. */
70
+ getMessageCount() {
71
+ return this.messages.length;
72
+ }
73
+ /** Clear the buffer entirely. */
74
+ clear() {
75
+ this.messages = [];
76
+ this.totalTokens = 0;
77
+ this.drainedTokens = 0;
78
+ this.drainCursor = 0;
79
+ }
80
+ }
81
+ //# sourceMappingURL=ObservationBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservationBuffer.js","sourceRoot":"","sources":["../../../src/memory/observation/ObservationBuffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmBH,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,iEAAiE;AACjE,SAAS,cAAc,CA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