@mastra/memory 1.17.4 → 1.17.5-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 (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-4C4ERX6N.js → chunk-BPJLUC2F.js} +44 -21
  3. package/dist/chunk-BPJLUC2F.js.map +1 -0
  4. package/dist/{chunk-M6QU3KKP.cjs → chunk-UZDSNIGD.cjs} +44 -21
  5. package/dist/chunk-UZDSNIGD.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +29 -29
  8. package/dist/docs/references/docs-agents-supervisor-agents.md +16 -0
  9. package/dist/docs/references/docs-memory-observational-memory.md +3 -3
  10. package/dist/docs/references/reference-vectors-mongodb.md +0 -2
  11. package/dist/index.cjs +32 -14
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +23 -5
  16. package/dist/index.js.map +1 -1
  17. package/dist/{observational-memory-ZS2HJPUO.js → observational-memory-FBBKXNO5.js} +3 -3
  18. package/dist/{observational-memory-ZS2HJPUO.js.map → observational-memory-FBBKXNO5.js.map} +1 -1
  19. package/dist/{observational-memory-TC2CBKCL.cjs → observational-memory-KWFKMLG6.cjs} +26 -26
  20. package/dist/{observational-memory-TC2CBKCL.cjs.map → observational-memory-KWFKMLG6.cjs.map} +1 -1
  21. package/dist/processors/index.cjs +24 -24
  22. package/dist/processors/index.js +1 -1
  23. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observational-memory.d.ts +3 -0
  26. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/observer-runner.d.ts +4 -0
  28. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  29. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/reflector-runner.d.ts +4 -0
  31. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/types.d.ts +3 -0
  33. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  34. package/package.json +7 -7
  35. package/dist/chunk-4C4ERX6N.js.map +0 -1
  36. package/dist/chunk-M6QU3KKP.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.17.4"
6
+ version: "1.17.5-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,119 +1,119 @@
1
1
  {
2
- "version": "1.17.4",
2
+ "version": "1.17.5-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-4C4ERX6N.js",
7
+ "implementation": "dist/chunk-BPJLUC2F.js",
8
8
  "line": 745
9
9
  },
10
10
  "OBSERVER_SYSTEM_PROMPT": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-4C4ERX6N.js"
12
+ "implementation": "dist/chunk-BPJLUC2F.js"
13
13
  },
14
14
  "ObservationalMemory": {
15
15
  "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-4C4ERX6N.js",
17
- "line": 6573
16
+ "implementation": "dist/chunk-BPJLUC2F.js",
17
+ "line": 6598
18
18
  },
19
19
  "ObservationalMemoryProcessor": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-4C4ERX6N.js",
22
- "line": 9117
21
+ "implementation": "dist/chunk-BPJLUC2F.js",
22
+ "line": 9140
23
23
  },
24
24
  "TokenCounter": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-4C4ERX6N.js",
27
- "line": 6043
26
+ "implementation": "dist/chunk-BPJLUC2F.js",
27
+ "line": 6068
28
28
  },
29
29
  "buildObserverPrompt": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-4C4ERX6N.js",
31
+ "implementation": "dist/chunk-BPJLUC2F.js",
32
32
  "line": 3567
33
33
  },
34
34
  "buildObserverSystemPrompt": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-4C4ERX6N.js",
36
+ "implementation": "dist/chunk-BPJLUC2F.js",
37
37
  "line": 2950
38
38
  },
39
39
  "combineObservationGroupRanges": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-4C4ERX6N.js",
41
+ "implementation": "dist/chunk-BPJLUC2F.js",
42
42
  "line": 837
43
43
  },
44
44
  "deriveObservationGroupProvenance": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-4C4ERX6N.js",
46
+ "implementation": "dist/chunk-BPJLUC2F.js",
47
47
  "line": 871
48
48
  },
49
49
  "extractCurrentTask": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-4C4ERX6N.js",
51
+ "implementation": "dist/chunk-BPJLUC2F.js",
52
52
  "line": 3681
53
53
  },
54
54
  "formatMessagesForObserver": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-4C4ERX6N.js",
56
+ "implementation": "dist/chunk-BPJLUC2F.js",
57
57
  "line": 3293
58
58
  },
59
59
  "getObservationsAsOf": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-4C4ERX6N.js",
62
- "line": 9323
61
+ "implementation": "dist/chunk-BPJLUC2F.js",
62
+ "line": 9346
63
63
  },
64
64
  "hasCurrentTaskSection": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-4C4ERX6N.js",
66
+ "implementation": "dist/chunk-BPJLUC2F.js",
67
67
  "line": 3669
68
68
  },
69
69
  "injectAnchorIds": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-4C4ERX6N.js",
