@mastra/memory 1.16.0 → 1.17.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 (36) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-HAUWGR76.cjs → chunk-5MTY2UYL.cjs} +206 -10
  3. package/dist/chunk-5MTY2UYL.cjs.map +1 -0
  4. package/dist/{chunk-OOA4C7IX.js → chunk-MPBMHIAQ.js} +206 -10
  5. package/dist/chunk-MPBMHIAQ.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 +31 -0
  9. package/dist/docs/references/reference-memory-observational-memory.md +2 -0
  10. package/dist/index.cjs +16 -14
  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 +7 -5
  15. package/dist/index.js.map +1 -1
  16. package/dist/{observational-memory-CIGODMXV.js → observational-memory-7YYZIIX4.js} +3 -3
  17. package/dist/{observational-memory-CIGODMXV.js.map → observational-memory-7YYZIIX4.js.map} +1 -1
  18. package/dist/{observational-memory-EWU3QFIE.cjs → observational-memory-UCFGVLVW.cjs} +26 -26
  19. package/dist/{observational-memory-EWU3QFIE.cjs.map → observational-memory-UCFGVLVW.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/date-utils.d.ts +6 -0
  23. package/dist/processors/observational-memory/date-utils.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/processor.d.ts +5 -1
  26. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/string-utils.d.ts +13 -0
  28. package/dist/processors/observational-memory/string-utils.d.ts.map +1 -0
  29. package/dist/processors/observational-memory/temporal-markers.d.ts +4 -0
  30. package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -0
  31. package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/types.d.ts +7 -0
  33. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  34. package/package.json +7 -7
  35. package/dist/chunk-HAUWGR76.cjs.map +0 -1
  36. package/dist/chunk-OOA4C7IX.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.16.0"
6
+ version: "1.17.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,120 +1,120 @@
1
1
  {
2
- "version": "1.16.0",
2
+ "version": "1.17.0",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "ModelByInputTokens": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-OOA4C7IX.js",
8
- "line": 684
7
+ "implementation": "dist/chunk-MPBMHIAQ.js",
8
+ "line": 745
9
9
  },
10
10
  "OBSERVER_SYSTEM_PROMPT": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-OOA4C7IX.js"
12
+ "implementation": "dist/chunk-MPBMHIAQ.js"
13
13
  },
14
14
  "ObservationalMemory": {
15
15
  "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-OOA4C7IX.js",
17
- "line": 6432
16
+ "implementation": "dist/chunk-MPBMHIAQ.js",
17
+ "line": 6518
18
18
  },
19
19
  "ObservationalMemoryProcessor": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-OOA4C7IX.js",
22
- "line": 8870
21
+ "implementation": "dist/chunk-MPBMHIAQ.js",
22
+ "line": 9060
23
23
  },
24
24
  "TokenCounter": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-OOA4C7IX.js",
27
- "line": 5902
26
+ "implementation": "dist/chunk-MPBMHIAQ.js",
27
+ "line": 5988
28
28
  },
29
29
  "buildObserverPrompt": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-OOA4C7IX.js",
32
- "line": 3443
31
+ "implementation": "dist/chunk-MPBMHIAQ.js",
32
+ "line": 3529
33
33
  },
34
34
  "buildObserverSystemPrompt": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-OOA4C7IX.js",
37
- "line": 2842
36
+ "implementation": "dist/chunk-MPBMHIAQ.js",
37
+ "line": 2912
38
38
  },
39
39
  "combineObservationGroupRanges": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-OOA4C7IX.js",
42
- "line": 776
41
+ "implementation": "dist/chunk-MPBMHIAQ.js",
42
+ "line": 837
43
43
  },
44
44
  "deriveObservationGroupProvenance": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-OOA4C7IX.js",
47
- "line": 810
46
+ "implementation": "dist/chunk-MPBMHIAQ.js",
47
+ "line": 871
48
48
  },
49
49
  "extractCurrentTask": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-OOA4C7IX.js",
52
- "line": 3557
51
+ "implementation": "dist/chunk-MPBMHIAQ.js",
52
+ "line": 3643
53
53
  },
54
54
  "formatMessagesForObserver": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-OOA4C7IX.js",
57
- "line": 3169
56
+ "implementation": "dist/chunk-MPBMHIAQ.js",
57
+ "line": 3255
58
58
  },
