@mastra/memory 1.15.1 → 1.16.0-alpha.1

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 (34) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-3TU4GGH3.cjs → chunk-3NECGYWZ.cjs} +117 -16
  3. package/dist/chunk-3NECGYWZ.cjs.map +1 -0
  4. package/dist/{chunk-7NCBGOHT.js → chunk-HB6AYAFD.js} +117 -16
  5. package/dist/chunk-HB6AYAFD.js.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +47 -47
  8. package/dist/docs/references/docs-memory-observational-memory.md +23 -7
  9. package/dist/docs/references/reference-memory-observational-memory.md +2 -0
  10. package/dist/index.cjs +14 -13
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +5 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/{observational-memory-4TDIBXK6.js → observational-memory-WWAB2MMI.js} +3 -3
  17. package/dist/{observational-memory-4TDIBXK6.js.map → observational-memory-WWAB2MMI.js.map} +1 -1
  18. package/dist/{observational-memory-GH6IRH6E.cjs → observational-memory-X4N2R4CA.cjs} +26 -26
  19. package/dist/{observational-memory-GH6IRH6E.cjs.map → observational-memory-X4N2R4CA.cjs.map} +1 -1
  20. package/dist/processors/index.cjs +24 -24
  21. package/dist/processors/index.js +1 -1
  22. package/dist/processors/observational-memory/markers.d.ts +3 -0
  23. package/dist/processors/observational-memory/markers.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observational-memory.d.ts +6 -0
  26. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  28. package/dist/processors/observational-memory/reflector-runner.d.ts +1 -0
  29. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/types.d.ts +19 -0
  31. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  32. package/package.json +5 -5
  33. package/dist/chunk-3TU4GGH3.cjs.map +0 -1
  34. package/dist/chunk-7NCBGOHT.js.map +0 -1
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.15.1"
6
+ version: "1.16.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,120 +1,120 @@
1
1
  {
2
- "version": "1.15.1",
2
+ "version": "1.16.0-alpha.1",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "ModelByInputTokens": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-7NCBGOHT.js",
8
- "line": 666
7
+ "implementation": "dist/chunk-HB6AYAFD.js",
8
+ "line": 669
9
9
  },
10
10
  "OBSERVER_SYSTEM_PROMPT": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-7NCBGOHT.js"
12
+ "implementation": "dist/chunk-HB6AYAFD.js"
13
13
  },
14
14
  "ObservationalMemory": {
15
15
  "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-7NCBGOHT.js",
17
- "line": 6234
16
+ "implementation": "dist/chunk-HB6AYAFD.js",
17
+ "line": 6311
18
18
  },
19
19
  "ObservationalMemoryProcessor": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-7NCBGOHT.js",
22
- "line": 8633
21
+ "implementation": "dist/chunk-HB6AYAFD.js",
22
+ "line": 8734
23
23
  },
24
24
  "TokenCounter": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-7NCBGOHT.js",
27
- "line": 5786
26
+ "implementation": "dist/chunk-HB6AYAFD.js",
27
+ "line": 5811
28
28
  },
29
29
  "buildObserverPrompt": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-7NCBGOHT.js",
32
- "line": 3416
31
+ "implementation": "dist/chunk-HB6AYAFD.js",
32
+ "line": 3421
33
33
  },
34
34
  "buildObserverSystemPrompt": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-7NCBGOHT.js",
37
- "line": 2815
36
+ "implementation": "dist/chunk-HB6AYAFD.js",
37
+ "line": 2820
38
38
  },
39
39
  "combineObservationGroupRanges": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-7NCBGOHT.js",
42
- "line": 758
41
+ "implementation": "dist/chunk-HB6AYAFD.js",
42
+ "line": 761
43
43
  },
44
44
  "deriveObservationGroupProvenance": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-7NCBGOHT.js",
47
- "line": 792
46
+ "implementation": "dist/chunk-HB6AYAFD.js",
47
+ "line": 795
48
48
  },
49
49
  "extractCurrentTask": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-7NCBGOHT.js",
52
- "line": 3530
51
+ "implementation": "dist/chunk-HB6AYAFD.js",
52
+ "line": 3535
53
53
  },
54
54
  "formatMessagesForObserver": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-7NCBGOHT.js",
57
- "line": 3142
56
+ "implementation": "dist/chunk-HB6AYAFD.js",
57
+ "line": 3147
58
58
  },
59
59
  "getObservationsAsOf": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-7NCBGOHT.js",
62
- "line": 8818
61
+ "implementation": "dist/chunk-HB6AYAFD.js",
62
+ "line": 8919
63
63
  },
64
64
  "hasCurrentTaskSection": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-7NCBGOHT.js",
67
- "line": 3518
66
+ "implementation": "dist/chunk-HB6AYAFD.js",
67
+ "line": 3523
68
68
  },
