@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
@@ -1,32 +1,16 @@
1
1
  # Agent networks
2
2
 
3
- > **Agent Network Deprecated — Supervisor Pattern Recommended:** Agent networks are deprecated and will be removed in a future release. The [supervisor pattern](https://mastra.ai/docs/agents/supervisor-agents) using `agent.stream()` or `agent.generate()` is now the recommended approach for coordinating multiple agents. It provides the same multi-agent coordination capabilities as `.network()` with significant improvements:
3
+ > **Deprecated — Use supervisor agents:** Agent networks are deprecated and will be removed in a future major release. [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents) using `agent.stream()` or `agent.generate()` are now the recommended approach. It provides the same multi-agent coordination with better control, a simpler API, and easier debugging.
4
4
  >
5
- > - **Better control**: Iteration hooks, delegation hooks, and task completion scoring give you fine-grained control over execution
6
- > - **Simpler API**: Uses familiar `stream()` and `generate()` methods instead of a separate `.network()` API
7
- > - **More flexible**: Stop execution early, modify delegations, filter context, and provide feedback to guide the agent
8
- > - **Type-safe**: Full TypeScript support for all hooks and callbacks
9
- > - **Easier debugging**: Monitor progress with `onIterationComplete`, track delegations with `onDelegationStart`/`onDelegationComplete`
10
- >
11
- > See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade from `.network()`.
12
-
13
- Agent networks in Mastra coordinate multiple agents, workflows, and tools to handle tasks that aren't clearly defined upfront but can be inferred from the user's message or context. A top-level **routing agent** (a Mastra agent with other agents, workflows, and tools configured) uses an LLM to interpret the request and decide which primitives (subagents, workflows, or tools) to call, in what order, and with what data.
14
-
15
- ## When to use networks
5
+ > See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
16
6
 
17
- Use networks for complex tasks that require coordination across multiple primitives. Unlike workflows, which follow a predefined sequence, networks rely on LLM reasoning to interpret the request and decide what to run.
7
+ A **routing agent** uses an LLM to interpret a request and decide which primitives (subagents, workflows, or tools) to call, in what order, and with what data.
18
8
 
19
- ## Core principles
9
+ ## Create an agent network
20
10
 
21
- Mastra agent networks operate using these principles:
11
+ Configure a routing agent with `agents`, `workflows`, and `tools`. Memory is required as `.network()` uses it to store task history and determine when a task is complete.
22
12
 
23
- - Memory is required when using `.network()` and is used to store task history and determine when a task is complete.
24
- - Primitives are selected based on their descriptions. Clear, specific descriptions improve routing. For workflows and tools, the input schema helps determine the right inputs at runtime.
25
- - If multiple primitives have overlapping functionality, the agent favors the more specific one, using a combination of schema and descriptions to decide which to run.
26
-
27
- ## Creating an agent network
28
-
29
- An agent network is built around a top-level routing agent that delegates tasks to subagents, workflows, and tools defined in its configuration. Memory is configured on the routing agent using the `memory` option, and `instructions` define the agent's routing behavior.
13
+ Each primitive needs a clear `description` so the routing agent can decide which to use. For workflows and tools, `inputSchema` and `outputSchema` also help the router determine the right inputs.
30
14
 
31
15
  ```typescript
32
16
  import { Agent } from '@mastra/core/agent'
@@ -35,7 +19,6 @@ import { LibSQLStore } from '@mastra/libsql'
35
19
 
36
20
  import { researchAgent } from './research-agent'
37
21
  import { writingAgent } from './writing-agent'
38
-
39
22
  import { cityWorkflow } from '../workflows/city-workflow'
40
23
  import { weatherTool } from '../tools/weather-tool'
41
24
 
@@ -43,11 +26,7 @@ export const routingAgent = new Agent({
43
26
  id: 'routing-agent',
44
27
  name: 'Routing Agent',
45
28
  instructions: `
46
- You are a network of writers and researchers.
47
- The user will ask you to research a topic.
48
- Always respond with a complete report—no bullet points.
49
- Write in full paragraphs, like a blog post.
50
- Do not answer with incomplete or uncertain information.`,
29
+ You are a network of writers and researchers. The user will ask you to research a topic. Always respond with a complete report—no bullet points. Write in full paragraphs, like a blog post. Do not answer with incomplete or uncertain information.`,
51
30
  model: 'openai/gpt-5.4',
52
31
  agents: {
53
32
  researchAgent,
@@ -68,81 +47,11 @@ export const routingAgent = new Agent({
68
47
  })
69
48
  ```
70
49
 
71
- ### Writing descriptions for network primitives
72
-
73
- When configuring a Mastra agent network, each primitive (agent, workflow, or tool) needs a clear description to help the routing agent decide which to use. The routing agent uses each primitive's description and schema to determine what it does and how to use it. Clear descriptions and well-defined input and output schemas improve routing accuracy.
74
-
75
- #### Agent descriptions
76
-
77
- Each subagent in a network should include a clear `description` that explains what the agent does.
78
-
79
- ```typescript
80
- export const researchAgent = new Agent({
81
- id: 'research-agent',
82
- name: 'Research Agent',
83
- description: `This agent gathers concise research insights in bullet-point form.
84
- It's designed to extract key facts without generating full
85
- responses or narrative content.`,
86
- })
87
- ```
88
-
89
- ```typescript
90
- export const writingAgent = new Agent({
91
- id: 'writing-agent',
92
- name: 'Writing Agent',
93
- description: `This agent turns researched material into well-structured
94
- written content. It produces full-paragraph reports with no bullet points,
95
- suitable for use in articles, summaries, or blog posts.`,
96
- })
97
- ```
98
-
99
- #### Workflow descriptions
100
-
101
- Workflows in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
102
-
103
- ```typescript
104
- export const cityWorkflow = createWorkflow({
105
- id: 'city-workflow',
106
- description: `This workflow handles city-specific research tasks.
107
- It first gathers factual information about the city, then synthesizes
108
- that research into a full written report. Use it when the user input
109
- includes a city to be researched.`,
110
- inputSchema: z.object({
111
- city: z.string(),
112
- }),
113
- outputSchema: z.object({
114
- text: z.string(),
115
- }),
116
- })
117
- ```
118
-
119
- #### Tool descriptions
120
-
121
- Tools in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
122
-
123
- ```typescript
124
- export const weatherTool = createTool({
125
- id: 'weather-tool',
126
- description: ` Retrieves current weather information using the wttr.in API.
127
- Accepts a city or location name as input and returns a short weather summary.
128
- Use this tool whenever up-to-date weather data is requested.
129
- `,
130
- inputSchema: z.object({
131
- location: z.string(),
132
- }),
133
- outputSchema: z.object({
134
- weather: z.string(),
135
- }),
136
- })
137
- ```
138
-
139
- ## Calling agent networks
140
-
141
- Call a Mastra agent network using `.network()` with a user message. The method returns a stream of events that you can iterate over to track execution progress and retrieve the final result.
50
+ > **Note:** Subagents need a `description` on the `Agent` instance. Workflows and tools need a `description` plus `inputSchema` and `outputSchema` on `createWorkflow()` or `createTool()`.
142
51
 
143
- ### Agent example
52
+ ## Call the network
144
53
 
145
- In this example, the network interprets the message and would route the request to both the `researchAgent` and `writingAgent` to generate a complete response.
54
+ Call `.network()` with a user message. The method returns a stream of events you can iterate over.
146
55
 
147
56
  ```typescript
148
57
  const result = await routingAgent.network('Tell me three cool ways to use Mastra')
@@ -155,145 +64,119 @@ for await (const chunk of result) {
155
64
  }
156
65
  ```
157
66
 
158
- #### Agent output
159
-
160
- The following `chunk.type` events are emitted during this request:
161
-
162
- ```text
163
- routing-agent-start
164
- routing-agent-end
165
- agent-execution-start
166
- agent-execution-event-start
167
- agent-execution-event-step-start
168
- agent-execution-event-text-start
169
- agent-execution-event-text-delta
170
- agent-execution-event-text-end
171
- agent-execution-event-step-finish
172
- agent-execution-event-finish
173
- agent-execution-end
174
- network-execution-event-step-finish
175
- ```
176
-
177
- ## Workflow example
67
+ ## Structured output
178
68
 
179
- In this example, the routing agent recognizes the city name in the message and runs the `cityWorkflow`. The workflow defines steps that call the `researchAgent` to gather facts, then the `writingAgent` to generate the final text.
69
+ Pass `structuredOutput` to get typed, validated results. Use `objectStream` for partial objects as they generate.
180
70
 
181
71
  ```typescript
182
- const result = await routingAgent.network('Tell me some historical facts about London')
72
+ import { z } from 'zod'
183
73
 
184
- for await (const chunk of result) {
185
- console.log(chunk.type)
186
- if (chunk.type === 'network-execution-event-step-finish') {
187
- console.log(chunk.payload.result)
188
- }
189
- }
190
- ```
74
+ const resultSchema = z.object({
75
+ summary: z.string().describe('A brief summary of the findings'),
76
+ recommendations: z.array(z.string()).describe('List of recommendations'),
77
+ confidence: z.number().min(0).max(1).describe('Confidence score'),
78
+ })
191
79
 
192
- ### Workflow output
80
+ const stream = await routingAgent.network('Research AI trends', {
81
+ structuredOutput: { schema: resultSchema },
82
+ })
193
83
 
194
- The following `chunk.type` events are emitted during this request:
84
+ for await (const partial of stream.objectStream) {
85
+ console.log('Building result:', partial)
86
+ }
195
87
 
196
- ```text
197
- routing-agent-end
198
- workflow-execution-start
199
- workflow-execution-event-workflow-start
200
- workflow-execution-event-workflow-step-start
201
- workflow-execution-event-workflow-step-result
202
- workflow-execution-event-workflow-finish
203
- workflow-execution-end
204
- routing-agent-start
205
- network-execution-event-step-finish
88
+ const final = await stream.object
89
+ console.log(final?.summary)
206
90
  ```
207
91
 
208
- ### Tool example
92
+ ## Approve and decline tool calls
93
+
94
+ When a primitive requires approval, the stream emits an `agent-execution-approval` or `tool-execution-approval` chunk. Use `approveNetworkToolCall()` or `declineNetworkToolCall()` to respond.
209
95
 
210
- In this example, the routing agent skips the `researchAgent`, `writingAgent`, and `cityWorkflow`, and calls the `weatherTool` directly to complete the task.
96
+ Network approval uses snapshots to capture execution state. Ensure a [storage provider](https://mastra.ai/docs/memory/storage) is enabled in your Mastra instance.
211
97
 
212
98
  ```typescript
213
- const result = await routingAgent.network("What's the weather in London?")
99
+ const stream = await routingAgent.network('Perform some sensitive action', {
100
+ memory: {
101
+ thread: 'user-123',
102
+ resource: 'my-app',
103
+ },
104
+ })
214
105
 
215
- for await (const chunk of result) {
216
- console.log(chunk.type)
217
- if (chunk.type === 'network-execution-event-step-finish') {
218
- console.log(chunk.payload.result)
106
+ for await (const chunk of stream) {
107
+ if (chunk.type === 'agent-execution-approval' || chunk.type === 'tool-execution-approval') {
108
+ // Approve
109
+ const approvedStream = await routingAgent.approveNetworkToolCall(chunk.payload.toolCallId, {
110
+ runId: stream.runId,
111
+ memory: { thread: 'user-123', resource: 'my-app' },
112
+ })
113
+
114
+ for await (const c of approvedStream) {
115
+ if (c.type === 'network-execution-event-step-finish') {
116
+ console.log(c.payload.result)
117
+ }
118
+ }
219
119
  }
220
120
  }
221
121
  ```
222
122
 
223
- #### Tool output
123
+ To decline instead, call `declineNetworkToolCall()` with the same arguments.
224
124
 
225
- The following `chunk.type` events are emitted during this request:
125
+ ## Suspend and resume
226
126
 
227
- ```text
228
- routing-agent-start
229
- routing-agent-end
230
- tool-execution-start
231
- tool-execution-end
232
- network-execution-event-step-finish
233
- ```
234
-
235
- ## Structured output
236
-
237
- When you need typed, validated results from a network, use the `structuredOutput` option. After the network completes its task, it generates a structured response matching your schema.
127
+ When a primitive calls `suspend()`, the stream emits a suspension chunk (e.g., `tool-execution-suspended`). Use `resumeNetwork()` to provide the requested data and continue execution.
238
128
 
239
129
  ```typescript
240
- import { z } from 'zod'
241
-
242
- const resultSchema = z.object({
243
- summary: z.string().describe('A brief summary of the findings'),
244
- recommendations: z.array(z.string()).describe('List of recommendations'),
245
- confidence: z.number().min(0).max(1).describe('Confidence score'),
246
- })
247
-
248
- const stream = await routingAgent.network('Research AI trends', {
249
- structuredOutput: {
250
- schema: resultSchema,
251
- },
130
+ const stream = await routingAgent.network('Delete the old records', {
131
+ memory: { thread: 'user-123', resource: 'my-app' },
252
132
  })
253
133
 
254
- // Consume the stream
255
134
  for await (const chunk of stream) {
256
- if (chunk.type === 'network-object') {
257
- // Partial object during generation
258
- console.log('Partial:', chunk.payload.object)
259
- }
260
- if (chunk.type === 'network-object-result') {
261
- // Final structured object
262
- console.log('Final:', chunk.payload.object)
135
+ if (chunk.type === 'workflow-execution-suspended') {
136
+ console.log(chunk.payload.suspendPayload)
263
137
  }
264
138
  }
265
139
 
266
- // Get the typed result
267
- const result = await stream.object
268
- console.log(result?.summary)
269
- console.log(result?.recommendations)
270
- console.log(result?.confidence)
140
+ // Resume with user confirmation
141
+ const resumedStream = await routingAgent.resumeNetwork(
142
+ { confirmed: true },
143
+ {
144
+ runId: stream.runId,
145
+ memory: { thread: 'user-123', resource: 'my-app' },
146
+ },
147
+ )
148
+
149
+ for await (const chunk of resumedStream) {
150
+ if (chunk.type === 'network-execution-event-step-finish') {
151
+ console.log(chunk.payload.result)
152
+ }
153
+ }
271
154
  ```
272
155
 
273
- ### Streaming partial objects
156
+ ### Automatic resumption
274
157
 
275
- For real-time updates during structured output generation, use `objectStream`:
158
+ Set `autoResumeSuspendedTools` to `true` so the network resumes suspended primitives based on the user's next message. This creates a conversational flow where users provide the required information naturally.
276
159
 
277
160
  ```typescript
278
- const stream = await routingAgent.network('Analyze market data', {
279
- structuredOutput: { schema: resultSchema },
161
+ const stream = await routingAgent.network('Delete the old records', {
162
+ autoResumeSuspendedTools: true,
163
+ memory: { thread: 'user-123', resource: 'my-app' },
280
164
  })
165
+ ```
281
166
 
282
- // Stream partial objects as they're generated
283
- for await (const partial of stream.objectStream) {
284
- console.log('Building result:', partial)
285
- }
167
+ Requirements for automatic resumption:
286
168
 
287
- // Get the final typed result
288
- const final = await stream.object
289
- ```
169
+ - **Memory configured**: The agent needs memory to track suspended tools across messages.
170
+ - **Same thread**: The follow-up message must use the same `thread` and `resource` identifiers.
171
+ - **`resumeSchema` defined**: The tool must define a `resumeSchema` so the network can extract data from the user's message.
172
+
173
+ | | Manual (`resumeNetwork`) | Automatic (`autoResumeSuspendedTools`) |
174
+ | -------- | ---------------------------------------------- | ----------------------------------------- |
175
+ | Best for | Custom UIs with approval buttons | Chat-style interfaces |
176
+ | Control | Full control over resume timing and data | Network extracts data from user's message |
177
+ | Setup | Handle suspension chunks, call `resumeNetwork` | Set flag, define `resumeSchema` on tools |
290
178
 
291
179
  ## Related
292
180
 
293
- - [Supervisor Agents](https://mastra.ai/docs/agents/supervisor-agents)
294
- - [Migration: .network() to Supervisor Pattern](https://mastra.ai/guides/migrations/network-to-supervisor)
295
- - [Guide: Research Coordinator](https://mastra.ai/guides/guide/research-coordinator)
296
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
297
- - [Agent Approval](https://mastra.ai/docs/agents/agent-approval)
298
- - [Workflows Overview](https://mastra.ai/docs/workflows/overview)
299
- - [Request Context](https://mastra.ai/docs/server/request-context)
181
+ - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
182
+ - [Migration: `.network()` to supervisor agents](https://mastra.ai/guides/migrations/network-to-supervisor)