@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
@@ -6,7 +6,7 @@ Structured output lets an agent return an object that matches the shape defined
6
6
 
7
7
  Use structured output when you need an agent to return a data object rather than text. Having well defined fields can make it simpler to pull out the values you need for API calls, UI rendering, or application logic.
8
8
 
9
- ## Defining schemas
9
+ ## Define schemas
10
10
 
11
11
  Agents can return structured data by defining the expected output with either [Zod](https://zod.dev/) or [JSON Schema](https://json-schema.org/). Zod is recommended because it provides TypeScript type inference and runtime validation, while JSON Schema is useful when you need a language agnostic format.
12
12
 
@@ -58,11 +58,9 @@ const response = await testAgent.generate('Help me plan my day.', {
58
58
  console.log(response.object)
59
59
  ```
60
60
 
61
- > **Info:** Visit [.generate()](https://mastra.ai/reference/agents/generate) for a full list of configuration options.
61
+ > **Note:** Visit [`.generate()`](https://mastra.ai/reference/agents/generate) for a full list of configuration options.
62
62
 
63
- ### Example output
64
-
65
- The `response.object` will contain the structured data as defined by the schema.
63
+ **Example output:** The `response.object` will contain the structured data as defined by the schema.
66
64
 
67
65
  ```json
68
66
  [
@@ -81,7 +79,7 @@ The `response.object` will contain the structured data as defined by the schema.
81
79
  ]
82
80
  ```
83
81
 
84
- ## Streaming
82
+ ## Stream structured output
85
83
 
86
84
  Streaming also supports structured output. The final structured object is available on `stream.fullStream` and after the stream completes on `stream.object`. Text stream chunks are still emitted, but they contain natural language text rather than structured data.
87
85
 
@@ -144,7 +142,7 @@ const response = await testAgent.generate('Analyze the TypeScript programming la
144
142
  console.log(response.object)
145
143
  ```
146
144
 
147
- ## Combining tools and structured output
145
+ ## Combine tools and structured output
148
146
 
149
147
  When an agent has both tools and structured output configured, some models may not support using both features together. This is a limitation of the underlying model APIs, not Mastra itself.
150
148
 
@@ -199,17 +197,17 @@ console.log(response.object)
199
197
  > })
200
198
  > ```
201
199
 
202
- ### Using a separate structuring model
200
+ ### Use a separate structuring model
203
201
 
204
202
  When `model` is provided to the `structuredOutput` property, Mastra uses a separate internal agent to handle the structured output. The main agent will handle all of the steps (including tool calling) and the structured output model will handle only the generation of structured output.
205
203
 
206
204
  ```typescript
207
- const response = await testAgent.generate("Tell me about TypeScript.", {
205
+ const response = await testAgent.generate('Tell me about TypeScript.', {
208
206
  structuredOutput: {
209
- schema: yourSchema
210
- model: 'openai/gpt-5.4'
211
- }
212
- });
207
+ schema: yourSchema,
208
+ model: 'openai/gpt-5.4',
209
+ },
210
+ })
213
211
  ```
214
212
 
215
213
  ### Multi-step approach with `prepareStep`
@@ -243,13 +241,11 @@ const result = await agent.stream('weather in vancouver?', {
243
241
  })
244
242
  ```
245
243
 
246
- ## Error handling
244
+ ## Handle errors
247
245
 
248
246
  When schema validation fails, you can control how errors are handled using `errorStrategy`. The default `strict` strategy throws an error, while `warn` logs a warning and continues. The `fallback` strategy returns the values provided using `fallbackValue`.
249
247
 
