@mastra/memory 1.3.0 → 1.4.0-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 (31) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/{chunk-F5P5HTMC.js → chunk-D4AWAGLM.js} +270 -203
  3. package/dist/chunk-D4AWAGLM.js.map +1 -0
  4. package/dist/{chunk-LXATBJ2L.cjs → chunk-QRKB5I2S.cjs} +270 -203
  5. package/dist/chunk-QRKB5I2S.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +25 -25
  8. package/dist/docs/references/reference-memory-observational-memory.md +36 -0
  9. package/dist/index.cjs +7 -5
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/{observational-memory-3DA7KJIH.js → observational-memory-53AFLLSH.js} +3 -3
  15. package/dist/{observational-memory-3DA7KJIH.js.map → observational-memory-53AFLLSH.js.map} +1 -1
  16. package/dist/{observational-memory-SA5RITIG.cjs → observational-memory-UCOMAMSF.cjs} +17 -17
  17. package/dist/{observational-memory-SA5RITIG.cjs.map → observational-memory-UCOMAMSF.cjs.map} +1 -1
  18. package/dist/processors/index.cjs +15 -15
  19. package/dist/processors/index.js +1 -1
  20. package/dist/processors/observational-memory/observational-memory.d.ts +6 -1
  21. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  22. package/dist/processors/observational-memory/observer-agent.d.ts +2 -2
  23. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/reflector-agent.d.ts +5 -3
  25. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
  26. package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/types.d.ts +10 -0
  28. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  29. package/package.json +6 -6
  30. package/dist/chunk-F5P5HTMC.js.map +0 -1
  31. package/dist/chunk-LXATBJ2L.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.3.0"
6
+ version: "1.4.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,71 +1,71 @@
1
1
  {
2
- "version": "1.3.0",
2
+ "version": "1.4.0-alpha.0",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-F5P5HTMC.js"
7
+ "implementation": "dist/chunk-D4AWAGLM.js"
8
8
  },
9
9
  "OBSERVATION_CONTEXT_INSTRUCTIONS": {
10
10
  "types": "dist/processors/index.d.ts",
11
- "implementation": "dist/chunk-F5P5HTMC.js"
11
+ "implementation": "dist/chunk-D4AWAGLM.js"
12
12
  },
13
13
  "OBSERVATION_CONTEXT_PROMPT": {
14
14
  "types": "dist/processors/index.d.ts",
15
- "implementation": "dist/chunk-F5P5HTMC.js"
15
+ "implementation": "dist/chunk-D4AWAGLM.js"
16
16
  },
17
17
  "OBSERVATION_CONTINUATION_HINT": {
18
18
  "types": "dist/processors/index.d.ts",
19
- "implementation": "dist/chunk-F5P5HTMC.js"
19
+ "implementation": "dist/chunk-D4AWAGLM.js"
20
20
  },
21
21
  "OBSERVER_SYSTEM_PROMPT": {
22
22
  "types": "dist/processors/index.d.ts",
23
- "implementation": "dist/chunk-F5P5HTMC.js"
23
+ "implementation": "dist/chunk-D4AWAGLM.js"
24
24
  },
25
25
  "ObservationalMemory": {
26
26
  "types": "dist/processors/index.d.ts",
27
- "implementation": "dist/chunk-F5P5HTMC.js",
28
- "line": 1294
27
+ "implementation": "dist/chunk-D4AWAGLM.js",
28
+ "line": 1273
29
29
  },
30
30
  "TokenCounter": {
31
31
  "types": "dist/processors/index.d.ts",
32
- "implementation": "dist/chunk-F5P5HTMC.js",
33
- "line": 957
32
+ "implementation": "dist/chunk-D4AWAGLM.js",
33
+ "line": 936
34
34
  },
35
35
  "buildObserverPrompt": {
36
36
  "types": "dist/processors/index.d.ts",
37
- "implementation": "dist/chunk-F5P5HTMC.js",
38
- "line": 646
37
+ "implementation": "dist/chunk-D4AWAGLM.js",
38
+ "line": 606
39
39
  },
