@mastra/memory 1.17.1 → 1.17.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 +11 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-background-tasks.md +242 -0
- package/dist/docs/references/docs-agents-supervisor-agents.md +35 -4
- package/dist/docs/references/reference-memory-clone-utilities.md +4 -2
- package/dist/docs/references/reference-memory-cloneThread.md +4 -2
- package/dist/index.cjs +113 -748
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +113 -748
- package/dist/index.js.map +1 -1
- package/dist/tools/om-tools.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.17.2-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed Observational Memory duplicate assistant messages when a thread is rerun or an agent continues a long-running loop. ([#15774](https://github.com/mastra-ai/mastra/pull/15774))
|
|
8
|
+
|
|
9
|
+
- Fixed the recall tool so message browsing uses the current thread by default and explains when it does. ([#15807](https://github.com/mastra-ai/mastra/pull/15807))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`c1ae974`](https://github.com/mastra-ai/mastra/commit/c1ae97491f6e57378ce880c3a397778c42adcdf1), [`13b4d7c`](https://github.com/mastra-ai/mastra/commit/13b4d7c16de34dff9095d1cd80f22f544b6cfe75), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`6c8c6c7`](https://github.com/mastra-ai/mastra/commit/6c8c6c71518394321a4692614aa4b11f3bb0a343), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`ec4cb26`](https://github.com/mastra-ai/mastra/commit/ec4cb26919972eb2031fea510f8f013e1d5b7ee2)]:
|
|
12
|
+
- @mastra/core@1.29.0-alpha.6
|
|
13
|
+
|
|
3
14
|
## 1.17.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
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.17.
|
|
6
|
+
version: "1.17.2-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -17,6 +17,7 @@ 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.
|
|
20
21
|
- [Agent networks](references/docs-agents-networks.md) - Coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
|
|
21
22
|
- [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.
|
|
22
23
|
- [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.
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Background tasks
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.28.0`
|
|
4
|
+
|
|
5
|
+
Background tasks let an agent dispatch a long-running tool call without blocking the agentic loop. The tool returns an immediate acknowledgement, the LLM continues responding, and the task runs to completion in the background. When it finishes, its result is written to memory and if you use [`streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) the agent is re-invoked automatically so the result is processed in the same call.
|
|
6
|
+
|
|
7
|
+
## When to use background tasks
|
|
8
|
+
|
|
9
|
+
Use background tasks when a tool call may take long enough that the user shouldn't wait for it before seeing a response. Common cases:
|
|
10
|
+
|
|
11
|
+
- Subagent delegations that themselves run multi-step research or writing.
|
|
12
|
+
- Tool calls that hit slow external services, queues, or large data jobs.
|
|
13
|
+
- Workflows triggered from a tool call that may take minutes to complete.
|
|
14
|
+
|
|
15
|
+
For tool calls that return quickly, foreground execution using `agent.stream()` and `agent.generate()` is simpler.
|
|
16
|
+
|
|
17
|
+
> **Note:** Background tasks require a configured [storage](https://mastra.ai/docs/memory/storage) backend on the Mastra instance. Tasks are persisted so they survive process restarts.
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
Background tasks are off by default. Enable them by setting `backgroundTasks.enabled` on the Mastra instance:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Mastra } from '@mastra/core'
|
|
25
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
26
|
+
|
|
27
|
+
export const mastra = new Mastra({
|
|
28
|
+
storage: new LibSQLStore({ id: 'storage', url: 'file:mastra.db' }),
|
|
29
|
+
backgroundTasks: {
|
|
30
|
+
enabled: true,
|
|
31
|
+
globalConcurrency: 10,
|
|
32
|
+
perAgentConcurrency: 5,
|
|
33
|
+
backpressure: 'queue',
|
|
34
|
+
defaultTimeoutMs: 300_000,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The full set of options is listed in the [backgroundTasks configuration reference](https://mastra.ai/reference/configuration).
|
|
40
|
+
|
|
41
|
+
## Run a tool in the background
|
|
42
|
+
|
|
43
|
+
Enabling the manager doesn't run anything in the background by itself as every tool defaults to foreground execution. You can run a tool in the background at one of three layers, in priority order:
|
|
44
|
+
|
|
45
|
+
1. **LLM per-call override**: the model decides it should run in the background and includes a `_background` field in the tool arguments.
|
|
46
|
+
2. **Agent-level config**: the agent declares which of its tools are background-eligible.
|
|
47
|
+
3. **Tool-level config**: the tool itself declares it as background-eligible.
|
|
48
|
+
|
|
49
|
+
### Tool-level
|
|
50
|
+
|
|
51
|
+
Set `backgroundTasks.enabled: true` on the tool definition. Tools opted in at this layer run in the background whenever called by an agent that has the manager enabled.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createTool } from '@mastra/core/tools'
|
|
55
|
+
import { z } from 'zod'
|
|
56
|
+
|
|
57
|
+
export const researchTool = createTool({
|
|
58
|
+
id: 'research',
|
|
59
|
+
description: 'Run a long research job',
|
|
60
|
+
inputSchema: z.object({ topic: z.string() }),
|
|
61
|
+
backgroundTasks: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
timeoutMs: 600_000,
|
|
64
|
+
maxRetries: 1,
|
|
65
|
+
},
|
|
66
|
+
execute: async ({ context }) => {
|
|
67
|
+
// ...
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Agent-level
|
|
73
|
+
|
|
74
|
+
Use `backgroundTasks.tools` on the agent to opt in specific tools, override timeouts for individual tools, or run all background-eligible tools in the background. Use `disabled: true` to short-circuit background dispatch for the agent entirely.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Agent } from '@mastra/core/agent'
|
|
78
|
+
|
|
79
|
+
export const researcher = new Agent({
|
|
80
|
+
id: 'researcher',
|
|
81
|
+
instructions: 'You research topics and answer questions.',
|
|
82
|
+
model: 'openai/gpt-5.4',
|
|
83
|
+
tools: { researchTool, summarizeTool },
|
|
84
|
+
backgroundTasks: {
|
|
85
|
+
tools: {
|
|
86
|
+
researchTool: { enabled: true, timeoutMs: 600_000 },
|
|
87
|
+
summarizeTool: false,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Set `tools: 'all'` to opt in every tool the agent has.
|
|
94
|
+
|
|
95
|
+
### LLM per-call override
|
|
96
|
+
|
|
97
|
+
When a tool is registered on an agent that has background tasks enabled, the model can include a `_background` field in the tool arguments to override the resolved configuration for that specific call. The model only includes what it wants to override, all fields in `_background` are optional. The override is stripped from the arguments before the tool runs.
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"topic": "solana",
|
|
102
|
+
"_background": { "enabled": true, "timeoutMs": 900_000 }
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Resolution order
|
|
107
|
+
|
|
108
|
+
When a tool call is dispatched, the resolved background config is computed in this priority order:
|
|
109
|
+
|
|
110
|
+
1. LLM `_background` override (if present in the call's arguments).
|
|
111
|
+
2. Agent-level `backgroundTasks.tools` entry for the tool.
|
|
112
|
+
3. Tool-level `backgroundTasks` config.
|
|
113
|
+
4. Manager defaults (`defaultTimeoutMs`, `defaultRetries`).
|
|
114
|
+
|
|
115
|
+
If the agent has `backgroundTasks.disabled: true`, every tool call runs synchronously regardless of the layers above.
|
|
116
|
+
|
|
117
|
+
## Background tasks related stream chunks
|
|
118
|
+
|
|
119
|
+
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/streaming/background-task-streaming) SSE stream. Each stream covers a different set of chunk types:
|
|
120
|
+
|
|
121
|
+
| Chunk type | When it fires | Emitted by |
|
|
122
|
+
| --------------------------- | -------------------------------------------------------------------------------------- | -------------- |
|
|
123
|
+
| `background-task-started` | The task has been enqueued and assigned a `taskId`. | Agent stream |
|
|
124
|
+
| `background-task-running` | The task picked up a worker and started executing. | Manager stream |
|
|
125
|
+
| `background-task-progress` | Shows number of running background tasks. | Agent stream |
|
|
126
|
+
| `background-task-output` | A streamed output chunk from the task's `execute`. | Manager stream |
|
|
127
|
+
| `background-task-completed` | The task finished successfully. The `payload.result` matches the eventual tool result. | Manager stream |
|
|
128
|
+
| `background-task-failed` | The task threw or timed out. | Manager stream |
|
|
129
|
+
| `background-task-cancelled` | The task was cancelled before completing. | Manager stream |
|
|
130
|
+
|
|
131
|
+
`agent.stream().fullStream` only emits the agent-loop chunks (`background-task-started`, `background-task-progress`) on its own. `agent.streamUntilIdle()` emits the same two chunks and additionally subscribes to the manager pubsub for the run's memory scope and pipes the five manager chunks (`background-task-running`, `background-task-output`, `background-task-completed`, `background-task-failed`, `background-task-cancelled`) into the same `fullStream`, so consumers of `streamUntilIdle().fullStream` see all seven types.
|
|
132
|
+
|
|
133
|
+
`backgroundTaskManager.stream()` only emits the five manager chunks.
|
|
134
|
+
|
|
135
|
+
The full payload shapes are documented in the [background task chunks reference](https://mastra.ai/reference/streaming/ChunkType).
|
|
136
|
+
|
|
137
|
+
## Keep the agent stream open with `streamUntilIdle()`
|
|
138
|
+
|
|
139
|
+
`agent.stream()` returns once the LLM emits a final response even if a background task is still running. Use `agent.streamUntilIdle()` when you want the stream to stay open until every dispatched background task has completed and the LLM has had a chance to respond to the result:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const stream = await agent.streamUntilIdle('Research solana for me', {
|
|
143
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
144
|
+
maxIdleMs: 5 * 60_000,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
for await (const chunk of stream.fullStream) {
|
|
148
|
+
// chunks from the initial turn AND any continuation turns triggered by
|
|
149
|
+
// background task completions flow through here
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
When a background task completes, the result is injected into the agent memory, `streamUntilIdle()` re-enters the agentic loop so the LLM can react to it. The stream closes when no tasks are running and no completions are queued.
|
|
154
|
+
|
|
155
|
+
`maxIdleMs` caps how long the stream waits between turns. The timer only runs while the wrapper is between turns, so a slow first token won't close the stream. The default is 5 minutes.
|
|
156
|
+
|
|
157
|
+
> **Note:** Visit [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) for the full API.
|
|
158
|
+
|
|
159
|
+
### Aggregate properties
|
|
160
|
+
|
|
161
|
+
`streamUntilIdle()` returns a `MastraModelOutput` that looks like the one from `stream()`, but only `fullStream` spans the initial turn **and** any auto-continuations. Aggregate properties (`text`, `toolCalls`, `toolResults`, `finishReason`, `messageList`, `getFullOutput()`) still resolve against the **first turn's** internal buffer. If you need an aggregate view across continuations, consume `fullStream` yourself and accumulate.
|
|
162
|
+
|
|
163
|
+
## Subagents in the background
|
|
164
|
+
|
|
165
|
+
Subagent invocations are dispatched as tool calls under the hood, so the same background configuration applies. The recommended pattern is to opt each subagent in on the supervisor, it's clearer and lets you tune `timeoutMs` per subagent in one place:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { Agent } from '@mastra/core/agent'
|
|
169
|
+
|
|
170
|
+
const supervisor = new Agent({
|
|
171
|
+
id: 'supervisor',
|
|
172
|
+
instructions: 'Coordinate research and writing using the available agents.',
|
|
173
|
+
model: 'openai/gpt-5.4',
|
|
174
|
+
agents: { researchAgent, writingAgent },
|
|
175
|
+
backgroundTasks: {
|
|
176
|
+
tools: {
|
|
177
|
+
researchAgent: { enabled: true, timeoutMs: 900_000 },
|
|
178
|
+
writingAgent: { enabled: true, timeoutMs: 900_000 },
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
const stream = await supervisor.streamUntilIdle('Research AI in education and write an article', {
|
|
184
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
185
|
+
})
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Inheriting from the subagent
|
|
189
|
+
|
|
190
|
+
If a subagent isn't listed under the supervisor's `backgroundTasks.tools` but has background-eligible tools of its own (either via tool-level `backgroundTasks.enabled: true` or its own `backgroundTasks.tools` entry) the framework still dispatches the entire subagent invocation as a background task. The supervisor inherits the subagent's intent: the subagent itself becomes the background task, and its inner tools run in the foreground inside the subagent's loop.
|
|
191
|
+
|
|
192
|
+
The background config used for the inherited dispatch (for example `waitTimeoutMs`) is derived from the subagent's own `backgroundTasks` config.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const researchAgent = new Agent({
|
|
196
|
+
id: 'research-agent',
|
|
197
|
+
description: 'Gathers factual information.',
|
|
198
|
+
model: 'openai/gpt-5-mini',
|
|
199
|
+
tools: { deepResearchTool },
|
|
200
|
+
backgroundTasks: {
|
|
201
|
+
tools: {
|
|
202
|
+
deepResearchTool: { enabled: true, timeoutMs: 600_000 },
|
|
203
|
+
},
|
|
204
|
+
waitTimeoutMs: 900_000,
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
When this `researchAgent` is delegated to from a supervisor that has no backgroundTask configuration for the `researchAgent`, the supervisor still dispatches the whole `researchAgent` invocation as a background task, and `deepResearchTool` runs in the foreground inside that invocation, instead of dispatching its own nested background task.
|
|
210
|
+
|
|
211
|
+
Use this pattern when you want a subagent to behave consistently in the background regardless of which supervisor invokes it. Use the supervisor-side opt-in (above) when you want to tune background behavior centrally per supervisor.
|
|
212
|
+
|
|
213
|
+
## Lifecycle callbacks
|
|
214
|
+
|
|
215
|
+
Each layer can register terminal-state callbacks. They don't replace one another, and success/failure hooks fire for their respective outcomes:
|
|
216
|
+
|
|
217
|
+
- Tool-level `backgroundTasks.onComplete` / `onFailed`: scoped to one tool.
|
|
218
|
+
- Agent-level `backgroundTasks.onTaskComplete` / `onTaskFailed`: scoped to all tasks dispatched by this agent.
|
|
219
|
+
- Manager-level `onTaskComplete` / `onTaskFailed`: scoped globally.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
export const mastra = new Mastra({
|
|
223
|
+
storage,
|
|
224
|
+
backgroundTasks: {
|
|
225
|
+
enabled: true,
|
|
226
|
+
onTaskComplete: task => {
|
|
227
|
+
logger.info('Background task complete', { taskId: task.id, toolName: task.toolName })
|
|
228
|
+
},
|
|
229
|
+
onTaskFailed: task => {
|
|
230
|
+
logger.error('Background task failed', { taskId: task.id, error: task.error })
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Related
|
|
237
|
+
|
|
238
|
+
- [`Agent.streamUntilIdle()` reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
|
|
239
|
+
- [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
|
|
240
|
+
- [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
|
|
241
|
+
- [Stream chunk types](https://mastra.ai/reference/streaming/ChunkType)
|
|
242
|
+
- [Storage](https://mastra.ai/docs/memory/storage)
|
|
@@ -300,9 +300,38 @@ Success criteria:
|
|
|
300
300
|
})
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
-
##
|
|
303
|
+
## Running subagents in the background
|
|
304
304
|
|
|
305
|
-
|
|
305
|
+
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.
|
|
306
|
+
|
|
307
|
+
Enable the [backgroundTasks manager](https://mastra.ai/reference/configuration) on the Mastra instance, then opt subagents in on the supervisor:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const supervisor = new Agent({
|
|
311
|
+
id: 'supervisor',
|
|
312
|
+
instructions: 'Coordinate research and writing using the available agents.',
|
|
313
|
+
model: 'openai/gpt-5.4',
|
|
314
|
+
agents: { researchAgent, writingAgent },
|
|
315
|
+
backgroundTasks: {
|
|
316
|
+
tools: {
|
|
317
|
+
researchAgent: { enabled: true, timeoutMs: 900_000 },
|
|
318
|
+
writingAgent: { enabled: true, timeoutMs: 900_000 },
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
const stream = await supervisor.streamUntilIdle('Research AI in education and write an article', {
|
|
324
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
325
|
+
})
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
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.
|
|
329
|
+
|
|
330
|
+
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.
|
|
331
|
+
|
|
332
|
+
## Subagent versioning
|
|
333
|
+
|
|
334
|
+
When using the [editor](https://mastra.ai/docs/editor/overview), you can control which stored version of each subagent the supervisor uses at runtime. Set version overrides on the Mastra instance or per invocation:
|
|
306
335
|
|
|
307
336
|
```typescript
|
|
308
337
|
const result = await supervisor.generate('Research and write about AI safety', {
|
|
@@ -315,13 +344,15 @@ const result = await supervisor.generate('Research and write about AI safety', {
|
|
|
315
344
|
})
|
|
316
345
|
```
|
|
317
346
|
|
|
318
|
-
Version overrides propagate automatically through delegation. See [
|
|
347
|
+
Version overrides propagate automatically through delegation. See [Subagent versioning](https://mastra.ai/docs/editor/overview) for details on resolution order and server API usage.
|
|
319
348
|
|
|
320
349
|
## Related
|
|
321
350
|
|
|
322
|
-
- [
|
|
351
|
+
- [Background tasks](https://mastra.ai/docs/agents/background-tasks)
|
|
352
|
+
- [Subagent versioning](https://mastra.ai/docs/editor/overview)
|
|
323
353
|
- [Guide: Research coordinator](https://mastra.ai/guides/guide/research-coordinator)
|
|
324
354
|
- [Agent.stream() reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
355
|
+
- [Agent.streamUntilIdle() reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
|
|
325
356
|
- [Agent.generate() reference](https://mastra.ai/reference/agents/generate)
|
|
326
357
|
- [Agent approval](https://mastra.ai/docs/agents/agent-approval)
|
|
327
358
|
- [Memory in multi-agent systems](https://mastra.ai/docs/memory/overview)
|
|
@@ -153,8 +153,10 @@ async function manageClones() {
|
|
|
153
153
|
|
|
154
154
|
// Have a conversation...
|
|
155
155
|
await agent.generate("Hello! Let's discuss project options.", {
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
memory: {
|
|
157
|
+
thread: originalThread.id,
|
|
158
|
+
resource: 'user-123',
|
|
159
|
+
},
|
|
158
160
|
})
|
|
159
161
|
|
|
160
162
|
// Create multiple branches (clones) to explore different paths
|
|
@@ -93,8 +93,10 @@ const { thread: dateFilteredClone } = await memory.cloneThread({
|
|
|
93
93
|
|
|
94
94
|
// Continue conversation on the cloned thread
|
|
95
95
|
const response = await agent.generate("Let's try a different approach", {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
memory: {
|
|
97
|
+
thread: fullClone.id,
|
|
98
|
+
resource: fullClone.resourceId,
|
|
99
|
+
},
|
|
98
100
|
})
|
|
99
101
|
```
|
|
100
102
|
|