250
248
  ```typescript
251
- import { z } from 'zod'
252
-
253
249
  const response = await testAgent.generate('Tell me about TypeScript.', {
254
250
  structuredOutput: {
255
251
  schema: z.object({
@@ -265,9 +261,4 @@ const response = await testAgent.generate('Tell me about TypeScript.', {
265
261
  })
266
262
 
267
263
  console.log(response.object)
268
- ```
269
-
270
- ## Related
271
-
272
- - [Using Tools](https://mastra.ai/docs/agents/using-tools)
273
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
264
+ ```
@@ -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,14 +1,14 @@
1
- # Using tools
1
+ # Tools
2
2
 
3
3
  Agents use tools to call APIs, query databases, or run custom functions from your codebase. Tools give agents capabilities beyond language generation by providing structured access to data and performing clearly defined operations. You can also load tools from remote [MCP servers](https://mastra.ai/docs/mcp/overview) to expand an agent's capabilities.
4
4
 
5
5
  ## When to use tools
6
6
 
7
- Use tools when an agent needs additional context or information from remote resources, or when it needs to run code that performs a specific operation. This includes tasks a model can't reliably handle on its own, such as fetching live data or returning consistent, well defined outputs.
7
+ Use tools when an agent needs additional context or information from remote resources, or when it needs to run code that performs a specific operation. This includes tasks a model can't reliably handle on its own, such as fetching live data or returning consistent, well-defined outputs.
8
8
 
9
- ## Creating a tool
9
+ ## Quickstart
10
10
 
11
- When creating tools, keep descriptions concise and focused on what the tool does, emphasizing its primary use case. Descriptive schema names can also help guide the agent on how to use the tool.
11
+ Import [`createTool`](https://mastra.ai/reference/tools/create-tool) from `@mastra/core/tools` and define a tool with an `id`, `description`, `inputSchema`, `outputSchema`, and `execute` function.
12
12
 
13
13
  This example shows how to create a tool that fetches weather data from an API. When the agent calls the tool, it provides the required input as defined by the tool's `inputSchema`. The tool accesses this data through its `inputData` parameter, which in this example includes the `location` used in the weather API query.
14
14
 
@@ -36,45 +36,11 @@ export const weatherTool = createTool({
36
36
  })
37
37
  ```
38
38
 
39
- ## Shaping output for the model
40
-
41
- Use `toModelOutput` when your tool returns rich structured data for your application, but you want the model to receive a smaller or multimodal representation. This keeps model context focused while preserving the full tool result in your app.
42
-
43
- ```typescript
44
- export const weatherTool = createTool({
45
- // ...other config
46
- execute: async ({ location }) => {
47
- const response = await fetch(`https://wttr.in/${location}?format=j1`)
48
- const data = await response.json()
49
-
50
- return {
51
- location,
52
- temperature: data.current_condition[0].temp_F,
53
- condition: data.current_condition[0].weatherDesc[0].value,
54
- weatherIconUrl: data.current_condition[0].weatherIconUrl[0].value,
55
- source: data,
56
- }
57
- },
58
- toModelOutput: output => {
59
- return {
60
- type: 'content',
61
- value: [
62
- {
63
- type: 'text',
64
- text: `${output.location}: ${output.temperature}F and ${output.condition}`,
65
- },
66
- { type: 'image-url', url: output.weatherIconUrl },
67
- ],
68
- }
69
- },
70
- })
71
- ```
72
-
73
- ## Adding tools to an agent
39
+ When creating tools, keep descriptions concise and focused on what the tool does, emphasizing its primary use case. Descriptive schema names can also help guide the agent on how to use the tool.
74
40
 
75
- To make a tool available to an agent, add it to `tools`. Mentioning available tools and their general purpose in the agent's system prompt helps the agent decide when to call a tool and when not to.
41
+ > **Note:** Visit the [`createTool`](https://mastra.ai/reference/tools/create-tool) reference for more information on available properties, configurations, and examples.
76
42
 
77
- An agent can use multiple tools to handle more complex tasks by delegating specific parts to individual tools. The agent decides which tools to use based on the user's message, the agent's instructions, and the tool descriptions and schemas.
43
+ To make a tool available to an agent, add it to the `tools` property on the `Agent` class. Mentioning available tools and their general purpose in the agent's system prompt helps the agent decide when to call a tool and when not to.
78
44
 
79
45
  ```typescript
80
46
  import { Agent } from '@mastra/core/agent'