40
40
  "buildObserverSystemPrompt": {
41
41
  "types": "dist/processors/index.d.ts",
42
- "implementation": "dist/chunk-F5P5HTMC.js",
43
- "line": 405
42
+ "implementation": "dist/chunk-D4AWAGLM.js",
43
+ "line": 357
44
44
  },
45
45
  "extractCurrentTask": {
46
46
  "types": "dist/processors/index.d.ts",
47
- "implementation": "dist/chunk-F5P5HTMC.js",
48
- "line": 732
47
+ "implementation": "dist/chunk-D4AWAGLM.js",
48
+ "line": 692
49
49
  },
50
50
  "formatMessagesForObserver": {
51
51
  "types": "dist/processors/index.d.ts",
52
- "implementation": "dist/chunk-F5P5HTMC.js",
53
- "line": 492
52
+ "implementation": "dist/chunk-D4AWAGLM.js",
53
+ "line": 452
54
54
  },
55
55
  "hasCurrentTaskSection": {
56
56
  "types": "dist/processors/index.d.ts",
57
- "implementation": "dist/chunk-F5P5HTMC.js",
58
- "line": 720
57
+ "implementation": "dist/chunk-D4AWAGLM.js",
58
+ "line": 680
59
59
  },
60
60
  "optimizeObservationsForContext": {
61
61
  "types": "dist/processors/index.d.ts",
62
- "implementation": "dist/chunk-F5P5HTMC.js",
63
- "line": 743
62
+ "implementation": "dist/chunk-D4AWAGLM.js",
63
+ "line": 703
64
64
  },
65
65
  "parseObserverOutput": {
66
66
  "types": "dist/processors/index.d.ts",
67
- "implementation": "dist/chunk-F5P5HTMC.js",
68
- "line": 677
67
+ "implementation": "dist/chunk-D4AWAGLM.js",
68
+ "line": 637
69
69
  },
70
70
  "extractWorkingMemoryContent": {
71
71
  "types": "dist/index.d.ts",
@@ -96,7 +96,7 @@
96
96
  "processors": {
97
97
  "index": "dist/processors/index.js",
98
98
  "chunks": [
99
- "chunk-F5P5HTMC.js"
99
+ "chunk-D4AWAGLM.js"
100
100
  ]
101
101
  }
102
102
  }
@@ -42,6 +42,8 @@ The `observationalMemory` option accepts `true`, a configuration object, or `fal
42
42
 
43
43
  **model?:** (`string | LanguageModel | DynamicModel | ModelWithRetries[]`): Model for the Observer agent. Cannot be set if a top-level \`model\` is also provided. If neither this nor the top-level \`model\` is set, falls back to \`reflection.model\`.
44
44
 
45
+ **instruction?:** (`string`): Custom instruction appended to the Observer's system prompt. Use this to customize what the Observer focuses on, such as domain-specific preferences or priorities.
46
+
45
47
  **messageTokens?:** (`number`): Token count of unobserved messages that triggers observation. When unobserved message tokens exceed this threshold, the Observer agent is called. (Default: `30000`)
46
48
 
47
49
  **maxTokensPerBatch?:** (`number`): Maximum tokens per batch when observing multiple threads in resource scope. Threads are chunked into batches of this size and processed in parallel. Lower values mean more parallelism but more API calls. (Default: `10000`)
@@ -58,6 +60,8 @@ The `observationalMemory` option accepts `true`, a configuration object, or `fal
58
60
 
59
61
  **model?:** (`string | LanguageModel | DynamicModel | ModelWithRetries[]`): Model for the Reflector agent. Cannot be set if a top-level \`model\` is also provided. If neither this nor the top-level \`model\` is set, falls back to \`observation.model\`.
60
62
 
63
+ **instruction?:** (`string`): Custom instruction appended to the Reflector's system prompt. Use this to customize how the Reflector consolidates observations, such as prioritizing certain types of information.
64
+
61
65
  **observationTokens?:** (`number`): Token count of observations that triggers reflection. When observation tokens exceed this threshold, the Reflector agent is called to condense them. (Default: `40000`)
62
66
 
63
67
  **modelSettings?:** (`ObservationalMemoryModelSettings`): Model settings for the Reflector agent. (Default: `{ temperature: 0, maxOutputTokens: 100_000 }`)
@@ -175,6 +179,38 @@ export const agent = new Agent({
175
179
  });
176
180
  ```
