@mastra/memory 1.22.3-alpha.0 → 1.23.0-alpha.2

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 (33) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/{chunk-G6PR4XBO.cjs → chunk-2ZR7CKDV.cjs} +6504 -6350
  3. package/dist/chunk-2ZR7CKDV.cjs.map +1 -0
  4. package/dist/{chunk-5PG7DW2T.js → chunk-GHFCSEEP.js} +6504 -6352
  5. package/dist/chunk-GHFCSEEP.js.map +1 -0
  6. package/dist/docs/SKILL.md +4 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +53 -45
  8. package/dist/docs/references/docs-agents-supervisor-agents.md +2 -1
  9. package/dist/docs/references/docs-memory-observational-memory.md +2 -1
  10. package/dist/docs/references/docs-memory-overview.md +2 -0
  11. package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
  12. package/dist/docs/references/docs-memory-working-memory.md +3 -3
  13. package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
  14. package/dist/docs/references/reference-memory-memory-class.md +1 -1
  15. package/dist/docs/references/reference-memory-summarizeConversation.md +99 -0
  16. package/dist/docs/references/reference-memory-summarizeThread.md +93 -0
  17. package/dist/index.cjs +21 -13
  18. package/dist/index.d.ts +48 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/{observational-memory-JABZ6XNI.js → observational-memory-HUPMKPOX.js} +3 -3
  22. package/dist/{observational-memory-JABZ6XNI.js.map → observational-memory-HUPMKPOX.js.map} +1 -1
  23. package/dist/{observational-memory-36K5KQCO.cjs → observational-memory-RJL2PW6O.cjs} +32 -28
  24. package/dist/{observational-memory-36K5KQCO.cjs.map → observational-memory-RJL2PW6O.cjs.map} +1 -1
  25. package/dist/processors/index.cjs +30 -26
  26. package/dist/processors/index.js +1 -1
  27. package/dist/processors/observational-memory/index.d.ts +2 -0
  28. package/dist/processors/observational-memory/index.d.ts.map +1 -1
  29. package/dist/processors/observational-memory/summarize.d.ts +92 -0
  30. package/dist/processors/observational-memory/summarize.d.ts.map +1 -0
  31. package/package.json +4 -4
  32. package/dist/chunk-5PG7DW2T.js.map +0 -1
  33. package/dist/chunk-G6PR4XBO.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.22.3-alpha.0"
6
+ version: "1.23.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -35,6 +35,7 @@ Read the individual reference documents for detailed explanations and code examp
35
35
 
36
36
  - [Reference: Mastra.getMemory()](references/reference-core-getMemory.md) - Documentation for the `Mastra.getMemory()` method in Mastra, which retrieves a registered memory instance by its registry key.
37
37
  - [Reference: Mastra.listMemory()](references/reference-core-listMemory.md) - Documentation for the `Mastra.listMemory()` method in Mastra, which returns all registered memory instances.
38
+ - [Memory](references/reference-file-based-agents-memory.md) - Give a file-based agent persistent memory with a memory.ts module.
38
39
  - [Reference: Cloned thread utilities](references/reference-memory-clone-utilities.md) - Documentation for utility methods to work with cloned threads in Mastra Memory.
39
40
  - [Reference: Memory.cloneThread()](references/reference-memory-cloneThread.md) - Documentation for the `Memory.cloneThread()` method in Mastra, which creates a copy of a conversation thread with all its messages.
40
41
  - [Reference: Memory.createThread()](references/reference-memory-createThread.md) - Documentation for the `Memory.createThread()` method in Mastra, which creates a new conversation thread in the memory system.
@@ -42,6 +43,8 @@ Read the individual reference documents for detailed explanations and code examp
42
43
  - [Reference: Memory.listThreads()](references/reference-memory-listThreads.md) - Documentation for the `Memory.listThreads()` method in Mastra, which retrieves threads with optional filtering by resourceId and/or metadata.
43
44
  - [Reference: Memory class](references/reference-memory-memory-class.md) - Documentation for the `Memory` class in Mastra, which provides a robust system for managing conversation history and thread-based message storage.
