@mastra/libsql 0.0.0-workflow-timeout-issue-20260220185702 → 0.0.0-workflow-graph-crash-20260527191009

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 (73) hide show
  1. package/CHANGELOG.md +1085 -3
  2. package/LICENSE.md +15 -0
  3. package/dist/docs/SKILL.md +18 -19
  4. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  5. package/dist/docs/references/docs-agent-builder-deploying.md +121 -0
  6. package/dist/docs/references/docs-agent-builder-overview.md +97 -0
  7. package/dist/docs/references/docs-agents-agent-approval.md +336 -202
  8. package/dist/docs/references/docs-agents-networks.md +107 -215
  9. package/dist/docs/references/docs-memory-memory-processors.md +86 -88
  10. package/dist/docs/references/docs-memory-message-history.md +71 -63
  11. package/dist/docs/references/docs-memory-multi-user-threads.md +206 -0
  12. package/dist/docs/references/docs-memory-overview.md +221 -24
  13. package/dist/docs/references/docs-memory-semantic-recall.md +162 -75
  14. package/dist/docs/references/docs-memory-storage.md +72 -73
  15. package/dist/docs/references/docs-memory-working-memory.md +62 -62
  16. package/dist/docs/references/docs-rag-retrieval.md +132 -135
  17. package/dist/docs/references/docs-workflows-snapshots.md +31 -31
  18. package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +36 -36
  19. package/dist/docs/references/reference-core-getMemory.md +15 -16
  20. package/dist/docs/references/reference-core-listMemory.md +17 -18
  21. package/dist/docs/references/reference-core-mastra-class.md +37 -27
  22. package/dist/docs/references/reference-memory-memory-class.md +41 -43
  23. package/dist/docs/references/reference-storage-composite.md +65 -55
  24. package/dist/docs/references/reference-storage-dynamodb.md +36 -36
  25. package/dist/docs/references/reference-storage-libsql.md +27 -27
  26. package/dist/docs/references/reference-vectors-libsql.md +72 -72
  27. package/dist/index.cjs +7896 -3257
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +7888 -3259
  30. package/dist/index.js.map +1 -1
  31. package/dist/storage/db/index.d.ts +14 -1
  32. package/dist/storage/db/index.d.ts.map +1 -1
  33. package/dist/storage/db/utils.d.ts +16 -0
  34. package/dist/storage/db/utils.d.ts.map +1 -1
  35. package/dist/storage/domains/agents/index.d.ts.map +1 -1
  36. package/dist/storage/domains/background-tasks/index.d.ts +18 -0
  37. package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
  38. package/dist/storage/domains/blobs/index.d.ts +17 -0
  39. package/dist/storage/domains/blobs/index.d.ts.map +1 -0
  40. package/dist/storage/domains/channels/index.d.ts +20 -0
  41. package/dist/storage/domains/channels/index.d.ts.map +1 -0
  42. package/dist/storage/domains/datasets/index.d.ts +43 -0
  43. package/dist/storage/domains/datasets/index.d.ts.map +1 -0
  44. package/dist/storage/domains/experiments/index.d.ts +31 -0
  45. package/dist/storage/domains/experiments/index.d.ts.map +1 -0
  46. package/dist/storage/domains/favorites/index.d.ts +17 -0
  47. package/dist/storage/domains/favorites/index.d.ts.map +1 -0
  48. package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -1
  49. package/dist/storage/domains/mcp-servers/index.d.ts +26 -0
  50. package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
  51. package/dist/storage/domains/memory/index.d.ts +7 -3
  52. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  53. package/dist/storage/domains/observability/index.d.ts +2 -1
  54. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  55. package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
  56. package/dist/storage/domains/schedules/index.d.ts +19 -0
  57. package/dist/storage/domains/schedules/index.d.ts.map +1 -0
  58. package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -1
  59. package/dist/storage/domains/skills/index.d.ts +26 -0
  60. package/dist/storage/domains/skills/index.d.ts.map +1 -0
  61. package/dist/storage/domains/workflows/index.d.ts +1 -0
  62. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  63. package/dist/storage/domains/workspaces/index.d.ts +26 -0
  64. package/dist/storage/domains/workspaces/index.d.ts.map +1 -0
  65. package/dist/storage/index.d.ts +38 -1
  66. package/dist/storage/index.d.ts.map +1 -1
  67. package/dist/vector/index.d.ts +14 -1
  68. package/dist/vector/index.d.ts.map +1 -1
  69. package/package.json +12 -12
  70. package/dist/docs/references/docs-agents-agent-memory.md +0 -212
  71. package/dist/docs/references/docs-agents-network-approval.md +0 -275
  72. package/dist/docs/references/docs-observability-overview.md +0 -70
  73. package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -211