@@ -84,60 +50,61 @@ export const weatherAgent = new Agent({
84
50
  id: 'weather-agent',
85
51
  name: 'Weather Agent',
86
52
  instructions: `
87
- You are a helpful weather assistant.
88
- Use the weatherTool to fetch current weather data.`,
53
+ You are a helpful weather assistant.
54
+ Use the weatherTool to fetch current weather data.`,
89
55
  model: 'openai/gpt-5.4',
90
56
  tools: { weatherTool },
91
57
  })
92
58
  ```
93
59
 
94
- ## Using multiple tools
60
+ ## Multiple tools
95
61
 
96
- When multiple tools are available, the agent may choose to use one, several, or none, depending on what's needed to answer the query.
62
+ An agent can use multiple tools to handle more complex tasks by delegating specific parts to individual tools. The agent decides which tools to use based on the user's message, the agent's instructions, and the tool descriptions and schemas.
97
63
 
98
64
  ```typescript
65
+ import { Agent } from '@mastra/core/agent'
99
66
  import { weatherTool } from '../tools/weather-tool'
100
- import { activitiesTool } from '../tools/activities-tool'
67
+ import { hazardsTool } from '../tools/hazards-tool'
101
68
 
102
69
  export const weatherAgent = new Agent({
103
70
  id: 'weather-agent',
104
71
  name: 'Weather Agent',
105
- tools: { weatherTool, activitiesTool },
72
+ instructions: `
73
+ You are a helpful weather assistant.
74
+ Use the weatherTool to fetch current weather data.
75
+ Use the hazardsTool to provide information about potential weather hazards.`,
76
+ model: 'openai/gpt-5.4',
77
+ tools: { weatherTool, hazardsTool },
106
78
  })
107
79
  ```
108
80
 
109
- ## Using agents as tools
81
+ ## Agents as tools
110
82
 
111
- Agents can be added to other agents through the `agents` configuration. When you add subagents, the parent agent becomes a supervisor. A supervisor can delegate tasks to subagents using the [supervisor pattern](https://mastra.ai/docs/agents/supervisor-agents), with support for delegation hooks, message filtering, iteration monitoring, and task completion scoring. Mastra automatically converts each subagent to a tool that the parent agent can call, named `agent-<agentName>`.
83
+ Add subagents through the `agents` configuration to create a [supervisor](https://mastra.ai/docs/agents/supervisor-agents). Mastra converts each subagent to a tool named `agent-<key>`. Include a `description` on each subagent so the supervisor knows when to delegate.
112
84
 
113
85
  ```typescript
114
86
  import { Agent } from '@mastra/core/agent'
115
87
 
116
- export const parentAgent = new Agent({
117
- id: 'parent-agent',
118
- name: 'Parent Agent',
119
- description: 'Take care in writing a good description here',
120
- instructions: `Instructions`,
88
+ const writer = new Agent({
89
+ id: 'writer',
90
+ name: 'Writer',
91
+ description: 'Drafts and edits written content',
92
+ instructions: 'You are a skilled writer.',
121
93
  model: 'openai/gpt-5.4',
122
- agents: {
123
- subAgent,
124
- },
125
94
  })
126
95
 
127
- const subAgent = new Agent({
128
- id: 'sub-agent',
129
- name: 'Sub Agent',
130
- description: 'Take care in writing a good description here',
131
- instructions: `Instructions`,
96
+ export const supervisor = new Agent({
97
+ id: 'supervisor',
98
+ name: 'Supervisor',
99
+ instructions: 'Coordinate the writer to produce content.',
132
100
  model: 'openai/gpt-5.4',
101
+ agents: { writer },
133
102
  })
134
103
  ```
135
104
 
136
- The subagent should include a `description` to help the parent agent understand when to use it. See the [`toolName` docs](#subagents-and-workflows-as-tools) to learn more about the tool naming scheme.
137
-
138
- ## Using workflows as tools
105
+ ## Workflows as tools
139
106
 
140
- Workflows can be added to agents through the `workflows` configuration. When you add a workflow, Mastra automatically converts it to a tool that the agent can call. The generated tool is named `workflow-<workflowName>` and uses the workflow's `inputSchema` and `outputSchema`.
107
+ Add workflows through the `workflows` configuration. Mastra converts each workflow to a tool named `workflow-<key>`, using the workflow's `inputSchema` and `outputSchema`. Include a `description` on the workflow so the agent knows when to trigger it.
141
108
 
142
109
  ```typescript
143
110
  import { Agent } from '@mastra/core/agent'
@@ -146,53 +113,66 @@ import { researchWorkflow } from '../workflows/research-workflow'
146
113
  export const researchAgent = new Agent({
147
114
  id: 'research-agent',
148
115
  name: 'Research Agent',
149
- instructions: `
150
- You are a research assistant.
151
- Use the research workflow to gather and compile information on topics.`,
116
+ instructions: 'You are a research assistant.',
152
117
  model: 'openai/gpt-5.4',
153
- tools: {
154
- weatherTool,
155
- },
156
- workflows: {
157
- researchWorkflow,
158
- },
118
+ workflows: { researchWorkflow },
159
119
  })
160
120
  ```
161
121
 
162
- The workflow should include a `description` to help the agent understand when to use it:
122
+ ## Shape output for the model
123
+
124
+ Use `toModelOutput` when your tool returns rich structured data for your application, but you want the model to receive a smaller or multimodal representation. This keeps model context focused while preserving the full tool result in your app.
163
125
 
164
126
  ```typescript
165
- import { createWorkflow } from '@mastra/core/workflows'
166
- import { z } from 'zod'
127
+ export const weatherTool = createTool({
128
+ execute: async ({ location }) => {
129
+ const response = await fetch(`https://wttr.in/${location}?format=j1`)
130
+ const data = await response.json()
167
131
 
168
- export const researchWorkflow = createWorkflow({
169
- id: 'research-workflow',
170
- description: 'Gathers information on a topic and compiles a summary report.',
171
- // Rest of the workflow...
172
- }).commit()
132
+ return {
133
+ location,
134
+ temperature: data.current_condition[0].temp_F,
135
+ condition: data.current_condition[0].weatherDesc[0].value,
136
+ weatherIconUrl: data.current_condition[0].weatherIconUrl[0].value,
137
+ source: data,
138
+ }
139
+ },
140
+ toModelOutput: output => {
141
+ return {
142
+ type: 'content',
143
+ value: [
144
+ {
145
+ type: 'text',
146
+ text: `${output.location}: ${output.temperature}F and ${output.condition}`,
147
+ },
148
+ { type: 'image-url', url: output.weatherIconUrl },
149
+ ],
150
+ }
151
+ },
152
+ })
173
153
  ```
174
154
 
175
- When the agent calls the workflow tool, it receives a response containing the workflow result and a `runId` that can be used to track the execution:
155
+ ## Control tool selection
156
+
157
+ Pass `toolChoice` or `activeTools` to `.generate()` or `.stream()` to control which tools the agent uses at runtime.
176
158
 
177
159
  ```typescript
178
- {
179
- result: { summary: "...", sources: ["..."] },
180
- runId: "abc-123"
181
- }
160
+ await agent.generate('Check the forecast', {
161
+ toolChoice: 'required',
162
+ activeTools: ['weatherTool'],
163
+ })
182
164
  ```
183
165
 
184
- See the [`toolName` docs](#subagents-and-workflows-as-tools) to learn more about the tool naming scheme.
166
+ > **Note:** See the [`Agent.generate()` reference](https://mastra.ai/reference/agents/generate) for all runtime options including `toolsets`, `clientTools`, and `prepareStep`.
185
167
 
186
- ## Controlling `toolName` in stream responses
168
+ ## Control `toolName` in stream responses
187
169
 
188
170
  The `toolName` in stream responses is determined by the **object key** you use, not the `id` property of the tool, agent, or workflow.
189
171
 
190
172
  ```typescript
191
- // Tool defined with id: "weather-tool"
192
173
  export const weatherTool = createTool({
193
- id: "weather-tool",
194
- // ...
195
- });
174
+ id: 'weather-tool',
175
+ })
196
176
 
