@mastra/memory 1.20.0-alpha.2 → 1.20.1-alpha.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 (32) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/{chunk-BCWFD5J7.js → chunk-LXU26UVM.js} +18 -5
  3. package/dist/chunk-LXU26UVM.js.map +1 -0
  4. package/dist/{chunk-SMKIROLC.cjs → chunk-R2H7SJS2.cjs} +18 -5
  5. package/dist/chunk-R2H7SJS2.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +39 -39
  8. package/dist/docs/references/docs-memory-observational-memory.md +19 -0
  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.map +1 -1
  13. package/dist/index.js +5 -4
  14. package/dist/index.js.map +1 -1
  15. package/dist/{observational-memory-E6F7NKJP.js → observational-memory-GE5MP6W7.js} +3 -3
  16. package/dist/{observational-memory-E6F7NKJP.js.map → observational-memory-GE5MP6W7.js.map} +1 -1
  17. package/dist/{observational-memory-LGCWMUEM.cjs → observational-memory-L32TPJ5J.cjs} +26 -26
  18. package/dist/{observational-memory-LGCWMUEM.cjs.map → observational-memory-L32TPJ5J.cjs.map} +1 -1
  19. package/dist/processors/index.cjs +24 -24
  20. package/dist/processors/index.js +1 -1
  21. package/dist/processors/observational-memory/observation-strategies/types.d.ts +4 -2
  22. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
  23. package/dist/processors/observational-memory/observation-turn/turn.d.ts +5 -1
  24. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observational-memory.d.ts +5 -1
  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/types.d.ts +11 -0
  29. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  30. package/package.json +7 -7
  31. package/dist/chunk-BCWFD5J7.js.map +0 -1
  32. package/dist/chunk-SMKIROLC.cjs.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.20.0-alpha.2"
6
+ version: "1.20.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,119 +1,119 @@
1
1
  {
2
- "version": "1.20.0-alpha.2",
2
+ "version": "1.20.1-alpha.0",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "ModelByInputTokens": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-BCWFD5J7.js",
7
+ "implementation": "dist/chunk-LXU26UVM.js",
8
8
  "line": 787
9
9
  },
10
10
  "OBSERVER_SYSTEM_PROMPT": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-BCWFD5J7.js"
12
+ "implementation": "dist/chunk-LXU26UVM.js"
13
13
  },
14
14
  "ObservationalMemory": {
15
15
  "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-BCWFD5J7.js",
17
- "line": 7051
16
+ "implementation": "dist/chunk-LXU26UVM.js",
17
+ "line": 7060
18
18
  },
19
19
  "ObservationalMemoryProcessor": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-BCWFD5J7.js",
22
- "line": 9619
21
+ "implementation": "dist/chunk-LXU26UVM.js",
22
+ "line": 9631
23
23
  },
24
24
  "TokenCounter": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-BCWFD5J7.js",
27
- "line": 6497
26
+ "implementation": "dist/chunk-LXU26UVM.js",
27
+ "line": 6506
28
28
  },
29
29
  "buildObserverPrompt": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-BCWFD5J7.js",
32
- "line": 3765
31
+ "implementation": "dist/chunk-LXU26UVM.js",
32
+ "line": 3774
33
33
  },
34
34
  "buildObserverSystemPrompt": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-BCWFD5J7.js",
37
- "line": 3036
36
+ "implementation": "dist/chunk-LXU26UVM.js",
37
+ "line": 3045
38
38
  },
39
39
  "combineObservationGroupRanges": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-BCWFD5J7.js",
41
+ "implementation": "dist/chunk-LXU26UVM.js",
42
42
  "line": 879
43
43
  },
44
44
  "deriveObservationGroupProvenance": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-BCWFD5J7.js",
46
+ "implementation": "dist/chunk-LXU26UVM.js",
47
47
  "line": 913
48
48
  },
49
49
  "extractCurrentTask": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-BCWFD5J7.js",
52
- "line": 3879
51
+ "implementation": "dist/chunk-LXU26UVM.js",
52
+ "line": 3888
53
53
  },
54
54
  "formatMessagesForObserver": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-BCWFD5J7.js",
57
- "line": 3491
56
+ "implementation": "dist/chunk-LXU26UVM.js",
57
+ "line": 3500
58
58
  },
