@mastra/libsql 1.7.1 → 1.7.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 1.7.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Added storage support for dataset targeting and experiment status fields. ([#14470](https://github.com/mastra-ai/mastra/pull/14470))
8
+ - Added `targetType` (text) and `targetIds` (jsonb) columns to datasets table for entity association
9
+ - Added `tags` (jsonb) column to datasets table for tag vocabulary
10
+ - Added `status` column to experiment results for review workflow tracking
11
+ - Added migration logic to add new columns to existing tables
12
+
13
+ - Updated dependencies [[`68ed4e9`](https://github.com/mastra-ai/mastra/commit/68ed4e9f118e8646b60a6112dabe854d0ef53902), [`085c1da`](https://github.com/mastra-ai/mastra/commit/085c1daf71b55a97b8ebad26623089e40055021c), [`4a75e10`](https://github.com/mastra-ai/mastra/commit/4a75e106bd31c283a1b3fe74c923610dcc46415b), [`085c1da`](https://github.com/mastra-ai/mastra/commit/085c1daf71b55a97b8ebad26623089e40055021c)]:
14
+ - @mastra/core@1.16.0-alpha.0
15
+
3
16
  ## 1.7.1
4
17
 
5
18
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-libsql
3
3
  description: Documentation for @mastra/libsql. Use when working with @mastra/libsql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/libsql"
6
- version: "1.7.1"
6
+ version: "1.7.2-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -17,9 +17,7 @@ Read the individual reference documents for detailed explanations and code examp
17
17
  ### Docs
18
18
 
19
19
  - [Agent approval](references/docs-agents-agent-approval.md) - Learn how to require approvals, suspend tool execution, and automatically resume suspended tools while keeping humans in control of agent workflows.
20
- - [Agent memory](references/docs-agents-agent-memory.md) - Learn how to add memory to agents to store message history and maintain context across interactions.
21
- - [Network approval](references/docs-agents-network-approval.md) - Learn how to require approvals, suspend execution, and resume suspended networks while keeping humans in control of agent network workflows.
22
- - [Agent networks](references/docs-agents-networks.md) - Learn how to coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
20
+ - [Agent networks](references/docs-agents-networks.md) - Coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
23
21
  - [Memory processors](references/docs-memory-memory-processors.md) - Learn how to use memory processors in Mastra to filter, trim, and transform messages before they're sent to the language model to manage context window limits.
24
22
  - [Message history](references/docs-memory-message-history.md) - Learn how to configure message history in Mastra to store recent messages from the current conversation.
25
23
  - [Memory overview](references/docs-memory-overview.md) - Learn how Mastra's memory system works with working memory, message history, semantic recall, and observational memory.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.1",
2
+ "version": "1.7.2-alpha.0",
3
3
  "package": "@mastra/libsql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -2,111 +2,99 @@
2
2
 
3
3
  Agents sometimes require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in workflows when calling tools that handle sensitive operations, like deleting resources or running long processes. With agent approval you can suspend a tool call before it executes so a human can approve or decline it, or let tools suspend themselves to request additional context from the user.
4
4
 
5
- ## How approval works
5
+ ## When to use agent approval
6
6
 
7
- Mastra offers two distinct mechanisms for pausing tool calls: **pre-execution approval** and **runtime suspension**.
7
+ - **Destructive or irreversible actions** such as deleting records, sending emails, or processing payments.
8
+ - **Cost-heavy operations** like calling expensive third-party APIs where you want to verify arguments first.
9
+ - **Conditional confirmation** where a tool starts executing and then discovers it needs the user to confirm or supply extra data before finishing.
8
10
 
9
- ### Pre-execution approval
11
+ ## Quickstart
10
12
 
11
- Pre-execution approval pauses a tool call _before_ its `execute` function runs. The LLM still decides which tool to call and provides arguments, but `execute` doesn't run until you explicitly approve.
13
+ Mark a tool with `requireApproval: true`, then check for the `tool-call-approval` chunk in the stream to approve or decline:
12
14
 
13
- Two flags control this, combined with OR logic. If _either_ is `true`, the call pauses:
15
+ ```typescript
16
+ import { Agent } from '@mastra/core/agent'
17
+ import { createTool } from '@mastra/core/tools'
18
+ import { z } from 'zod'
14
19
 
15
- | Flag | Where to set it | Scope |
16
- | --------------------------- | --------------------------------- | ------------------------------------------- |
17
- | `requireToolApproval: true` | `stream()` / `generate()` options | Pauses **every** tool call for that request |
18
- | `requireApproval: true` | `createTool()` definition | Pauses calls to **that specific tool** |
20
+ const deleteTool = createTool({
21
+ id: 'delete-record',
22
+ description: 'Delete a record by ID',
23
+ inputSchema: z.object({ id: z.string() }),
24
+ outputSchema: z.object({ deleted: z.boolean() }),
25
+ requireApproval: true,
26
+ execute: async ({ id }) => {
27
+ await db.delete(id)
28
+ return { deleted: true }
29
+ },
30
+ })
19
31
 
20
- The stream emits a `tool-call-approval` chunk when a call is paused this way. You then call `approveToolCall()` or `declineToolCall()` to continue.
32
+ const agent = new Agent({
33
+ id: 'my-agent',
34
+ name: 'My Agent',
35
+ model: 'openai/gpt-5-mini',
36
+ tools: { deleteTool },
37
+ })
21
38
 
22
- ### Runtime suspension with `suspend()`
39
+ const stream = await agent.stream('Delete record abc-123')
23
40
 
24
- A tool can also pause _during_ its `execute` function by calling `suspend()`. This is useful when the tool starts running and then discovers it needs additional user input or confirmation before it can finish.
41
+ for await (const chunk of stream.fullStream) {
42
+ if (chunk.type === 'tool-call-approval') {
43
+ const approved = await agent.approveToolCall({ runId: stream.runId })
44
+ for await (const c of approved.textStream) process.stdout.write(c)
45
+ }
46
+ }
47
+ ```
25
48
 
26
- The stream emits a `tool-call-suspended` chunk with a custom payload defined by the tool's `suspendSchema`. You resume by calling `resumeStream()` with data matching the tool's `resumeSchema`.
49
+ > **Note:** Agent approval uses snapshots to capture request state. Configure a [storage provider](https://mastra.ai/docs/memory/storage) on your Mastra instance or you'll see a "snapshot not found" error.
27
50
 
28
- ### Storage
51
+ ## How approval works
29
52
 
30
- Agent approval uses a snapshot to capture the state of the request. Ensure you've enabled a storage provider in your main Mastra instance. If storage isn't enabled you'll see an error relating to snapshot not found.
53
+ Mastra offers two distinct mechanisms for pausing tool calls: **pre-execution approval** and **runtime suspension**.
31
54
 
32
- ```typescript
33
- import { Mastra } from '@mastra/core/mastra'
34
- import { LibSQLStore } from '@mastra/libsql'
55
+ ### Pre-execution approval
35
56
 
36
- export const mastra = new Mastra({
37
- storage: new LibSQLStore({
38
- id: 'mastra-storage',
39
- url: ':memory:',
40
- }),
41
- })
42
- ```
57
+ Pre-execution approval pauses a tool call _before_ its `execute` function runs. The LLM still decides which tool to call and provides arguments, but `execute` doesn't run until you explicitly approve.
43
58
 
44
- ## Agent-level approval
59
+ Two flags control this, combined with OR logic. If _either_ is `true`, the call pauses:
45
60
 
46
- Pass `requireToolApproval: true` to `stream()` or `generate()` to pause every tool call before execution. The LLM still decides which tools to call and with what arguments but no tool runs until you approve or decline.
61
+ | Flag | Where to set it | Scope |
62
+ | --------------------------- | --------------------------------- | ------------------------------------------- |
63
+ | `requireToolApproval: true` | `stream()` / `generate()` options | Pauses **every** tool call for that request |
64
+ | `requireApproval: true` | `createTool()` definition | Pauses calls to **that specific tool** |
65
+
66
+ The stream emits a `tool-call-approval` chunk containing the `toolCallId`, `toolName`, and `args`. Call `approveToolCall()` or `declineToolCall()` with the stream's `runId` to continue:
47
67
 
48
68
  ```typescript
49
69
  const stream = await agent.stream("What's the weather in London?", {
50
70
  requireToolApproval: true,
51
71
  })
52
- ```
53
-
54
- When a tool call is paused, the stream emits a `tool-call-approval` chunk containing the `toolCallId`, `toolName`, and `args`. Use this to inspect the pending call and decide whether to approve or decline:
55
72
 
56
- ```typescript
57
73
  for await (const chunk of stream.fullStream) {
58
74
  if (chunk.type === 'tool-call-approval') {
59
75
  console.log('Tool:', chunk.payload.toolName)
60
76
  console.log('Args:', chunk.payload.args)
61
- }
62
- }
63
- ```
64
-
65
- ### Approving tool calls
66
77
 
67
- Call `approveToolCall()` on the agent with the `runId` of the stream to resume the suspended tool call and let it execute:
68
-
69
- ```typescript
70
- const handleApproval = async () => {
71
- const approvedStream = await agent.approveToolCall({ runId: stream.runId })
78
+ // Approve
79
+ const approved = await agent.approveToolCall({ runId: stream.runId })
80
+ for await (const c of approved.textStream) process.stdout.write(c)
72
81
 
73
- for await (const chunk of approvedStream.textStream) {
74
- process.stdout.write(chunk)
82
+ // Or decline
83
+ const declined = await agent.declineToolCall({ runId: stream.runId })
84
+ for await (const c of declined.textStream) process.stdout.write(c)
75
85
  }
76
- process.stdout.write('\n')
77
86
  }
78
87
  ```
79
88
 
80
- ### Declining tool calls
81
-
82
- Call `declineToolCall()` on the agent to skip the tool call. The agent continues without executing the tool and responds accordingly:
89
+ ### Runtime suspension with `suspend()`
83
90
 
84
- ```typescript
85
- const handleDecline = async () => {
86
- const declinedStream = await agent.declineToolCall({ runId: stream.runId })
91
+ A tool can also pause _during_ its `execute` function by calling `suspend()`. This is useful when the tool starts running and then discovers it needs additional user input or confirmation before it can finish.
87
92
 
88
- for await (const chunk of declinedStream.textStream) {
89
- process.stdout.write(chunk)
90
- }
91
- process.stdout.write('\n')
92
- }
93
- ```
93
+ The stream emits a `tool-call-suspended` chunk with a custom payload defined by the tool's `suspendSchema`. You resume by calling `resumeStream()` with data matching the tool's `resumeSchema`.
94
94
 
95
95
  ## Tool approval with `generate()`
96
96
 
97
- Tool approval also works with the `generate()` method for non-streaming use cases. When a tool requires approval during a `generate()` call, the method returns immediately instead of executing the tool.
98
-
99
- ### How it works
100
-
101
- When a tool requires approval during a `generate()` call, the response includes:
102
-
103
- - `finishReason: 'suspended'`: Indicates the agent is waiting for approval
104
- - `suspendPayload`: Contains tool call details (`toolCallId`, `toolName`, `args`)
105
- - `runId`: Needed to approve or decline the tool call
106
-
107
- ### Approving tool calls
108
-
109
- Use `approveToolCallGenerate()` to approve the tool call and get the final result:
97
+ Tool approval also works with `generate()` for non-streaming use cases. When a tool requires approval, `generate()` returns immediately with `finishReason: 'suspended'`, a `suspendPayload` containing the tool call details (`toolCallId`, `toolName`, `args`), and a `runId`:
110
98
 
111
99
  ```typescript
112
100
  const output = await agent.generate('Find user John', {
@@ -115,31 +103,19 @@ const output = await agent.generate('Find user John', {
115
103
 
116
104
  if (output.finishReason === 'suspended') {
117
105
  console.log('Tool requires approval:', output.suspendPayload.toolName)
118
- console.log('Arguments:', output.suspendPayload.args)
119
106
 
120
- // Approve the tool call and get the final result
107
+ // Approve
121
108
  const result = await agent.approveToolCallGenerate({
122
109
  runId: output.runId,
123
110
  toolCallId: output.suspendPayload.toolCallId,
124
111
  })
125
-
126
112
  console.log('Final result:', result.text)
127
- }
128
- ```
129
113
 
130
- ### Declining tool calls
131
-
132
- Use `declineToolCallGenerate()` to skip the tool call:
133
-
134
- ```typescript
135
- if (output.finishReason === 'suspended') {
114
+ // Or decline
136
115
  const result = await agent.declineToolCallGenerate({
137
116
  runId: output.runId,
138
117
  toolCallId: output.suspendPayload.toolCallId,
139
118
  })
140
-
141
- // Agent responds acknowledging the declined tool
142
- console.log(result.text)
143
119
  }
144
120
  ```
145
121
 
@@ -153,9 +129,11 @@ if (output.finishReason === 'suspended') {
153
129
  | Decline method | `declineToolCall({ runId })` | `declineToolCallGenerate({ runId, toolCallId })` |
154
130
  | Result | Stream to iterate | Full output object |
155
131
 
132
+ > **Note:** `toolCallId` is optional on all four methods. Pass it when multiple tool calls may be pending at the same time (common in supervisor agents). When omitted, the agent resumes the most recent suspended tool call.
133
+
156
134
  ## Tool-level approval
157
135
 
158
- Instead of pausing every tool call at the agent level, you can mark individual tools as requiring approval. This gives you granular control only specific tools pause, while others execute immediately.
136
+ Instead of pausing every tool call at the agent level, you can mark individual tools as requiring approval. This gives you granular control: only specific tools pause, while others execute immediately.
159
137
 
160
138
  ### Approval using `requireApproval`
161
139
 
@@ -205,9 +183,9 @@ const handleApproval = async () => {
205
183
  }
206
184
  ```
207
185
 
208
- ### Approval using `suspend`
186
+ ### Approval using `suspend()`
209
187
 
210
- With this approach, neither the agent nor the tool uses `requireApproval`. Instead, the tool's `execute` function calls `suspend` to pause at a specific point and return context or confirmation prompts to the user. This is useful when approval depends on runtime conditions rather than being unconditional.
188
+ With this approach, neither the agent nor the tool uses `requireApproval`. Instead, the tool's `execute` function calls `suspend()` to pause at a specific point and return context or confirmation prompts to the user. This is useful when approval depends on runtime conditions rather than being unconditional.
211
189
 
212
190
  ```typescript
213
191
  export const testToolB = createTool({
@@ -263,17 +241,12 @@ const handleResume = async () => {
263
241
 
264
242
  ## Automatic tool resumption
265
243
 
266
- When using tools that call `suspend()`, you can enable automatic resumption so the agent resumes suspended tools based on the user's next message. This creates a conversational flow where users provide the required information naturally, without your application needing to call `resumeStream()` explicitly.
267
-
268
- ### Enabling auto-resume
269
-
270
- Set `autoResumeSuspendedTools` to `true` in the agent's default options or when calling `stream()`:
244
+ When using tools that call `suspend()`, you can enable automatic resumption so the agent resumes suspended tools based on the user's next message. Set `autoResumeSuspendedTools` to `true` in the agent's default options or per-request:
271
245
 
272
246
  ```typescript
273
247
  import { Agent } from '@mastra/core/agent'
274
248
  import { Memory } from '@mastra/memory'
275
249
 
276
- // Option 1: In agent configuration
277
250
  const agent = new Agent({
278
251
  id: 'my-agent',
279
252
  name: 'My Agent',
@@ -285,72 +258,47 @@ const agent = new Agent({
285
258
  autoResumeSuspendedTools: true,
286
259
  },
287
260
  })
288
-
289
- // Option 2: Per-request
290
- const stream = await agent.stream("What's the weather?", {
291
- autoResumeSuspendedTools: true,
292
- })
293
261
  ```
294
262
 
295
- ### How it works
296
-
297
- When `autoResumeSuspendedTools` is enabled:
298
-
299
- 1. A tool suspends execution by calling `suspend()` with a payload (e.g., requesting more information)
300
-
301
- 2. The suspension is persisted to memory along with the conversation
302
-
303
- 3. When the user sends their next message on the same thread, the agent:
304
-
305
- - Detects the suspended tool from message history
306
- - Extracts `resumeData` from the user's message based on the tool's `resumeSchema`
307
- - Automatically resumes the tool with the extracted data
308
-
309
- ### Example
263
+ When enabled, the agent detects suspended tools from message history on the next user message, extracts `resumeData` based on the tool's `resumeSchema`, and automatically resumes the tool. The following example shows a complete conversational flow:
310
264
 
311
265
  ```typescript
312
266
  import { createTool } from '@mastra/core/tools'
313
267
  import { z } from 'zod'
314
268
 
315
- export const weatherTool = createTool({
316
- id: 'weather-info',
317
- description: 'Fetches weather information for a city',
269
+ const weatherTool = createTool({
270
+ id: 'weather-tool',
271
+ description: 'Fetches weather for a city',
272
+ inputSchema: z.object({
273
+ city: z.string(),
274
+ }),
275
+ outputSchema: z.object({
276
+ weather: z.string(),
277
+ }),
318
278
  suspendSchema: z.object({
319
279
  message: z.string(),
320
280
  }),
321
281
  resumeSchema: z.object({
322
282
  city: z.string(),
323
283
  }),
324
- execute: async (_inputData, context) => {
325
- // Check if this is a resume with data
326
- if (!context?.agent?.resumeData) {
327
- // First call - suspend and ask for the city
328
- return context?.agent?.suspend({
329
- message: 'What city do you want to know the weather for?',
330
- })
284
+ execute: async (inputData, context) => {
285
+ const { resumeData, suspend } = context?.agent ?? {}
286
+
287
+ // If no city provided, ask the user
288
+ if (!inputData.city && !resumeData?.city) {
289
+ return suspend?.({ message: 'What city do you want to know the weather for?' })
331
290
  }
332
291
 
333
- // Resume call - city was extracted from user's message
334
- const { city } = context.agent.resumeData
292
+ const city = resumeData?.city ?? inputData.city
335
293
  const response = await fetch(`https://wttr.in/${city}?format=3`)
336
294
  const weather = await response.text()
337
295
 
338
- return { city, weather }
339
- },
340
- })
341
-
342
- const agent = new Agent({
343
- id: 'my-agent',
344
- name: 'My Agent',
345
- instructions: 'You are a helpful assistant',
346
- model: 'openai/gpt-5-mini',
347
- tools: { weatherTool },
348
- memory: new Memory(),
349
- defaultOptions: {
350
- autoResumeSuspendedTools: true,
296
+ return { weather: `${city}: ${weather}` }
351
297
  },
352
298
  })
299
+ ```
353
300
 
301
+ ```typescript
354
302
  const stream = await agent.stream("What's the weather like?")
355
303
 
356
304
  for await (const chunk of stream.fullStream) {
@@ -359,18 +307,13 @@ for await (const chunk of stream.fullStream) {
359
307
  }
360
308
  }
361
309
 
362
- const handleResume = async () => {
363
- const resumedStream = await agent.stream('San Francisco')
364
-
365
- for await (const chunk of resumedStream.textStream) {
366
- process.stdout.write(chunk)
367
- }
368
- process.stdout.write('\n')
310
+ // User sends follow-up on the same thread
311
+ const resumedStream = await agent.stream('San Francisco')
312
+ for await (const chunk of resumedStream.textStream) {
313
+ process.stdout.write(chunk)
369
314
  }
370
315
  ```
371
316
 
372
- **Conversation flow:**
373
-
374
317
  ```text
375
318
  User: "What's the weather like?"
376
319
  Agent: "What city do you want to know the weather for?"
@@ -379,7 +322,7 @@ User: "San Francisco"
379
322
  Agent: "The weather in San Francisco is: San Francisco: ☀️ +72°F"
380
323
  ```
381
324
 
382
- The second message automatically resumes the suspended tool, the agent extracts `{ city: "San Francisco" }` from the user's message and passes it as `resumeData`.
325
+ The second message automatically resumes the suspended tool. The agent extracts `{ city: "San Francisco" }` from the user's message and passes it as `resumeData`.
383
326
 
384
327
  ### Requirements
385
328
 
@@ -398,21 +341,21 @@ For automatic tool resumption to work:
398
341
 
399
342
  Both approaches work with the same tool definitions. Automatic resumption triggers only when suspended tools exist in the message history and the user sends a new message on the same thread.
400
343
 
401
- ## Tool approval: Supervisor pattern
402
-
403
- The [supervisor pattern](https://mastra.ai/docs/agents/networks) lets a supervisor agent coordinate multiple subagents using `.stream()` or `.generate()`. The supervisor delegates tasks to subagents, which may use tools that require approval. When this happens, tool approvals properly propagate through the delegation chain — the approval request surfaces at the supervisor level where you can handle it, regardless of which subagent triggered it.
344
+ ## Tool approval: Supervisor agents
404
345
 
405
- ### How it works
346
+ A [supervisor agent](https://mastra.ai/docs/agents/supervisor-agents) coordinates multiple subagents using `.stream()` or `.generate()`. When a subagent calls a tool that requires approval, the request propagates up through the delegation chain and surfaces at the supervisor level:
406
347
 
407
- 1. The supervisor agent delegates a task to a subagent.
348
+ 1. The supervisor delegates a task to a subagent.
408
349
  2. The subagent calls a tool that has `requireApproval: true` or uses `suspend()`.
409
- 3. The approval request bubbles up through the delegation chain to the supervisor.
410
- 4. You handle the approval or decline at the supervisor level.
411
- 5. The decision propagates back down to the subagent, which continues or terminates accordingly.
350
+ 3. The approval request bubbles up to the supervisor.
351
+ 4. You approve or decline at the supervisor level.
352
+ 5. The decision propagates back down to the subagent.
412
353
 
413
- ### Example
354
+ Tool approvals also propagate through multiple levels of delegation. If a supervisor delegates to subagent A, which delegates to subagent B that has a tool with `requireApproval: true`, the approval request still surfaces at the top-level supervisor.
414
355
 
415
- The following example creates a subagent with a database lookup tool that requires approval. The supervisor delegates to this subagent, and when the tool triggers an approval request, it surfaces in the supervisor's stream as a `tool-call-approval` chunk. You then approve the tool call using `approveToolCall` with the stream's `runId`.
356
+ ### Approve and decline in supervisor agents
357
+
358
+ The example below creates a subagent with a tool requiring approval. When the tool triggers an approval request, it surfaces in the supervisor's stream as a `tool-call-approval` chunk:
416
359
 
417
360
  ```typescript
418
361
  import { Agent } from '@mastra/core/agent'
@@ -420,7 +363,6 @@ import { createTool } from '@mastra/core/tools'
420
363
  import { Memory } from '@mastra/memory'
421
364
  import { z } from 'zod'
422
365
 
423
- // subagent with approval-required tool
424
366
  const findUserTool = createTool({
425
367
  id: 'find-user',
426
368
  description: 'Finds user by ID in the database',
@@ -434,7 +376,7 @@ const findUserTool = createTool({
434
376
  email: z.string(),
435
377
  }),
436
378
  }),
437
- requireApproval: true, // Requires approval before execution
379
+ requireApproval: true,
438
380
  execute: async input => {
439
381
  const user = await database.findUser(input.userId)
440
382
  return { user }
@@ -459,7 +401,6 @@ const supervisorAgent = new Agent({
459
401
  memory: new Memory(),
460
402
  })
461
403
 
462
- // When supervisor delegates to dataAgent and tool requires approval
463
404
  const stream = await supervisorAgent.stream('Find user with ID 12345')
464
405
 
465
406
  for await (const chunk of stream.fullStream) {
@@ -473,40 +414,22 @@ for await (const chunk of stream.fullStream) {
473
414
  toolCallId: chunk.payload.toolCallId,
474
415
  })
475
416
 
476
- // Process resumed stream
477
417
  for await (const resumeChunk of resumeStream.textStream) {
478
418
  process.stdout.write(resumeChunk)
479
419
  }
480
- }
481
- }
482
- ```
483
420
 
484
- ### Declining tool calls in supervisor pattern
485
-
486
- Decline tool calls at the supervisor level by calling `declineToolCall`. The supervisor responds acknowledging the declined tool without executing it:
487
-
488
- ```typescript
489
- for await (const chunk of stream.fullStream) {
490
- if (chunk.type === 'tool-call-approval') {
491
- console.log('Declining tool call:', chunk.payload.toolName)
492
-
493
- // Decline the tool call
421
+ // To decline instead, use:
494
422
  const declineStream = await supervisorAgent.declineToolCall({
495
423
  runId: stream.runId,
496
424
  toolCallId: chunk.payload.toolCallId,
497
425
  })
498
-
499
- // The supervisor responds acknowledging the declined tool
500
- for await (const declineChunk of declineStream.textStream) {
501
- process.stdout.write(declineChunk)
502
- }
503
426
  }
504
427
  }
505
428
  ```
506
429
 
507
- ### Using `suspend()` in supervisor pattern
430
+ ### Use `suspend()` in supervisor agents
508
431
 
509
- Tools can also use [`suspend()`](#approval-using-suspend) to pause execution and return context to the user. This approach works through the supervisor delegation chain the same way `requireApproval` does the suspension surfaces at the supervisor level:
432
+ Tools can also use [`suspend()`](#approval-using-suspend) to pause execution and return context to the user. This approach works through the supervisor delegation chain the same way `requireApproval` does: the suspension surfaces at the supervisor level:
510
433
 
511
434
  ```typescript
512
435
  const conditionalTool = createTool({
@@ -534,8 +457,10 @@ const conditionalTool = createTool({
534
457
  return await performOperation(input.operation)
535
458
  },
536
459
  })
460
+ ```
537
461
 
538
- // When using this tool through a subagent in supervisor pattern
462
+ ```typescript
463
+ // When using this tool through a subagent in supervisor agents
539
464
  for await (const chunk of stream.fullStream) {
540
465
  if (chunk.type === 'tool-call-suspended') {
541
466
  console.log('Tool suspended:', chunk.payload.suspendPayload.message)
@@ -553,9 +478,9 @@ for await (const chunk of stream.fullStream) {
553
478
  }
554
479
  ```
555
480
 
556
- ### Tool approval with `generate()`
481
+ ### Supervisor approval with `generate()`
557
482
 
558
- Tool approval propagation also works with `generate()` in supervisor pattern:
483
+ Tool approval propagation also works with `generate()` in supervisor agents:
559
484
 
560
485
  ```typescript
561
486
  const output = await supervisorAgent.generate('Find user with ID 12345', {
@@ -575,14 +500,10 @@ if (output.finishReason === 'suspended') {
575
500
  }
576
501
  ```
577
502
 
578
- ### Multi-level delegation
579
-
580
- Tool approvals propagate through multiple levels of delegation. For example, if a supervisor delegates to subagent A, which in turn delegates to subagent B that has a tool with `requireApproval: true`, the approval request still surfaces at the top-level supervisor. You handle the approval or decline there, and the result flows back down through the entire delegation chain to the tool that requested it.
581
-
582
503
  ## Related
583
504
 
584
- - [Using Tools](https://mastra.ai/docs/agents/using-tools)
585
- - [Agent Overview](https://mastra.ai/docs/agents/overview)
586
- - [Tools Overview](https://mastra.ai/docs/mcp/overview)
587
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
588
- - [Request Context](https://mastra.ai/docs/server/request-context)
505
+ - [Tools](https://mastra.ai/docs/agents/using-tools)
506
+ - [Agent overview](https://mastra.ai/docs/agents/overview)
507
+ - [MCP overview](https://mastra.ai/docs/mcp/overview)
508
+ - [Memory](https://mastra.ai/docs/memory/overview)
509
+ - [Request context](https://mastra.ai/docs/server/request-context)