@@ -1,44 +1,33 @@
1
- # Agent Networks
1
+ # Agent networks
2
2
 
3
- Agent networks in Mastra coordinate multiple agents, workflows, and tools to handle tasks that aren't clearly defined upfront but can be inferred from the user's message or context. A top-level **routing agent** (a Mastra agent with other agents, workflows, and tools configured) uses an LLM to interpret the request and decide which primitives (subagents, workflows, or tools) to call, in what order, and with what data.
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
+ >
5
+ > See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
4
6
 
5
- ## When to use networks
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.
6
8
 
7
- 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.
9
+ ## Create an agent network
8
10
 
9
- ## Core 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.
10
12
 
11
- Mastra agent networks operate using these principles:
12
-
13
- - Memory is required when using `.network()` and is used to store task history and determine when a task is complete.
14
- - 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.
15
- - 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.
16
-
17
- ## Creating an agent network
18
-
19
- An agent network is built around a top-level routing agent that delegates tasks to subagents, workflows, and tools defined in its configuration. Memory is configured on the routing agent using the `memory` option, and `instructions` define the agent's routing behavior.
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.
20
14
 
21
15
  ```typescript
22
- import { Agent } from "@mastra/core/agent";
23
- import { Memory } from "@mastra/memory";
24
- import { LibSQLStore } from "@mastra/libsql";
25
-
26
- import { researchAgent } from "./research-agent";
27
- import { writingAgent } from "./writing-agent";
16
+ import { Agent } from '@mastra/core/agent'
17
+ import { Memory } from '@mastra/memory'
18
+ import { LibSQLStore } from '@mastra/libsql'
28
19
 
29
- import { cityWorkflow } from "../workflows/city-workflow";
30
- import { weatherTool } from "../tools/weather-tool";
20
+ import { researchAgent } from './research-agent'
21
+ import { writingAgent } from './writing-agent'
22
+ import { cityWorkflow } from '../workflows/city-workflow'
23
+ import { weatherTool } from '../tools/weather-tool'
31
24
 
32
25
  export const routingAgent = new Agent({
33
- id: "routing-agent",
34
- name: "Routing Agent",
26
+ id: 'routing-agent',
27
+ name: 'Routing Agent',
35
28
  instructions: `
36
- You are a network of writers and researchers.
37
- The user will ask you to research a topic.
38
- Always respond with a complete report—no bullet points.
39
- Write in full paragraphs, like a blog post.
40
- Do not answer with incomplete or uncertain information.`,
41
- model: "openai/gpt-5.1",
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.`,
30
+ model: 'openai/gpt-5.4',
42
31
  agents: {
43
32
  researchAgent,
44
33
  writingAgent,
@@ -52,239 +41,142 @@ export const routingAgent = new Agent({
52
41
  memory: new Memory({
53
42
  storage: new LibSQLStore({
54
43
  id: 'mastra-storage',
55
- url: "file:../mastra.db",
44
+ url: 'file:../mastra.db',
56
45
  }),
57
46
  }),
58
- });
47
+ })
59
48
  ```
60
49
 
61
- ### Writing descriptions for network primitives
50
+ > **Note:** Subagents need a `description` on the `Agent` instance. Workflows and tools need a `description` plus `inputSchema` and `outputSchema` on `createWorkflow()` or `createTool()`.
62
51
 
63
- 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.
52
+ ## Call the network
64
53
 
65
- #### Agent descriptions
66
-
67
- Each subagent in a network should include a clear `description` that explains what the agent does.
54
+ Call `.network()` with a user message. The method returns a stream of events you can iterate over.
68
55
 
69
56
  ```typescript