59
59
  "getObservationsAsOf": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-BCWFD5J7.js",
62
- "line": 9831
61
+ "implementation": "dist/chunk-LXU26UVM.js",
62
+ "line": 9844
63
63
  },
64
64
  "hasCurrentTaskSection": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-BCWFD5J7.js",
67
- "line": 3867
66
+ "implementation": "dist/chunk-LXU26UVM.js",
67
+ "line": 3876
68
68
  },
69
69
  "injectAnchorIds": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-BCWFD5J7.js",
72
- "line": 2584
71
+ "implementation": "dist/chunk-LXU26UVM.js",
72
+ "line": 2593
73
73
  },
74
74
  "optimizeObservationsForContext": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-BCWFD5J7.js",
77
- "line": 3890
76
+ "implementation": "dist/chunk-LXU26UVM.js",
77
+ "line": 3899
78
78
  },
79
79
  "parseAnchorId": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-BCWFD5J7.js",
82
- "line": 2557
81
+ "implementation": "dist/chunk-LXU26UVM.js",
82
+ "line": 2566
83
83
  },
84
84
  "parseObservationGroups": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-BCWFD5J7.js",
86
+ "implementation": "dist/chunk-LXU26UVM.js",
87
87
  "line": 848
88
88
  },
89
89
  "parseObserverOutput": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-BCWFD5J7.js",
92
- "line": 3775
91
+ "implementation": "dist/chunk-LXU26UVM.js",
92
+ "line": 3784
93
93
  },
94
94
  "reconcileObservationGroupsFromReflection": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-BCWFD5J7.js",
96
+ "implementation": "dist/chunk-LXU26UVM.js",
97
97
  "line": 937
98
98
  },
99
99
  "renderObservationGroupsForReflection": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-BCWFD5J7.js",
101
+ "implementation": "dist/chunk-LXU26UVM.js",
102
102
  "line": 893
103
103
  },
104
104
  "stripEphemeralAnchorIds": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-BCWFD5J7.js",
107
- "line": 2614
106
+ "implementation": "dist/chunk-LXU26UVM.js",
107
+ "line": 2623
108
108
  },
109
109
  "stripObservationGroups": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-BCWFD5J7.js",
111
+ "implementation": "dist/chunk-LXU26UVM.js",
112
112
  "line": 870
113
113
  },
114
114
  "wrapInObservationGroup": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-BCWFD5J7.js",
116
+ "implementation": "dist/chunk-LXU26UVM.js",
117
117
  "line": 841
118
118
  },
119
119
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
@@ -149,7 +149,7 @@
149
149
  "processors": {
150
150
  "index": "dist/processors/index.js",
151
151
  "chunks": [
152
- "chunk-BCWFD5J7.js",
152
+ "chunk-LXU26UVM.js",
153
153
  "chunk-VKRZ3O5X.js"
154
154
  ]
155
155
  }