69
69
  "injectAnchorIds": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-7NCBGOHT.js",
72
- "line": 2372
71
+ "implementation": "dist/chunk-HB6AYAFD.js",
72
+ "line": 2377
73
73
  },
74
74
  "optimizeObservationsForContext": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-7NCBGOHT.js",
77
- "line": 3541
76
+ "implementation": "dist/chunk-HB6AYAFD.js",
77
+ "line": 3546
78
78
  },
79
79
  "parseAnchorId": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-7NCBGOHT.js",
82
- "line": 2345
81
+ "implementation": "dist/chunk-HB6AYAFD.js",
82
+ "line": 2350
83
83
  },
84
84
  "parseObservationGroups": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-7NCBGOHT.js",
87
- "line": 727
86
+ "implementation": "dist/chunk-HB6AYAFD.js",
87
+ "line": 730
88
88
  },
89
89
  "parseObserverOutput": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-7NCBGOHT.js",
92
- "line": 3426
91
+ "implementation": "dist/chunk-HB6AYAFD.js",
92
+ "line": 3431
93
93
  },
94
94
  "reconcileObservationGroupsFromReflection": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-7NCBGOHT.js",
97
- "line": 816
96
+ "implementation": "dist/chunk-HB6AYAFD.js",
97
+ "line": 819
98
98
  },
99
99
  "renderObservationGroupsForReflection": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-7NCBGOHT.js",
102
- "line": 772
101
+ "implementation": "dist/chunk-HB6AYAFD.js",
102
+ "line": 775
103
103
  },
104
104
  "stripEphemeralAnchorIds": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-7NCBGOHT.js",
107
- "line": 2402
106
+ "implementation": "dist/chunk-HB6AYAFD.js",
107
+ "line": 2407
108
108
  },
109
109
  "stripObservationGroups": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-7NCBGOHT.js",
112
- "line": 749
111
+ "implementation": "dist/chunk-HB6AYAFD.js",
112
+ "line": 752
113
113
  },
114
114
  "wrapInObservationGroup": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-7NCBGOHT.js",
117
- "line": 720
116
+ "implementation": "dist/chunk-HB6AYAFD.js",
117
+ "line": 723
118
118
  },
119
119
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
120
120
  "types": "dist/processors/index.d.ts",
@@ -161,7 +161,7 @@
161
161
  "processors": {
162
162
  "index": "dist/processors/index.js",
163
163
  "chunks": [
164
- "chunk-7NCBGOHT.js",
164
+ "chunk-HB6AYAFD.js",
165
165
  "chunk-LSJJAJAF.js"
166
166
  ]
167
167
  }
@@ -333,13 +333,29 @@ Reflection works similarly — the Reflector runs in the background when observa
333
333
 
334
334
  ### Settings
335
335
 
336
- | Setting | Default | What it controls |
337
- | ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
338
- | `observation.bufferTokens` | `0.2` | How often to buffer. `0.2` means every 20% of `messageTokens` — with the default 30k threshold, that's roughly every 6k tokens. Can also be an absolute token count (e.g. `5000`). |
339
- | `observation.bufferActivation` | `0.8` | How aggressively to clear the message window on activation. `0.8` means remove enough messages to keep only 20% of `messageTokens` remaining. Lower values keep more message history. |
340
- | `observation.blockAfter` | `1.2` | Safety threshold as a multiplier of `messageTokens`. At `1.2`, synchronous observation is forced at 36k tokens (1.2 × 30k). Only matters if buffering can't keep up. |
341
- | `reflection.bufferActivation` | `0.5` | When to start background reflection. `0.5` means reflection begins when observations reach 50% of the `observationTokens` threshold. |
342
- | `reflection.blockAfter` | `1.2` | Safety threshold for reflection, same logic as observation. |
336
+ | Setting | Default | What it controls |
337
+ | ------------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
338
+ | `observation.bufferTokens` | `0.2` | How often to buffer. `0.2` means every 20% of `messageTokens` — with the default 30k threshold, that's roughly every 6k tokens. Can also be an absolute token count (e.g. `5000`). |
339
+ | `observation.bufferActivation` | `0.8` | How aggressively to clear the message window on activation. `0.8` means remove enough messages to keep only 20% of `messageTokens` remaining. Lower values keep more message history. |
340
+ | `observation.blockAfter` | `1.2` | Safety threshold as a multiplier of `messageTokens`. At `1.2`, synchronous observation is forced at 36k tokens (1.2 × 30k). Only matters if buffering can't keep up. |
341
+ | `activateAfterIdle` | none | Forces buffered observations and buffered reflections to activate after a period of inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like `300_000`, `"5m"`, or `"1hr"`. Set this to your prompt cache TTL if you want activation to happen before the next cold prompt. |
342
+ | `reflection.bufferActivation` | `0.5` | When to start background reflection. `0.5` means reflection begins when observations reach 50% of the `observationTokens` threshold. |
343
+ | `reflection.blockAfter` | `1.2` | Safety threshold for reflection, same logic as observation. |
344
+
345
+ If you're relying on prompt caching, set `activateAfterIdle` to match your cache TTL. That way, once a thread has been idle long enough for the cache to expire, the next request can activate buffered observations or reflections first and send a smaller compressed context window.
346
+
347
+ ```typescript
348
+ const memory = new Memory({
349
+ options: {
350
+ observationalMemory: {
351
+ model: 'google/gemini-2.5-flash',
352
+ activateAfterIdle: '5m',
353
+ },
354
+ },
355
+ })
356
+ ```
357
+
358
+ With a 5-minute prompt cache TTL, this activates buffered context after 5 minutes of inactivity so the next uncached prompt uses observations and reflections instead of a larger raw message window. If you prefer, `300_000` works the same way.
343
359
 