70
- export const researchAgent = new Agent({
71
- id: "research-agent",
72
- name: "Research Agent",
73
- description: `This agent gathers concise research insights in bullet-point form.
74
- It's designed to extract key facts without generating full
75
- responses or narrative content.`,
76
- });
77
- ```
57
+ const result = await routingAgent.network('Tell me three cool ways to use Mastra')
78
58
 
79
- ```typescript
80
- export const writingAgent = new Agent({
81
- id: "writing-agent",
82
- name: "Writing Agent",
83
- description: `This agent turns researched material into well-structured
84
- written content. It produces full-paragraph reports with no bullet points,
85
- suitable for use in articles, summaries, or blog posts.`,
86
- });
87
- ```
88
-
89
- #### Workflow descriptions
90
-
91
- Workflows in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
92
-
93
- ```typescript
94
- export const cityWorkflow = createWorkflow({
95
- id: "city-workflow",
96
- description: `This workflow handles city-specific research tasks.
97
- It first gathers factual information about the city, then synthesizes
98
- that research into a full written report. Use it when the user input
99
- includes a city to be researched.`,
100
- inputSchema: z.object({
101
- city: z.string(),
102
- }),
103
- outputSchema: z.object({
104
- text: z.string(),
105
- }),
106
- });
59
+ for await (const chunk of result) {
60
+ console.log(chunk.type)
61
+ if (chunk.type === 'network-execution-event-step-finish') {
62
+ console.log(chunk.payload.result)
63
+ }
64
+ }
107
65
  ```
108
66
 
109
- #### Tool descriptions
67
+ ## Structured output
110
68
 
111
- Tools in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
69
+ Pass `structuredOutput` to get typed, validated results. Use `objectStream` for partial objects as they generate.
112
70
 
113
71
  ```typescript
114
- export const weatherTool = createTool({
115
- id: "weather-tool",
116
- description: ` Retrieves current weather information using the wttr.in API.
117
- Accepts a city or location name as input and returns a short weather summary.
118
- Use this tool whenever up-to-date weather data is requested.
119
- `,
120
- inputSchema: z.object({
121
- location: z.string(),
122
- }),
123
- outputSchema: z.object({
124
- weather: z.string(),
125
- }),
126
- });
127
- ```
128
-
129
- ## Calling agent networks
130
-
131
- 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.
72
+ import { z } from 'zod'
132
73
 
133
- ### Agent example
134
-
135
- In this example, the network interprets the message and would route the request to both the `researchAgent` and `writingAgent` to generate a complete response.
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
+ })
136
79
 
137
- ```typescript
138
- const result = await routingAgent.network(
139
- "Tell me three cool ways to use Mastra",
140
- );
80
+ const stream = await routingAgent.network('Research AI trends', {
81
+ structuredOutput: { schema: resultSchema },
82
+ })
141
83
 
142
- for await (const chunk of result) {
143
- console.log(chunk.type);
144
- if (chunk.type === "network-execution-event-step-finish") {
145
- console.log(chunk.payload.result);
146
- }
84
+ for await (const partial of stream.objectStream) {
85
+ console.log('Building result:', partial)
147
86
  }
148
- ```
149
87
 
150
- #### Agent output
151
-
152
- The following `chunk.type` events are emitted during this request:
153
-
154
- ```text
155
- routing-agent-start
156
- routing-agent-end
157
- agent-execution-start
158
- agent-execution-event-start
159
- agent-execution-event-step-start
160
- agent-execution-event-text-start
161
- agent-execution-event-text-delta
162
- agent-execution-event-text-end
163
- agent-execution-event-step-finish
164
- agent-execution-event-finish
165
- agent-execution-end
166
- network-execution-event-step-finish
88
+ const final = await stream.object
89
+ console.log(final?.summary)
167
90
  ```
168
91
 
169
- ## Workflow 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.
170
95
 
171
- 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.
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.
172
97
 
173
98
  ```typescript
174
- const result = await routingAgent.network(
175
- "Tell me some historical facts about London",
176
- );
99
+ const stream = await routingAgent.network('Perform some sensitive action', {
100
+ memory: {
101
+ thread: 'user-123',
102
+ resource: 'my-app',
103
+ },
104
+ })
177
105
 
178
- for await (const chunk of result) {
179
- console.log(chunk.type);
180
- if (chunk.type === "network-execution-event-step-finish") {
181
- 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
+ }
182
119
  }
183
120
  }