71
+ "implementation": "dist/chunk-BPJLUC2F.js",
72
72
  "line": 2498
73
73
  },
74
74
  "optimizeObservationsForContext": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-4C4ERX6N.js",
76
+ "implementation": "dist/chunk-BPJLUC2F.js",
77
77
  "line": 3692
78
78
  },
79
79
  "parseAnchorId": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-4C4ERX6N.js",
81
+ "implementation": "dist/chunk-BPJLUC2F.js",
82
82
  "line": 2471
83
83
  },
84
84
  "parseObservationGroups": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-4C4ERX6N.js",
86
+ "implementation": "dist/chunk-BPJLUC2F.js",
87
87
  "line": 806
88
88
  },
89
89
  "parseObserverOutput": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-4C4ERX6N.js",
91
+ "implementation": "dist/chunk-BPJLUC2F.js",
92
92
  "line": 3577
93
93
  },
94
94
  "reconcileObservationGroupsFromReflection": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-4C4ERX6N.js",
96
+ "implementation": "dist/chunk-BPJLUC2F.js",
97
97
  "line": 895
98
98
  },
99
99
  "renderObservationGroupsForReflection": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-4C4ERX6N.js",
101
+ "implementation": "dist/chunk-BPJLUC2F.js",
102
102
  "line": 851
103
103
  },
104
104
  "stripEphemeralAnchorIds": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-4C4ERX6N.js",
106
+ "implementation": "dist/chunk-BPJLUC2F.js",
107
107
  "line": 2528
108
108
  },
109
109
  "stripObservationGroups": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-4C4ERX6N.js",
111
+ "implementation": "dist/chunk-BPJLUC2F.js",
112
112
  "line": 828
113
113
  },
114
114
  "wrapInObservationGroup": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-4C4ERX6N.js",
116
+ "implementation": "dist/chunk-BPJLUC2F.js",
117
117
  "line": 799
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-4C4ERX6N.js",
152
+ "chunk-BPJLUC2F.js",
153
153
  "chunk-LSJJAJAF.js"
154
154
  ]
155
155
  }