59
59
  "getObservationsAsOf": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-OOA4C7IX.js",
62
- "line": 9056
61
+ "implementation": "dist/chunk-MPBMHIAQ.js",
62
+ "line": 9252
63
63
  },
64
64
  "hasCurrentTaskSection": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-OOA4C7IX.js",
67
- "line": 3545
66
+ "implementation": "dist/chunk-MPBMHIAQ.js",
67
+ "line": 3631
68
68
  },
69
69
  "injectAnchorIds": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-OOA4C7IX.js",
72
- "line": 2399
71
+ "implementation": "dist/chunk-MPBMHIAQ.js",
72
+ "line": 2460
73
73
  },
74
74
  "optimizeObservationsForContext": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-OOA4C7IX.js",
77
- "line": 3568
76
+ "implementation": "dist/chunk-MPBMHIAQ.js",
77
+ "line": 3654
78
78
  },
79
79
  "parseAnchorId": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-OOA4C7IX.js",
82
- "line": 2372
81
+ "implementation": "dist/chunk-MPBMHIAQ.js",
82
+ "line": 2433
83
83
  },
84
84
  "parseObservationGroups": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-OOA4C7IX.js",
87
- "line": 745
86
+ "implementation": "dist/chunk-MPBMHIAQ.js",
87
+ "line": 806
88
88
  },
89
89
  "parseObserverOutput": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-OOA4C7IX.js",
92
- "line": 3453
91
+ "implementation": "dist/chunk-MPBMHIAQ.js",
92
+ "line": 3539
93
93
  },
94
94
  "reconcileObservationGroupsFromReflection": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-OOA4C7IX.js",
97
- "line": 834
96
+ "implementation": "dist/chunk-MPBMHIAQ.js",
97
+ "line": 895
98
98
  },
99
99
  "renderObservationGroupsForReflection": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-OOA4C7IX.js",
102
- "line": 790
101
+ "implementation": "dist/chunk-MPBMHIAQ.js",
102
+ "line": 851
103
103
  },
104
104
  "stripEphemeralAnchorIds": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-OOA4C7IX.js",
107
- "line": 2429
106
+ "implementation": "dist/chunk-MPBMHIAQ.js",
107
+ "line": 2490
108
108
  },
109
109
  "stripObservationGroups": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-OOA4C7IX.js",
112
- "line": 767
111
+ "implementation": "dist/chunk-MPBMHIAQ.js",
112
+ "line": 828
113
113
  },
114
114
  "wrapInObservationGroup": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-OOA4C7IX.js",
117
- "line": 738
116
+ "implementation": "dist/chunk-MPBMHIAQ.js",
117
+ "line": 799
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-OOA4C7IX.js",
164
+ "chunk-MPBMHIAQ.js",
165
165
  "chunk-LSJJAJAF.js"
166
166
  ]
167
167
  }
