@mastra/memory 1.22.1 → 1.22.2-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.
- package/CHANGELOG.md +6 -0
- package/dist/{chunk-YWAAIUB6.cjs → chunk-3JX4RMDN.cjs} +14 -13
- package/dist/chunk-3JX4RMDN.cjs.map +1 -0
- package/dist/{chunk-2NSPHF6Q.js → chunk-TB6SV7QK.js} +14 -13
- package/dist/chunk-TB6SV7QK.js.map +1 -0
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/assets/SOURCE_MAP.json +44 -44
- package/dist/docs/references/docs-agents-agent-approval.md +25 -0
- package/dist/docs/references/docs-agents-supervisor-agents.md +3 -3
- package/dist/docs/references/{docs-agents-background-tasks.md → docs-long-running-agents-background-tasks.md} +2 -2
- package/dist/docs/references/{docs-agents-goals.md → docs-long-running-agents-goals.md} +1 -1
- package/dist/docs/references/docs-memory-working-memory.md +1 -1
- package/dist/docs/references/reference-memory-cloneThread.md +35 -4
- package/dist/docs/references/reference-memory-memory-class.md +5 -5
- package/dist/docs/references/reference-memory-observational-memory.md +43 -43
- package/dist/docs/references/reference-storage-dynamodb.md +1 -1
- package/dist/docs/references/reference-storage-libsql.md +1 -1
- package/dist/docs/references/reference-storage-postgresql.md +2 -2
- package/dist/docs/references/reference-storage-redis.md +2 -2
- package/dist/docs/references/reference-vectors-mongodb.md +1 -1
- package/dist/docs/references/reference-vectors-pg.md +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.js +1 -1
- package/dist/{observational-memory-QL6BKIQX.js → observational-memory-NNGAOKRQ.js} +3 -3
- package/dist/{observational-memory-QL6BKIQX.js.map → observational-memory-NNGAOKRQ.js.map} +1 -1
- package/dist/{observational-memory-CZ22AU3H.cjs → observational-memory-TEIGXE56.cjs} +28 -28
- package/dist/{observational-memory-CZ22AU3H.cjs.map → observational-memory-TEIGXE56.cjs.map} +1 -1
- package/dist/processors/index.cjs +26 -26
- package/dist/processors/index.js +1 -1
- package/dist/tools/om-tools.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/chunk-2NSPHF6Q.js.map +0 -1
- package/dist/chunk-YWAAIUB6.cjs.map +0 -1
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.
|
|
6
|
+
version: "1.22.2-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -17,11 +17,11 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
17
17
|
### Docs
|
|
18
18
|
|
|
19
19
|
- [Agent approval](references/docs-agents-agent-approval.md) - Learn how to require approvals, suspend tool execution, and automatically resume suspended tools while keeping humans in control of agent workflows.
|
|
20
|
-
- [Background tasks](references/docs-agents-background-tasks.md) - Learn how to dispatch long-running tool calls in the background, keep the stream open until they complete, and orchestrate subagents asynchronously.
|
|
21
|
-
- [Goals](references/docs-agents-goals.md) - Learn how to set a durable objective on an agent that is judged in the execution loop, so the agent keeps working until the goal is complete or the run budget is exhausted.
|
|
22
20
|
- [Agent networks](references/docs-agents-networks.md) - Coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
|
|
23
21
|
- [Supervisor agents](references/docs-agents-supervisor-agents.md) - Learn how to coordinate multiple agents with delegation hooks, iteration monitoring, message filtering, and task completion scoring.
|
|
24
22
|
- [Evals with memory](references/docs-evals-evals-with-memory.md) - Run scorers against memory-enabled agents — including observational memory in thread scope — using runEvals and dataset experiments.
|
|
23
|
+
- [Background tasks](references/docs-long-running-agents-background-tasks.md) - Learn how to dispatch long-running tool calls in the background, keep the stream open until they complete, and orchestrate subagents asynchronously.
|
|
24
|
+
- [Goals](references/docs-long-running-agents-goals.md) - Learn how to set a durable objective on an agent that is judged in the execution loop, so the agent keeps working until the goal is complete or the run budget is exhausted.
|
|
25
25
|
- [Memory processors](references/docs-memory-memory-processors.md) - Learn how to use memory processors in Mastra to filter, trim, and transform messages before they're sent to the language model to manage context window limits.
|
|
26
26
|
- [Message history](references/docs-memory-message-history.md) - Learn how to configure message history in Mastra to store recent messages from the current conversation.
|
|
27
27
|
- [Multi-user threads](references/docs-memory-multi-user-threads.md) - Share one Mastra thread between multiple users by carrying speaker identity in the message body.
|
|
@@ -1,129 +1,129 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.22.
|
|
2
|
+
"version": "1.22.2-alpha.0",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
5
|
"Extractor": {
|
|
6
6
|
"types": "dist/processors/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
7
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
8
8
|
"line": 316
|
|
9
9
|
},
|
|
10
10
|
"ModelByInputTokens": {
|
|
11
11
|
"types": "dist/processors/index.d.ts",
|
|
12
|
-
"implementation": "dist/chunk-
|
|
12
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
13
13
|
"line": 1354
|
|
14
14
|
},
|
|
15
15
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
16
16
|
"types": "dist/processors/index.d.ts",
|
|
17
|
-
"implementation": "dist/chunk-
|
|
17
|
+
"implementation": "dist/chunk-TB6SV7QK.js"
|
|
18
18
|
},
|
|
19
19
|
"ObservationalMemory": {
|
|
20
20
|
"types": "dist/processors/index.d.ts",
|
|
21
|
-
"implementation": "dist/chunk-
|
|
22
|
-
"line":
|
|
21
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
22
|
+
"line": 27533
|
|
23
23
|
},
|
|
24
24
|
"ObservationalMemoryProcessor": {
|
|
25
25
|
"types": "dist/processors/index.d.ts",
|
|
26
|
-
"implementation": "dist/chunk-
|
|
27
|
-
"line":
|
|
26
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
27
|
+
"line": 30164
|
|
28
28
|
},
|
|
29
29
|
"TokenCounter": {
|
|
30
30
|
"types": "dist/processors/index.d.ts",
|
|
31
|
-
"implementation": "dist/chunk-
|
|
32
|
-
"line":
|
|
31
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
32
|
+
"line": 26858
|
|
33
33
|
},
|
|
34
34
|
"WorkingMemoryExtractor": {
|
|
35
35
|
"types": "dist/processors/index.d.ts",
|
|
36
|
-
"implementation": "dist/chunk-
|
|
36
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
37
37
|
"line": 20684
|
|
38
38
|
},
|
|
39
39
|
"buildObserverPrompt": {
|
|
40
40
|
"types": "dist/processors/index.d.ts",
|
|
41
|
-
"implementation": "dist/chunk-
|
|
41
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
42
42
|
"line": 4465
|
|
43
43
|
},
|
|
44
44
|
"buildObserverSystemPrompt": {
|
|
45
45
|
"types": "dist/processors/index.d.ts",
|
|
46
|
-
"implementation": "dist/chunk-
|
|
46
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
47
47
|
"line": 3732
|
|
48
48
|
},
|
|
49
49
|
"combineObservationGroupRanges": {
|
|
50
50
|
"types": "dist/processors/index.d.ts",
|
|
51
|
-
"implementation": "dist/chunk-
|
|
51
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
52
52
|
"line": 1446
|
|
53
53
|
},
|
|
54
54
|
"deriveObservationGroupProvenance": {
|
|
55
55
|
"types": "dist/processors/index.d.ts",
|
|
56
|
-
"implementation": "dist/chunk-
|
|
56
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
57
57
|
"line": 1480
|
|
58
58
|
},
|
|
59
59
|
"extractCurrentTask": {
|
|
60
60
|
"types": "dist/processors/index.d.ts",
|
|
61
|
-
"implementation": "dist/chunk-
|
|
61
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
62
62
|
"line": 4588
|
|
63
63
|
},
|
|
64
64
|
"formatMessagesForObserver": {
|
|
65
65
|
"types": "dist/processors/index.d.ts",
|
|
66
|
-
"implementation": "dist/chunk-
|
|
66
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
67
67
|
"line": 4187
|
|
68
68
|
},
|
|
69
69
|
"getObservationsAsOf": {
|
|
70
70
|
"types": "dist/processors/index.d.ts",
|
|
71
|
-
"implementation": "dist/chunk-
|
|
72
|
-
"line":
|
|
71
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
72
|
+
"line": 30386
|
|
73
73
|
},
|
|
74
74
|
"hasCurrentTaskSection": {
|
|
75
75
|
"types": "dist/processors/index.d.ts",
|
|
76
|
-
"implementation": "dist/chunk-
|
|
76
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
77
77
|
"line": 4576
|
|
78
78
|
},
|
|
79
79
|
"injectAnchorIds": {
|
|
80
80
|
"types": "dist/processors/index.d.ts",
|
|
81
|
-
"implementation": "dist/chunk-
|
|
81
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
82
82
|
"line": 3287
|
|
83
83
|
},
|
|
84
84
|
"optimizeObservationsForContext": {
|
|
85
85
|
"types": "dist/processors/index.d.ts",
|
|
86
|
-
"implementation": "dist/chunk-
|
|
86
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
87
87
|
"line": 4599
|
|
88
88
|
},
|
|
89
89
|
"parseAnchorId": {
|
|
90
90
|
"types": "dist/processors/index.d.ts",
|
|
91
|
-
"implementation": "dist/chunk-
|
|
91
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
92
92
|
"line": 3260
|
|
93
93
|
},
|
|
94
94
|
"parseObservationGroups": {
|
|
95
95
|
"types": "dist/processors/index.d.ts",
|
|
96
|
-
"implementation": "dist/chunk-
|
|
96
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
97
97
|
"line": 1415
|
|
98
98
|
},
|
|
99
99
|
"parseObserverOutput": {
|
|
100
100
|
"types": "dist/processors/index.d.ts",
|
|
101
|
-
"implementation": "dist/chunk-
|
|
101
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
102
102
|
"line": 4479
|
|
103
103
|
},
|
|
104
104
|
"reconcileObservationGroupsFromReflection": {
|
|
105
105
|
"types": "dist/processors/index.d.ts",
|
|
106
|
-
"implementation": "dist/chunk-
|
|
106
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
107
107
|
"line": 1504
|
|
108
108
|
},
|
|
109
109
|
"renderObservationGroupsForReflection": {
|
|
110
110
|
"types": "dist/processors/index.d.ts",
|
|
111
|
-
"implementation": "dist/chunk-
|
|
111
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
112
112
|
"line": 1460
|
|
113
113
|
},
|
|
114
114
|
"stripEphemeralAnchorIds": {
|
|
115
115
|
"types": "dist/processors/index.d.ts",
|
|
116
|
-
"implementation": "dist/chunk-
|
|
116
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
117
117
|
"line": 3317
|
|
118
118
|
},
|
|
119
119
|
"stripObservationGroups": {
|
|
120
120
|
"types": "dist/processors/index.d.ts",
|
|
121
|
-
"implementation": "dist/chunk-
|
|
121
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
122
122
|
"line": 1437
|
|
123
123
|
},
|
|
124
124
|
"wrapInObservationGroup": {
|
|
125
125
|
"types": "dist/processors/index.d.ts",
|
|
126
|
-
"implementation": "dist/chunk-
|
|
126
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
127
127
|
"line": 1408
|
|
128
128
|
},
|
|
129
129
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
@@ -144,40 +144,40 @@
|
|
|
144
144
|
},
|
|
145
145
|
"Memory": {
|
|
146
146
|
"types": "dist/index.d.ts",
|
|
147
|
-
"implementation": "dist/chunk-
|
|
148
|
-
"line":
|
|
147
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
148
|
+
"line": 22109
|
|
149
149
|
},
|
|
150
150
|
"MessageHistory": {
|
|
151
151
|
"types": "dist/index.d.ts",
|
|
152
|
-
"implementation": "dist/chunk-
|
|
152
|
+
"implementation": "dist/chunk-TB6SV7QK.js"
|
|
153
153
|
},
|
|
154
154
|
"SemanticRecall": {
|
|
155
155
|
"types": "dist/index.d.ts",
|
|
156
|
-
"implementation": "dist/chunk-
|
|
156
|
+
"implementation": "dist/chunk-TB6SV7QK.js"
|
|
157
157
|
},
|
|
158
158
|
"WorkingMemory": {
|
|
159
159
|
"types": "dist/index.d.ts",
|
|
160
|
-
"implementation": "dist/chunk-
|
|
160
|
+
"implementation": "dist/chunk-TB6SV7QK.js"
|
|
161
161
|
},
|
|
162
162
|
"deepMergeWorkingMemory": {
|
|
163
163
|
"types": "dist/index.d.ts",
|
|
164
|
-
"implementation": "dist/chunk-
|
|
165
|
-
"line":
|
|
164
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
165
|
+
"line": 21748
|
|
166
166
|
},
|
|
167
167
|
"extractWorkingMemoryContent": {
|
|
168
168
|
"types": "dist/index.d.ts",
|
|
169
|
-
"implementation": "dist/chunk-
|
|
170
|
-
"line":
|
|
169
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
170
|
+
"line": 22064
|
|
171
171
|
},
|
|
172
172
|
"extractWorkingMemoryTags": {
|
|
173
173
|
"types": "dist/index.d.ts",
|
|
174
|
-
"implementation": "dist/chunk-
|
|
175
|
-
"line":
|
|
174
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
175
|
+
"line": 22032
|
|
176
176
|
},
|
|
177
177
|
"removeWorkingMemoryTags": {
|
|
178
178
|
"types": "dist/index.d.ts",
|
|
179
|
-
"implementation": "dist/chunk-
|
|
180
|
-
"line":
|
|
179
|
+
"implementation": "dist/chunk-TB6SV7QK.js",
|
|
180
|
+
"line": 22045
|
|
181
181
|
},
|
|
182
182
|
"WORKING_MEMORY_STATE_ID": {
|
|
183
183
|
"types": "dist/index.d.ts",
|
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
"processors": {
|
|
198
198
|
"index": "dist/processors/index.js",
|
|
199
199
|
"chunks": [
|
|
200
|
-
"chunk-
|
|
200
|
+
"chunk-TB6SV7QK.js",
|
|
201
201
|
"chunk-LSJJAJAF.js"
|
|
202
202
|
]
|
|
203
203
|
}
|
|
@@ -49,6 +49,8 @@ for await (const chunk of stream.fullStream) {
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
> **Note:** Agent approval uses snapshots to capture request state. Configure a [storage provider](https://mastra.ai/docs/memory/storage) on your Mastra instance or you'll see a "snapshot not found" error.
|
|
52
|
+
>
|
|
53
|
+
> Snapshots for agent runs are minimal resume artifacts: they hold only what's needed to resume the suspended run and are deleted once the run finishes. Use [tracing](https://mastra.ai/docs/observability/overview) for the execution record and [memory](https://mastra.ai/docs/memory/overview) for the conversation history.
|
|
52
54
|
|
|
53
55
|
## How approval works
|
|
54
56
|
|
|
@@ -108,6 +110,29 @@ A tool can also pause _during_ its `execute` function by calling `suspend()`. Th
|
|
|
108
110
|
|
|
109
111
|
The stream emits a `tool-call-suspended` chunk with a custom payload defined by the tool's `suspendSchema`. You resume by calling `resumeStream()` with data matching the tool's `resumeSchema`.
|
|
110
112
|
|
|
113
|
+
```typescript
|
|
114
|
+
const weatherTool = createTool({
|
|
115
|
+
id: 'get-weather',
|
|
116
|
+
inputSchema: z.object({
|
|
117
|
+
location: z.string().optional(),
|
|
118
|
+
}),
|
|
119
|
+
suspendSchema: z.object({
|
|
120
|
+
question: z.string(),
|
|
121
|
+
}),
|
|
122
|
+
resumeSchema: z.object({
|
|
123
|
+
location: z.string(),
|
|
124
|
+
}),
|
|
125
|
+
execute: async ({ location }, context) => {
|
|
126
|
+
if (!location) {
|
|
127
|
+
return await context?.agent?.suspend({
|
|
128
|
+
question: 'Which city would you like the weather for?',
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
return await fetchWeather(location)
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
111
136
|
> **Note:** `suspend()` doesn't throw — return immediately after calling it (e.g. `return await suspend({ ... })`). Code after `await suspend(...)` still runs before the tool pauses.
|
|
112
137
|
|
|
113
138
|
## Tool approval with `generate()`
|
|
@@ -374,7 +374,7 @@ Success criteria:
|
|
|
374
374
|
|
|
375
375
|
## Running subagents in the background
|
|
376
376
|
|
|
377
|
-
Subagent invocations are dispatched as tool calls, so they can run as [background tasks](https://mastra.ai/docs/agents/background-tasks). This is useful when one or more delegations are long-running and you don't want them to block the supervisor's response.
|
|
377
|
+
Subagent invocations are dispatched as tool calls, so they can run as [background tasks](https://mastra.ai/docs/long-running-agents/background-tasks). This is useful when one or more delegations are long-running and you don't want them to block the supervisor's response.
|
|
378
378
|
|
|
379
379
|
Enable the [backgroundTasks manager](https://mastra.ai/reference/configuration) on the Mastra instance, then opt subagents in on the supervisor:
|
|
380
380
|
|
|
@@ -399,7 +399,7 @@ const stream = await supervisor.streamUntilIdle('Research AI in education and wr
|
|
|
399
399
|
|
|
400
400
|
Use [`streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) instead of `stream()` so the stream stays open until the subagents complete and the supervisor has had a chance to respond to their results.
|
|
401
401
|
|
|
402
|
-
If a subagent isn't listed on the supervisor but has its own background-eligible tools, the supervisor still dispatches the subagent as a background task and inherits its config. See [Inheriting from the subagent](https://mastra.ai/docs/agents/background-tasks) for details.
|
|
402
|
+
If a subagent isn't listed on the supervisor but has its own background-eligible tools, the supervisor still dispatches the subagent as a background task and inherits its config. See [Inheriting from the subagent](https://mastra.ai/docs/long-running-agents/background-tasks) for details.
|
|
403
403
|
|
|
404
404
|
## Subagent versioning
|
|
405
405
|
|
|
@@ -420,7 +420,7 @@ Version overrides propagate automatically through delegation. See [Subagent vers
|
|
|
420
420
|
|
|
421
421
|
## Related
|
|
422
422
|
|
|
423
|
-
- [Background tasks](https://mastra.ai/docs/agents/background-tasks)
|
|
423
|
+
- [Background tasks](https://mastra.ai/docs/long-running-agents/background-tasks)
|
|
424
424
|
- [Subagent versioning](https://mastra.ai/docs/editor/overview)
|
|
425
425
|
- [Guide: Research coordinator](https://mastra.ai/guides/guide/research-coordinator)
|
|
426
426
|
- [Agent.stream() reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
@@ -121,7 +121,7 @@ If the agent has `backgroundTasks.disabled: true`, every tool call runs synchron
|
|
|
121
121
|
|
|
122
122
|
## Background tasks related stream chunks
|
|
123
123
|
|
|
124
|
-
When a tool call dispatches as a background task, two streams may surface lifecycle events for it: the agent's own stream and the [`backgroundTaskManager.stream()`](https://mastra.ai/docs/agents/background-tasks) SSE stream. Each stream covers a different set of chunk types:
|
|
124
|
+
When a tool call dispatches as a background task, two streams may surface lifecycle events for it: the agent's own stream and the [`backgroundTaskManager.stream()`](https://mastra.ai/docs/long-running-agents/background-tasks) SSE stream. Each stream covers a different set of chunk types:
|
|
125
125
|
|
|
126
126
|
| Chunk type | When it fires | Emitted by |
|
|
127
127
|
| --------------------------- | -------------------------------------------------------------------------------------- | -------------- |
|
|
@@ -376,7 +376,7 @@ These read from storage rather than the pubsub stream, so they're suitable for p
|
|
|
376
376
|
|
|
377
377
|
- [`Agent.stream()` reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
378
378
|
- [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
|
|
379
|
-
- [Durable agents](https://mastra.ai/docs/agents/durable-agents)
|
|
379
|
+
- [Durable agents](https://mastra.ai/docs/long-running-agents/durable-agents)
|
|
380
380
|
- [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
|
|
381
381
|
- [Stream chunk types](https://mastra.ai/reference/streaming/ChunkType)
|
|
382
382
|
- [Storage](https://mastra.ai/docs/memory/storage)
|
|
@@ -110,5 +110,5 @@ Per-objective values written by `setObjective` / `updateObjectiveOptions` take p
|
|
|
110
110
|
## Related
|
|
111
111
|
|
|
112
112
|
- [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents) — `isTaskComplete` and the rubric scorer
|
|
113
|
-
- [Signal providers](https://mastra.ai/docs/agents/signal-providers) — how the objective is projected into context
|
|
113
|
+
- [Signal providers](https://mastra.ai/docs/long-running-agents/signal-providers) — how the objective is projected into context
|
|
114
114
|
- [Memory storage](https://mastra.ai/docs/memory/storage) — the storage backend goals require
|
|
@@ -399,7 +399,7 @@ const response = await agent.generate('What do you know about me?', {
|
|
|
399
399
|
|
|
400
400
|
## Opt in to state signals (experimental)
|
|
401
401
|
|
|
402
|
-
By default, working memory reaches the model as part of the system message. You can opt into delivering it as a [state signal](https://mastra.ai/docs/agents/signals) instead by setting `useStateSignals: true`:
|
|
402
|
+
By default, working memory reaches the model as part of the system message. You can opt into delivering it as a [state signal](https://mastra.ai/docs/long-running-agents/signals) instead by setting `useStateSignals: true`:
|
|
403
403
|
|
|
404
404
|
```typescript
|
|
405
405
|
const memory = new Memory({
|
|
@@ -6,7 +6,16 @@ The `.cloneThread()` method creates a copy of an existing conversation thread, i
|
|
|
6
6
|
|
|
7
7
|
## Usage example
|
|
8
8
|
|
|
9
|
+
The following example creates a `Memory` instance and clones an existing thread.
|
|
10
|
+
|
|
9
11
|
```typescript
|
|
12
|
+
import { Memory } from '@mastra/memory'
|
|
13
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
14
|
+
|
|
15
|
+
const memory = new Memory({
|
|
16
|
+
storage: new LibSQLStore({ id: 'memory-store', url: 'file:./memory.db' }),
|
|
17
|
+
})
|
|
18
|
+
|
|
10
19
|
const { thread, clonedMessages } = await memory.cloneThread({
|
|
11
20
|
sourceThreadId: 'original-thread-123',
|
|
12
21
|
})
|
|
@@ -20,7 +29,7 @@ const { thread, clonedMessages } = await memory.cloneThread({
|
|
|
20
29
|
|
|
21
30
|
**resourceId** (`string`): Optional resource ID for the cloned thread. Defaults to the source thread's resourceId.
|
|
22
31
|
|
|
23
|
-
**title** (`string`): Optional title for the cloned thread.
|
|
32
|
+
**title** (`string`): Optional title for the cloned thread. If omitted, the clone uses Clone of ${sourceThread.title} when the source thread has a title. Otherwise, the title is empty.
|
|
24
33
|
|
|
25
34
|
**metadata** (`Record<string, unknown>`): Optional metadata to merge with the source thread's metadata. Clone metadata is automatically added.
|
|
26
35
|
|
|
@@ -44,7 +53,7 @@ const { thread, clonedMessages } = await memory.cloneThread({
|
|
|
44
53
|
|
|
45
54
|
**messageIdMap** (`Record<string, string>`): A mapping from source message IDs to their corresponding cloned message IDs.
|
|
46
55
|
|
|
47
|
-
### Clone
|
|
56
|
+
### Clone metadata
|
|
48
57
|
|
|
49
58
|
The cloned thread's metadata includes a `clone` property with:
|
|
50
59
|
|
|
@@ -93,8 +102,18 @@ const { thread: dateFilteredClone } = await memory.cloneThread({
|
|
|
93
102
|
},
|
|
94
103
|
})
|
|
95
104
|
|
|
105
|
+
// Clone specific messages
|
|
106
|
+
const { thread: selectedMessagesClone } = await memory.cloneThread({
|
|
107
|
+
sourceThreadId: 'original-thread-123',
|
|
108
|
+
options: {
|
|
109
|
+
messageFilter: {
|
|
110
|
+
messageIds: ['message-1', 'message-2'],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
|
|
96
115
|
// Continue conversation on the cloned thread
|
|
97
|
-
const response = await agent.generate(
|
|
116
|
+
const response = await agent.generate('Try a different approach', {
|
|
98
117
|
memory: {
|
|
99
118
|
thread: fullClone.id,
|
|
100
119
|
resource: fullClone.resourceId,
|
|
@@ -102,9 +121,13 @@ const response = await agent.generate("Let's try a different approach", {
|
|
|
102
121
|
})
|
|
103
122
|
```
|
|
104
123
|
|
|
124
|
+
Pass the cloned `thread.id` and `thread.resourceId` to `agent.generate()` to continue the conversation from the cloned thread.
|
|
125
|
+
|
|
105
126
|
## Vector embeddings
|
|
106
127
|
|
|
107
|
-
When the Memory instance has semantic recall enabled
|
|
128
|
+
When the Memory instance has semantic recall enabled with a vector store and embedder configured, `cloneThread()` automatically creates vector embeddings for all cloned messages. This ensures that semantic search works correctly on the cloned thread.
|
|
129
|
+
|
|
130
|
+
In this example, `embeddingModel` is the embedding model configured for the project.
|
|
108
131
|
|
|
109
132
|
```typescript
|
|
110
133
|
import { Memory } from '@mastra/memory'
|
|
@@ -131,6 +154,14 @@ const results = await memory.recall({
|
|
|
131
154
|
})
|
|
132
155
|
```
|
|
133
156
|
|
|
157
|
+
## Working memory
|
|
158
|
+
|
|
159
|
+
When working memory is enabled, `cloneThread()` copies or shares working memory based on the working-memory scope and the clone's `resourceId`:
|
|
160
|
+
|
|
161
|
+
- **Thread-scoped working memory**: The working memory is copied to the cloned thread.
|
|
162
|
+
- **Resource-scoped working memory with the same `resourceId`**: The working memory is shared because the source and cloned threads belong to the same resource.
|
|
163
|
+
- **Resource-scoped working memory with a different `resourceId`**: The working memory is copied to the cloned thread's resource.
|
|
164
|
+
|
|
134
165
|
## Observational Memory
|
|
135
166
|
|
|
136
167
|
When [Observational Memory](https://mastra.ai/docs/memory/observational-memory) is enabled, `cloneThread()` automatically clones the OM records associated with the source thread. The behavior depends on the OM scope:
|
|
@@ -29,23 +29,23 @@ export const agent = new Agent({
|
|
|
29
29
|
|
|
30
30
|
## Constructor parameters
|
|
31
31
|
|
|
32
|
-
**storage** (`MastraCompositeStore`): Storage implementation for persisting memory data. Defaults to
|
|
32
|
+
**storage** (`MastraCompositeStore`): Storage implementation for persisting memory data. Defaults to new DefaultStorage({ config: { url: "file:memory.db" } }) if not provided.
|
|
33
33
|
|
|
34
|
-
**vector** (`MastraVector | false`): Vector store for semantic search capabilities. Set to
|
|
34
|
+
**vector** (`MastraVector | false`): Vector store for semantic search capabilities. Set to false to disable vector operations.
|
|
35
35
|
|
|
36
36
|
**embedder** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder instance for vector embeddings. Required when semantic recall is enabled.
|
|
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
|
|
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.
|
|
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
|
|
|
44
44
|
**options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires both vector store and embedder to be configured. Default topK is 4, default messageRange is {before: 1, after: 1}.
|
|
45
45
|
|
|
46
|
-
**options.workingMemory** (`WorkingMemory`): Configuration for working memory feature. Can be
|
|
46
|
+
**options.workingMemory** (`WorkingMemory`): Configuration for working memory feature. Can be { enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' } or { enabled: boolean } to disable.
|
|
47
47
|
|
|
48
|
-
**options.observationalMemory** (`boolean | ObservationalMemoryOptions`): Enable Observational Memory for long-context agentic memory. Set to
|
|
48
|
+
**options.observationalMemory** (`boolean | ObservationalMemoryOptions`): Enable Observational Memory for long-context agentic memory. Set to true for defaults, or pass a config object to customize token budgets, models, and scope. See Observational Memory reference for configuration details.
|
|
49
49
|
|
|
50
50
|
**options.generateTitle** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the user's first message. Can be a boolean or an object with custom model and instructions.
|
|
51
51
|
|