344
360
  ### Disabling
345
361
 
@@ -36,6 +36,8 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
36
36
 
37
37
  **scope** (`'resource' | 'thread'`): Memory scope for observations. \`'thread'\` keeps observations per-thread. \`'resource'\` (experimental) shares observations across all threads for a resource, enabling cross-conversation memory. (Default: `'thread'`)
38
38
 
39
+ **activateAfterIdle** (`number | string`): Time before buffered observations or buffered reflections are forced to activate after inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like \`300\_000\`, \`"5m"\`, or \`"1hr"\`. When the gap between the current time and the last assistant message part timestamp exceeds this value, buffered observational memory activates before the next prompt. Useful for aligning with prompt cache TTLs.
40
+
39
41
  **shareTokenBudget** (`boolean`): Share the token budget between messages and observations. When enabled, the total budget is \`observation.messageTokens + reflection.observationTokens\`. Messages can use more space when observations are small, and vice versa. This maximizes context usage through flexible allocation. \`shareTokenBudget\` is not yet compatible with async buffering. You must set \`observation: { bufferTokens: false }\` when using this option (this is a temporary limitation). (Default: `false`)
40
42
 
41
43
  **retrieval** (`boolean | { vector?: boolean; scope?: 'thread' | 'resource' }`): \*\*Experimental.\*\* Enable retrieval-mode observation groups as durable pointers to raw message history. \`true\` enables cross-thread browsing by default. \`{ vector: true }\` also enables semantic search using Memory's vector store and embedder. \`{ scope: 'thread' }\` restricts the recall tool to the current thread only. Default scope is \`'resource'\`. (Default: `false`)
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  var chunkCK4U3AYR_cjs = require('./chunk-CK4U3AYR.cjs');
4
4
  var chunkIDRQZVB4_cjs = require('./chunk-IDRQZVB4.cjs');
5
- var chunk3TU4GGH3_cjs = require('./chunk-3TU4GGH3.cjs');
5
+ var chunk3NECGYWZ_cjs = require('./chunk-3NECGYWZ.cjs');
6
6
  var v3 = require('zod/v3');
7
7
  var zod = require('zod');
8
8
  var z4 = require('zod/v4');
@@ -15709,7 +15709,7 @@ function formatTimestamp(date) {
15709
15709
  }
15710
15710
  function truncateByTokens(text4, maxTokens, hint) {
15711
15711
  if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
15712
- const truncated = chunk3TU4GGH3_cjs.truncateStringByTokens(text4, maxTokens);
15712
+ const truncated = chunk3NECGYWZ_cjs.truncateStringByTokens(text4, maxTokens);
15713
15713
  const suffix = hint ? ` [${hint} for more]` : "";
15714
15714
  return { text: truncated + suffix, wasTruncated: true };
15715
15715
  }
@@ -15761,11 +15761,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
15761
15761
  });
15762
15762
  }
15763
15763
  if (inv.state === "result") {
15764
- const { value: resultValue } = chunk3TU4GGH3_cjs.resolveToolResultValue(
15764
+ const { value: resultValue } = chunk3NECGYWZ_cjs.resolveToolResultValue(
15765
15765
  part,
15766
15766
  inv.result
15767
15767
  );
15768
- const resultStr = chunk3TU4GGH3_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15768
+ const resultStr = chunk3NECGYWZ_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15769
15769
  const fullText = `[Tool Result: ${inv.toolName}]
15770
15770
  ${resultStr}`;
15771
15771
  parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
@@ -15792,7 +15792,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
15792
15792
  const toolName = part.toolName;
15793
15793
  if (toolName) {
15794
15794
  const rawResult = part.output ?? part.result;
15795
- const resultStr = chunk3TU4GGH3_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15795
+ const resultStr = chunk3NECGYWZ_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15796
15796
  const fullText = `[Tool Result: ${toolName}]