44
45
  - [Reference: Observational Memory](references/reference-memory-observational-memory.md) - API reference for Observational Memory in Mastra — a three-tier memory system that uses Observer and Reflector agents to maintain long-term memory across conversations.
46
+ - [Reference: summarizeConversation()](references/reference-memory-summarizeConversation.md) - Documentation for the standalone `summarizeConversation()` function in Mastra, which summarizes messages you pass in and extracts structured values from them.
47
+ - [Reference: Memory.summarizeThread()](references/reference-memory-summarizeThread.md) - Documentation for the `Memory.summarizeThread()` method in Mastra, which summarizes a thread's conversation in one shot and extracts structured values from it.
45
48
  - [Reference: TokenLimiterProcessor](references/reference-processors-token-limiter-processor.md) - Documentation for the TokenLimiterProcessor in Mastra, which limits the number of tokens in messages.
46
49
  - [Reference: Aurora DSQL Storage](references/reference-storage-dsql.md) - Documentation for the Amazon Aurora DSQL storage implementation in Mastra.
47
50
  - [Reference: DynamoDB storage](references/reference-storage-dynamodb.md) - Documentation for the DynamoDB storage implementation in Mastra, using a single-table design with ElectroDB.
@@ -1,129 +1,133 @@
1
1
  {
2
- "version": "1.22.3-alpha.0",
2
+ "version": "1.23.0-alpha.2",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "Extractor": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-5PG7DW2T.js",
7
+ "implementation": "dist/chunk-GHFCSEEP.js",
8
8
  "line": 316
9
9
  },
10
10
  "ModelByInputTokens": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-5PG7DW2T.js",
12
+ "implementation": "dist/chunk-GHFCSEEP.js",
13
13
  "line": 1354
14
14
  },
15
15
  "OBSERVER_SYSTEM_PROMPT": {
16
16
  "types": "dist/processors/index.d.ts",
17
- "implementation": "dist/chunk-5PG7DW2T.js"
17
+ "implementation": "dist/chunk-GHFCSEEP.js"
18
18
  },
19
19
  "ObservationalMemory": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-5PG7DW2T.js",
22
- "line": 27533
21
+ "implementation": "dist/chunk-GHFCSEEP.js",
22
+ "line": 27685
23
23
  },
24
24
  "ObservationalMemoryProcessor": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-5PG7DW2T.js",
27
- "line": 30164
26
+ "implementation": "dist/chunk-GHFCSEEP.js",
27
+ "line": 30316
28
28
  },
29
29
  "TokenCounter": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-5PG7DW2T.js",
32
- "line": 26858
31
+ "implementation": "dist/chunk-GHFCSEEP.js",
32
+ "line": 21467
33
33
  },
34
34
  "WorkingMemoryExtractor": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-5PG7DW2T.js",
37
- "line": 20684
36
+ "implementation": "dist/chunk-GHFCSEEP.js",
37
+ "line": 22134
38
38
  },
39
39
  "buildObserverPrompt": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-5PG7DW2T.js",
41
+ "implementation": "dist/chunk-GHFCSEEP.js",
42
42
  "line": 4465
43
43
  },
44
44
  "buildObserverSystemPrompt": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-5PG7DW2T.js",
46
+ "implementation": "dist/chunk-GHFCSEEP.js",
47
47
  "line": 3732
48
48
  },
49
49
  "combineObservationGroupRanges": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-5PG7DW2T.js",
51
+ "implementation": "dist/chunk-GHFCSEEP.js",
52
52
  "line": 1446
53
53
  },
54
54
  "deriveObservationGroupProvenance": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-5PG7DW2T.js",
56
+ "implementation": "dist/chunk-GHFCSEEP.js",
57
57
  "line": 1480
58
58
  },
59
59
  "extractCurrentTask": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-5PG7DW2T.js",
61
+ "implementation": "dist/chunk-GHFCSEEP.js",
62
62
  "line": 4588
63
63
  },
