@mastra/memory 1.1.0 → 1.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +30 -17
  3. package/dist/{chunk-FQJWVCDF.cjs → chunk-AWE2QQPI.cjs} +1884 -312
  4. package/dist/chunk-AWE2QQPI.cjs.map +1 -0
  5. package/dist/chunk-EQ4M72KU.js +439 -0
  6. package/dist/chunk-EQ4M72KU.js.map +1 -0
  7. package/dist/{chunk-O3CS4UGX.cjs → chunk-IDRQZVB4.cjs} +4 -4
  8. package/dist/{chunk-O3CS4UGX.cjs.map → chunk-IDRQZVB4.cjs.map} +1 -1
  9. package/dist/{chunk-YF4R74L2.js → chunk-RC6RZVYE.js} +4 -4
  10. package/dist/{chunk-YF4R74L2.js.map → chunk-RC6RZVYE.js.map} +1 -1
  11. package/dist/{chunk-6TXUWFIU.js → chunk-TYVPTNCP.js} +1885 -313
  12. package/dist/chunk-TYVPTNCP.js.map +1 -0
  13. package/dist/chunk-ZD3BKU5O.cjs +441 -0
  14. package/dist/chunk-ZD3BKU5O.cjs.map +1 -0
  15. package/dist/docs/SKILL.md +51 -50
  16. package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +22 -22
  17. package/dist/docs/{agents/03-agent-approval.md → references/docs-agents-agent-approval.md} +19 -19
  18. package/dist/docs/references/docs-agents-agent-memory.md +212 -0
  19. package/dist/docs/{agents/04-network-approval.md → references/docs-agents-network-approval.md} +13 -12
  20. package/dist/docs/{agents/02-networks.md → references/docs-agents-networks.md} +10 -12
  21. package/dist/docs/{memory/06-memory-processors.md → references/docs-memory-memory-processors.md} +6 -8
  22. package/dist/docs/{memory/03-message-history.md → references/docs-memory-message-history.md} +31 -20
  23. package/dist/docs/references/docs-memory-observational-memory.md +238 -0
  24. package/dist/docs/{memory/01-overview.md → references/docs-memory-overview.md} +8 -8
  25. package/dist/docs/{memory/05-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
  26. package/dist/docs/{memory/02-storage.md → references/docs-memory-storage.md} +29 -39
  27. package/dist/docs/{memory/04-working-memory.md → references/docs-memory-working-memory.md} +16 -27
  28. package/dist/docs/references/reference-core-getMemory.md +50 -0
  29. package/dist/docs/references/reference-core-listMemory.md +56 -0
  30. package/dist/docs/references/reference-memory-clone-utilities.md +199 -0
  31. package/dist/docs/references/reference-memory-cloneThread.md +130 -0
  32. package/dist/docs/references/reference-memory-createThread.md +68 -0
  33. package/dist/docs/references/reference-memory-getThreadById.md +24 -0
  34. package/dist/docs/references/reference-memory-listThreads.md +145 -0
  35. package/dist/docs/references/reference-memory-memory-class.md +147 -0
  36. package/dist/docs/references/reference-memory-observational-memory.md +528 -0
  37. package/dist/docs/{processors/01-reference.md → references/reference-processors-token-limiter-processor.md} +25 -12
  38. package/dist/docs/references/reference-storage-dynamodb.md +282 -0
  39. package/dist/docs/references/reference-storage-libsql.md +135 -0
  40. package/dist/docs/references/reference-storage-mongodb.md +262 -0
  41. package/dist/docs/references/reference-storage-postgresql.md +529 -0
  42. package/dist/docs/references/reference-storage-upstash.md +160 -0
  43. package/dist/docs/references/reference-vectors-libsql.md +305 -0
  44. package/dist/docs/references/reference-vectors-mongodb.md +295 -0
  45. package/dist/docs/references/reference-vectors-pg.md +408 -0
  46. package/dist/docs/references/reference-vectors-upstash.md +294 -0
  47. package/dist/index.cjs +919 -507
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +914 -502
  51. package/dist/index.js.map +1 -1
  52. package/dist/{observational-memory-3Q42SITP.cjs → observational-memory-3UO64HYD.cjs} +14 -14
  53. package/dist/{observational-memory-3Q42SITP.cjs.map → observational-memory-3UO64HYD.cjs.map} +1 -1
  54. package/dist/{observational-memory-VXLHOSDZ.js → observational-memory-TVHT3HP4.js} +3 -3
  55. package/dist/{observational-memory-VXLHOSDZ.js.map → observational-memory-TVHT3HP4.js.map} +1 -1
  56. package/dist/processors/index.cjs +12 -12
  57. package/dist/processors/index.js +1 -1
  58. package/dist/processors/observational-memory/index.d.ts +1 -1
  59. package/dist/processors/observational-memory/index.d.ts.map +1 -1
  60. package/dist/processors/observational-memory/observational-memory.d.ts +267 -1
  61. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  62. package/dist/processors/observational-memory/observer-agent.d.ts +3 -1
  63. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  64. package/dist/processors/observational-memory/reflector-agent.d.ts +10 -3
  65. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
  66. package/dist/processors/observational-memory/types.d.ts +243 -19
  67. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  68. package/dist/{token-6GSAFR2W-WGTMOPEU.js → token-APYSY3BW-2DN6RAUY.js} +11 -11
  69. package/dist/token-APYSY3BW-2DN6RAUY.js.map +1 -0
  70. package/dist/{token-6GSAFR2W-2B4WM6AQ.cjs → token-APYSY3BW-ZQ7TMBY7.cjs} +14 -14
  71. package/dist/token-APYSY3BW-ZQ7TMBY7.cjs.map +1 -0
  72. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs +10 -0
  73. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs.map +1 -0
  74. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js +8 -0
  75. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js.map +1 -0
  76. package/dist/tools/working-memory.d.ts.map +1 -1
  77. package/package.json +6 -7
  78. package/dist/chunk-6TXUWFIU.js.map +0 -1
  79. package/dist/chunk-FQJWVCDF.cjs.map +0 -1
  80. package/dist/chunk-WM6IIUQW.js +0 -250
  81. package/dist/chunk-WM6IIUQW.js.map +0 -1
  82. package/dist/chunk-ZSBBXHNM.cjs +0 -252
  83. package/dist/chunk-ZSBBXHNM.cjs.map +0 -1
  84. package/dist/docs/README.md +0 -36
  85. package/dist/docs/agents/01-agent-memory.md +0 -166
  86. package/dist/docs/core/01-reference.md +0 -114
  87. package/dist/docs/memory/07-reference.md +0 -687
  88. package/dist/docs/storage/01-reference.md +0 -1218
  89. package/dist/docs/vectors/01-reference.md +0 -942
  90. package/dist/token-6GSAFR2W-2B4WM6AQ.cjs.map +0 -1
  91. package/dist/token-6GSAFR2W-WGTMOPEU.js.map +0 -1
  92. package/dist/token-util-NEHG7TUY-TV2H7N56.js +0 -8
  93. package/dist/token-util-NEHG7TUY-TV2H7N56.js.map +0 -1
  94. package/dist/token-util-NEHG7TUY-WJZIPNNX.cjs +0 -10
  95. package/dist/token-util-NEHG7TUY-WJZIPNNX.cjs.map +0 -1
@@ -1,59 +1,59 @@
1
1
  {
2
- "version": "1.1.0",
2
+ "version": "1.2.0-alpha.0",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-6TXUWFIU.js"
7
+ "implementation": "dist/chunk-TYVPTNCP.js"
8
8
  },
9
9
  "OBSERVER_SYSTEM_PROMPT": {
10
10
  "types": "dist/processors/index.d.ts",
11
- "implementation": "dist/chunk-6TXUWFIU.js"
11
+ "implementation": "dist/chunk-TYVPTNCP.js"
12
12
  },
13
13
  "ObservationalMemory": {
14
14
  "types": "dist/processors/index.d.ts",
15
- "implementation": "dist/chunk-6TXUWFIU.js",
16
- "line": 1206
15
+ "implementation": "dist/chunk-TYVPTNCP.js",
16
+ "line": 1283
17
17
  },
18
18
  "TokenCounter": {
19
19
  "types": "dist/processors/index.d.ts",
20
- "implementation": "dist/chunk-6TXUWFIU.js",
21
- "line": 925
20
+ "implementation": "dist/chunk-TYVPTNCP.js",
21
+ "line": 957
22
22
  },
23
23
  "buildObserverPrompt": {
24
24
  "types": "dist/processors/index.d.ts",
25
- "implementation": "dist/chunk-6TXUWFIU.js",
26
- "line": 644
25
+ "implementation": "dist/chunk-TYVPTNCP.js",
26
+ "line": 646
27
27
  },
28
28
  "buildObserverSystemPrompt": {
29
29
  "types": "dist/processors/index.d.ts",
30
- "implementation": "dist/chunk-6TXUWFIU.js",
31
- "line": 403
30
+ "implementation": "dist/chunk-TYVPTNCP.js",
31
+ "line": 405
32
32
  },
33
33
  "extractCurrentTask": {
34
34
  "types": "dist/processors/index.d.ts",
35
- "implementation": "dist/chunk-6TXUWFIU.js",
36
- "line": 725
35
+ "implementation": "dist/chunk-TYVPTNCP.js",
36
+ "line": 732
37
37
  },
38
38
  "formatMessagesForObserver": {
39
39
  "types": "dist/processors/index.d.ts",
40
- "implementation": "dist/chunk-6TXUWFIU.js",
41
- "line": 490
40
+ "implementation": "dist/chunk-TYVPTNCP.js",
41
+ "line": 492
42
42
  },
43
43
  "hasCurrentTaskSection": {
44
44
  "types": "dist/processors/index.d.ts",
45
- "implementation": "dist/chunk-6TXUWFIU.js",
46
- "line": 713
45
+ "implementation": "dist/chunk-TYVPTNCP.js",
46
+ "line": 720
47
47
  },
48
48
  "optimizeObservationsForContext": {
49
49
  "types": "dist/processors/index.d.ts",
50
- "implementation": "dist/chunk-6TXUWFIU.js",
51
- "line": 736
50
+ "implementation": "dist/chunk-TYVPTNCP.js",
51
+ "line": 743
52
52
  },
53
53
  "parseObserverOutput": {
54
54
  "types": "dist/processors/index.d.ts",
55
- "implementation": "dist/chunk-6TXUWFIU.js",
56
- "line": 670
55
+ "implementation": "dist/chunk-TYVPTNCP.js",
56
+ "line": 677
57
57
  },
58
58
  "extractWorkingMemoryContent": {
59
59
  "types": "dist/index.d.ts",
@@ -84,7 +84,7 @@
84
84
  "processors": {
85
85
  "index": "dist/processors/index.js",
86
86
  "chunks": [
87
- "chunk-6TXUWFIU.js"
87
+ "chunk-TYVPTNCP.js"
88
88
  ]
89
89
  }
90
90
  }
@@ -1,5 +1,3 @@
1
- > Learn how to require approvals, suspend tool execution, and automatically resume suspended tools while keeping humans in control of agent workflows.
2
-
3
1
  # Agent Approval
4
2
 
5
3
  Agents sometimes require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in workflows when calling tools that handle sensitive operations, like deleting resources or performing running long processes. With agent approval you can suspend a tool call and provide feedback to the user, or approve or decline a tool call based on targeted application conditions.
@@ -12,7 +10,7 @@ Tool call approval can be enabled at the agent level and apply to every tool the
12
10
 
13
11
  Agent approval uses a snapshot to capture the state of the request. Ensure you've enabled a storage provider in your main Mastra instance. If storage isn't enabled you'll see an error relating to snapshot not found.
14
12
 
15
- ```typescript title="src/mastra/index.ts"
13
+ ```typescript
16
14
  import { Mastra } from "@mastra/core/mastra";
17
15
  import { LibSQLStore } from "@mastra/libsql";
18
16
 
@@ -117,13 +115,13 @@ if (output.finishReason === "suspended") {
117
115
 
118
116
  ### Stream vs Generate comparison
119
117
 
120
- | Aspect | `stream()` | `generate()` |
121
- |--------|-----------|--------------|
122
- | Response type | Streaming chunks | Complete response |
123
- | Approval detection | `tool-call-approval` chunk | `finishReason: 'suspended'` |
124
- | Approve method | `approveToolCall({ runId })` | `approveToolCallGenerate({ runId, toolCallId })` |
125
- | Decline method | `declineToolCall({ runId })` | `declineToolCallGenerate({ runId, toolCallId })` |
126
- | Result | Stream to iterate | Full output object |
118
+ | Aspect | `stream()` | `generate()` |
119
+ | ------------------ | ---------------------------- | ------------------------------------------------ |
120
+ | Response type | Streaming chunks | Complete response |
121
+ | Approval detection | `tool-call-approval` chunk | `finishReason: 'suspended'` |
122
+ | Approve method | `approveToolCall({ runId })` | `approveToolCallGenerate({ runId, toolCallId })` |
123
+ | Decline method | `declineToolCall({ runId })` | `declineToolCallGenerate({ runId, toolCallId })` |
124
+ | Result | Stream to iterate | Full output object |
127
125
 
128
126
  ## Tool-level approval
129
127
 
@@ -231,7 +229,6 @@ const handleResume = async () => {
231
229
  }
232
230
  process.stdout.write("\n");
233
231
  };
234
-
235
232
  ```
236
233
 
237
234
  ## Automatic tool resumption
@@ -270,8 +267,11 @@ const stream = await agent.stream("What's the weather?", {
270
267
  When `autoResumeSuspendedTools` is enabled:
271
268
 
272
269
  1. A tool suspends execution by calling `suspend()` with a payload (e.g., requesting more information)
270
+
273
271
  2. The suspension is persisted to memory along with the conversation
272
+
274
273
  3. When the user sends their next message on the same thread, the agent:
274
+
275
275
  - Detects the suspended tool from message history
276
276
  - Extracts `resumeData` from the user's message based on the tool's `resumeSchema`
277
277
  - Automatically resumes the tool with the extracted data
@@ -341,7 +341,7 @@ const handleResume = async () => {
341
341
 
342
342
  **Conversation flow:**
343
343
 
344
- ```
344
+ ```text
345
345
  User: "What's the weather like?"
346
346
  Agent: "What city do you want to know the weather for?"
347
347
 
@@ -361,17 +361,17 @@ For automatic tool resumption to work:
361
361
 
362
362
  ### Manual vs automatic resumption
363
363
 
364
- | Approach | Use case |
365
- |----------|----------|
366
- | Manual (`resumeStream()`) | Programmatic control, webhooks, button clicks, external triggers |
364
+ | Approach | Use case |
365
+ | -------------------------------------- | ------------------------------------------------------------------------ |
366
+ | Manual (`resumeStream()`) | Programmatic control, webhooks, button clicks, external triggers |
367
367
  | Automatic (`autoResumeSuspendedTools`) | Conversational flows where users provide resume data in natural language |
368
368
 
369
369
  Both approaches work with the same tool definitions. Automatic resumption triggers only when suspended tools exist in the message history and the user sends a new message on the same thread.
370
370
 
371
371
  ## Related
372
372
 
373
- - [Using Tools](./using-tools)
374
- - [Agent Overview](./overview)
375
- - [Tools Overview](../mcp/overview)
376
- - [Agent Memory](./agent-memory)
373
+ - [Using Tools](https://mastra.ai/docs/agents/using-tools)
374
+ - [Agent Overview](https://mastra.ai/docs/agents/overview)
375
+ - [Tools Overview](https://mastra.ai/docs/mcp/overview)
376
+ - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
377
377
  - [Request Context](https://mastra.ai/docs/server/request-context)
@@ -0,0 +1,212 @@
1
+ # Agent memory
2
+
3
+ Agents use memory to maintain context across interactions. LLMs are stateless and don't retain information between calls, so agents need memory to track message history and recall relevant information.
4
+
5
+ Mastra agents can be configured to store message history, with optional [working memory](https://mastra.ai/docs/memory/working-memory) to maintain recent context, [semantic recall](https://mastra.ai/docs/memory/semantic-recall) to retrieve past messages based on meaning, or [observational memory](https://mastra.ai/docs/memory/observational-memory) for automatic long-term memory that compresses conversations as they grow.
6
+
7
+ ## When to use memory
8
+
9
+ 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.
10
+
11
+ ## Setting up memory
12
+
13
+ To enable memory in Mastra, install the `@mastra/memory` package along with a storage provider.
14
+
15
+ **npm**:
16
+
17
+ ```bash
18
+ npm install @mastra/memory@latest @mastra/libsql@latest
19
+ ```
20
+
21
+ **pnpm**:
22
+
23
+ ```bash
24
+ pnpm add @mastra/memory@latest @mastra/libsql@latest
25
+ ```
26
+
27
+ **Yarn**:
28
+
29
+ ```bash
30
+ yarn add @mastra/memory@latest @mastra/libsql@latest
31
+ ```
32
+
33
+ **Bun**:
34
+
35
+ ```bash
36
+ bun add @mastra/memory@latest @mastra/libsql@latest
37
+ ```
38
+
39
+ ## Storage providers
40
+
41
+ Memory requires a storage provider to persist message history, including user messages and agent responses. For more details on available providers and how storage works in Mastra, see the [Storage](https://mastra.ai/docs/memory/storage) documentation.
42
+
43
+ ## Configuring memory
44
+
45
+ 1. Enable memory by creating a `Memory` instance and passing it to the agent’s `memory` option.
46
+
47
+ ```typescript
48
+ import { Agent } from "@mastra/core/agent";
49
+ import { Memory } from "@mastra/memory";
50
+
51
+ export const memoryAgent = new Agent({
52
+ id: 'memory-agent',
53
+ name: 'Memory Agent',
54
+ memory: new Memory({
55
+ options: {
56
+ lastMessages: 20,
57
+ },
58
+ }),
59
+ });
60
+ ```
61
+
62
+ > **Info:** Visit [Memory Class](https://mastra.ai/reference/memory/memory-class) for a full list of configuration options.
63
+
64
+ 2. Add a storage provider to your main Mastra instance to enable memory across all configured agents.
65
+
66
+ ```typescript
67
+ import { Mastra } from "@mastra/core";
68
+ import { LibSQLStore } from "@mastra/libsql";
69
+
70
+ export const mastra = new Mastra({
71
+ storage: new LibSQLStore({
72
+ id: 'mastra-storage',
73
+ url: ":memory:",
74
+ }),
75
+ });
76
+ ```
77
+
78
+ > **Info:** Visit [libSQL Storage](https://mastra.ai/reference/storage/libsql) for a full list of configuration options.
79
+
80
+ Alternatively, add storage directly to an agent’s memory to keep data separate or use different providers per agent.
81
+
82
+ ```typescript
83
+ import { Agent } from "@mastra/core/agent";
84
+ import { Memory } from "@mastra/memory";
85
+ import { LibSQLStore } from "@mastra/libsql";
86
+
87
+ export const memoryAgent = new Agent({
88
+ id: 'memory-agent',
89
+ name: 'Memory Agent',
90
+ memory: new Memory({
91
+ storage: new LibSQLStore({
92
+ id: 'mastra-storage',
93
+ url: ":memory:",
94
+ }),
95
+ }),
96
+ });
97
+ ```
98
+
99
+ > **Mastra Cloud Store limitation:** Agent-level storage is not supported when using [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment). If you use Mastra Cloud Store, configure storage on the Mastra instance instead. This limitation does not apply if you bring your own database.
100
+
101
+ ## Message history
102
+
103
+ Include a `memory` object with both `resource` and `thread` to track message history during agent calls.
104
+
105
+ - `resource`: A stable identifier for the user or entity.
106
+ - `thread`: An ID that isolates a specific conversation or session.
107
+
108
+ These fields tell the agent where to store and retrieve context, enabling persistent, thread-aware memory across a conversation.
109
+
110
+ ```typescript
111
+ const response = await memoryAgent.generate(
112
+ "Remember my favorite color is blue.",
113
+ {
114
+ memory: {
115
+ resource: "user-123",
116
+ thread: "conversation-123",
117
+ },
118
+ },
119
+ );
120
+ ```
121
+
122
+ To recall information stored in memory, call the agent with the same `resource` and `thread` values used in the original conversation.
123
+
124
+ ```typescript
125
+ const response = await memoryAgent.generate("What's my favorite color?", {
126
+ memory: {
127
+ resource: "user-123",
128
+ thread: "conversation-123",
129
+ },
130
+ });
131
+ ```
132
+
133
+ > **Warning:** Each thread has an owner (`resourceId`) that cannot be changed after creation. Avoid reusing the same thread ID for threads with different owners, as this will cause errors when querying.
134
+
135
+ To learn more about memory see the [Memory](https://mastra.ai/docs/memory/overview) documentation.
136
+
137
+ ## Observational Memory
138
+
139
+ For long-running conversations, raw message history grows until it fills the context window, degrading agent performance. [Observational Memory](https://mastra.ai/docs/memory/observational-memory) solves this by running background agents that compress old messages into dense observations, keeping the context window small while preserving long-term memory.
140
+
141
+ ```typescript
142
+ import { Agent } from "@mastra/core/agent";
143
+ import { Memory } from "@mastra/memory";
144
+
145
+ export const memoryAgent = new Agent({
146
+ id: 'memory-agent',
147
+ name: 'Memory Agent',
148
+ memory: new Memory({
149
+ options: {
150
+ observationalMemory: true,
151
+ },
152
+ }),
153
+ });
154
+ ```
155
+
156
+ Setting `observationalMemory: true` uses `google/gemini-2.5-flash` as the default model for the Observer and Reflector. To use a different model or customize thresholds, pass a config object:
157
+
158
+ ```typescript
159
+ import { Agent } from "@mastra/core/agent";
160
+ import { Memory } from "@mastra/memory";
161
+
162
+ export const memoryAgent = new Agent({
163
+ id: 'memory-agent',
164
+ name: 'Memory Agent',
165
+ memory: new Memory({
166
+ options: {
167
+ observationalMemory: {
168
+ model: "deepseek/deepseek-reasoner",
169
+ observation: {
170
+ messageTokens: 20_000,
171
+ },
172
+ },
173
+ },
174
+ }),
175
+ });
176
+ ```
177
+
178
+ > **Info:** See [Observational Memory](https://mastra.ai/docs/memory/observational-memory) for details on how observations and reflections work, and [the reference](https://mastra.ai/reference/memory/observational-memory) for all configuration options.
179
+
180
+ ## Using `RequestContext`
181
+
182
+ Use [RequestContext](https://mastra.ai/docs/server/request-context) to access request-specific values. This lets you conditionally select different memory or storage configurations based on the context of the request.
183
+
184
+ ```typescript
185
+ export type UserTier = {
186
+ "user-tier": "enterprise" | "pro";
187
+ };
188
+
189
+ const premiumMemory = new Memory();
190
+
191
+ const standardMemory = new Memory();
192
+
193
+ export const memoryAgent = new Agent({
194
+ id: 'memory-agent',
195
+ name: 'Memory Agent',
196
+ memory: ({ requestContext }) => {
197
+ const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
198
+
199
+ return userTier === "enterprise" ? premiumMemory : standardMemory;
200
+ },
201
+ });
202
+ ```
203
+
204
+ > **Info:** Visit [Request Context](https://mastra.ai/docs/server/request-context) for more information.
205
+
206
+ ## Related
207
+
208
+ - [Observational Memory](https://mastra.ai/docs/memory/observational-memory)
209
+ - [Working Memory](https://mastra.ai/docs/memory/working-memory)
210
+ - [Semantic Recall](https://mastra.ai/docs/memory/semantic-recall)
211
+ - [Storage](https://mastra.ai/docs/memory/storage)
212
+ - [Request Context](https://mastra.ai/docs/server/request-context)
@@ -1,14 +1,12 @@
1
- > Learn how to require approvals, suspend execution, and resume suspended networks while keeping humans in control of agent network workflows.
2
-
3
1
  # Network Approval
4
2
 
5
- Agent networks can require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in individual agents and workflows. When a tool, sub-agent, or workflow within a network requires approval or suspends execution, the network pauses and emits events that allow your application to collect user input before resuming.
3
+ Agent networks can require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in individual agents and workflows. When a tool, subagent, or workflow within a network requires approval or suspends execution, the network pauses and emits events that allow your application to collect user input before resuming.
6
4
 
7
5
  ## Storage
8
6
 
9
7
  Network approval uses snapshots to capture execution state. Ensure you've enabled a storage provider in your Mastra instance. If storage isn't enabled you'll see an error relating to snapshot not found.
10
8
 
11
- ```typescript title="src/mastra/index.ts"
9
+ ```typescript
12
10
  import { Mastra } from "@mastra/core/mastra";
13
11
  import { LibSQLStore } from "@mastra/libsql";
14
12
 
@@ -37,7 +35,7 @@ let runId: string;
37
35
  for await (const chunk of stream) {
38
36
  runId = stream.runId;
39
37
  // if the requirApproval is in a tool inside a subAgent or the subAgent has requireToolApproval set to true
40
- if (chunk.type === "agent-execution-approval") {
38
+ if (chunk.type === "agent-execution-approval") {
41
39
  console.log("Tool requires approval:", chunk.payload);
42
40
  }
43
41
 
@@ -199,8 +197,11 @@ const stream = await routingAgent.network("Process this request", {
199
197
  When `autoResumeSuspendedTools` is enabled:
200
198
 
201
199
  1. A primitive suspends execution by calling `suspend()` with a payload
200
+
202
201
  2. The suspension is persisted to memory along with the conversation
202
+
203
203
  3. When the user sends their next message on the same thread, the network:
204
+
204
205
  - Detects the suspended primitive from message history
205
206
  - Extracts `resumeData` from the user's message based on the tool's `resumeSchema`
206
207
  - Automatically resumes the primitive with the extracted data
@@ -241,7 +242,7 @@ for await (const chunk of resumedStream) {
241
242
 
242
243
  **Conversation flow:**
243
244
 
244
- ```
245
+ ```text
245
246
  User: "Delete the old records"
246
247
  Agent: "Please confirm: delete old records"
247
248
 
@@ -259,16 +260,16 @@ For automatic tool resumption to work:
259
260
 
260
261
  ### Manual vs automatic resumption
261
262
 
262
- | Approach | Use case |
263
- |----------|----------|
264
- | Manual (`resumeNetwork()`) | Programmatic control, webhooks, button clicks, external triggers |
263
+ | Approach | Use case |
264
+ | -------------------------------------- | ------------------------------------------------------------------------ |
265
+ | Manual (`resumeNetwork()`) | Programmatic control, webhooks, button clicks, external triggers |
265
266
  | Automatic (`autoResumeSuspendedTools`) | Conversational flows where users provide resume data in natural language |
266
267
 
267
268
  Both approaches work with the same tool definitions. Automatic resumption triggers only when suspended tools exist in the message history and the user sends a new message on the same thread.
268
269
 
269
270
  ## Related
270
271
 
271
- - [Agent Networks](./networks)
272
- - [Agent Approval](./agent-approval)
272
+ - [Agent Networks](https://mastra.ai/docs/agents/networks)
273
+ - [Agent Approval](https://mastra.ai/docs/agents/agent-approval)
273
274
  - [Human-in-the-Loop](https://mastra.ai/docs/workflows/human-in-the-loop)
274
- - [Agent Memory](./agent-memory)
275
+ - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
@@ -1,8 +1,6 @@
1
- > Learn how to coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
2
-
3
1
  # Agent Networks
4
2
 
5
- 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 (sub-agents, workflows, or tools) to call, in what order, and with what data.
3
+ 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.
6
4
 
7
5
  ## When to use networks
8
6
 
@@ -18,9 +16,9 @@ Mastra agent networks operate using these principles:
18
16
 
19
17
  ## Creating an agent network
20
18
 
21
- An agent network is built around a top-level routing agent that delegates tasks to agents, 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.
19
+ 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.
22
20
 
23
- ```typescript {22-23,26,29} title="src/mastra/agents/routing-agent.ts"
21
+ ```typescript
24
22
  import { Agent } from "@mastra/core/agent";
25
23
  import { Memory } from "@mastra/memory";
26
24
  import { LibSQLStore } from "@mastra/libsql";
@@ -66,9 +64,9 @@ When configuring a Mastra agent network, each primitive (agent, workflow, or too
66
64
 
67
65
  #### Agent descriptions
68
66
 
69
- Each agent in a network should include a clear `description` that explains what the agent does.
67
+ Each subagent in a network should include a clear `description` that explains what the agent does.
70
68
 
71
- ```typescript title="src/mastra/agents/research-agent.ts"
69
+ ```typescript
72
70
  export const researchAgent = new Agent({
73
71
  id: "research-agent",
74
72
  name: "Research Agent",
@@ -78,7 +76,7 @@ export const researchAgent = new Agent({
78
76
  });
79
77
  ```
80
78
 
81
- ```typescript title="src/mastra/agents/writing-agent.ts"
79
+ ```typescript
82
80
  export const writingAgent = new Agent({
83
81
  id: "writing-agent",
84
82
  name: "Writing Agent",
@@ -92,7 +90,7 @@ export const writingAgent = new Agent({
92
90
 
93
91
  Workflows in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
94
92
 
95
- ```typescript title="src/mastra/workflows/city-workflow.ts"
93
+ ```typescript
96
94
  export const cityWorkflow = createWorkflow({
97
95
  id: "city-workflow",
98
96
  description: `This workflow handles city-specific research tasks.
@@ -112,7 +110,7 @@ export const cityWorkflow = createWorkflow({
112
110
 
113
111
  Tools in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
114
112
 
115
- ```typescript title="src/mastra/tools/weather-tool.ts"
113
+ ```typescript
116
114
  export const weatherTool = createTool({
117
115
  id: "weather-tool",
118
116
  description: ` Retrieves current weather information using the wttr.in API.
@@ -286,7 +284,7 @@ const final = await stream.object;
286
284
 
287
285
  ## Related
288
286
 
289
- - [Agent Memory](./agent-memory)
290
- - [Workflows Overview](../workflows/overview)
287
+ - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
288
+ - [Workflows Overview](https://mastra.ai/docs/workflows/overview)
291
289
  - [Request Context](https://mastra.ai/docs/server/request-context)
292
290
  - [Supervisor example](https://github.com/mastra-ai/mastra/tree/main/examples/supervisor-agent)
@@ -1,5 +1,3 @@
1
- > Learn how to use memory processors in Mastra to filter, trim, and transform messages before they
2
-
3
1
  # Memory Processors
4
2
 
5
3
  Memory processors transform and filter messages as they pass through an agent with memory enabled. They manage context window limits, remove unnecessary content, and optimize the information sent to the language model.
@@ -200,7 +198,7 @@ Understanding the execution order is important when combining guardrails with me
200
198
 
201
199
  ### Input Processors
202
200
 
203
- ```
201
+ ```text
204
202
  [Memory Processors] → [Your inputProcessors]
205
203
  ```
206
204
 
@@ -211,7 +209,7 @@ This means memory loads message history before your processors can validate or f
211
209
 
212
210
  ### Output Processors
213
211
 
214
- ```
212
+ ```text
215
213
  [Your outputProcessors] → [Memory Processors]
216
214
  ```
217
215
 
@@ -302,10 +300,10 @@ const agent = new Agent({
302
300
 
303
301
  ### Summary
304
302
 
305
- | Guardrail Type | When it runs | If it aborts |
306
- | -------------- | ------------ | ------------ |
307
- | Input | After memory loads history | LLM not called, nothing saved |
308
- | Output | Before memory saves | Nothing saved to storage |
303
+ | Guardrail Type | When it runs | If it aborts |
304
+ | -------------- | -------------------------- | ----------------------------- |
305
+ | Input | After memory loads history | LLM not called, nothing saved |
306
+ | Output | Before memory saves | Nothing saved to storage |
309
307
 
310
308
  Both scenarios are safe - guardrails prevent inappropriate content from being persisted to memory
311
309