@@ -117,6 +117,25 @@ const memory = new Memory({
117
117
 
118
118
  In this example, the top-level idle setting is disabled for observations, while reflections opt into idle and provider-change activation.
119
119
 
120
+ ### Buffer on idle
121
+
122
+ Set `observation.bufferOnIdle` to `true` to run background observation buffering when an agent turn ends and the agent becomes idle. This is useful for apps that want short turns to be observed without waiting for the next turn or the `messageTokens` threshold.
123
+
124
+ ```typescript
125
+ const memory = new Memory({
126
+ options: {
127
+ observationalMemory: {
128
+ model: 'openai/gpt-5-mini',
129
+ observation: {
130
+ bufferOnIdle: true,
131
+ },
132
+ },
133
+ },
134
+ })
135
+ ```
136
+
137
+ `bufferOnIdle` is off by default. It is separate from `bufferTokens`: `bufferTokens` controls step-time async buffering, while `bufferOnIdle` controls end-of-turn buffering for idle turns.
138
+
120
139
  See [the API reference](https://mastra.ai/reference/memory/observational-memory) for the full configuration shape.
121
140
 
122
141
  ## Benefits
@@ -68,6 +68,8 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
68
68
 
69
69
  **observation.bufferTokens** (`number | false`): Token interval for async background observation buffering. Can be an absolute token count (e.g. \`5000\`) or a fraction of \`messageTokens\` (e.g. \`0.25\` = buffer every 25% of threshold). When set, observations run in the background at this interval, storing results in a buffer. When the main \`messageTokens\` threshold is reached, buffered observations activate instantly without a blocking LLM call. Must resolve to less than \`messageTokens\`. Set to \`false\` to explicitly disable all async buffering (both observation and reflection).
70
70
 
71
+ **observation.bufferOnIdle** (`boolean`): Run background observation buffering when an agent turn ends and the agent becomes idle. This is separate from \`bufferTokens\`, which controls step-time async buffering. Set this to \`true\` to buffer short idle turns without waiting for the next turn or the \`messageTokens\` threshold.
72
+
71
73
  **observation.bufferActivation** (`number`): Controls how much of the message window to retain after activation. Accepts a ratio (0-1) or an absolute token count (≥ 1000). For example, \`0.8\` means: activate enough buffers to remove 80% of \`messageTokens\` and leave 20% as active message history. An absolute token count like \`4000\` targets a goal of keeping \~4k message tokens remaining after activation. Higher values remove more message history per activation when using a ratio. Higher values keep more message history when using a token count.
72
74
 
73
75
  **observation.activateAfterIdle** (`number | string | false | "auto"`): Time before buffered observations are forced to activate after inactivity. Accepts milliseconds, a duration string, \`"auto"\` for a provider-aware prompt cache TTL, or \`false\`. If unset, the top-level \`activateAfterIdle\` value is used for observations. Set \`false\` to disable the top-level idle setting for observations.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkSMKIROLC_cjs = require('./chunk-SMKIROLC.cjs');
3
+ var chunkR2H7SJS2_cjs = require('./chunk-R2H7SJS2.cjs');
4
4
  var chunk3Q3LOVQP_cjs = require('./chunk-3Q3LOVQP.cjs');
5
5
  var agent = require('@mastra/core/agent');
6
6
  var features = require('@mastra/core/features');
@@ -45971,7 +45971,7 @@ function formatTimestamp(date9) {
45971
45971
  }
45972
45972
  function truncateByTokens(text4, maxTokens, hint) {
45973
45973
  if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
45974
- const truncated = chunkSMKIROLC_cjs.truncateStringByTokens(text4, maxTokens);
45974
+ const truncated = chunkR2H7SJS2_cjs.truncateStringByTokens(text4, maxTokens);
45975
45975
  const suffix = hint ? ` [${hint} for more]` : "";
45976
45976
  return { text: truncated + suffix, wasTruncated: true };
45977
45977
  }
@@ -46023,11 +46023,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
46023
46023
  });
46024
46024
  }
46025
46025
  if (inv.state === "result") {
46026
- const { value: resultValue } = chunkSMKIROLC_cjs.resolveToolResultValue(
46026
+ const { value: resultValue } = chunkR2H7SJS2_cjs.resolveToolResultValue(
46027
46027
  part,
46028
46028
  inv.result
46029
46029
  );
46030
- const resultStr = chunkSMKIROLC_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46030
+ const resultStr = chunkR2H7SJS2_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46031
46031
  const fullText = `[Tool Result: ${inv.toolName}]
46032
46032
  ${resultStr}`;
46033
46033
  parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
@@ -46054,7 +46054,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
46054
46054
  const toolName = part.toolName;
46055
46055
  if (toolName) {
46056
46056
  const rawResult = part.output ?? part.result;
46057
- const resultStr = chunkSMKIROLC_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46057
+ const resultStr = chunkR2H7SJS2_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46058
46058
  const fullText = `[Tool Result: ${toolName}]
46059
46059
  ${resultStr}`;
46060
46060
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
@@ -46133,7 +46133,7 @@ function renderFormattedParts(parts, timestamps, options) {
46133
46133
  const text4 = buildRenderedText(parts, timestamps);
46134
46134
  let totalTokens = tokenx.estimateTokenCount(text4);
46135
46135
  if (totalTokens > options.maxTokens) {
46136
- const truncated = chunkSMKIROLC_cjs.truncateStringByTokens(text4, options.maxTokens);
46136
+ const truncated = chunkR2H7SJS2_cjs.truncateStringByTokens(text4, options.maxTokens);
46137
46137
  return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
46138
46138
  }
46139
46139
  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));
@@ -46166,7 +46166,7 @@ function renderFormattedParts(parts, timestamps, options) {
46166
46166
  if (expandedTokens <= options.maxTokens) {
46167
46167
  return { text: expanded, truncated: false, tokenOffset: 0 };
46168
46168
  }
46169
- const hardTruncated = chunkSMKIROLC_cjs.truncateStringByTokens(expanded, options.maxTokens);
46169
+ const hardTruncated = chunkR2H7SJS2_cjs.truncateStringByTokens(expanded, options.maxTokens);
46170
46170
  return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
46171
46171
  }
46172
46172
  async function recallPart({
@@ -46217,7 +46217,7 @@ async function recallPart({
46217
46217
 
46218
46218
  `;
46219
46219
  const fallbackText = `${fallbackNote}${firstNextPart.text}`;
46220
- const truncatedText2 = chunkSMKIROLC_cjs.truncateStringByTokens(fallbackText, maxTokens);
46220
+ const truncatedText2 = chunkR2H7SJS2_cjs.truncateStringByTokens(fallbackText, maxTokens);
46221
46221
  const wasTruncated2 = truncatedText2 !== fallbackText;
46222
46222
  return {
46223
46223
  text: truncatedText2,
@@ -46232,7 +46232,7 @@ async function recallPart({
46232
46232
  }
46233
46233
  throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
46234
46234
  }
46235
- const truncatedText = chunkSMKIROLC_cjs.truncateStringByTokens(target.text, maxTokens);
46235
+ const truncatedText = chunkR2H7SJS2_cjs.truncateStringByTokens(target.text, maxTokens);
46236
46236
  const wasTruncated = truncatedText !== target.text;
46237
46237
  return {
46238
46238
  text: truncatedText,
@@ -48051,7 +48051,7 @@ ${workingMemory}`;
48051
48051
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
48052
48052
  );
48053
48053
  }
48054
- const { ObservationalMemory: OMClass } = await import('./observational-memory-LGCWMUEM.cjs');
48054
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-L32TPJ5J.cjs');
48055
48055
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
48056
48056
  await this.indexObservation(observation);
48057
48057
  } : void 0;
@@ -48072,6 +48072,7 @@ ${workingMemory}`;
48072
48072
  maxTokensPerBatch: omConfig.observation.maxTokensPerBatch,
48073
48073
  providerOptions: omConfig.observation.providerOptions,
48074
48074
  bufferTokens: omConfig.observation.bufferTokens,
48075
+ bufferOnIdle: omConfig.observation.bufferOnIdle,
48075
48076
  bufferActivation: omConfig.observation.bufferActivation,
48076
48077
  blockAfter: omConfig.observation.blockAfter,
48077
48078
  previousObserverTokens: omConfig.observation.previousObserverTokens,
@@ -48978,7 +48979,7 @@ Notes:
48978
48979
  if (!effectiveConfig) return null;
48979
48980
  const engine = await this.omEngine;
48980
48981
  if (!engine) return null;
48981
- const { ObservationalMemoryProcessor } = await import('./observational-memory-LGCWMUEM.cjs');
48982
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-L32TPJ5J.cjs');
48982
48983
  return new ObservationalMemoryProcessor(engine, this, {
48983
48984
  temporalMarkers: effectiveConfig.temporalMarkers
48984
48985
  });
@@ -48987,11 +48988,11 @@ Notes:
48987
48988
 
48988
48989
  Object.defineProperty(exports, "ModelByInputTokens", {
48989
48990
  enumerable: true,
48990
- get: function () { return chunkSMKIROLC_cjs.ModelByInputTokens; }
48991
+ get: function () { return chunkR2H7SJS2_cjs.ModelByInputTokens; }
48991
48992
  });
48992
48993
  Object.defineProperty(exports, "getObservationsAsOf", {
48993
48994
  enumerable: true,
48994
- get: function () { return chunkSMKIROLC_cjs.getObservationsAsOf; }
48995
+ get: function () { return chunkR2H7SJS2_cjs.getObservationsAsOf; }
48995
48996
  });
48996
48997
  Object.defineProperty(exports, "MessageHistory", {
48997
48998
  enumerable: true,