64
64
  "formatMessagesForObserver": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-5PG7DW2T.js",
66
+ "implementation": "dist/chunk-GHFCSEEP.js",
67
67
  "line": 4187
68
68
  },
69
69
  "getObservationsAsOf": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-5PG7DW2T.js",
72
- "line": 30386
71
+ "implementation": "dist/chunk-GHFCSEEP.js",
72
+ "line": 30538
73
73
  },
74
74
  "hasCurrentTaskSection": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-5PG7DW2T.js",
76
+ "implementation": "dist/chunk-GHFCSEEP.js",
77
77
  "line": 4576
78
78
  },
79
79
  "injectAnchorIds": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-5PG7DW2T.js",
81
+ "implementation": "dist/chunk-GHFCSEEP.js",
82
82
  "line": 3287
83
83
  },
84
84
  "optimizeObservationsForContext": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-5PG7DW2T.js",
86
+ "implementation": "dist/chunk-GHFCSEEP.js",
87
87
  "line": 4599
88
88
  },
89
89
  "parseAnchorId": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-5PG7DW2T.js",
91
+ "implementation": "dist/chunk-GHFCSEEP.js",
92
92
  "line": 3260
93
93
  },
94
94
  "parseObservationGroups": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-5PG7DW2T.js",
96
+ "implementation": "dist/chunk-GHFCSEEP.js",
97
97
  "line": 1415
98
98
  },
99
99
  "parseObserverOutput": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-5PG7DW2T.js",
101
+ "implementation": "dist/chunk-GHFCSEEP.js",
102
102
  "line": 4479
103
103
  },
104
104
  "reconcileObservationGroupsFromReflection": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-5PG7DW2T.js",
106
+ "implementation": "dist/chunk-GHFCSEEP.js",
107
107
  "line": 1504
108
108
  },
109
109
  "renderObservationGroupsForReflection": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-5PG7DW2T.js",
111
+ "implementation": "dist/chunk-GHFCSEEP.js",
112
112
  "line": 1460
113
113
  },
114
114
  "stripEphemeralAnchorIds": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-5PG7DW2T.js",
116
+ "implementation": "dist/chunk-GHFCSEEP.js",
117
117
  "line": 3317
118
118
  },
119
119
  "stripObservationGroups": {
120
120
  "types": "dist/processors/index.d.ts",
121
- "implementation": "dist/chunk-5PG7DW2T.js",
121
+ "implementation": "dist/chunk-GHFCSEEP.js",
122
122
  "line": 1437
123
123
  },
124
+ "summarizeConversation": {
125
+ "types": "dist/processors/index.d.ts",
126
+ "implementation": "dist/chunk-GHFCSEEP.js"
127
+ },
124
128
  "wrapInObservationGroup": {
125
129
  "types": "dist/processors/index.d.ts",
126
- "implementation": "dist/chunk-5PG7DW2T.js",
130
+ "implementation": "dist/chunk-GHFCSEEP.js",
127
131
  "line": 1408
128
132
  },
129
133
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
@@ -144,40 +148,44 @@
144
148
  },
145
149
  "Memory": {
146
150
  "types": "dist/index.d.ts",
147
- "implementation": "dist/chunk-5PG7DW2T.js",
148
- "line": 22109
151
+ "implementation": "dist/chunk-GHFCSEEP.js",
152
+ "line": 23559
149
153
  },
150
154
  "MessageHistory": {
151
155
  "types": "dist/index.d.ts",
152
- "implementation": "dist/chunk-5PG7DW2T.js"
156
+ "implementation": "dist/chunk-GHFCSEEP.js"
157
+ },
158
+ "SUMMARIZE_THREAD_DEFAULTS": {
159
+ "types": "dist/index.d.ts",
160
+ "implementation": "dist/chunk-GHFCSEEP.js"
153
161
  },
154
162
  "SemanticRecall": {
155
163
  "types": "dist/index.d.ts",
156
- "implementation": "dist/chunk-5PG7DW2T.js"
164
+ "implementation": "dist/chunk-GHFCSEEP.js"
157
165
  },
