@mastra/libsql 1.6.0 → 1.6.1-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.
Files changed (32) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/index.cjs +17 -8
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +17 -8
  5. package/dist/index.js.map +1 -1
  6. package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
  7. package/package.json +4 -4
  8. package/dist/docs/SKILL.md +0 -50
  9. package/dist/docs/assets/SOURCE_MAP.json +0 -6
  10. package/dist/docs/references/docs-agents-agent-approval.md +0 -377
  11. package/dist/docs/references/docs-agents-agent-memory.md +0 -212
  12. package/dist/docs/references/docs-agents-network-approval.md +0 -275
  13. package/dist/docs/references/docs-agents-networks.md +0 -290
  14. package/dist/docs/references/docs-memory-memory-processors.md +0 -316
  15. package/dist/docs/references/docs-memory-message-history.md +0 -260
  16. package/dist/docs/references/docs-memory-overview.md +0 -45
  17. package/dist/docs/references/docs-memory-semantic-recall.md +0 -272
  18. package/dist/docs/references/docs-memory-storage.md +0 -261
  19. package/dist/docs/references/docs-memory-working-memory.md +0 -400
  20. package/dist/docs/references/docs-observability-overview.md +0 -70
  21. package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -211
  22. package/dist/docs/references/docs-rag-retrieval.md +0 -521
  23. package/dist/docs/references/docs-workflows-snapshots.md +0 -238
  24. package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +0 -140
  25. package/dist/docs/references/reference-core-getMemory.md +0 -50
  26. package/dist/docs/references/reference-core-listMemory.md +0 -56
  27. package/dist/docs/references/reference-core-mastra-class.md +0 -66
  28. package/dist/docs/references/reference-memory-memory-class.md +0 -147
  29. package/dist/docs/references/reference-storage-composite.md +0 -235
  30. package/dist/docs/references/reference-storage-dynamodb.md +0 -282
  31. package/dist/docs/references/reference-storage-libsql.md +0 -135
  32. package/dist/docs/references/reference-vectors-libsql.md +0 -305