@@ -46,6 +46,37 @@ See [configuration options](https://mastra.ai/reference/memory/observational-mem
46
46
 
47
47
  > **Note:** OM currently only supports `@mastra/pg`, `@mastra/libsql`, and `@mastra/mongodb` storage adapters. It uses background agents for managing memory. When using `observationalMemory: true`, the default model is `google/gemini-2.5-flash`. When passing a config object, a `model` must be explicitly set.
48
48
 
49
+ ## Temporal gap markers
50
+
51
+ Temporal gap markers insert a short reminder before a new user message when enough time has passed since the previous message in the thread. They help the agent and the UI see that the conversation resumed after a meaningful pause.
52
+
53
+ Temporal gap markers are off by default. Enable them with `temporalMarkers: true` in the `observationalMemory` config:
54
+
55
+ ```typescript
56
+ import { Memory } from '@mastra/memory'
57
+ import { Agent } from '@mastra/core/agent'
58
+
59
+ export const agent = new Agent({
60
+ name: 'my-agent',
61
+ instructions: 'You are a helpful assistant.',
62
+ model: 'openai/gpt-5-mini',
63
+ memory: new Memory({
64
+ options: {
65
+ observationalMemory: {
66
+ model: 'google/gemini-2.5-flash',
67
+ temporalMarkers: true,
68
+ },
69
+ },
70
+ }),
71
+ })
72
+ ```
73
+
74
+ Mastra inserts a temporal gap marker when the gap is at least 10 minutes. The marker is stored in memory and also emitted as a transient reminder event, so clients can render it as a lightweight timeline hint.
75
+
76
+ The observer also sees these markers when it processes the thread, so the observations it writes can anchor memories to when they happened (for example, "User asked about deployment after a 2-day gap").
77
+
78
+ See [the API reference](https://mastra.ai/reference/memory/observational-memory) for the full configuration shape.
79
+
49
80
  ## Benefits
50
81
 
51
82
  - **Prompt caching**: OM's context is stable and observations append over time rather than being dynamically retrieved each turn. This keeps the prompt prefix cacheable, which reduces costs.
@@ -40,6 +40,8 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
40
40
 
41
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`)
42
42
 
43
+ **temporalMarkers** (`boolean`): Insert temporal-gap reminder markers before new user messages when the previous message in the thread is at least 10 minutes older. The marker is persisted in memory, emitted as an inline reminder event so clients can render it specially, and shown to the observer so it can anchor observations to when events occurred. (Default: `false`)
44
+
43
45
  **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`)
44
46
 
45
47
  **observation** (`ObservationalMemoryObservationConfig`): Configuration for the observation step. Controls when the Observer agent runs and how it behaves.
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 chunkHAUWGR76_cjs = require('./chunk-HAUWGR76.cjs');
5
+ var chunk5MTY2UYL_cjs = require('./chunk-5MTY2UYL.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 = chunkHAUWGR76_cjs.truncateStringByTokens(text4, maxTokens);
15712
+ const truncated = chunk5MTY2UYL_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 } = chunkHAUWGR76_cjs.resolveToolResultValue(
15764
+ const { value: resultValue } = chunk5MTY2UYL_cjs.resolveToolResultValue(
15765
15765
  part,
15766
15766
  inv.result
15767
15767
  );
15768
- const resultStr = chunkHAUWGR76_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15768
+ const resultStr = chunk5MTY2UYL_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 = chunkHAUWGR76_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15795
+ const resultStr = chunk5MTY2UYL_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 = chunkHAUWGR76_cjs.truncateStringByTokens(text4, options.maxTokens);
15874
+ const truncated = chunk5MTY2UYL_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 = chunkHAUWGR76_cjs.truncateStringByTokens(expanded, options.maxTokens);
15907
+ const hardTruncated = chunk5MTY2UYL_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 = chunkHAUWGR76_cjs.truncateStringByTokens(fallbackText, maxTokens);
15958
+ const truncatedText2 = chunk5MTY2UYL_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 = chunkHAUWGR76_cjs.truncateStringByTokens(target.text, maxTokens);
15973
+ const truncatedText = chunk5MTY2UYL_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-EWU3QFIE.cjs');
17604
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-UCFGVLVW.cjs');
17605
17605
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
17606
17606
  await this.indexObservation(observation);
17607
17607
  } : void 0;
@@ -18526,18 +18526,20 @@ Notes:
18526
18526
  if (!effectiveConfig) return null;
18527
18527
  const engine = await this.omEngine;
18528
18528
  if (!engine) return null;
18529
- const { ObservationalMemoryProcessor } = await import('./observational-memory-EWU3QFIE.cjs');
18530
- return new ObservationalMemoryProcessor(engine, this);
18529
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-UCFGVLVW.cjs');
18530
+ return new ObservationalMemoryProcessor(engine, this, {
18531
+ temporalMarkers: effectiveConfig.temporalMarkers
18532
+ });
18531
18533
  }
18532
18534
  };
18533
18535
 
18534
18536
  Object.defineProperty(exports, "ModelByInputTokens", {
18535
18537
  enumerable: true,
18536
- get: function () { return chunkHAUWGR76_cjs.ModelByInputTokens; }
18538
+ get: function () { return chunk5MTY2UYL_cjs.ModelByInputTokens; }
18537
18539
  });
18538
18540
  Object.defineProperty(exports, "getObservationsAsOf", {
18539
18541
  enumerable: true,
18540
- get: function () { return chunkHAUWGR76_cjs.getObservationsAsOf; }
18542
+ get: function () { return chunk5MTY2UYL_cjs.getObservationsAsOf; }
18541
18543
  });
18542
18544
  Object.defineProperty(exports, "extractWorkingMemoryContent", {
18543
18545
  enumerable: true,