184
121
  ```
185
122
 
186
- #### Workflow output
187
-
188
- The following `chunk.type` events are emitted during this request:
189
-
190
- ```text
191
- routing-agent-end
192
- workflow-execution-start
193
- workflow-execution-event-workflow-start
194
- workflow-execution-event-workflow-step-start
195
- workflow-execution-event-workflow-step-result
196
- workflow-execution-event-workflow-finish
197
- workflow-execution-end
198
- routing-agent-start
199
- network-execution-event-step-finish
200
- ```
123
+ To decline instead, call `declineNetworkToolCall()` with the same arguments.
201
124
 
202
- ### Tool example
125
+ ## Suspend and resume
203
126
 
204
- In this example, the routing agent skips the `researchAgent`, `writingAgent`, and `cityWorkflow`, and calls the `weatherTool` directly to complete the task.
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.
205
128
 
206
129
  ```typescript
207
- const result = await routingAgent.network("What's the weather in London?");
130
+ const stream = await routingAgent.network('Delete the old records', {
131
+ memory: { thread: 'user-123', resource: 'my-app' },
132
+ })
208
133
 
209
- for await (const chunk of result) {
210
- console.log(chunk.type);
211
- if (chunk.type === "network-execution-event-step-finish") {
212
- console.log(chunk.payload.result);
134
+ for await (const chunk of stream) {
135
+ if (chunk.type === 'workflow-execution-suspended') {
136
+ console.log(chunk.payload.suspendPayload)
213
137
  }
214
138
  }
215
- ```
216
-
217
- #### Tool output
218
-
219
- The following `chunk.type` events are emitted during this request:
220
-
221
- ```text
222
- routing-agent-start
223
- routing-agent-end
224
- tool-execution-start
225
- tool-execution-end
226
- network-execution-event-step-finish
227
- ```
228
139
 
229
- ## Structured output
230
-
231
- 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.
232
-
233
- ```typescript
234
- import { z } from "zod";
235
-
236
- const resultSchema = z.object({
237
- summary: z.string().describe("A brief summary of the findings"),
238
- recommendations: z.array(z.string()).describe("List of recommendations"),
239
- confidence: z.number().min(0).max(1).describe("Confidence score"),
240
- });
241
-
242
- const stream = await routingAgent.network("Research AI trends", {
243
- structuredOutput: {
244
- schema: resultSchema,
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' },
245
146
  },
246
- });
147
+ )
247
148
 
248
- // Consume the stream
249
- for await (const chunk of stream) {
250
- if (chunk.type === "network-object") {
251
- // Partial object during generation
252
- console.log("Partial:", chunk.payload.object);
253
- }
254
- if (chunk.type === "network-object-result") {
255
- // Final structured object
256
- console.log("Final:", chunk.payload.object);
149
+ for await (const chunk of resumedStream) {
150
+ if (chunk.type === 'network-execution-event-step-finish') {
151
+ console.log(chunk.payload.result)
257
152
  }
258
153
  }
259
-
260
- // Get the typed result
261
- const result = await stream.object;
262
- console.log(result?.summary);
263
- console.log(result?.recommendations);
264
- console.log(result?.confidence);
265
154
  ```
266
155
 
267
- ### Streaming partial objects
156
+ ### Automatic resumption
268
157
 
269
- 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.
270
159
 
271
160
  ```typescript
272
- const stream = await routingAgent.network("Analyze market data", {
273
- structuredOutput: { schema: resultSchema },
274
- });
161
+ const stream = await routingAgent.network('Delete the old records', {
162
+ autoResumeSuspendedTools: true,
163
+ memory: { thread: 'user-123', resource: 'my-app' },
164
+ })
165
+ ```
275
166
 
276
- // Stream partial objects as they're generated
277
- for await (const partial of stream.objectStream) {
278
- console.log("Building result:", partial);
279
- }
167
+ Requirements for automatic resumption:
280
168
 
281
- // Get the final typed result
282
- const final = await stream.object;
283
- ```
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 |
284
178
 
285
179
  ## Related
286
180
 
287
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
288
- - [Workflows Overview](https://mastra.ai/docs/workflows/overview)
289
- - [Request Context](https://mastra.ai/docs/server/request-context)
290
- - [Supervisor example](https://github.com/mastra-ai/mastra/tree/main/examples/supervisor-agent)
181
+ - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
182
+ - [Migration: `.network()` to supervisor agents](https://mastra.ai/guides/migrations/network-to-supervisor)