@@ -1,275 +0,0 @@
1
- # Network Approval
2
-
3
- Agent networks can require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in individual agents and workflows. When a tool, subagent, or workflow within a network requires approval or suspends execution, the network pauses and emits events that allow your application to collect user input before resuming.
4
-
5
- ## Storage
6
-
7
- Network approval uses snapshots to capture execution state. Ensure you've enabled a storage provider in your Mastra instance. If storage isn't enabled you'll see an error relating to snapshot not found.
8
-
9
- ```typescript
10
- import { Mastra } from "@mastra/core/mastra";
11
- import { LibSQLStore } from "@mastra/libsql";
12
-
13
- export const mastra = new Mastra({
14
- storage: new LibSQLStore({
15
- id: "mastra-storage",
16
- url: ":memory:"
17
- })
18
- });
19
- ```
20
-
21
- ## Approving network tool calls
22
-
23
- When a tool within a network has `requireApproval: true`, the network stream emits an `agent-execution-approval` chunk and pauses. To allow the tool to execute, call `approveNetworkToolCall` with the `runId`.
24
-
25
- ```typescript
26
- const stream = await routingAgent.network("Process this query", {
27
- memory: {
28
- thread: "user-123",
29
- resource: "my-app"
30
- }
31
- });
32
-
33
- let runId: string;
34
-
35
- for await (const chunk of stream) {
36
- runId = stream.runId;
37
- // if the requirApproval is in a tool inside a subAgent or the subAgent has requireToolApproval set to true
38
- if (chunk.type === "agent-execution-approval") {
39
- console.log("Tool requires approval:", chunk.payload);
40
- }
41
-
42
- // if the requirApproval is in a tool directly in the network agent
43
- if (chunk.type === "tool-execution-approval") {
44
- console.log("Tool requires approval:", chunk.payload);
45
- }
46
- }
47
-
48
- // Approve and resume execution
49
- const approvedStream = await routingAgent.approveNetworkToolCall({
50
- runId,
51
- memory: {
52
- thread: "user-123",
53
- resource: "my-app"
54
- }
55
- });
56
-
57
- for await (const chunk of approvedStream) {
58
- if (chunk.type === "network-execution-event-step-finish") {
59
- console.log(chunk.payload.result);
60
- }
61
- }
62
- ```
63
-
64
- ## Declining network tool calls
65
-
66
- To decline a pending tool call and prevent execution, call `declineNetworkToolCall`. The network continues without executing the tool.
67
-
68
- ```typescript
69
- const declinedStream = await routingAgent.declineNetworkToolCall({
70
- runId,
71
- memory: {
72
- thread: "user-123",
73
- resource: "my-app"
74
- }
75
- });
76
-
77
- for await (const chunk of declinedStream) {
78
- if (chunk.type === "network-execution-event-step-finish") {
79
- console.log(chunk.payload.result);
80
- }
81
- }
82
- ```
83
-
84
- ## Resuming suspended networks
85
-
86
- When a primitive in the network calls `suspend()`, the stream emits an `agent-execution-suspended`/`tool-execution-suspended`/`workflow-execution-suspended` chunk with a `suspendPayload` containing context from the primitive. Use `resumeNetwork` to provide the data requested by the primitive and continue execution.
87
-
88
- ```typescript
89
- import { createTool } from "@mastra/core/tools";
90
- import { z } from "zod";
91
-
92
- const confirmationTool = createTool({
93
- id: "confirmation-tool",
94
- description: "Requests user confirmation before proceeding",
95
- inputSchema: z.object({
96
- action: z.string()
97
- }),
98
- outputSchema: z.object({
99
- confirmed: z.boolean(),
100
- action: z.string()
101
- }),
102
- suspendSchema: z.object({
103
- message: z.string(),
104
- action: z.string()
105
- }),
106
- resumeSchema: z.object({
107
- confirmed: z.boolean()
108
- }),
109
- execute: async (inputData, context) => {
110
- const { resumeData, suspend } = context?.agent ?? {};
111
-
112
- if (!resumeData?.confirmed) {
113
- return suspend?.({
114
- message: `Please confirm: ${inputData.action}`,
115
- action: inputData.action
116
- });
117
- }
118
-
119
- return { confirmed: true, action: inputData.action };
120
- }
121
- });
122
- ```
123
-
124
- Handle the suspension and resume with user-provided data:
125
-
126
- ```typescript
127
- const stream = await routingAgent.network("Delete the old records", {
128
- memory: {
129
- thread: "user-123",
130
- resource: "my-app"
131
- }
132
- });
133
-
134
- for await (const chunk of stream) {
135
- if (chunk.type === "workflow-execution-suspended") {
136
- console.log(chunk.payload.suspendPayload);
137
- // { message: "Please confirm: delete old records", action: "delete old records" }
138
- }
139
- }
140
-
141
- // Resume with user confirmation
142
- const resumedStream = await routingAgent.resumeNetwork(
143
- { confirmed: true },
144
- {
145
- runId: stream.runId,
146
- memory: {
147
- thread: "user-123",
148
- resource: "my-app"
149
- }
150
- }
151
- );
152
-
153
- for await (const chunk of resumedStream) {
154
- if (chunk.type === "network-execution-event-step-finish") {
155
- console.log(chunk.payload.result);
156
- }
157
- }
158
- ```
159
-
160
- ## Automatic primitive resumption
161
-
162
- When using primitives that call `suspend()`, you can enable automatic resumption 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.
163
-
164
- ### Enabling auto-resume
165
-
166
- Set `autoResumeSuspendedTools` to `true` in the agent's `defaultNetworkOptions` or when calling `network()`:
167
-
168
- ```typescript
169
- import { Agent } from "@mastra/core/agent";
170
- import { Memory } from "@mastra/memory";
171
-
172
- // Option 1: In agent configuration
173
- const routingAgent = new Agent({
174
- id: "routing-agent",
175
- name: "Routing Agent",
176
- instructions: "You coordinate tasks across multiple agents",
177
- model: "openai/gpt-4o-mini",
178
- tools: { confirmationTool },
179
- memory: new Memory(),
180
- defaultNetworkOptions: {
181
- autoResumeSuspendedTools: true,
182
- },
183
- });
184
-
185
- // Option 2: Per-request
186
- const stream = await routingAgent.network("Process this request", {
187
- autoResumeSuspendedTools: true,
188
- memory: {
189
- thread: "user-123",
190
- resource: "my-app"
191
- }
192
- });
193
- ```
194
-
195
- ### How it works
196
-
197
- When `autoResumeSuspendedTools` is enabled:
198
-
199
- 1. A primitive suspends execution by calling `suspend()` with a payload
200
-
201
- 2. The suspension is persisted to memory along with the conversation
202
-
203
- 3. When the user sends their next message on the same thread, the network:
204
-
205
- - Detects the suspended primitive from message history
206
- - Extracts `resumeData` from the user's message based on the tool's `resumeSchema`
207
- - Automatically resumes the primitive with the extracted data
208
-
209
- ### Example
210
-
211
- ```typescript
212
- const stream = await routingAgent.network("Delete the old records", {
213
- autoResumeSuspendedTools: true,
214
- memory: {
215
- thread: "user-123",
216
- resource: "my-app"
217
- }
218
- });
219
-
220
- for await (const chunk of stream) {
221
- if (chunk.type === "workflow-execution-suspended") {
222
- console.log(chunk.payload.suspendPayload);
223
- // { message: "Please confirm: delete old records", action: "delete old records" }
224
- }
225
- }
226
-
227
- // User provides confirmation in their next message
228
- const resumedStream = await routingAgent.network("Yes, confirmed", {
229
- autoResumeSuspendedTools: true,
230
- memory: {
231
- thread: "user-123",
232
- resource: "my-app"
233
- }
234
- });
235
-
236
- for await (const chunk of resumedStream) {
237
- if (chunk.type === "network-execution-event-step-finish") {
238
- console.log(chunk.payload.result);
239
- }
240
- }
241
- ```
242
-
243
- **Conversation flow:**
244
-
245
- ```text
246
- User: "Delete the old records"
247
- Agent: "Please confirm: delete old records"
248
-
249
- User: "Yes, confirmed"
250
- Agent: "Records deleted successfully"
251
- ```
252
-
253
- ### Requirements
254
-
255
- For automatic tool resumption to work:
256
-
257
- - **Memory configured**: The agent needs memory to track suspended tools across messages
258
- - **Same thread**: The follow-up message must use the same memory thread and resource identifiers
259
- - **`resumeSchema` defined**: The tool (either directly in the network agent or in a subAgent) / workflow (step that gets suspended) must define a `resumeSchema` so the agent knows what data to extract from the user's message
260
-
261
- ### Manual vs automatic resumption
262
-
263
- | Approach | Use case |
264
- | -------------------------------------- | ------------------------------------------------------------------------ |
265
- | Manual (`resumeNetwork()`) | Programmatic control, webhooks, button clicks, external triggers |
266
- | Automatic (`autoResumeSuspendedTools`) | Conversational flows where users provide resume data in natural language |
267
-
268
- 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.
269
-
270
- ## Related
271
-
272
- - [Agent Networks](https://mastra.ai/docs/agents/networks)
273
- - [Agent Approval](https://mastra.ai/docs/agents/agent-approval)
274
- - [Human-in-the-Loop](https://mastra.ai/docs/workflows/human-in-the-loop)
275
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
@@ -1,290 +0,0 @@
1
- # Agent Networks
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.
4
-
5
- ## When to use networks
6
-
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.
8
-
9
- ## Core principles
10
-
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.
20
-
21
- ```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";
28
-
29
- import { cityWorkflow } from "../workflows/city-workflow";
30
- import { weatherTool } from "../tools/weather-tool";
31
-
32
- export const routingAgent = new Agent({
33
- id: "routing-agent",
34
- name: "Routing Agent",
35
- 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",
42
- agents: {
43
- researchAgent,
44
- writingAgent,
45
- },
46
- workflows: {
47
- cityWorkflow,
48
- },
49
- tools: {
50
- weatherTool,
51
- },
52
- memory: new Memory({
53
- storage: new LibSQLStore({
54
- id: 'mastra-storage',
55
- url: "file:../mastra.db",
56
- }),
57
- }),
58
- });
59
- ```
60
-
61
- ### Writing descriptions for network primitives
62
-
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.
64
-
65
- #### Agent descriptions
66
-
67
- Each subagent in a network should include a clear `description` that explains what the agent does.
68
-
69
- ```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
- ```
78
-
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
- });
107
- ```
108
-
109
- #### Tool descriptions
110
-
111
- Tools in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
112
-
113
- ```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.
132
-
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.
136
-
137
- ```typescript
138
- const result = await routingAgent.network(
139
- "Tell me three cool ways to use Mastra",
140
- );
141
-
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
- }
147
- }
148
- ```
149
-
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
167
- ```
168
-
169
- ## Workflow example
170
-
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.
172
-
173
- ```typescript
174
- const result = await routingAgent.network(
175
- "Tell me some historical facts about London",
176
- );
177
-
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);
182
- }
183
- }
184
- ```
185
-
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
- ```
201
-
202
- ### Tool example
203
-
204
- In this example, the routing agent skips the `researchAgent`, `writingAgent`, and `cityWorkflow`, and calls the `weatherTool` directly to complete the task.
205
-
206
- ```typescript
207
- const result = await routingAgent.network("What's the weather in London?");
208
-
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);
213
- }
214
- }
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
-
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,
245
- },
246
- });
247
-
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);
257
- }
258
- }
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
- ```
266
-
267
- ### Streaming partial objects
268
-
269
- For real-time updates during structured output generation, use `objectStream`:
270
-
271
- ```typescript
272
- const stream = await routingAgent.network("Analyze market data", {
273
- structuredOutput: { schema: resultSchema },
274
- });
275
-
276
- // Stream partial objects as they're generated
277
- for await (const partial of stream.objectStream) {
278
- console.log("Building result:", partial);
279
- }
280
-
281
- // Get the final typed result
282
- const final = await stream.object;
283
- ```
284
-
285
- ## Related
286
-
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)