@mastra/memory 1.9.0-alpha.1 → 1.9.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 (51) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-5SMKVGJP.js → chunk-JJBSFPC5.js} +315 -25
  3. package/dist/chunk-JJBSFPC5.js.map +1 -0
  4. package/dist/{chunk-AR52LM55.cjs → chunk-LVV2RT42.cjs} +327 -24
  5. package/dist/chunk-LVV2RT42.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +5 -7
  7. package/dist/docs/assets/SOURCE_MAP.json +77 -27
  8. package/dist/docs/references/docs-agents-agent-approval.md +114 -193
  9. package/dist/docs/references/docs-agents-networks.md +88 -205
  10. package/dist/docs/references/docs-agents-supervisor-agents.md +24 -18
  11. package/dist/docs/references/docs-memory-observational-memory.md +30 -2
  12. package/dist/docs/references/docs-memory-overview.md +219 -24
  13. package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
  14. package/dist/docs/references/docs-memory-storage.md +4 -4
  15. package/dist/docs/references/docs-memory-working-memory.md +1 -1
  16. package/dist/docs/references/reference-core-getMemory.md +1 -2
  17. package/dist/docs/references/reference-core-listMemory.md +1 -2
  18. package/dist/docs/references/reference-memory-cloneThread.md +1 -1
  19. package/dist/docs/references/reference-memory-observational-memory.md +39 -1
  20. package/dist/index.cjs +432 -11
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +432 -10
  24. package/dist/index.js.map +1 -1
  25. package/dist/observational-memory-3XFCO6MX.js +3 -0
  26. package/dist/{observational-memory-5NFPG6M3.js.map → observational-memory-3XFCO6MX.js.map} +1 -1
  27. package/dist/observational-memory-MJJFU26W.cjs +108 -0
  28. package/dist/{observational-memory-NH7VDTXM.cjs.map → observational-memory-MJJFU26W.cjs.map} +1 -1
  29. package/dist/processors/index.cjs +56 -16
  30. package/dist/processors/index.js +1 -1
  31. package/dist/processors/observational-memory/anchor-ids.d.ts +4 -0
  32. package/dist/processors/observational-memory/anchor-ids.d.ts.map +1 -0
  33. package/dist/processors/observational-memory/index.d.ts +2 -0
  34. package/dist/processors/observational-memory/index.d.ts.map +1 -1
  35. package/dist/processors/observational-memory/observation-groups.d.ts +15 -0
  36. package/dist/processors/observational-memory/observation-groups.d.ts.map +1 -0
  37. package/dist/processors/observational-memory/observational-memory.d.ts +14 -0
  38. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  39. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  40. package/dist/processors/observational-memory/reflector-agent.d.ts +1 -1
  41. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
  42. package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -1
  43. package/dist/tools/om-tools.d.ts +77 -0
  44. package/dist/tools/om-tools.d.ts.map +1 -0
  45. package/package.json +3 -3
  46. package/dist/chunk-5SMKVGJP.js.map +0 -1
  47. package/dist/chunk-AR52LM55.cjs.map +0 -1
  48. package/dist/docs/references/docs-agents-agent-memory.md +0 -209
  49. package/dist/docs/references/docs-agents-network-approval.md +0 -278
  50. package/dist/observational-memory-5NFPG6M3.js +0 -3
  51. package/dist/observational-memory-NH7VDTXM.cjs +0 -68
@@ -1,32 +1,16 @@
1
1
  # Agent networks
2
2
 