15797
15797
  ${resultStr}`;
15798
15798
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
@@ -15871,7 +15871,7 @@ function renderFormattedParts(parts, timestamps, options) {
15871
15871
  const text4 = buildRenderedText(parts, timestamps);
15872
15872
  let totalTokens = tokenx.estimateTokenCount(text4);
15873
15873
  if (totalTokens > options.maxTokens) {
15874
- const truncated = chunk3TU4GGH3_cjs.truncateStringByTokens(text4, options.maxTokens);
15874
+ const truncated = chunk3NECGYWZ_cjs.truncateStringByTokens(text4, options.maxTokens);
15875
15875
  return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
15876
15876
  }
15877
15877
  const truncatedIndices = parts.map((p, i) => ({ part: p, index: i })).filter(({ part }) => part.text !== part.fullText).sort((a, b) => expandPriority(a.part) - expandPriority(b.part));
@@ -15904,7 +15904,7 @@ function renderFormattedParts(parts, timestamps, options) {
15904
15904
  if (expandedTokens <= options.maxTokens) {
15905
15905
  return { text: expanded, truncated: false, tokenOffset: 0 };
15906
15906
  }
15907
- const hardTruncated = chunk3TU4GGH3_cjs.truncateStringByTokens(expanded, options.maxTokens);
15907
+ const hardTruncated = chunk3NECGYWZ_cjs.truncateStringByTokens(expanded, options.maxTokens);
15908
15908
  return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
15909
15909
  }
15910
15910
  async function recallPart({
@@ -15955,7 +15955,7 @@ async function recallPart({
15955
15955
 
15956
15956
  `;
15957
15957
  const fallbackText = `${fallbackNote}${firstNextPart.text}`;
15958
- const truncatedText2 = chunk3TU4GGH3_cjs.truncateStringByTokens(fallbackText, maxTokens);
15958
+ const truncatedText2 = chunk3NECGYWZ_cjs.truncateStringByTokens(fallbackText, maxTokens);
15959
15959
  const wasTruncated2 = truncatedText2 !== fallbackText;
15960
15960
  return {
15961
15961
  text: truncatedText2,
@@ -15970,7 +15970,7 @@ async function recallPart({
15970
15970
  }
15971
15971
  throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
15972
15972
  }
15973
- const truncatedText = chunk3TU4GGH3_cjs.truncateStringByTokens(target.text, maxTokens);
15973
+ const truncatedText = chunk3NECGYWZ_cjs.truncateStringByTokens(target.text, maxTokens);
15974
15974
  const wasTruncated = truncatedText !== target.text;
15975
15975
  return {
15976
15976
  text: truncatedText,
@@ -17601,7 +17601,7 @@ ${workingMemory}`;
17601
17601
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
17602
17602
  );
17603
17603
  }
17604
- const { ObservationalMemory: OMClass } = await import('./observational-memory-GH6IRH6E.cjs');
17604
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-X4N2R4CA.cjs');
17605
17605
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
17606
17606
  await this.indexObservation(observation);
17607
17607
  } : void 0;
@@ -17609,6 +17609,7 @@ ${workingMemory}`;
17609
17609
  storage: memoryStore,
17610
17610
  scope: omConfig.scope,
17611
17611
  retrieval: omConfig.retrieval,
17612
+ activateAfterIdle: omConfig.activateAfterIdle,
17612
17613
  shareTokenBudget: omConfig.shareTokenBudget,
17613
17614
  model: omConfig.model,
17614
17615
  onIndexObservations,
@@ -18524,18 +18525,18 @@ Notes:
18524
18525
  if (!effectiveConfig) return null;
18525
18526
  const engine = await this.omEngine;
18526
18527
  if (!engine) return null;
18527
- const { ObservationalMemoryProcessor } = await import('./observational-memory-GH6IRH6E.cjs');
18528
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-X4N2R4CA.cjs');
18528
18529
  return new ObservationalMemoryProcessor(engine, this);
18529
18530
  }
18530
18531
  };
18531
18532
 
18532
18533
  Object.defineProperty(exports, "ModelByInputTokens", {
18533
18534
  enumerable: true,
18534
- get: function () { return chunk3TU4GGH3_cjs.ModelByInputTokens; }
18535
+ get: function () { return chunk3NECGYWZ_cjs.ModelByInputTokens; }
18535
18536
  });
18536
18537
  Object.defineProperty(exports, "getObservationsAsOf", {
18537
18538
  enumerable: true,
18538
- get: function () { return chunk3TU4GGH3_cjs.getObservationsAsOf; }
18539
+ get: function () { return chunk3NECGYWZ_cjs.getObservationsAsOf; }
18539
18540
  });
18540
18541
  Object.defineProperty(exports, "extractWorkingMemoryContent", {
18541
18542
  enumerable: true,