158
166
  "WorkingMemory": {
159
167
  "types": "dist/index.d.ts",
160
- "implementation": "dist/chunk-5PG7DW2T.js"
168
+ "implementation": "dist/chunk-GHFCSEEP.js"
161
169
  },
162
170
  "deepMergeWorkingMemory": {
163
171
  "types": "dist/index.d.ts",
164
- "implementation": "dist/chunk-5PG7DW2T.js",
165
- "line": 21748
172
+ "implementation": "dist/chunk-GHFCSEEP.js",
173
+ "line": 23198
166
174
  },
167
175
  "extractWorkingMemoryContent": {
168
176
  "types": "dist/index.d.ts",
169
- "implementation": "dist/chunk-5PG7DW2T.js",
170
- "line": 22064
177
+ "implementation": "dist/chunk-GHFCSEEP.js",
178
+ "line": 23514
171
179
  },
172
180
  "extractWorkingMemoryTags": {
173
181
  "types": "dist/index.d.ts",
174
- "implementation": "dist/chunk-5PG7DW2T.js",
175
- "line": 22032
182
+ "implementation": "dist/chunk-GHFCSEEP.js",
183
+ "line": 23482
176
184
  },
177
185
  "removeWorkingMemoryTags": {
178
186
  "types": "dist/index.d.ts",
179
- "implementation": "dist/chunk-5PG7DW2T.js",
180
- "line": 22045
187
+ "implementation": "dist/chunk-GHFCSEEP.js",
188
+ "line": 23495
181
189
  },