3
- > **Agent Network Deprecated — Supervisor Pattern Recommended:** Agent networks are deprecated and will be removed in a future release. The [supervisor pattern](https://mastra.ai/docs/agents/supervisor-agents) using `agent.stream()` or `agent.generate()` is now the recommended approach for coordinating multiple agents. It provides the same multi-agent coordination capabilities as `.network()` with significant improvements:
3
+ > **Deprecated — Use supervisor agents:** Agent networks are deprecated and will be removed in a future major release. [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents) using `agent.stream()` or `agent.generate()` are now the recommended approach. It provides the same multi-agent coordination with better control, a simpler API, and easier debugging.
4
4
  >
5
- > - **Better control**: Iteration hooks, delegation hooks, and task completion scoring give you fine-grained control over execution
6
- > - **Simpler API**: Uses familiar `stream()` and `generate()` methods instead of a separate `.network()` API
7
- > - **More flexible**: Stop execution early, modify delegations, filter context, and provide feedback to guide the agent
8
- > - **Type-safe**: Full TypeScript support for all hooks and callbacks
9
- > - **Easier debugging**: Monitor progress with `onIterationComplete`, track delegations with `onDelegationStart`/`onDelegationComplete`
10
- >
11
- > See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade from `.network()`.
12
-
13
- Agent networks in Mastra coordinate multiple agents, workflows, and tools to handle tasks that aren't clearly defined upfront but can be inferred from the user's message or context. A top-level **routing agent** (a Mastra agent with other agents, workflows, and tools configured) uses an LLM to interpret the request and decide which primitives (subagents, workflows, or tools) to call, in what order, and with what data.
14
-
15
- ## When to use networks
5
+ > See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
16
6
 
17
- Use networks for complex tasks that require coordination across multiple primitives. Unlike workflows, which follow a predefined sequence, networks rely on LLM reasoning to interpret the request and decide what to run.
7
+ A **routing agent** uses an LLM to interpret a request and decide which primitives (subagents, workflows, or tools) to call, in what order, and with what data.
18
8
 
19
- ## Core principles
9
+ ## Create an agent network
20
10
 
21
- Mastra agent networks operate using these principles:
11
+ Configure a routing agent with `agents`, `workflows`, and `tools`. Memory is required as `.network()` uses it to store task history and determine when a task is complete.
22
12
 
23
- - Memory is required when using `.network()` and is used to store task history and determine when a task is complete.
24
- - Primitives are selected based on their descriptions. Clear, specific descriptions improve routing. For workflows and tools, the input schema helps determine the right inputs at runtime.
25
- - If multiple primitives have overlapping functionality, the agent favors the more specific one, using a combination of schema and descriptions to decide which to run.
26
-
27
- ## Creating an agent network
28
-
29
- An agent network is built around a top-level routing agent that delegates tasks to subagents, workflows, and tools defined in its configuration. Memory is configured on the routing agent using the `memory` option, and `instructions` define the agent's routing behavior.
13
+ Each primitive needs a clear `description` so the routing agent can decide which to use. For workflows and tools, `inputSchema` and `outputSchema` also help the router determine the right inputs.
30
14
 
31
15
  ```typescript
32
16
  import { Agent } from '@mastra/core/agent'
@@ -35,7 +19,6 @@ import { LibSQLStore } from '@mastra/libsql'
35
19
 
36
20
  import { researchAgent } from './research-agent'
37
21
  import { writingAgent } from './writing-agent'
38
-
39
22
  import { cityWorkflow } from '../workflows/city-workflow'
40
23
  import { weatherTool } from '../tools/weather-tool'
41
24
 
@@ -43,11 +26,7 @@ export const routingAgent = new Agent({
43
26
  id: 'routing-agent',
44
27
  name: 'Routing Agent',
45
28
  instructions: `
46
- You are a network of writers and researchers.
47
- The user will ask you to research a topic.
48
- Always respond with a complete report—no bullet points.
49
- Write in full paragraphs, like a blog post.
50
- Do not answer with incomplete or uncertain information.`,
29
+ You are a network of writers and researchers. The user will ask you to research a topic. Always respond with a complete report—no bullet points. Write in full paragraphs, like a blog post. Do not answer with incomplete or uncertain information.`,
51
30
  model: 'openai/gpt-5.4',
52
31
  agents: {
53
32
  researchAgent,
@@ -68,81 +47,11 @@ export const routingAgent = new Agent({
68
47
  })
69
48
  ```
70
49
 
71
- ### Writing descriptions for network primitives
72
-
73
- When configuring a Mastra agent network, each primitive (agent, workflow, or tool) needs a clear description to help the routing agent decide which to use. The routing agent uses each primitive's description and schema to determine what it does and how to use it. Clear descriptions and well-defined input and output schemas improve routing accuracy.
74
-
75
- #### Agent descriptions
76
-
77
- Each subagent in a network should include a clear `description` that explains what the agent does.
78
-
79
- ```typescript
80
- export const researchAgent = new Agent({
81
- id: 'research-agent',
82
- name: 'Research Agent',
83
- description: `This agent gathers concise research insights in bullet-point form.
84
- It's designed to extract key facts without generating full
85
- responses or narrative content.`,
86
- })
87
- ```
88
-
89
- ```typescript
90
- export const writingAgent = new Agent({
91
- id: 'writing-agent',
92
- name: 'Writing Agent',
93
- description: `This agent turns researched material into well-structured
94
- written content. It produces full-paragraph reports with no bullet points,
95
- suitable for use in articles, summaries, or blog posts.`,
96
- })
97
- ```
98
-
99
- #### Workflow descriptions
100
-
101
- Workflows in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
102
-
103
- ```typescript
104
- export const cityWorkflow = createWorkflow({
105
- id: 'city-workflow',
106
- description: `This workflow handles city-specific research tasks.
107
- It first gathers factual information about the city, then synthesizes
108
- that research into a full written report. Use it when the user input
109
- includes a city to be researched.`,
110
- inputSchema: z.object({
111
- city: z.string(),
112
- }),
113
- outputSchema: z.object({
114
- text: z.string(),
115
- }),
116
- })
117
- ```
118
-
119
- #### Tool descriptions
120
-
121
- Tools in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
122
-
123
- ```typescript
124
- export const weatherTool = createTool({
125
- id: 'weather-tool',
126
- description: ` Retrieves current weather information using the wttr.in API.
127
- Accepts a city or location name as input and returns a short weather summary.
128
- Use this tool whenever up-to-date weather data is requested.
129
- `,
130
- inputSchema: z.object({
131
- location: z.string(),
132
- }),
133
- outputSchema: z.object({
134
- weather: z.string(),
135
- }),
136
- })
137
- ```
138
-
139
- ## Calling agent networks
140
-
141
- Call a Mastra agent network using `.network()` with a user message. The method returns a stream of events that you can iterate over to track execution progress and retrieve the final result.
50
+ > **Note:** Subagents need a `description` on the `Agent` instance. Workflows and tools need a `description` plus `inputSchema` and `outputSchema` on `createWorkflow()` or `createTool()`.
142
51
 
143
- ### Agent example
52
+ ## Call the network
144
53
 
145
- In this example, the network interprets the message and would route the request to both the `researchAgent` and `writingAgent` to generate a complete response.
54
+ Call `.network()` with a user message. The method returns a stream of events you can iterate over.
146
55
 
147
56
  ```typescript
148
57
  const result = await routingAgent.network('Tell me three cool ways to use Mastra')
@@ -155,145 +64,119 @@ for await (const chunk of result) {
155
64
  }
156
65
  ```
157
66
 
158
- #### Agent output
159
-
160
- The following `chunk.type` events are emitted during this request:
161
-
162
- ```text
163
- routing-agent-start
164
- routing-agent-end
165
- agent-execution-start
166
- agent-execution-event-start
167
- agent-execution-event-step-start
168
- agent-execution-event-text-start
169
- agent-execution-event-text-delta
170
- agent-execution-event-text-end
171
- agent-execution-event-step-finish
172
- agent-execution-event-finish
173
- agent-execution-end
174
- network-execution-event-step-finish
175
- ```
176
-
177
- ## Workflow example
67
+ ## Structured output
178
68
 
179
- In this example, the routing agent recognizes the city name in the message and runs the `cityWorkflow`. The workflow defines steps that call the `researchAgent` to gather facts, then the `writingAgent` to generate the final text.
69
+ Pass `structuredOutput` to get typed, validated results. Use `objectStream` for partial objects as they generate.
180
70
 
181
71
  ```typescript
182
- const result = await routingAgent.network('Tell me some historical facts about London')
72
+ import { z } from 'zod'
183
73
 
184
- for await (const chunk of result) {
185
- console.log(chunk.type)
186
- if (chunk.type === 'network-execution-event-step-finish') {
187
- console.log(chunk.payload.result)
188
- }
189
- }
190
- ```
74
+ const resultSchema = z.object({
75
+ summary: z.string().describe('A brief summary of the findings'),
76
+ recommendations: z.array(z.string()).describe('List of recommendations'),
77
+ confidence: z.number().min(0).max(1).describe('Confidence score'),
78
+ })
191
79
 
192
- ### Workflow output
80
+ const stream = await routingAgent.network('Research AI trends', {
81
+ structuredOutput: { schema: resultSchema },
82
+ })
193
83
 
194
- The following `chunk.type` events are emitted during this request:
84
+ for await (const partial of stream.objectStream) {
85
+ console.log('Building result:', partial)
86
+ }
195
87
 
196
- ```text
197
- routing-agent-end
198
- workflow-execution-start
199
- workflow-execution-event-workflow-start
200
- workflow-execution-event-workflow-step-start
201
- workflow-execution-event-workflow-step-result
202
- workflow-execution-event-workflow-finish
203
- workflow-execution-end
204
- routing-agent-start
205
- network-execution-event-step-finish
88
+ const final = await stream.object
89
+ console.log(final?.summary)
206
90
  ```
207
91
 
208
- ### Tool example
92
+ ## Approve and decline tool calls
93
+
94
+ When a primitive requires approval, the stream emits an `agent-execution-approval` or `tool-execution-approval` chunk. Use `approveNetworkToolCall()` or `declineNetworkToolCall()` to respond.
209
95
 
210
- In this example, the routing agent skips the `researchAgent`, `writingAgent`, and `cityWorkflow`, and calls the `weatherTool` directly to complete the task.
96
+ Network approval uses snapshots to capture execution state. Ensure a [storage provider](https://mastra.ai/docs/memory/storage) is enabled in your Mastra instance.
211
97
 
212
98
  ```typescript
213
- const result = await routingAgent.network("What's the weather in London?")
99
+ const stream = await routingAgent.network('Perform some sensitive action', {
100
+ memory: {
101
+ thread: 'user-123',
102
+ resource: 'my-app',
103
+ },
104
+ })
214
105
 
215
- for await (const chunk of result) {
216
- console.log(chunk.type)
217
- if (chunk.type === 'network-execution-event-step-finish') {
218
- console.log(chunk.payload.result)
106
+ for await (const chunk of stream) {
107
+ if (chunk.type === 'agent-execution-approval' || chunk.type === 'tool-execution-approval') {
108
+ // Approve
109
+ const approvedStream = await routingAgent.approveNetworkToolCall(chunk.payload.toolCallId, {
110
+ runId: stream.runId,
111
+ memory: { thread: 'user-123', resource: 'my-app' },
112
+ })
113
+
114
+ for await (const c of approvedStream) {
115
+ if (c.type === 'network-execution-event-step-finish') {
116
+ console.log(c.payload.result)
117
+ }
118
+ }
219
119
  }
220
120
  }
221
121
  ```
222
122
 
223
- #### Tool output
123
+ To decline instead, call `declineNetworkToolCall()` with the same arguments.
224
124
 
225
- The following `chunk.type` events are emitted during this request:
125
+ ## Suspend and resume
226
126
 
227
- ```text
228
- routing-agent-start
229
- routing-agent-end
230
- tool-execution-start
231
- tool-execution-end
232
- network-execution-event-step-finish
233
- ```
234
-
235
- ## Structured output
236
-
237
- When you need typed, validated results from a network, use the `structuredOutput` option. After the network completes its task, it generates a structured response matching your schema.
127
+ When a primitive calls `suspend()`, the stream emits a suspension chunk (e.g., `tool-execution-suspended`). Use `resumeNetwork()` to provide the requested data and continue execution.
238
128
 
239
129
  ```typescript
240
- import { z } from 'zod'
241
-
242
- const resultSchema = z.object({
243
- summary: z.string().describe('A brief summary of the findings'),
244
- recommendations: z.array(z.string()).describe('List of recommendations'),
245
- confidence: z.number().min(0).max(1).describe('Confidence score'),
246
- })
247
-
248
- const stream = await routingAgent.network('Research AI trends', {
249
- structuredOutput: {
250
- schema: resultSchema,
251
- },
130
+ const stream = await routingAgent.network('Delete the old records', {
131
+ memory: { thread: 'user-123', resource: 'my-app' },
252
132
  })
253
133
 
254
- // Consume the stream
255
134
  for await (const chunk of stream) {
256
- if (chunk.type === 'network-object') {
257
- // Partial object during generation
258
- console.log('Partial:', chunk.payload.object)
259
- }
260
- if (chunk.type === 'network-object-result') {
261
- // Final structured object
262
- console.log('Final:', chunk.payload.object)
135
+ if (chunk.type === 'workflow-execution-suspended') {
136
+ console.log(chunk.payload.suspendPayload)
263
137
  }
264
138
  }
265
139
 
266
- // Get the typed result
267
- const result = await stream.object
268
- console.log(result?.summary)
269
- console.log(result?.recommendations)
270
- console.log(result?.confidence)
140
+ // Resume with user confirmation
141
+ const resumedStream = await routingAgent.resumeNetwork(
142
+ { confirmed: true },
143
+ {
144
+ runId: stream.runId,
145
+ memory: { thread: 'user-123', resource: 'my-app' },
146
+ },
147
+ )
148
+
149
+ for await (const chunk of resumedStream) {
150
+ if (chunk.type === 'network-execution-event-step-finish') {
151
+ console.log(chunk.payload.result)
152
+ }
153
+ }
271
154
  ```
272
155
 
273
- ### Streaming partial objects
156
+ ### Automatic resumption
274
157
 
275
- For real-time updates during structured output generation, use `objectStream`:
158
+ Set `autoResumeSuspendedTools` to `true` so the network resumes suspended primitives based on the user's next message. This creates a conversational flow where users provide the required information naturally.
276
159
 
277
160
  ```typescript
278
- const stream = await routingAgent.network('Analyze market data', {
279
- structuredOutput: { schema: resultSchema },
161
+ const stream = await routingAgent.network('Delete the old records', {
162
+ autoResumeSuspendedTools: true,
163
+ memory: { thread: 'user-123', resource: 'my-app' },
280
164
  })
165
+ ```
281
166
 
282
- // Stream partial objects as they're generated
283
- for await (const partial of stream.objectStream) {
284
- console.log('Building result:', partial)
285
- }
167
+ Requirements for automatic resumption:
286
168
 
287
- // Get the final typed result
288
- const final = await stream.object
289
- ```
169
+ - **Memory configured**: The agent needs memory to track suspended tools across messages.
170
+ - **Same thread**: The follow-up message must use the same `thread` and `resource` identifiers.
171
+ - **`resumeSchema` defined**: The tool must define a `resumeSchema` so the network can extract data from the user's message.
172
+
173
+ | | Manual (`resumeNetwork`) | Automatic (`autoResumeSuspendedTools`) |
174
+ | -------- | ---------------------------------------------- | ----------------------------------------- |
175
+ | Best for | Custom UIs with approval buttons | Chat-style interfaces |
176
+ | Control | Full control over resume timing and data | Network extracts data from user's message |
177
+ | Setup | Handle suspension chunks, call `resumeNetwork` | Set flag, define `resumeSchema` on tools |
290
178
 
291
179
  ## Related
292
180
 
293
- - [Supervisor Agents](https://mastra.ai/docs/agents/supervisor-agents)
294
- - [Migration: .network() to Supervisor Pattern](https://mastra.ai/guides/migrations/network-to-supervisor)
295
- - [Guide: Research Coordinator](https://mastra.ai/guides/guide/research-coordinator)
296
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
297
- - [Agent Approval](https://mastra.ai/docs/agents/agent-approval)
298
- - [Workflows Overview](https://mastra.ai/docs/workflows/overview)
299
- - [Request Context](https://mastra.ai/docs/server/request-context)
181
+ - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
182
+ - [Migration: `.network()` to supervisor agents](https://mastra.ai/guides/migrations/network-to-supervisor)
@@ -1,6 +1,8 @@
1
1
  # Supervisor agents
2
2
 
3
- A supervisor agent coordinates multiple subagents using `agent.stream()` or `agent.generate()`. You configure subagents on the supervisor's `agents` property, and the supervisor uses its instructions and each subagent's `description` to decide when and how to delegate tasks.
3
+ **Added in:** `@mastra/core@1.8.0`
4
+
5
+ A supervisor agent coordinates multiple subagents using [`Agent.stream()`](https://mastra.ai/reference/streaming/agents/stream) or [`Agent.generate()`](https://mastra.ai/reference/agents/generate). You configure subagents on the supervisor's `agents` property, and the supervisor uses its instructions and each subagent's `description` to decide when and how to delegate tasks.
4
6
 
5
7
  ## When to use supervisor agents
6
8
 
@@ -12,7 +14,9 @@ Common use cases:
12
14
  - Multi-step tasks that need different expertise at each stage
13
15
  - Tasks where you need fine-grained control over delegation behavior
14
16
 
15
- ## Quick start
17
+ > **Note:** Supervisor agents are one approach to building multi-agent systems in Mastra. For other patterns, read the [conceptual overview](https://mastra.ai/guides/concepts/multi-agent-systems).
18
+
19
+ ## Quickstart
16
20
 
17
21
  Define subagents with clear descriptions, then create a supervisor agent that references them:
18
22
 
@@ -61,10 +65,10 @@ Delegation hooks let you intercept, modify, or reject delegations as they happen
61
65
 
62
66
  Called before the supervisor delegates to a subagent. Return an object to control the delegation:
63
67
 
64
- - `proceed: true` allow the delegation (default behavior)
65
- - `proceed: false` reject the delegation with a `rejectionReason`
66
- - `modifiedPrompt` rewrite the prompt sent to the subagent
67
- - `modifiedMaxSteps` limit the subagent's iteration count
68
+ - `proceed: true`: Allow the delegation (default behavior)
69
+ - `proceed: false`: Reject the delegation with a `rejectionReason`
70
+ - `modifiedPrompt`: Rewrite the prompt sent to the subagent
71
+ - `modifiedMaxSteps`: Limit the subagent's iteration count
68
72
 
69
73
  ```typescript
70
74
  const stream = await supervisor.stream('Research AI trends', {
@@ -108,8 +112,8 @@ The `context` object includes:
108
112
 
109
113
  Called after a delegation finishes. Use it to inspect results, provide feedback, or stop execution:
110
114
 
111
- - `context.bail()` stop the supervisor loop immediately
112
- - Return `{ feedback: '...' }` add feedback that gets saved to the supervisor's memory and is visible to subsequent iterations
115
+ - `context.bail()`: Stop the supervisor loop immediately
116
+ - Return `{ feedback: '...' }`: Add feedback that gets saved to the supervisor's memory and is visible to subsequent iterations
113
117
 
114
118
  ```typescript
115
119
  const stream = await supervisor.stream('Research AI trends', {
@@ -196,16 +200,18 @@ Return `{ continue: true }` to keep iterating, or `{ continue: false }` to stop.
196
200
 
197
201
  ## Memory isolation
198
202
 
199
- The supervisor pattern implements memory isolation subagents receive the full conversation context for better decision-making, but only their specific delegation prompt and response are saved to their memory.
203
+ Supervisor agents implement memory isolation. Subagents receive the full conversation context for better decision-making, but only their specific delegation prompt and response are saved to their memory.
200
204
 
201
205
  How it works:
202
206
 
203
- 1. **Full context forwarded** When the supervisor delegates, the subagent receives all messages from the supervisor's conversation
204
- 2. **Scoped memory saves** Only the delegation prompt and the subagent's response are saved to the subagent's memory
205
- 3. **Fresh thread per invocation** Each delegation uses a unique thread ID, ensuring clean separation
207
+ 1. **Full context forwarded**: When the supervisor delegates, the subagent receives all messages from the supervisor's conversation
208
+ 2. **Scoped memory saves**: Only the delegation prompt and the subagent's response are saved to the subagent's memory
209
+ 3. **Fresh thread per invocation**: Each delegation uses a unique thread ID, ensuring clean separation
206
210
 
207
211
  This ensures subagents have the context they need without cluttering their memory with the entire supervisor conversation.
208
212
 
213
+ > **Note:** Visit [memory in multi-agent systems](https://mastra.ai/docs/memory/overview) for more details.
214
+
209
215
  ## Tool approval propagation
210
216
 
211
217
  Tool approvals propagate through the delegation chain. When a subagent uses a tool with `requireApproval: true` or calls `suspend()`, the approval request surfaces to the supervisor level.
@@ -296,9 +302,9 @@ Success criteria:
296
302
 
297
303
  ## Related
298
304
 
299
- - [Agent Networks](https://mastra.ai/docs/agents/networks)
300
- - [Migration: .network() to Supervisor Pattern](https://mastra.ai/guides/migrations/network-to-supervisor)
301
- - [Guide: Research Coordinator](https://mastra.ai/guides/guide/research-coordinator)
302
- - [Agent.stream() Reference](https://mastra.ai/reference/streaming/agents/stream)
303
- - [Agent.generate() Reference](https://mastra.ai/reference/agents/generate)
304
- - [Agent Approval](https://mastra.ai/docs/agents/agent-approval)
305
+ - [Guide: Research coordinator](https://mastra.ai/guides/guide/research-coordinator)
306
+ - [Agent.stream() reference](https://mastra.ai/reference/streaming/agents/stream)
307
+ - [Agent.generate() reference](https://mastra.ai/reference/agents/generate)
308
+ - [Agent approval](https://mastra.ai/docs/agents/agent-approval)
309
+ - [Memory in multi-agent systems](https://mastra.ai/docs/memory/overview)
310
+ - [Concept: Multi-agent systems](https://mastra.ai/guides/concepts/multi-agent-systems)
@@ -1,10 +1,10 @@
1
- # Observational memory
1
+ # Observational Memory
2
2
 
3
3
  **Added in:** `@mastra/memory@1.1.0`
4
4
 
5
5
  Observational Memory (OM) is Mastra's memory system for long-context agentic memory. Two background agents — an **Observer** and a **Reflector** — watch your agent's conversations and maintain a dense observation log that replaces raw message history as it grows.
6
6
 
7
- ## Quick start
7
+ ## Quickstart
8
8
 
9
9
  Enable `observationalMemory` in the memory options when creating your agent:
10
10
 
@@ -89,6 +89,34 @@ The result is a three-tier system:
89
89
  2. **Observations**: A log of what the Observer has seen
90
90
  3. **Reflections**: Condensed observations when memory becomes too long
91
91
 
92
+ ### Retrieval mode (experimental)
93
+
94
+ > **Note:** Retrieval mode is experimental. The API may change in future releases.
95
+
96
+ Normal OM compresses messages into observations, which is great for staying on task — but the original wording is gone. Retrieval mode fixes this by keeping each observation group linked to the raw messages that produced it. When the agent needs exact wording, tool output, or chronology that the summary compressed away, it can call a `recall` tool to page through the source messages.
97
+
98
+ ```typescript
99
+ const memory = new Memory({
100
+ options: {
101
+ observationalMemory: {
102
+ model: 'google/gemini-2.5-flash',
103
+ scope: 'thread',
104
+ retrieval: true,
105
+ },
106
+ },
107
+ })
108
+ ```
109
+
110
+ With retrieval mode enabled, OM:
111
+
112
+ - Stores a `range` (e.g. `startId:endId`) on each observation group pointing to the messages it was derived from
113
+ - Keeps range metadata visible in the agent's context so the agent knows which observations map to which messages
114
+ - Registers a `recall` tool the agent can call to page through the raw messages behind any range
115
+
116
+ Retrieval mode is only active for thread-scoped OM. Setting `retrieval: true` with `scope: 'resource'` has no effect — OM keeps resource-scoped behavior but skips retrieval-mode context and does not register the `recall` tool.
117
+
118
+ See the [recall tool reference](https://mastra.ai/reference/memory/observational-memory) for the full API (detail levels, part indexing, pagination, and token limiting).
119
+
92
120
  ## Models
93
121
 
94
122
  The Observer and Reflector run in the background. Any model that works with Mastra's [model routing](https://mastra.ai/models) (`provider/model`) can be used. When using `observationalMemory: true`, the default model is `google/gemini-2.5-flash`. When passing a config object, a `model` must be explicitly set.