197
177
  // Using the variable name as the key
198
178
  tools: { weatherTool }
@@ -234,15 +214,12 @@ Note that for subagents, you'll see two different identifiers in stream response
234
214
  - `toolName: "agent-weather"` in tool call events — the generated tool wrapper name
235
215
  - `id: "weather-agent"` in `data-tool-agent` chunks — the subagent's actual `id` property
236
216
 
237
- ## Tools with structured output
238
-
239
- When using tools with [structured output](https://mastra.ai/docs/agents/structured-output), some models don't support combining both features in the same API call. If your tools aren't being called when structured output is enabled, or you receive errors about incompatible options, see [Combining tools and structured output](https://mastra.ai/docs/agents/structured-output) for model compatibility information and workarounds.
240
-
241
217
  ## Related
242
218
 
243
- - [MCP Overview](https://mastra.ai/docs/mcp/overview)
244
- - [Dynamic Tool Search](https://mastra.ai/reference/processors/tool-search-processor) - Load tools on demand for agents with large tool libraries
245
- - [Structured Output](https://mastra.ai/docs/agents/structured-output)
246
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
247
- - [Supervisor Agents](https://mastra.ai/docs/agents/supervisor-agents)
248
- - [Request Context](https://mastra.ai/docs/server/request-context)
219
+ - [`createTool` reference](https://mastra.ai/reference/tools/create-tool)
220
+ - [`Agent.generate()` reference](https://mastra.ai/reference/agents/generate): Runtime options for tool selection, steps, and callbacks
221
+ - [MCP overview](https://mastra.ai/docs/mcp/overview)
222
+ - [Dynamic tool search](https://mastra.ai/reference/processors/tool-search-processor): Load tools on demand for agents with large tool libraries
223
+ - [Tools with structured output](https://mastra.ai/docs/agents/structured-output): Model compatibility when combining tools and structured output
224
+ - [Agent approval](https://mastra.ai/docs/agents/agent-approval)
225
+ - [Request context](https://mastra.ai/docs/server/request-context)
@@ -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
 
@@ -75,6 +75,8 @@ Date: 2026-01-15
75
75
 
76
76
  The compression is typically 5–40×. The Observer also tracks a **current task** and **suggested response** so the agent picks up where it left off.
77
77
 
78
+ If you enable `observation.threadTitle`, the Observer can also suggest a short thread title when the conversation topic meaningfully changes. Thread title generation is opt-in and updates the thread metadata, so apps like Mastra Code can show the latest title in thread lists and status UI.
79
+
78
80
  Example: an agent using Playwright MCP might see 50,000+ tokens per page snapshot. With OM, the Observer watches the interaction and creates a few hundred tokens of observations about what was on the page and what actions were taken. The agent stays on task without carrying every raw snapshot.
79
81
 
80
82
  ### Reflections