@@ -167,6 +167,22 @@ const stream = await supervisor.stream('Research AI trends', {
167
167
 
168
168
  The callback receives `messages` (the full conversation history), `primitiveId` (the subagent ID), and `prompt` (the delegation prompt). Return the filtered array of messages.
169
169
 
170
+ ## Subagent result context
171
+
172
+ When a subagent completes, the supervisor model receives the subagent's text response in later iterations. Nested tool calls and subagent metadata, such as thread and resource IDs, are not added to the supervisor model context.
173
+
174
+ Application code and UI integrations can still inspect the raw delegation result, including `subAgentToolResults`, from the tool result payload. This keeps debugging and display data available without sending nested tool arguments or outputs back into the supervisor's next model call.
175
+
176
+ Set `includeSubAgentToolResultsInModelContext` to include the full subagent result, including nested tool results and subagent metadata, in the supervisor model context.
177
+
178
+ ```typescript
179
+ await supervisor.generate('Research AI trends', {
180
+ delegation: {
181
+ includeSubAgentToolResultsInModelContext: true,
182
+ },
183
+ })
184
+ ```
185
+
170
186
  ## Iteration monitoring
171
187
 
172
188
  `onIterationComplete` is called after each iteration of the supervisor loop. Use it to log progress, inject feedback, or stop execution early.
@@ -24,7 +24,7 @@ export const agent = new Agent({
24
24
  })
25
25
  ```
26
26
 
27
- That's it. The agent now has humanlike long-term memory that persists across conversations. Setting `observationalMemory: true` uses `google/gemini-2.5-flash` by default. To use a different model or customize thresholds, pass a config object instead:
27
+ That's it. The agent now has humanlike long-term memory that persists across conversations. Setting `observationalMemory: true` uses `google/gemini-2.5-flash` by default. Config objects also use this model unless you set a different one. To use a different model, pass it in the config object:
28
28
 
29
29
  ```typescript
30
30
  const memory = new Memory({
@@ -44,7 +44,7 @@ See [configuration options](https://mastra.ai/reference/memory/observational-mem
44
44
  >
45
45
  > For an AI SDK example, see [Using Mastra Memory](https://mastra.ai/guides/build-your-ui/ai-sdk-ui).
46
46
 
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.
47
+ > **Note:** OM currently only supports `@mastra/pg`, `@mastra/libsql`, and `@mastra/mongodb` storage adapters. It uses background agents for managing memory. When no model is set, the default model is `google/gemini-2.5-flash`.
48
48
 
49
49
  ## Temporal gap markers
50
50
 
@@ -212,7 +212,7 @@ The progress bars update live while the agent is observing or reflecting, showin
212
212
 
213
213
  ## Models
214
214
 
215
- The Observer and Reflector run in the background. Any model that works with Mastra's [model routing](https://mastra.ai/models) (`provider/model`) can be used. When using `observationalMemory: true`, the default model is `google/gemini-2.5-flash`. When passing a config object, a `model` must be explicitly set.
215
+ The Observer and Reflector run in the background. Any model that works with Mastra's [model routing](https://mastra.ai/models) (`provider/model`) can be used. When no model is set, the default model is `google/gemini-2.5-flash`.
216
216
 
217
217
  Generally speaking, we recommend using a model that has a large context window (128K+ tokens) and is fast enough to run in the background without slowing down your actions.
218
218
 
@@ -107,8 +107,6 @@ Searches for similar vectors with optional metadata filtering.
107
107
 
108
108
  **includeVector** (`boolean`): Whether to include vector data in results (Default: `false`)
109
109
 
110
- **minScore** (`number`): Minimum similarity score threshold (Default: `0`)
111
-
112
110
  ### `describeIndex()`
113
111
 
114
112
  Returns information about the index (collection).
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkM6QU3KKP_cjs = require('./chunk-M6QU3KKP.cjs');
3
+ var chunkUZDSNIGD_cjs = require('./chunk-UZDSNIGD.cjs');
4
4
  var v3 = require('zod/v3');
5
5
  var zod = require('zod');
6
6
  var z4 = require('zod/v4');
@@ -15986,7 +15986,7 @@ function formatTimestamp(date) {
15986
15986
  }
15987
15987
  function truncateByTokens(text4, maxTokens, hint) {
15988
15988
  if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
15989
- const truncated = chunkM6QU3KKP_cjs.truncateStringByTokens(text4, maxTokens);
15989
+ const truncated = chunkUZDSNIGD_cjs.truncateStringByTokens(text4, maxTokens);
15990
15990
  const suffix = hint ? ` [${hint} for more]` : "";
15991
15991
  return { text: truncated + suffix, wasTruncated: true };
15992
15992
  }
@@ -16038,11 +16038,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
16038
16038
  });
16039
16039
  }
16040
16040
  if (inv.state === "result") {
16041
- const { value: resultValue } = chunkM6QU3KKP_cjs.resolveToolResultValue(
16041
+ const { value: resultValue } = chunkUZDSNIGD_cjs.resolveToolResultValue(
16042
16042
  part,
16043
16043
  inv.result
16044
16044
  );
16045
- const resultStr = chunkM6QU3KKP_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
16045
+ const resultStr = chunkUZDSNIGD_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
16046
16046
  const fullText = `[Tool Result: ${inv.toolName}]
16047
16047
  ${resultStr}`;
16048
16048
  parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
@@ -16069,7 +16069,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
16069
16069
  const toolName = part.toolName;
16070
16070
  if (toolName) {
16071
16071
  const rawResult = part.output ?? part.result;
16072
- const resultStr = chunkM6QU3KKP_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
16072
+ const resultStr = chunkUZDSNIGD_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
16073
16073
  const fullText = `[Tool Result: ${toolName}]
16074
16074
  ${resultStr}`;
16075
16075
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
@@ -16148,7 +16148,7 @@ function renderFormattedParts(parts, timestamps, options) {
16148
16148
  const text4 = buildRenderedText(parts, timestamps);
16149
16149
  let totalTokens = tokenx.estimateTokenCount(text4);
16150
16150
  if (totalTokens > options.maxTokens) {
16151
- const truncated = chunkM6QU3KKP_cjs.truncateStringByTokens(text4, options.maxTokens);
16151
+ const truncated = chunkUZDSNIGD_cjs.truncateStringByTokens(text4, options.maxTokens);
16152
16152
  return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
16153
16153
  }
16154
16154
  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));
@@ -16181,7 +16181,7 @@ function renderFormattedParts(parts, timestamps, options) {
16181
16181
  if (expandedTokens <= options.maxTokens) {
16182
16182
  return { text: expanded, truncated: false, tokenOffset: 0 };
16183
16183
  }
16184
- const hardTruncated = chunkM6QU3KKP_cjs.truncateStringByTokens(expanded, options.maxTokens);
16184
+ const hardTruncated = chunkUZDSNIGD_cjs.truncateStringByTokens(expanded, options.maxTokens);
16185
16185
  return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
16186
16186
  }
16187
16187
  async function recallPart({
@@ -16232,7 +16232,7 @@ async function recallPart({
16232
16232
 
16233
16233
  `;
16234
16234
  const fallbackText = `${fallbackNote}${firstNextPart.text}`;
16235
- const truncatedText2 = chunkM6QU3KKP_cjs.truncateStringByTokens(fallbackText, maxTokens);
16235
+ const truncatedText2 = chunkUZDSNIGD_cjs.truncateStringByTokens(fallbackText, maxTokens);
16236
16236
  const wasTruncated2 = truncatedText2 !== fallbackText;
16237
16237
  return {
16238
16238
  text: truncatedText2,
@@ -16247,7 +16247,7 @@ async function recallPart({
16247
16247
  }
16248
16248
  throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
16249
16249
  }
16250
- const truncatedText = chunkM6QU3KKP_cjs.truncateStringByTokens(target.text, maxTokens);
16250
+ const truncatedText = chunkUZDSNIGD_cjs.truncateStringByTokens(target.text, maxTokens);
16251
16251
  const wasTruncated = truncatedText !== target.text;
16252
16252
  return {
16253
16253
  text: truncatedText,
@@ -17058,13 +17058,30 @@ var DEFAULT_TOP_K = 4;
17058
17058
  var VECTOR_DELETE_BATCH_SIZE = 100;
17059
17059
  var Memory = class extends memory.MastraMemory {
17060
17060
  _omEngine;
17061
+ _omEngineInstance;
17062
+ _mastraInstance;
17061
17063
  /** The shared ObservationalMemory engine. Lazily created on first access. */
17062
17064
  get omEngine() {
17063
17065
  if (!this._omEngine) {
17064
- this._omEngine = this._initOMEngine();
17066
+ this._omEngine = this._initOMEngine().then((engine) => {
17067
+ this._omEngineInstance = engine;
17068
+ if (engine && this._mastraInstance) {
17069
+ engine.__registerMastra(this._mastraInstance);
17070
+ }
17071
+ return engine;
17072
+ });
17065
17073
  }
17066
17074
  return this._omEngine;
17067
17075
  }
17076
+ __registerMastra(mastra) {
17077
+ super.__registerMastra(mastra);
17078
+ this._mastraInstance = mastra;
17079
+ if (this._omEngineInstance) {
17080
+ this._omEngineInstance.__registerMastra(mastra);
17081
+ } else {
17082
+ void this._omEngine?.then((engine) => engine?.__registerMastra(mastra));
17083
+ }
17084
+ }
17068
17085
  constructor(config = {}) {
17069
17086
  super({ name: "Memory", ...config });
17070
17087
  const mergedConfig = this.getMergedThreadConfig({
@@ -17951,7 +17968,7 @@ ${workingMemory}`;
17951
17968
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
17952
17969
  );
17953
17970
  }
17954
- const { ObservationalMemory: OMClass } = await import('./observational-memory-TC2CBKCL.cjs');
17971
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-KWFKMLG6.cjs');
17955
17972
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
17956
17973
  await this.indexObservation(observation);
17957
17974
  } : void 0;
@@ -17963,6 +17980,7 @@ ${workingMemory}`;
17963
17980
  activateOnProviderChange: omConfig.activateOnProviderChange,
17964
17981
  shareTokenBudget: omConfig.shareTokenBudget,
17965
17982
  model: omConfig.model,
17983
+ mastra: this._mastraInstance,
17966
17984
  onIndexObservations,
17967
17985
  observation: omConfig.observation ? {
17968
17986
  model: omConfig.observation.model,
@@ -18876,7 +18894,7 @@ Notes:
18876
18894
  if (!effectiveConfig) return null;
18877
18895
  const engine = await this.omEngine;
18878
18896
  if (!engine) return null;
18879
- const { ObservationalMemoryProcessor } = await import('./observational-memory-TC2CBKCL.cjs');
18897
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-KWFKMLG6.cjs');
18880
18898
  return new ObservationalMemoryProcessor(engine, this, {
18881
18899
  temporalMarkers: effectiveConfig.temporalMarkers
18882
18900
  });
@@ -18885,11 +18903,11 @@ Notes:
18885
18903
 
18886
18904
  Object.defineProperty(exports, "ModelByInputTokens", {
18887
18905
  enumerable: true,
18888
- get: function () { return chunkM6QU3KKP_cjs.ModelByInputTokens; }
18906
+ get: function () { return chunkUZDSNIGD_cjs.ModelByInputTokens; }
18889
18907
  });
18890
18908
  Object.defineProperty(exports, "getObservationsAsOf", {
18891
18909
  enumerable: true,
18892
- get: function () { return chunkM6QU3KKP_cjs.getObservationsAsOf; }
18910
+ get: function () { return chunkUZDSNIGD_cjs.getObservationsAsOf; }
18893
18911
  });
18894
18912
  Object.defineProperty(exports, "MessageHistory", {
18895
18913
  enumerable: true,