177
181
 
182
+ ### Custom instructions
183
+
184
+ Customize what the Observer and Reflector focus on by providing custom instructions:
185
+
186
+ ```typescript
187
+ import { Memory } from "@mastra/memory";
188
+ import { Agent } from "@mastra/core/agent";
189
+
190
+ export const agent = new Agent({
191
+ name: "health-assistant",
192
+ instructions: "You are a health and wellness assistant.",
193
+ model: "openai/gpt-5-mini",
194
+ memory: new Memory({
195
+ options: {
196
+ observationalMemory: {
197
+ model: "google/gemini-2.5-flash",
198
+ observation: {
199
+ // Focus observations on health-related preferences and goals
200
+ instruction:
201
+ "Prioritize capturing user health goals, dietary restrictions, exercise preferences, and medical considerations. Avoid capturing general chit-chat.",
202
+ },
203
+ reflection: {
204
+ // Guide reflection to consolidate health patterns
205
+ instruction:
206
+ "When consolidating, group related health information together. Preserve specific metrics, dates, and medical details.",
207
+ },
208
+ },
209
+ },
210
+ }),
211
+ });
212
+ ```
213
+
178
214
  ### Async buffering
179
215
 
180
216
  Async buffering is **enabled by default**. It pre-computes observations in the background as the conversation grows — when the `messageTokens` threshold is reached, buffered observations activate instantly with no blocking LLM call.
package/dist/index.cjs CHANGED
@@ -15229,7 +15229,7 @@ var Memory = class extends memory.MastraMemory {
15229
15229
  }
15230
15230
  await memoryStore.updateThread({
15231
15231
  id: threadId,
15232
- title: thread.title || "Untitled Thread",
15232
+ title: thread.title || "",
15233
15233
  metadata: {
15234
15234
  ...thread.metadata,
15235
15235
  workingMemory
@@ -15309,7 +15309,7 @@ ${workingMemory}`;
15309
15309
  }
15310
15310
  await memoryStore.updateThread({
15311
15311
  id: threadId,
15312
- title: thread.title || "Untitled Thread",
15312
+ title: thread.title || "",
15313
15313
  metadata: {
15314
15314
  ...thread.metadata,
15315
15315
  workingMemory
@@ -16146,7 +16146,7 @@ Notes:
16146
16146
  "Observational memory async buffering is enabled by default but the installed version of @mastra/core does not support it. Either upgrade @mastra/core, @mastra/memory, and your storage adapter (@mastra/libsql, @mastra/pg, or @mastra/mongodb) to the latest version, or explicitly disable async buffering by setting `observation: { bufferTokens: false }` in your observationalMemory config."
16147
16147
  );
16148
16148
  }
16149
- const { ObservationalMemory } = await import('./observational-memory-SA5RITIG.cjs');
16149
+ const { ObservationalMemory } = await import('./observational-memory-UCOMAMSF.cjs');
16150
16150
  return new ObservationalMemory({
16151
16151
  storage: memoryStore,
16152
16152
  scope: omConfig.scope,
@@ -16160,7 +16160,8 @@ Notes:
16160
16160
  providerOptions: omConfig.observation.providerOptions,
16161
16161
  bufferTokens: omConfig.observation.bufferTokens,
16162
16162
  bufferActivation: omConfig.observation.bufferActivation,
16163
- blockAfter: omConfig.observation.blockAfter
16163
+ blockAfter: omConfig.observation.blockAfter,
16164
+ instruction: omConfig.observation.instruction
16164
16165
  } : void 0,
16165
16166
  reflection: omConfig.reflection ? {
16166
16167
  model: omConfig.reflection.model,
@@ -16168,7 +16169,8 @@ Notes:
16168
16169
  modelSettings: omConfig.reflection.modelSettings,
16169
16170
  providerOptions: omConfig.reflection.providerOptions,
16170
16171
  bufferActivation: omConfig.reflection.bufferActivation,
16171
- blockAfter: omConfig.reflection.blockAfter
16172
+ blockAfter: omConfig.reflection.blockAfter,
16173
+ instruction: omConfig.reflection.instruction
16172
16174
  } : void 0
16173
16175
  });
16174
16176
  }