@mastra/core 1.15.0-alpha.0 → 1.15.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 (161) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/agent/index.cjs +8 -8
  3. package/dist/agent/index.js +1 -1
  4. package/dist/{chunk-JBYJDZT5.js → chunk-4YKZNIK6.js} +4 -4
  5. package/dist/{chunk-JBYJDZT5.js.map → chunk-4YKZNIK6.js.map} +1 -1
  6. package/dist/{chunk-I5ON7TPA.cjs → chunk-7BM5LQHF.cjs} +82 -82
  7. package/dist/{chunk-I5ON7TPA.cjs.map → chunk-7BM5LQHF.cjs.map} +1 -1
  8. package/dist/{chunk-IST54Q37.js → chunk-ASVFCNLS.js} +7 -7
  9. package/dist/{chunk-IST54Q37.js.map → chunk-ASVFCNLS.js.map} +1 -1
  10. package/dist/{chunk-DGSXFZGZ.js → chunk-CTJLKJMO.js} +10 -6
  11. package/dist/chunk-CTJLKJMO.js.map +1 -0
  12. package/dist/{chunk-4JBWS3Y6.js → chunk-EAWVRIHS.js} +3 -3
  13. package/dist/{chunk-4JBWS3Y6.js.map → chunk-EAWVRIHS.js.map} +1 -1
  14. package/dist/{chunk-7GXY5CDK.js → chunk-ECAVJWAH.js} +4 -4
  15. package/dist/{chunk-7GXY5CDK.js.map → chunk-ECAVJWAH.js.map} +1 -1
  16. package/dist/{chunk-EG3QZTQQ.cjs → chunk-EFYYAFWD.cjs} +19 -15
  17. package/dist/chunk-EFYYAFWD.cjs.map +1 -0
  18. package/dist/{chunk-ORYC6WMY.js → chunk-EYLPPZIF.js} +4 -2
  19. package/dist/chunk-EYLPPZIF.js.map +1 -0
  20. package/dist/{chunk-FIOAZZAM.js → chunk-FNOAF2SZ.js} +3 -3
  21. package/dist/{chunk-FIOAZZAM.js.map → chunk-FNOAF2SZ.js.map} +1 -1
  22. package/dist/{chunk-GMUEV4ML.cjs → chunk-FYQXIWRH.cjs} +4 -2
  23. package/dist/chunk-FYQXIWRH.cjs.map +1 -0
  24. package/dist/{chunk-KZLBDSIF.js → chunk-HIZDAENF.js} +3 -3
  25. package/dist/{chunk-KZLBDSIF.js.map → chunk-HIZDAENF.js.map} +1 -1
  26. package/dist/{chunk-7XPMIQIK.js → chunk-JIBMK2QP.js} +8 -8
  27. package/dist/{chunk-7XPMIQIK.js.map → chunk-JIBMK2QP.js.map} +1 -1
  28. package/dist/{chunk-CBLM3UY3.js → chunk-KCZ3R5SF.js} +3 -3
  29. package/dist/{chunk-CBLM3UY3.js.map → chunk-KCZ3R5SF.js.map} +1 -1
  30. package/dist/{chunk-Y2I3C7FR.cjs → chunk-M5BDH7B4.cjs} +6 -6
  31. package/dist/{chunk-Y2I3C7FR.cjs.map → chunk-M5BDH7B4.cjs.map} +1 -1
  32. package/dist/{chunk-4CC2ZV3B.js → chunk-MHTWFVXK.js} +3 -3
  33. package/dist/{chunk-4CC2ZV3B.js.map → chunk-MHTWFVXK.js.map} +1 -1
  34. package/dist/{chunk-REVBDBHI.cjs → chunk-NWPRZZ2K.cjs} +48 -48
  35. package/dist/{chunk-REVBDBHI.cjs.map → chunk-NWPRZZ2K.cjs.map} +1 -1
  36. package/dist/{chunk-PEKFBFE2.cjs → chunk-ORHPD25N.cjs} +7 -7
  37. package/dist/{chunk-PEKFBFE2.cjs.map → chunk-ORHPD25N.cjs.map} +1 -1
  38. package/dist/{chunk-SV6VG3XO.cjs → chunk-OX63O3QG.cjs} +5 -5
  39. package/dist/{chunk-SV6VG3XO.cjs.map → chunk-OX63O3QG.cjs.map} +1 -1
  40. package/dist/{chunk-NSJS72DA.cjs → chunk-Q64Z437G.cjs} +15 -15
  41. package/dist/{chunk-NSJS72DA.cjs.map → chunk-Q64Z437G.cjs.map} +1 -1
  42. package/dist/{chunk-W4R4TA4Z.cjs → chunk-RFZB2PQE.cjs} +9 -9
  43. package/dist/{chunk-W4R4TA4Z.cjs.map → chunk-RFZB2PQE.cjs.map} +1 -1
  44. package/dist/{chunk-J7UJLVIQ.cjs → chunk-TJB7IK7N.cjs} +19 -11
  45. package/dist/chunk-TJB7IK7N.cjs.map +1 -0
  46. package/dist/{chunk-OT7UVM2Z.cjs → chunk-X4RVX77L.cjs} +185 -185
  47. package/dist/{chunk-OT7UVM2Z.cjs.map → chunk-X4RVX77L.cjs.map} +1 -1
  48. package/dist/{chunk-XVOLOB5X.cjs → chunk-YV5UMIRV.cjs} +3 -3
  49. package/dist/{chunk-XVOLOB5X.cjs.map → chunk-YV5UMIRV.cjs.map} +1 -1
  50. package/dist/{chunk-SCTBRRU3.js → chunk-Z76WT6W3.js} +18 -10
  51. package/dist/chunk-Z76WT6W3.js.map +1 -0
  52. package/dist/datasets/index.cjs +11 -11
  53. package/dist/datasets/index.js +1 -1
  54. package/dist/docs/SKILL.md +10 -11
  55. package/dist/docs/assets/SOURCE_MAP.json +154 -154
  56. package/dist/docs/references/docs-agents-agent-approval.md +114 -193
  57. package/dist/docs/references/docs-agents-guardrails.md +120 -167
  58. package/dist/docs/references/docs-agents-networks.md +88 -205
  59. package/dist/docs/references/docs-agents-overview.md +47 -256
  60. package/dist/docs/references/docs-agents-processors.md +201 -297
  61. package/dist/docs/references/docs-agents-structured-output.md +13 -22
  62. package/dist/docs/references/docs-agents-supervisor-agents.md +24 -18
  63. package/dist/docs/references/docs-agents-using-tools.md +81 -104
  64. package/dist/docs/references/docs-memory-observational-memory.md +4 -2
  65. package/dist/docs/references/docs-memory-overview.md +219 -24
  66. package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
  67. package/dist/docs/references/docs-memory-storage.md +4 -4
  68. package/dist/docs/references/docs-memory-working-memory.md +1 -1
  69. package/dist/docs/references/docs-observability-overview.md +1 -1
  70. package/dist/docs/references/docs-observability-tracing-exporters-arize.md +1 -1
  71. package/dist/docs/references/docs-server-request-context.md +1 -1
  72. package/dist/docs/references/docs-workflows-overview.md +1 -1
  73. package/dist/docs/references/docs-workspace-overview.md +1 -1
  74. package/dist/docs/references/guides-concepts-multi-agent-systems.md +75 -0
  75. package/dist/docs/references/reference-agents-agent.md +6 -8
  76. package/dist/docs/references/reference-agents-generate.md +74 -23
  77. package/dist/docs/references/reference-agents-getMemory.md +1 -1
  78. package/dist/docs/references/reference-agents-network.md +2 -2
  79. package/dist/docs/references/reference-ai-sdk-network-route.md +1 -1
  80. package/dist/docs/references/reference-ai-sdk-with-mastra.md +1 -1
  81. package/dist/docs/references/reference-core-getMemory.md +1 -2
  82. package/dist/docs/references/reference-core-listMemory.md +1 -2
  83. package/dist/docs/references/reference-harness-harness-class.md +2 -2
  84. package/dist/docs/references/reference-memory-observational-memory.md +3 -1
  85. package/dist/docs/references/reference-processors-processor-interface.md +2 -0
  86. package/dist/docs/references/reference-storage-overview.md +1 -1
  87. package/dist/docs/references/reference-templates-overview.md +1 -1
  88. package/dist/docs/references/reference-tools-create-tool.md +16 -4
  89. package/dist/evals/index.cjs +5 -5
  90. package/dist/evals/index.js +2 -2
  91. package/dist/evals/scoreTraces/index.cjs +3 -3
  92. package/dist/evals/scoreTraces/index.js +1 -1
  93. package/dist/harness/harness.d.ts +3 -0
  94. package/dist/harness/harness.d.ts.map +1 -1
  95. package/dist/harness/index.cjs +48 -13
  96. package/dist/harness/index.cjs.map +1 -1
  97. package/dist/harness/index.js +46 -11
  98. package/dist/harness/index.js.map +1 -1
  99. package/dist/harness/types.d.ts +11 -0
  100. package/dist/harness/types.d.ts.map +1 -1
  101. package/dist/index.cjs +2 -2
  102. package/dist/index.js +1 -1
  103. package/dist/llm/index.cjs +16 -16
  104. package/dist/llm/index.js +5 -5
  105. package/dist/llm/model/model.d.ts.map +1 -1
  106. package/dist/llm/model/provider-types.generated.d.ts +6 -2
  107. package/dist/loop/index.cjs +14 -14
  108. package/dist/loop/index.js +1 -1
  109. package/dist/mastra/index.cjs +2 -2
  110. package/dist/mastra/index.js +1 -1
  111. package/dist/memory/index.cjs +14 -14
  112. package/dist/memory/index.js +1 -1
  113. package/dist/memory/types.d.ts +7 -0
  114. package/dist/memory/types.d.ts.map +1 -1
  115. package/dist/models-dev-E6FRPGHV.js +3 -0
  116. package/dist/{models-dev-5BT32JYX.js.map → models-dev-E6FRPGHV.js.map} +1 -1
  117. package/dist/models-dev-WIROJ2IM.cjs +12 -0
  118. package/dist/{models-dev-OTMJW4WK.cjs.map → models-dev-WIROJ2IM.cjs.map} +1 -1
  119. package/dist/netlify-7IRBQ2BY.cjs +12 -0
  120. package/dist/{netlify-DT2P2NQD.cjs.map → netlify-7IRBQ2BY.cjs.map} +1 -1
  121. package/dist/netlify-OAGRP6WY.js +3 -0
  122. package/dist/{netlify-FJCQU3OY.js.map → netlify-OAGRP6WY.js.map} +1 -1
  123. package/dist/processor-provider/index.cjs +10 -10
  124. package/dist/processor-provider/index.js +1 -1
  125. package/dist/processors/index.cjs +42 -42
  126. package/dist/processors/index.js +1 -1
  127. package/dist/provider-registry-2MHU2NP6.js +3 -0
  128. package/dist/{provider-registry-BCSAL2IQ.js.map → provider-registry-2MHU2NP6.js.map} +1 -1
  129. package/dist/provider-registry-FINEGQHE.cjs +40 -0
  130. package/dist/{provider-registry-65WCBR2K.cjs.map → provider-registry-FINEGQHE.cjs.map} +1 -1
  131. package/dist/provider-registry.json +14 -6
  132. package/dist/relevance/index.cjs +3 -3
  133. package/dist/relevance/index.js +1 -1
  134. package/dist/stream/index.cjs +8 -8
  135. package/dist/stream/index.js +1 -1
  136. package/dist/test-utils/llm-mock.cjs +4 -4
  137. package/dist/test-utils/llm-mock.js +1 -1
  138. package/dist/tool-loop-agent/index.cjs +4 -4
  139. package/dist/tool-loop-agent/index.js +1 -1
  140. package/dist/workflows/default.d.ts +2 -2
  141. package/dist/workflows/default.d.ts.map +1 -1
  142. package/dist/workflows/evented/index.cjs +10 -10
  143. package/dist/workflows/evented/index.js +1 -1
  144. package/dist/workflows/index.cjs +24 -24
  145. package/dist/workflows/index.js +1 -1
  146. package/package.json +7 -7
  147. package/src/llm/model/provider-types.generated.d.ts +6 -2
  148. package/dist/chunk-DGSXFZGZ.js.map +0 -1
  149. package/dist/chunk-EG3QZTQQ.cjs.map +0 -1
  150. package/dist/chunk-GMUEV4ML.cjs.map +0 -1
  151. package/dist/chunk-J7UJLVIQ.cjs.map +0 -1
  152. package/dist/chunk-ORYC6WMY.js.map +0 -1
  153. package/dist/chunk-SCTBRRU3.js.map +0 -1
  154. package/dist/docs/references/docs-agents-agent-memory.md +0 -209
  155. package/dist/docs/references/docs-agents-network-approval.md +0 -278
  156. package/dist/models-dev-5BT32JYX.js +0 -3
  157. package/dist/models-dev-OTMJW4WK.cjs +0 -12
  158. package/dist/netlify-DT2P2NQD.cjs +0 -12
  159. package/dist/netlify-FJCQU3OY.js +0 -3
  160. package/dist/provider-registry-65WCBR2K.cjs +0 -40
  161. package/dist/provider-registry-BCSAL2IQ.js +0 -3