182
190
  "WORKING_MEMORY_STATE_ID": {
183
191
  "types": "dist/index.d.ts",
@@ -197,7 +205,7 @@
197
205
  "processors": {
198
206
  "index": "dist/processors/index.js",
199
207
  "chunks": [
200
- "chunk-5PG7DW2T.js",
208
+ "chunk-GHFCSEEP.js",
201
209
  "chunk-LSJJAJAF.js"
202
210
  ]
203
211
  }
@@ -428,4 +428,5 @@ Version overrides propagate automatically through delegation. See [Subagent vers
428
428
  - [Agent.generate() reference](https://mastra.ai/reference/agents/generate)
429
429
  - [Agent approval](https://mastra.ai/docs/agents/agent-approval)
430
430
  - [Memory in multi-agent systems](https://mastra.ai/docs/memory/overview)
431
- - [Concept: Multi-agent systems](https://mastra.ai/guides/concepts/multi-agent-systems)
431
+ - [Concept: Multi-agent systems](https://mastra.ai/guides/concepts/multi-agent-systems)
432
+ - 📹 [Mastra supervisor agents workshop](https://www.youtube.com/watch?v=FNb2fL9WhQg\&t=1872s)
@@ -714,4 +714,5 @@ In practical terms, OM replaces both working memory and message history, and has
714
714
  - [Memory Overview](https://mastra.ai/docs/memory/overview)
715
715
  - [Message History](https://mastra.ai/docs/memory/message-history)
716
716
  - [Memory Processors](https://mastra.ai/docs/memory/memory-processors)
717
- - [Mastra Code](https://code.mastra.ai/): A coding agent using Observational Memory
717
+ - [Mastra Code](https://code.mastra.ai/): A coding agent using Observational Memory
718
+ - 📹 [Mastra processors and Observational Memory workshop](https://www.youtube.com/watch?v=4Vpp7xQYvl0)
@@ -15,6 +15,8 @@ If the combined memory exceeds the model's context limit, [memory processors](ht
15
15
 
16
16
  Memory results will be stored in one or more of your configured [storage providers](https://mastra.ai/docs/storage/overview).
17
17
 
18
+ > **📹 Watch:** Watch [Mastra memory concepts](https://www.youtube.com/watch?v=18iIHQtIPmc) for a conceptual overview of the memory layers agents can use.
19
+
18
20
  ## When to use memory
19
21
 
20
22
  Use memory when your agent needs to maintain multi-turn conversations that reference prior exchanges, recall user preferences or facts from earlier in a session, or build context over time within a conversation thread. Skip memory for single-turn requests where each interaction is independent.
@@ -4,7 +4,7 @@
4
4
 
5
5
  If you ask your friend what they did last weekend, they will search in their memory for events associated with "last weekend" and then tell you what they did. That's sort of like how semantic recall works in Mastra.
6
6
 
7
- > **Watch 📹:** What semantic recall is, how it works, and how to configure it in Mastra [YouTube (5 minutes)](https://youtu.be/UVZtK8cK8xQ)
7
+ > **📹 Watch:** Watch [Mastra semantic recall](https://www.youtube.com/watch?v=UVZtK8cK8xQ\&pp=ygUVbWFzdHJhIHdvcmtpbmcgbWVtb3J5) to see how agents retrieve relevant messages from past conversations.
8
8
 
9
9
  ## How semantic recall works
10
10
 
@@ -10,6 +10,8 @@ This is useful for maintaining ongoing state that's always relevant and should a
10
10
 
11
11
  If you use [Observational Memory](https://mastra.ai/docs/memory/observational-memory), `observationalMemory.observation.manageWorkingMemory` lets OM update working memory for the agent.
12
12
 
13
+ > **📹 Watch:** Watch [Mastra working memory](https://www.youtube.com/watch?v=UMy_JHLf1n8\&pp=ygUVbWFzdHJhIHdvcmtpbmcgbWVtb3J5) to see how agents keep persistent user context available across interactions.
14
+
13
15
  Working memory can persist at two different scopes:
14
16
 
15
17
  - **Resource-scoped** (default): Memory persists across all conversation threads for the same user
@@ -43,9 +45,7 @@ const agent = new Agent({
43
45
 
44
46
  ## How it works
45
47
 
46
- Working memory is a block of Markdown text that the agent is able to update over time to store continuously relevant information:
47
-
48
- [YouTube video player](https://www.youtube-nocookie.com/embed/UMy_JHLf1n8)
48
+ Working memory is a block of Markdown text that the agent is able to update over time to store continuously relevant information.
49
49
 
50
50
  ## Memory persistence scopes
51
51
 
@@ -0,0 +1,58 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Memory
4
+
5
+ A file-based agent gets [memory](https://mastra.ai/docs/memory/overview) from a `memory.ts` file that default-exports a [`Memory`](https://mastra.ai/reference/memory/memory-class) instance. Use this page for the file-based convention; use the memory docs for message history, semantic recall, storage, and processors.
6
+
7
+ Without `memory.ts` or `config.memory`, the agent has no memory by default. Each `generate()` or `stream()` call starts without remembered conversation state unless you pass the prior context yourself.
8
+
9
+ ## Quickstart
10
+
11
+ Create `memory.ts` next to the agent's `config.ts`:
12
+
13
+ ```typescript
14
+ import { Memory } from '@mastra/memory'
15
+
16
+ export default new Memory()
17
+ ```
18
+
19
+ The exported instance becomes the agent's `memory`. If your app configures a storage provider on the main Mastra instance, memory data is stored there. See [storage](https://mastra.ai/docs/storage/overview) for more information.
20
+
21
+ Use the same `resource` and `thread` values when calling the agent to continue a conversation:
22
+
23
+ ```typescript
24
+ const response = await weatherAgent.generate('Remember that I prefer Celsius.', {
25
+ memory: {
26
+ resource: 'user-123',
27
+ thread: 'weather-chat',
28
+ },
29
+ })
30
+ ```
31
+
32
+ ## Configure memory
33
+
34
+ Pass options to `new Memory()` when the default behavior isn't enough.
35
+
36
+ ```typescript
37
+ import { Memory } from '@mastra/memory'
38
+
39
+ export default new Memory({
40
+ options: {
41
+ lastMessages: 20,
42
+ workingMemory: {
43
+ enabled: true,
44
+ scope: 'resource',
45
+ },
46
+ },
47
+ })
48
+ ```
49
+
50
+ Visit the [`Memory` reference](https://mastra.ai/reference/memory/memory-class) for constructor options. Use these pages for related memory features:
51
+
52
+ - [Storage](https://mastra.ai/docs/storage/overview): configure persistence for memory data.
53
+ - [Semantic recall](https://mastra.ai/docs/memory/semantic-recall): retrieve relevant past messages by semantic meaning.
54
+ - [Memory processors](https://mastra.ai/docs/memory/memory-processors): filter, trim, or transform messages before memory adds them to model context.
55
+
56
+ ## Precedence with config
57
+
58
+ `config.memory` wins over `memory.ts`. If neither is present, the assembled file-based agent has no memory. See [`config.ts` precedence](https://mastra.ai/reference/file-based-agents/config) for the full merge table.
@@ -37,7 +37,7 @@ export const agent = new Agent({
37
37
 
38
38
  **options** (`MemoryConfig`): Memory configuration options.
39
39
 
40
- **options.lastMessages** (`number | false`): Number of most recent messages to include in context. Set to false to disable loading conversation history into context. Use Number.MAX\_SAFE\_INTEGER to retrieve all messages with no limit. To prevent saving new messages, use the readOnly option instead.
40
+ **options.lastMessages** (`number | false`): Number of most recent messages to include in context. Set to false to disable the message history feature entirely (messages are not loaded into context or saved). Use Number.MAX\_SAFE\_INTEGER to retrieve all messages with no limit. To load messages without saving new ones, use the readOnly option.
41
41
 
42
42
  **options.readOnly** (`boolean`): When true, prevents memory from saving new messages and provides working memory as read-only context (without the updateWorkingMemory tool). Useful for read-only operations like previews, internal routing agents, or sub agents that should reference but not modify memory.
43
43
 
@@ -0,0 +1,99 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # summarizeConversation()
4
+
5
+ The standalone `summarizeConversation()` function summarizes a conversation in one shot. It distills the messages you pass in with the same Observer plumbing that powers [Observational Memory](https://mastra.ai/reference/memory/observational-memory) — without Observational Memory attached to an agent, and without reading from or writing to storage.
6
+
7
+ Nothing is written back to memory. The summary and extracted values are returned to you (and to each extractor's `onExtracted` hook), so you decide where they go — for example your own database.
8
+
9
+ Use this when you already have the messages in hand and want explicit control over what gets summarized. To summarize a stored thread by ID instead, use [`Memory.summarizeThread()`](https://mastra.ai/reference/memory/summarizeThread), which loads the messages for you.
10
+
11
+ ## Usage example
12
+
13
+ ```typescript
14
+ import { summarizeConversation } from '@mastra/memory'
15
+
16
+ const result = await summarizeConversation({
17
+ model: 'openai/gpt-5-mini',
18
+ messages,
19
+ instructions: 'Summarize this voicemail call for the business owner.',
20
+ })
21
+ ```
22
+
23
+ ## Parameters
24
+
25
+ **model** (`string | LanguageModel | DynamicModel`): Model that runs the summarization, such as a router string like '\_\_GATEWAY\_OPENAI\_MODEL\_MINI\_\_'.
26
+
27
+ **messages** (`MastraDBMessage[]`): The conversation to summarize. When empty, the function returns an empty result without calling the model.
28
+
29
+ **instructions** (`string`): Extra guidance appended to the summarizer's system prompt, such as what to focus on or who the summary is for.
30
+
31
+ **extract** (`Extractor[]`): Extractors to run over the conversation. Extractors with a Zod schema run as a follow-up structured output call; schema-less extractors are extracted inline. Each extractor's onExtracted hook fires with the extracted value.
32
+
33
+ **threadId** (`string`): Thread the conversation belongs to. Defaults to the first threadId found on messages. Passed to extractor contexts.
34
+
35
+ **resourceId** (`string`): Resource (user) the conversation belongs to. Defaults to the first resourceId found on messages. Passed to extractor contexts.
36
+
37
+ **memory** (`Memory`): Memory instance forwarded to extractor contexts. Set automatically when called through Memory.summarizeThread().
38
+
39
+ **mastra** (`Mastra`): Mastra instance used to resolve custom gateway models. Set automatically when called through Memory.summarizeThread().
40
+
41
+ **requestContext** (`RequestContext`): Request context forwarded to the summarizer model and extractor hooks.
42
+
43
+ **abortSignal** (`AbortSignal`): Signal to cancel the summarization call.
44
+
45
+ ## Returns
46
+
47
+ **summary** (`string`): The distilled observations produced from the conversation, in dense bullet form.
48
+
49
+ **extracted** (`Record<string, unknown>`): Values produced by extract extractors, keyed by extractor slug.
50
+
51
+ **extractionFailures** (`{ slug: string; error: string }[]`): Extractors that failed to produce a valid value, with the reason. Only present when at least one extractor failed.
52
+
53
+ **usage** (`{ inputTokens?: number; outputTokens?: number; totalTokens?: number }`): Token usage of the summarization call.
54
+
55
+ ## Extended usage example
56
+
57
+ The following example summarizes an in-flight voice session from messages the application already holds, and extracts a structured record:
58
+
59
+ ```typescript
60
+ import { summarizeConversation, Extractor } from '@mastra/memory'
61
+ import type { MastraDBMessage } from '@mastra/core/agent'
62
+ import { z } from 'zod'
63
+ import { sessionRecords } from './db'
64
+
65
+ const sessionSummary = new Extractor({
66
+ name: 'session-summary',
67
+ instructions: 'Return a concise summary of the session.',
68
+ schema: z.object({
69
+ summary: z.string(),
70
+ sentiment: z.enum(['positive', 'neutral', 'negative']),
71
+ followUps: z.array(z.string()),
72
+ }),
73
+ metadataKeyPath: false, // don't persist into memory metadata — the hook owns storage
74
+ onExtracted: async ({ current, threadId }) => {
75
+ await sessionRecords.upsert({ sessionId: threadId, record: current })
76
+ },
77
+ })
78
+
79
+ export async function onSessionEnd(messages: MastraDBMessage[]) {
80
+ const { summary, extracted, extractionFailures } = await summarizeConversation({
81
+ model: 'openai/gpt-5-mini',
82
+ messages,
83
+ instructions: 'Summarize this support session for the account manager.',
84
+ extract: [sessionSummary],
85
+ })
86
+
87
+ if (extractionFailures?.length) {
88
+ console.warn('Some extractors failed', extractionFailures)
89
+ }
90
+
91
+ return { summary, extracted }
92
+ }
93
+ ```
94
+
95
+ ### Related
96
+
97
+ - [.summarizeThread()](https://mastra.ai/reference/memory/summarizeThread)
98
+ - [Memory Class Reference](https://mastra.ai/reference/memory/memory-class)
99
+ - [Observational Memory](https://mastra.ai/reference/memory/observational-memory)
@@ -0,0 +1,93 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Memory.summarizeThread()
4
+
5
+ The `.summarizeThread()` method summarizes a thread's conversation in one shot. It loads the thread's messages from storage and distills them with the same Observer plumbing that powers [Observational Memory](https://mastra.ai/reference/memory/observational-memory) — as a standalone call, without Observational Memory attached to an agent.
6
+
7
+ Messages load page-by-page starting from the newest, bounded by `lastMessages` and `maxInputTokens`, so summarizing a long thread doesn't read its entire history from storage.
8
+
9
+ Nothing is written back to memory. The summary and extracted values are returned to you (and to each extractor's `onExtracted` hook), so you decide where they go — for example your own database.
10
+
11
+ Use this when a session ends and you want a summary or structured extraction of the whole conversation, such as a voice call at hang-up. To summarize messages you already have in hand (without loading them from a thread), use the standalone [`summarizeConversation()`](https://mastra.ai/reference/memory/summarizeConversation) function instead — it takes the same options with `messages` in place of `threadId`.
12
+
13
+ ## Usage example
14
+
15
+ ```typescript
16
+ const result = await memory.summarizeThread({
17
+ model: 'openai/gpt-5-mini',
18
+ threadId: 'thread-123',
19
+ instructions: 'Summarize this voicemail call for the business owner.',
20
+ })
21
+ ```
22
+
23
+ ## Parameters
24
+
25
+ **threadId** (`string`): The unique identifier of the thread to summarize.
26
+
27
+ **model** (`string | LanguageModel | DynamicModel`): Model that runs the summarization, such as a router string like '\_\_GATEWAY\_OPENAI\_MODEL\_MINI\_\_'.
28
+
29
+ **resourceId** (`string`): ID of the resource that owns the thread. If provided, validates thread ownership. Also passed to extractor contexts.
30
+
31
+ **lastMessages** (`number`): Only summarize the last N messages of the thread. By default the whole thread is loaded, bounded by maxInputTokens.
32
+
33
+ **maxInputTokens** (`number`): Stop loading older messages once the collected messages exceed this estimated token count. The newest message is always included. (Default: `1000000`)
34
+
35
+ **instructions** (`string`): Extra guidance appended to the summarizer's system prompt, such as what to focus on or who the summary is for.
36
+
37
+ **extract** (`Extractor[]`): Extractors to run over the conversation. Extractors with a Zod schema run as a follow-up structured output call; schema-less extractors are extracted inline. Each extractor's onExtracted hook fires with the extracted value.
38
+
39
+ **requestContext** (`RequestContext`): Request context forwarded to the summarizer model and extractor hooks.
40
+
41
+ **abortSignal** (`AbortSignal`): Signal to cancel the summarization call.
42
+
43
+ ## Returns
44
+
45
+ **summary** (`string`): The distilled observations produced from the conversation, in dense bullet form.
46
+
47
+ **extracted** (`Record<string, unknown>`): Values produced by extract extractors, keyed by extractor slug.
48
+
49
+ **extractionFailures** (`{ slug: string; error: string }[]`): Extractors that failed to produce a valid value, with the reason. Only present when at least one extractor failed.
50
+
51
+ **usage** (`{ inputTokens?: number; outputTokens?: number; totalTokens?: number }`): Token usage of the summarization call.
52
+
53
+ ## Extended usage example
54
+
55
+ The following example summarizes a finished voice call and stores a structured record in the application's own database:
56
+
57
+ ```typescript
58
+ import { Extractor } from '@mastra/memory'
59
+ import { z } from 'zod'
60
+ import { memory } from './mastra/memory'
61
+ import { callRecords } from './db'
62
+
63
+ const callSummary = new Extractor({
64
+ name: 'call-summary',
65
+ instructions: 'Return a concise summary of the call.',
66
+ schema: z.object({
67
+ summary: z.string(),
68
+ sentiment: z.enum(['positive', 'neutral', 'negative']),
69
+ requestedServices: z.array(z.string()),
70
+ }),
71
+ metadataKeyPath: false, // don't persist into memory metadata — the hook owns storage
72
+ onExtracted: async ({ current, threadId, resourceId }) => {
73
+ await callRecords.upsert({ callId: threadId, callerId: resourceId, record: current })
74
+ },
75
+ })
76
+
77
+ export async function onCallEnd(threadId: string, resourceId: string) {
78
+ await memory.summarizeThread({
79
+ model: 'openai/gpt-5-mini',
80
+ threadId,
81
+ resourceId,
82
+ instructions: 'Summarize this voicemail call for the business owner.',
83
+ extract: [callSummary],
84
+ })
85
+ }
86
+ ```
87
+
88
+ ### Related
89
+
90
+ - [summarizeConversation()](https://mastra.ai/reference/memory/summarizeConversation)
91
+ - [Memory Class Reference](https://mastra.ai/reference/memory/memory-class)
92
+ - [Observational Memory](https://mastra.ai/reference/memory/observational-memory)
93
+ - [.recall()](https://mastra.ai/reference/memory/recall)