@@ -2,44 +2,239 @@
2
2
 
3
3
  Memory enables your agent to remember user messages, agent replies, and tool results across interactions, giving it the context it needs to stay consistent, maintain conversation flow, and produce better answers over time.
4
4
 
5
- Mastra supports four complementary memory types:
5
+ Mastra agents can be configured to store [message history](https://mastra.ai/docs/memory/message-history). Additionally, you can enable:
6
6
 
7
- - [**Message history**](https://mastra.ai/docs/memory/message-history) - keeps recent messages from the current conversation so they can be rendered in the UI and used to maintain short-term continuity within the exchange.
8
- - [**Observational memory**](https://mastra.ai/docs/memory/observational-memory) - uses background Observer and Reflector agents to maintain a dense observation log that replaces raw message history as it grows, keeping the context window small while preserving long-term memory across conversations.
9
- - [**Working memory**](https://mastra.ai/docs/memory/working-memory) - stores persistent, structured user data such as names, preferences, and goals.
10
- - [**Semantic recall**](https://mastra.ai/docs/memory/semantic-recall) - retrieves relevant messages from older conversations based on semantic meaning rather than exact keywords, mirroring how humans recall information by association. Requires a [vector database](https://mastra.ai/docs/memory/semantic-recall) and an [embedding model](https://mastra.ai/docs/memory/semantic-recall).
7
+ - [Observational Memory](https://mastra.ai/docs/memory/observational-memory) (Recommended): Uses background agents to maintain a dense observation log that replaces raw message history as it grows. This keeps the context window small while preserving long-term memory.
8
+ - [Working memory](https://mastra.ai/docs/memory/working-memory): Stores persistent, structured user data such as names, preferences, and goals.
9
+ - [Semantic recall](https://mastra.ai/docs/memory/semantic-recall): Retrieves relevant past messages based on semantic meaning rather than exact keywords.
11
10
 
12
11
  If the combined memory exceeds the model's context limit, [memory processors](https://mastra.ai/docs/memory/memory-processors) can filter, trim, or prioritize content so the most relevant information is preserved.
13
12
 
14
- ## Getting started
13
+ Memory results will be stored in one or more of your configured [storage providers](https://mastra.ai/docs/memory/storage).
15
14
 
16
- Choose a memory option to get started:
15
+ ## When to use memory
17
16
 
18
- - [Message history](https://mastra.ai/docs/memory/message-history)
19
- - [Observational memory](https://mastra.ai/docs/memory/observational-memory)
20
- - [Working memory](https://mastra.ai/docs/memory/working-memory)
21
- - [Semantic recall](https://mastra.ai/docs/memory/semantic-recall)
17
+ 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.
22
18
 
23
- ## Storage
19
+ ## Quickstart
24
20
 
25
- Before enabling memory, you must first configure a storage adapter. Mastra supports several databases including PostgreSQL, MongoDB, libSQL, and [more](https://mastra.ai/docs/memory/storage).
21
+ 1. Install the `@mastra/memory` package.
26
22
 
27
- Storage can be configured at the [instance level](https://mastra.ai/docs/memory/storage) (shared across all agents) or at the [agent level](https://mastra.ai/docs/memory/storage) (dedicated per agent).
23
+ **npm**:
28
24
 
29
- For semantic recall, you can use a separate vector database like Pinecone alongside your primary storage.
25
+ ```bash
26
+ npm install @mastra/memory@latest
27
+ ```
30
28
 
31
- See the [Storage](https://mastra.ai/docs/memory/storage) documentation for configuration options, supported providers, and examples.
29
+ **pnpm**:
32
30
 
33
- ## Debugging memory
31
+ ```bash
32
+ pnpm add @mastra/memory@latest
33
+ ```
34
34
 
35
- When [tracing](https://mastra.ai/docs/observability/tracing/overview) is enabled, you can inspect exactly which messages the agent uses for context in each request. The trace output shows all memory included in the agent's context window - both recent message history and messages recalled via semantic recall.
35
+ **Yarn**:
36
36
 
37
- ![Trace output showing memory context included in an agent request](https://mastra.ai/_next/image?url=%2Ftracingafter.png\&w=1920\&q=75)
37
+ ```bash
38
+ yarn add @mastra/memory@latest
39
+ ```
38
40
 
39
- This visibility helps you understand why an agent made specific decisions and verify that memory retrieval is working as expected.
41
+ **Bun**:
40
42
 
41
- ## Next steps
43
+ ```bash
44
+ bun add @mastra/memory@latest
45
+ ```
42
46
 
43
- - Learn more about [Storage](https://mastra.ai/docs/memory/storage) providers and configuration options
44
- - Add [Message history](https://mastra.ai/docs/memory/message-history), [Observational memory](https://mastra.ai/docs/memory/observational-memory), [Working memory](https://mastra.ai/docs/memory/working-memory), or [Semantic recall](https://mastra.ai/docs/memory/semantic-recall)
45
- - Visit [Memory configuration reference](https://mastra.ai/reference/memory/memory-class) for all available options
47
+ 2. Memory **requires** a storage provider to persist message history, including user messages and agent responses.
48
+
49
+ For the purposes of this quickstart, use `@mastra/libsql`.
50
+
51
+ **npm**:
52
+
53
+ ```bash
54
+ npm install @mastra/libsql@latest
55
+ ```
56
+
57
+ **pnpm**:
58
+
59
+ ```bash
60
+ pnpm add @mastra/libsql@latest
61
+ ```
62
+
63
+ **Yarn**:
64
+
65
+ ```bash
66
+ yarn add @mastra/libsql@latest
67
+ ```
68
+
69
+ **Bun**:
70
+
71
+ ```bash
72
+ bun add @mastra/libsql@latest
73
+ ```
74
+
75
+ > **Note:** For more details on available providers and how storage works in Mastra, visit the [storage](https://mastra.ai/docs/memory/storage) documentation.
76
+
77
+ 3. Add the storage provider to your main Mastra instance to enable memory across all configured agents.
78
+
79
+ ```typescript
80
+ import { Mastra } from '@mastra/core'
81
+ import { LibSQLStore } from '@mastra/libsql'
82
+
83
+ export const mastra = new Mastra({
84
+ storage: new LibSQLStore({
85
+ id: 'mastra-storage',
86
+ url: ':memory:',
87
+ }),
88
+ })
89
+ ```
90
+
91
+ 4. Create a `Memory` instance and pass it to the agent's `memory` option.
92
+
93
+ ```typescript
94
+ import { Agent } from '@mastra/core/agent'
95
+ import { Memory } from '@mastra/memory'
96
+
97
+ export const memoryAgent = new Agent({
98
+ id: 'memory-agent',
99
+ name: 'Memory Agent',
100
+ memory: new Memory({
101
+ options: {
102
+ lastMessages: 20,
103
+ },
104
+ }),
105
+ })
106
+ ```
107
+
108
+ > **Note:** Visit [Memory Class](https://mastra.ai/reference/memory/memory-class) for a full list of configuration options.
109
+
110
+ 5. Call your agent, for example in [Mastra Studio](https://mastra.ai/docs/getting-started/studio). Inside Studio, start a new chat with your agent and take a look at the right sidebar. It'll now display various memory-related information.
111
+
112
+ ## Message history
113
+
114
+ Pass a `memory` object with `resource` and `thread` to track message history.
115
+
116
+ - `resource`: A stable identifier for the user or entity.
117
+ - `thread`: An ID that isolates a specific conversation or session.
118
+
119
+ ```typescript
120
+ const response = await memoryAgent.generate('Remember my favorite color is blue.', {
121
+ memory: {
122
+ resource: 'user-123',
123
+ thread: 'conversation-123',
124
+ },
125
+ })
126
+ ```
127
+
128
+ To recall information stored in memory, call the agent with the same `resource` and `thread` values used in the original conversation.
129
+
130
+ ```typescript
131
+ const response = await memoryAgent.generate("What's my favorite color?", {
132
+ memory: {
133
+ resource: 'user-123',
134
+ thread: 'conversation-123',
135
+ },
136
+ })
137
+
138
+ // Response: "Your favorite color is blue."
139
+ ```
140
+
141
+ > **Warning:** Each thread has an owner (`resourceId`) that can't be changed after creation. Avoid reusing the same thread ID for threads with different owners, as this will cause errors when querying.
142
+
143
+ To list all threads for a resource, or retrieve a specific thread, [use the memory API directly](https://mastra.ai/docs/memory/message-history).
144
+
145
+ ## Observational Memory
146
+
147
+ 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.
148
+
149
+ ```typescript
150
+ import { Agent } from '@mastra/core/agent'
151
+ import { Memory } from '@mastra/memory'
152
+
153
+ export const memoryAgent = new Agent({
154
+ id: 'memory-agent',
155
+ name: 'Memory Agent',
156
+ memory: new Memory({
157
+ options: {
158
+ observationalMemory: true,
159
+ },
160
+ }),
161
+ })
162
+ ```
163
+
164
+ > **Note:** 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.
165
+
166
+ ## Memory in multi-agent systems
167
+
168
+ When a [supervisor agent](https://mastra.ai/docs/agents/supervisor-agents) delegates to a subagent, Mastra isolates subagent memory automatically. There is no flag to enable this as it happens on every delegation. Understanding how this scoping works lets you decide what stays private and what to share intentionally.
169
+
170
+ ### How delegation scopes memory
171
+
172
+ Each delegation creates a fresh `threadId` and a deterministic `resourceId` for the subagent:
173
+
174
+ - **Thread ID**: Unique per delegation. The subagent starts with a clean message history every time it's called.
175
+ - **Resource ID**: Derived as `{parentResourceId}-{agentName}`. Because the resource ID is stable across delegations, resource-scoped memory persists between calls. A subagent remembers facts from previous delegations by the same user.
176
+ - **Memory instance**: If a subagent has no memory configured, it inherits the supervisor's `Memory` instance. If the subagent defines its own, that takes precedence.
177
+
178
+ The supervisor forwards its conversation context to the subagent so it has enough background to complete the task. Only the delegation prompt and the subagent's response are saved — the full parent conversation is not stored. You can control which messages reach the subagent with the [`messageFilter`](https://mastra.ai/docs/agents/supervisor-agents) callback.
179
+
180
+ > **Note:** Subagent resource IDs are always suffixed with the agent name (`{parentResourceId}-{agentName}`). Two different subagents under the same supervisor never share a resource ID through delegation.
181
+
182
+ To go beyond this default isolation, you can share memory between agents by passing matching identifiers when you call them directly.
183
+
184
+ ### Share memory between agents
185
+
186
+ When you call agents directly (outside the delegation flow), memory sharing is controlled by two identifiers: `resourceId` and `threadId`. Agents that use the same values read and write to the same data. This is useful when agents collaborate on a shared context — for example, a researcher that saves notes and a writer that reads them.
187
+
188
+ **Resource-scoped sharing** is the most common pattern. [Working memory](https://mastra.ai/docs/memory/working-memory) and [semantic recall](https://mastra.ai/docs/memory/semantic-recall) default to `scope: 'resource'`. If two agents share a `resourceId`, they share observations, working memory, and embeddings — even across different threads:
189
+
190
+ ```typescript
191
+ // Both agents share the same resource-scoped memory
192
+ await researcher.generate('Find information about quantum computing.', {
193
+ memory: { resource: 'project-42', thread: 'research-session' },
194
+ })
195
+
196
+ await writer.generate('Write a summary from the research notes.', {
197
+ memory: { resource: 'project-42', thread: 'writing-session' },
198
+ })
199
+ ```
200
+
201
+ Because both calls use `resource: 'project-42'`, the writer can access the researcher's observations, working memory, and semantic embeddings. Each agent still has its own thread, so message histories stay separate.
202
+
203
+ **Thread-scoped sharing** gives tighter coupling. [Observational Memory](https://mastra.ai/docs/memory/observational-memory) uses `scope: 'thread'` by default. If two agents use the same `resource` _and_ `thread`, they share the full message history. Each agent sees every message the other has written. This is useful when agents need to build on each other's exact outputs.
204
+
205
+ ## Observability
206
+
207
+ Enable [Tracing](https://mastra.ai/docs/observability/tracing/overview) to monitor and debug memory in action. Traces show you exactly which messages and observations the agent included in its context for each request, helping you understand agent behavior and verify that memory retrieval is working as expected.
208
+
209
+ Open [Mastra Studio](https://mastra.ai/docs/getting-started/studio) and select the **Observability** tab in the sidebar. Open the trace of a recent agent request, then look for spans of LLMs calls.
210
+
211
+ ## Switch memory per request
212
+
213
+ 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.
214
+
215
+ ```typescript
216
+ export type UserTier = {
217
+ 'user-tier': 'enterprise' | 'pro'
218
+ }
219
+
220
+ const premiumMemory = new Memory()
221
+ const standardMemory = new Memory()
222
+
223
+ export const memoryAgent = new Agent({
224
+ id: 'memory-agent',
225
+ name: 'Memory Agent',
226
+ memory: ({ requestContext }) => {
227
+ const userTier = requestContext.get('user-tier') as UserTier['user-tier']
228
+
229
+ return userTier === 'enterprise' ? premiumMemory : standardMemory
230
+ },
231
+ })
232
+ ```
233
+
234
+ > **Note:** Visit [Request Context](https://mastra.ai/docs/server/request-context) for more information.
235
+
236
+ ## Related
237
+
238
+ - [`Memory` reference](https://mastra.ai/reference/memory/memory-class)
239
+ - [Tracing](https://mastra.ai/docs/observability/tracing/overview)
240
+ - [Request Context](https://mastra.ai/docs/server/request-context)
@@ -16,7 +16,7 @@ When it's enabled, new messages are used to query a vector DB for semantically s
16
16
 
17
17
  After getting a response from the LLM, all new messages (user, assistant, and tool calls/results) are inserted into the vector DB to be recalled in later interactions.
18
18
 
19
- ## Quick start
19
+ ## Quickstart
20
20
 
21
21
  Semantic recall is enabled by default, so if you give your agent memory it will be included:
22
22
 
@@ -100,7 +100,7 @@ This is useful when different types of data have different performance or operat
100
100
 
101
101
  ### Agent-level storage
102
102
 
103
- Agent-level storage overrides storage configured at the instance level. Add storage to a specific agent when you need data boundaries or compliance requirements:
103
+ Agent-level storage overrides storage configured at the instance level. Add storage to a specific agent when you need to keep data separate or use different providers per agent.
104
104
 
105
105
  ```typescript
106
106
  import { Agent } from '@mastra/core/agent'
@@ -118,14 +118,14 @@ export const agent = new Agent({
118
118
  })
119
119
  ```
120
120
 
121
- > **Warning:** [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment) doesn't support agent-level storage.
121
+ > **Warning:** Agent-level storage isn't 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 doesn't apply if you bring your own database.
122
122
 
123
123
  ## Threads and resources
124
124
 
125
125
  Mastra organizes conversations using two identifiers:
126
126
 
127
- - **Thread** - a conversation session containing a sequence of messages.
128
- - **Resource** - the entity that owns the thread, such as a user, organization, project, or any other domain entity in your application.
127
+ - **Thread**: A conversation session containing a sequence of messages.
128
+ - **Resource**: The entity that owns the thread, such as a user, organization, project, or any other domain entity in your application.
129
129
 
130
130
  Both identifiers are required for agents to store information:
131
131
 
@@ -13,7 +13,7 @@ Working memory can persist at two different scopes:
13
13
 
14
14
  **Important:** Switching between scopes means the agent won't see memory from the other scope - thread-scoped memory is completely separate from resource-scoped memory.
15
15
 
16
- ## Quick start
16
+ ## Quickstart
17
17
 
18
18
  Here's a minimal example of setting up an agent with working memory:
19
19
 
@@ -19,7 +19,7 @@ The `DefaultExporter` persists traces to your configured storage backend. Not al
19
19
 
20
20
  For production environments with high traffic, we recommend using **ClickHouse** for the observability domain via [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](https://mastra.ai/docs/observability/tracing/exporters/default) for details.
21
21
 
22
- ## Quick start
22
+ ## Quickstart
23
23
 
24
24
  Configure Observability in your Mastra instance:
25
25
 
@@ -98,7 +98,7 @@ export const mastra = new Mastra({
98
98
  })
99
99
  ```
100
100
 
101
- > **Quick Start with Docker:** Test locally with an in-memory Phoenix instance:
101
+ > **Quickstart with Docker:** Test locally with an in-memory Phoenix instance:
102
102
  >
103
103
  > ```bash
104
104
  > docker run --pull=always -d --name arize-phoenix -p 6006:6006 \
@@ -465,7 +465,7 @@ When you select a preset from the dropdown, the JSON editor populates with that
465
465
 
466
466
  ## Related
467
467
 
468
- - [Agent Request Context](https://mastra.ai/docs/agents/overview)
468
+ - [Agent Request Context](https://mastra.ai/docs/memory/overview)
469
469
  - [Workflow Request Context](https://mastra.ai/docs/workflows/overview)
470
470
  - [Server Middleware](https://mastra.ai/docs/server/middleware)
471
471
  - [Authorization Middleware](https://mastra.ai/docs/server/middleware)
@@ -8,7 +8,7 @@ Workflows let you define complex sequences of tasks using clear, structured step
8
8
 
9
9
  Use workflows for tasks that are clearly defined upfront and involve multiple steps with a specific execution order. They give you fine-grained control over how data flows and transforms between steps, and which primitives are called at each stage.
10
10
 
11
- > **Watch an introduction:** An introduction to workflows, and how they compare to agents [YouTube (7 minutes)](https://youtu.be/0jg2g3sNvgw)
11
+ > **Tip:** Watch an introduction to workflows, and how they compare to agents on [YouTube (7 minutes)](https://youtu.be/0jg2g3sNvgw).
12
12
 
13
13
  ## Core principles
14
14
 
@@ -56,7 +56,7 @@ const mastra = new Mastra({
56
56
  })
57
57
  ```
58
58
 
59
- ### Agent-scoped workspace
59
+ ### Agent-level workspace
60
60
 
61
61
  Assign a workspace directly to an agent to override the global workspace:
62
62
 
@@ -0,0 +1,75 @@
1
+ # Multi-agent systems
2
+
3
+ A multi-agent system distributes a task across multiple agents instead of asking one agent to do everything. In Mastra, this usually means combining agents, workflows, or both so each part of the system has a clear role.
4
+
5
+ The goal is to assign the right context, tools, and responsibilities to the right component. When that split is clear, a multi-agent system can be easier to reason about than one agent with a long prompt, many tools, and too many responsibilities.
6
+
7
+ ## When to use multi-agent systems
8
+
9
+ Use a multi-agent system when one agent is no longer a good boundary for the work.
10
+
11
+ This is often the case when:
12
+
13
+ - A task spans different kinds of work, such as research, planning, writing, or review.
14
+ - One agent would need too much context or too many tools.
15
+ - Parts of the task should run in parallel.
16
+ - Different stages need different prompts, models, or guardrails.
17
+ - You want clear boundaries between routing, execution, and synthesis.
18
+
19
+ Start with one agent when possible. Add more agents when the added structure clearly improves quality, speed, or reliability.
20
+
21
+ Multi-agent patterns are useful when the system needs a clear way to divide context, decisions, and responsibilities across components. In practice, the key design question is which component stays in control as the task moves forward.
22
+
23
+ ## Handoffs
24
+
25
+ A handoff pattern transfers control from one agent to another. Unlike a supervisor pattern, the first agent does not stay in charge for the full task. Instead, the active specialist takes ownership of the next part of the interaction.
26
+
27
+ Use handoffs when the next specialist should continue the interaction directly instead of reporting back through a central coordinator. The tradeoff is that context management becomes more important, since the system must decide what the next agent inherits and what remains scoped.
28
+
29
+ In Mastra, implement this pattern by combining [agents](https://mastra.ai/docs/agents/overview), [workflows](https://mastra.ai/docs/workflows/overview), and [memory](https://mastra.ai/docs/memory/overview). A workflow can route the task, but the defining feature of the pattern is that ownership moves to the next agent.
30
+
31
+ ## Workflows
32
+
33
+ A workflow pattern defines the execution path in code. Instead of asking an agent to decide what happens next, you define the sequence through steps, branches, loops, and parallel blocks.
34
+
35
+ Use workflows when the task is well understood and the execution path is known in advance. The main advantage is predictability: The system is easier to debug, reason about, and audit because the structure is explicit. The tradeoff is flexibility, since workflows are less adaptive when the task changes as it unfolds.
36
+
37
+ In Mastra, [workflows](https://mastra.ai/docs/workflows/overview) can implement several coordination patterns, including handoffs and councils. What makes a workflow distinct is not which agents it calls, but that the control logic lives in the workflow itself.
38
+
39
+ ## Supervisors
40
+
41
+ A supervisor pattern keeps one lead agent in control for the full task. The supervisor decides when to delegate, which specialist to call, what context to pass, and how to combine the result.
42
+
43
+ Use this pattern when the task is open-ended and the full sequence is not known in advance. For example, a research task may require different lines of inquiry based on what earlier steps uncover. A supervisor can adapt as the task unfolds. The tradeoff is that the supervisor becomes the main coordination point. That makes the pattern flexible, but it also means the result depends heavily on good delegation behavior and clear subagent boundaries.
44
+
45
+ In Mastra, this pattern maps directly to [supervisor agents](https://mastra.ai/docs/agents/supervisor-agents). A supervisor agent defines subagents on the `agents` property and uses `stream()` or `generate()` to coordinate them. Mastra also provides delegation hooks, message filtering, and memory isolation to help control this pattern.
46
+
47
+ > **Tip:** Follow the [supervisor agents tutorial](https://mastra.ai/guides/guide/research-coordinator) for a step-by-step guide.
48
+
49
+ ## Council
50
+
51
+ A council pattern asks multiple agents to work on the same problem independently, then compares or synthesizes their outputs into one final answer. Unlike a supervisor, which divides the problem into parts, a council keeps the problem shared and brings multiple viewpoints to the same question.
52
+
53
+ Use this pattern when the question is ambiguous, evaluative, or high-stakes and answer quality matters more than speed. The tradeoff is cost, since councils intentionally duplicate effort and usually take longer and use more tokens than other patterns.
54
+
55
+ Mastra does not provide a dedicated council primitive. In Mastra, implement this pattern with [agents](https://mastra.ai/docs/agents/overview) and [workflows](https://mastra.ai/docs/workflows/overview): Run multiple agents in parallel, collect their outputs, and add a final synthesis or review step. Workflow control flow methods such as `.parallel()` provide the structure for this pattern.
56
+
57
+ ## Choosing a pattern
58
+
59
+ These patterns differ mainly in how they distribute control:
60
+
61
+ | Pattern | Who stays in control | Use when | Tradeoff | Mastra implementation |
62
+ | ----------------- | -------------------- | ------------------------------------------------ | -------------------------------------------------------- | -------------------------------------------------------------------- |
63
+ | Handoffs | Current specialist | Ownership should move between specialists | Context transfer becomes more important | Agents with workflows and memory |
64
+ | Workflows | Execution graph | The path is known in advance | Less adaptive when the task changes | [Workflows](https://mastra.ai/docs/workflows/overview) |
65
+ | Supervisor agents | One lead agent | The task needs dynamic delegation | Results depend on good coordination and clear boundaries | [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents) |
66
+ | Council | Final synthesis step | The task needs multiple independent perspectives | Higher cost and latency | Agents with workflow parallelism |
67
+
68
+ In practice, these patterns are often combined:
69
+
70
+ - A workflow can contain one or more supervisor-driven steps.
71
+ - A handoff flow can begin with a routing workflow.
72
+ - A council can run inside a workflow and feed into a final approval step.
73
+ - A supervisor can delegate to a workflow for a task with fixed internal structure.
74
+
75
+ Choose the pattern based on the coordination problem, not the task label.
@@ -6,6 +6,8 @@ The `Agent` class is the foundation for creating AI agents in Mastra. It provide
6
6
 
7
7
  ### Basic string instructions
8
8
 
9
+ Passing instructions as a string or array of strings is the simplest way to set up an agent. This is useful for straightforward use cases where you just need to provide a prompt without additional configuration.
10
+
9
11
  ```typescript
10
12
  import { Agent } from '@mastra/core/agent'
11
13
 
@@ -40,9 +42,9 @@ export const agent3 = new Agent({
40
42
  })
41
43
  ```
42
44
 
43
- ### Single `CoreSystemMessage`
45
+ ### Provider-specific configurations
44
46
 
45
- Use CoreSystemMessage format to access additional properties like `providerOptions` for provider-specific configurations:
47
+ Each model provider also enables a few different options, including prompt caching and configuring reasoning. You can set `providerOptions` on the instruction level to set different caching strategy per system instruction/prompt.
46
48
 
47
49
  ```typescript
48
50
  import { Agent } from '@mastra/core/agent'
@@ -63,7 +65,7 @@ export const agent = new Agent({
63
65
  })
64
66
  ```
65
67
 
66
- ### Multiple `CoreSystemMessages`
68
+ ### Mixed instruction formats
67
69
 
68
70
  ```typescript
69
71
  import { Agent } from '@mastra/core/agent'
@@ -134,8 +136,4 @@ export const agent = new Agent({
134
136
 
135
137
  ## Returns
136
138
 
137
- **agent** (`Agent<TAgentId, TTools>`): A new Agent instance with the specified configuration.
138
-
139
- ## Related
140
-
141
- - [Agents overview](https://mastra.ai/docs/agents/overview)
139
+ **agent** (`Agent<TAgentId, TTools>`): A new Agent instance with the specified configuration.
@@ -2,46 +2,103 @@
2
2
 
3
3
  The `.generate()` method enables non-streaming response generation from an agent with enhanced capabilities. It accepts messages and optional generation options.
4
4
 
5
- ## Usage example
5
+ ## Usage examples
6
6
 
7
- ```typescript
8
- // Basic usage
7
+ ### Basic usage
8
+
9
+ Call the agent with a message to generate a response:
10
+
11
+ ```ts
9
12
  const result = await agent.generate('message for agent')
13
+ ```
14
+
15
+ ### With model settings
10
16
 
11
- // With model settings (e.g., limiting output tokens)
17
+ Example of limiting output tokens and setting temperature:
18
+
19
+ ```ts
12
20
  const limitedResult = await agent.generate('Write a short poem about coding', {
13
21
  modelSettings: {
14
22
  maxOutputTokens: 50,
15
23
  temperature: 0.7,
16
24
  },
17
25
  })
26
+ ```
18
27
 
19
- // With structured output
20
- const structuredResult = await agent.generate("Extract the user's name and age", {
21
- structuredOutput: {
22
- schema: z.object({
23
- name: z.string(),
24
- age: z.number(),
25
- }),
26
- },
27
- })
28
+ ### With memory
28
29
 
29
- // With memory for conversation persistence
30
+ Give your agent access to conversation history and persistence by configuring memory options. This allows the agent to remember previous interactions and maintain context across messages.
31
+
32
+ ```ts
30
33
  const memoryResult = await agent.generate('Remember my favorite color is blue', {
31
34
  memory: {
32
35
  thread: 'user-123-thread',
33
36
  resource: 'user-123',
34
37
  },
35
38
  })
39
+ ```
40
+
41
+ ### Accessing response headers
36
42
 
37
- // Accessing response headers
43
+ Some model providers return useful information in response headers, such as remaining token counts or rate limit status. You can access these headers from the result object after generation completes.
44
+
45
+ ```ts
38
46
  const result = await agent.generate('Hello!')
39
47
  const remainingRequests = result.response?.headers?.['anthropic-ratelimit-requests-remaining']
40
48
  const remainingTokens = result.response?.headers?.['x-ratelimit-remaining-tokens']
41
49
  console.log(`Remaining requests: ${remainingRequests}, Remaining tokens: ${remainingTokens}`)
42
50
  ```
43
51
 
44
- > **Info:** **Model Compatibility**: This method requires AI SDK v5+ models. If you're using AI SDK v4 models, use the [`.generateLegacy()`](https://mastra.ai/reference/agents/generateLegacy) method instead. The framework automatically detects your model version and will throw an error if there's a mismatch.
52
+ ### Analyzing images
53
+
54
+ Agents can analyze and describe images by processing both the visual content and any text within them. To enable image analysis, pass an object with `type: 'image'` and the image URL in the `content` array. You can combine image content with text prompts to guide the agent's analysis.
55
+
56
+ ```typescript
57
+ const response = await agent.generate([
58
+ {
59
+ role: 'user',
60
+ content: [
61
+ {
62
+ type: 'image',
63
+ image: 'https://placebear.com/cache/395-205.jpg',
64
+ mimeType: 'image/jpeg',
65
+ },
66
+ {
67
+ type: 'text',
68
+ text: 'Describe the image in detail, and extract all the text in the image.',
69
+ },
70
+ ],
71
+ },
72
+ ])
73
+
74
+ console.log(response.text)
75
+ ```
76
+
77
+ ### Using `maxSteps`
78
+
79
+ The `maxSteps` parameter controls the maximum number of sequential LLM calls an agent can make. Each step includes generating a response, executing any tool calls, and processing the result. Limiting steps helps prevent infinite loops, reduce latency, and control token usage for agents that use tools. The default is 5, but can be increased:
80
+
81
+ ```typescript
82
+ const response = await agent.generate('Help me organize my day', {
83
+ maxSteps: 10,
84
+ })
85
+
86
+ console.log(response.text)
87
+ ```
88
+
89
+ ### Using `onStepFinish`
90
+
91
+ You can monitor the progress of multi-step operations using the `onStepFinish` callback. This is useful for debugging or providing progress updates to users.
92
+
93
+ `onStepFinish` is only available when streaming or generating text without structured output.
94
+
95
+ ```typescript
96
+ const response = await agent.generate('Help me organize my day', {
97
+ onStepFinish: ({ text, toolCalls, toolResults, finishReason, usage }) => {
98
+ console.log({ text, toolCalls, toolResults, finishReason, usage })
99
+ },
100
+ })
101
+ ```
45
102
 
46
103
  ## Parameters
47
104
 
@@ -313,10 +370,4 @@ console.log(`Remaining requests: ${remainingRequests}, Remaining tokens: ${remai
313
370
 
314
371
  **tripwire** (`StepTripwireData`): Tripwire data if content was blocked by a processor.
315
372
 
316
- **scoringData** (`object`): Scoring data for evals when \`returnScorerData\` is enabled.
317
-
318
- ## Related
319
-
320
- - [Agent Networks](https://mastra.ai/docs/agents/networks) - Using the supervisor pattern for multi-agent coordination
321
- - [Migration: .network() to Supervisor Pattern](https://mastra.ai/guides/migrations/network-to-supervisor)
322
- - [Guide: Research Coordinator](https://mastra.ai/guides/guide/research-coordinator)
373
+ **scoringData** (`object`): Scoring data for evals when \`returnScorerData\` is enabled.
@@ -28,5 +28,5 @@ await agent.getMemory({
28
28
 
29
29
  ## Related
30
30
 
31
- - [Agent memory](https://mastra.ai/docs/agents/agent-memory)
31
+ - [Memory](https://mastra.ai/docs/memory/overview)
32
32
  - [Request Context](https://mastra.ai/docs/server/request-context)
@@ -1,9 +1,9 @@
1
1
  # Agent.network()
2
2
 
3
- > **Deprecated:** Agent networks are deprecated and will be removed in a future release. Use the [supervisor pattern](https://mastra.ai/docs/agents/supervisor-agents) with `agent.stream()` or `agent.generate()` instead. See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
4
-
5
3
  The `.network()` method enables multi-agent collaboration and routing. This method accepts messages and optional execution options.
6
4
 
5
+ > **Deprecated:** The `.network()` primitive has been deprecated and will be removed in a future major release. Use [supervisor agents](https://mastra.ai/docs/agents/supervisor-agents) with `agent.stream()` or `agent.generate()` instead. See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
6
+
7
7
  ## Usage example
8
8
 
9
9
  ```typescript
@@ -1,6 +1,6 @@
1
1
  # networkRoute()
2
2
 
3
- > **Deprecated:** Agent networks are deprecated and will be removed in a future release. Use the [supervisor pattern](https://mastra.ai/docs/agents/supervisor-agents) with `agent.stream()` or `agent.generate()` instead. See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
3
+ > **Deprecated:** Agent networks are deprecated and will be removed in a future release. Use [supervisor agents](https://mastra.ai/docs/agents/supervisor-agents) with `agent.stream()` or `agent.generate()` instead. See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
4
4
 
5
5
  Creates a network route handler for streaming network execution using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts messages, executes an agent network, and streams the response back to the client in AI SDK-compatible format. Agent networks allow a routing agent to delegate tasks to other agents. You have to use it inside a [custom API route](https://mastra.ai/docs/server/custom-api-routes).
6
6