@mastra/libsql 1.0.0-beta.11 → 1.0.0-beta.12
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 +108 -0
- package/dist/docs/README.md +2 -2
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/docs/agents/02-networks.md +56 -0
- package/dist/docs/agents/03-agent-approval.md +5 -6
- package/dist/docs/agents/04-network-approval.md +274 -0
- package/dist/docs/core/01-reference.md +7 -8
- package/dist/docs/memory/02-storage.md +59 -25
- package/dist/docs/memory/03-working-memory.md +10 -6
- package/dist/docs/memory/04-semantic-recall.md +2 -4
- package/dist/docs/memory/05-memory-processors.md +2 -3
- package/dist/docs/memory/06-reference.md +2 -4
- package/dist/docs/rag/01-retrieval.md +5 -6
- package/dist/docs/storage/01-reference.md +106 -15
- package/dist/docs/vectors/01-reference.md +3 -5
- package/dist/index.cjs +104 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -59
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/utils.d.ts +16 -1
- package/dist/storage/db/utils.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +0 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +6 -2
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,113 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Changed JSON columns from TEXT to JSONB in `mastra_threads` and `mastra_workflow_snapshot` tables. ([#11853](https://github.com/mastra-ai/mastra/pull/11853))
|
|
8
|
+
|
|
9
|
+
**Why this change?**
|
|
10
|
+
|
|
11
|
+
These were the last remaining columns storing JSON as TEXT. This change aligns them with other tables that already use JSONB, enabling native JSON operators and improved performance. See [#8978](https://github.com/mastra-ai/mastra/issues/8978) for details.
|
|
12
|
+
|
|
13
|
+
**Columns Changed:**
|
|
14
|
+
- `mastra_threads.metadata` - Thread metadata
|
|
15
|
+
- `mastra_workflow_snapshot.snapshot` - Workflow run state
|
|
16
|
+
|
|
17
|
+
**PostgreSQL**
|
|
18
|
+
|
|
19
|
+
Migration Required - PostgreSQL enforces column types, so existing tables must be migrated. Note: Migration will fail if existing column values contain invalid JSON.
|
|
20
|
+
|
|
21
|
+
```sql
|
|
22
|
+
ALTER TABLE mastra_threads
|
|
23
|
+
ALTER COLUMN metadata TYPE jsonb
|
|
24
|
+
USING metadata::jsonb;
|
|
25
|
+
|
|
26
|
+
ALTER TABLE mastra_workflow_snapshot
|
|
27
|
+
ALTER COLUMN snapshot TYPE jsonb
|
|
28
|
+
USING snapshot::jsonb;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**LibSQL**
|
|
32
|
+
|
|
33
|
+
No Migration Required - LibSQL now uses native SQLite JSONB format (added in SQLite 3.45) for ~3x performance improvement on JSON operations. The changes are fully backwards compatible:
|
|
34
|
+
- Existing TEXT JSON data continues to work
|
|
35
|
+
- New data is stored in binary JSONB format
|
|
36
|
+
- Both formats can coexist in the same table
|
|
37
|
+
- All JSON functions (`json_extract`, etc.) work on both formats
|
|
38
|
+
|
|
39
|
+
New installations automatically use JSONB. Existing applications continue to work without any changes.
|
|
40
|
+
|
|
41
|
+
- Aligned vector store configuration with underlying library APIs, giving you access to all library options directly. ([#11742](https://github.com/mastra-ai/mastra/pull/11742))
|
|
42
|
+
|
|
43
|
+
**Why this change?**
|
|
44
|
+
|
|
45
|
+
Previously, each vector store defined its own configuration types that only exposed a subset of the underlying library's options. This meant users couldn't access advanced features like authentication, SSL, compression, or custom headers without creating their own client instances. Now, the configuration types extend the library types directly, so all options are available.
|
|
46
|
+
|
|
47
|
+
**@mastra/libsql** (Breaking)
|
|
48
|
+
|
|
49
|
+
Renamed `connectionUrl` to `url` to match the `@libsql/client` API and align with LibSQLStorage.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Before
|
|
53
|
+
new LibSQLVector({ id: 'my-vector', connectionUrl: 'file:./db.sqlite' });
|
|
54
|
+
|
|
55
|
+
// After
|
|
56
|
+
new LibSQLVector({ id: 'my-vector', url: 'file:./db.sqlite' });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**@mastra/opensearch** (Breaking)
|
|
60
|
+
|
|
61
|
+
Renamed `url` to `node` and added support for all OpenSearch `ClientOptions` including authentication, SSL, and compression.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Before
|
|
65
|
+
new OpenSearchVector({ id: 'my-vector', url: 'http://localhost:9200' });
|
|
66
|
+
|
|
67
|
+
// After
|
|
68
|
+
new OpenSearchVector({ id: 'my-vector', node: 'http://localhost:9200' });
|
|
69
|
+
|
|
70
|
+
// With authentication (now possible)
|
|
71
|
+
new OpenSearchVector({
|
|
72
|
+
id: 'my-vector',
|
|
73
|
+
node: 'https://localhost:9200',
|
|
74
|
+
auth: { username: 'admin', password: 'admin' },
|
|
75
|
+
ssl: { rejectUnauthorized: false },
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**@mastra/pinecone** (Breaking)
|
|
80
|
+
|
|
81
|
+
Removed `environment` parameter. Use `controllerHostUrl` instead (the actual Pinecone SDK field name). Added support for all `PineconeConfiguration` options.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Before
|
|
85
|
+
new PineconeVector({ id: 'my-vector', apiKey: '...', environment: '...' });
|
|
86
|
+
|
|
87
|
+
// After
|
|
88
|
+
new PineconeVector({ id: 'my-vector', apiKey: '...' });
|
|
89
|
+
|
|
90
|
+
// With custom controller host (if needed)
|
|
91
|
+
new PineconeVector({ id: 'my-vector', apiKey: '...', controllerHostUrl: '...' });
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**@mastra/clickhouse**
|
|
95
|
+
|
|
96
|
+
Added support for all `ClickHouseClientConfigOptions` like `request_timeout`, `compression`, `keep_alive`, and `database`. Existing configurations continue to work unchanged.
|
|
97
|
+
|
|
98
|
+
**@mastra/cloudflare, @mastra/cloudflare-d1, @mastra/lance, @mastra/libsql, @mastra/mongodb, @mastra/pg, @mastra/upstash**
|
|
99
|
+
|
|
100
|
+
Improved logging by replacing `console.warn` with structured logger in workflow storage domains.
|
|
101
|
+
|
|
102
|
+
**@mastra/deployer-cloud**
|
|
103
|
+
|
|
104
|
+
Updated internal LibSQLVector configuration for compatibility with the new API.
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- Updated dependencies [[`ebae12a`](https://github.com/mastra-ai/mastra/commit/ebae12a2dd0212e75478981053b148a2c246962d), [`c61a0a5`](https://github.com/mastra-ai/mastra/commit/c61a0a5de4904c88fd8b3718bc26d1be1c2ec6e7), [`69136e7`](https://github.com/mastra-ai/mastra/commit/69136e748e32f57297728a4e0f9a75988462f1a7), [`449aed2`](https://github.com/mastra-ai/mastra/commit/449aed2ba9d507b75bf93d427646ea94f734dfd1), [`eb648a2`](https://github.com/mastra-ai/mastra/commit/eb648a2cc1728f7678768dd70cd77619b448dab9), [`0131105`](https://github.com/mastra-ai/mastra/commit/0131105532e83bdcbb73352fc7d0879eebf140dc), [`9d5059e`](https://github.com/mastra-ai/mastra/commit/9d5059eae810829935fb08e81a9bb7ecd5b144a7), [`ef756c6`](https://github.com/mastra-ai/mastra/commit/ef756c65f82d16531c43f49a27290a416611e526), [`b00ccd3`](https://github.com/mastra-ai/mastra/commit/b00ccd325ebd5d9e37e34dd0a105caae67eb568f), [`3bdfa75`](https://github.com/mastra-ai/mastra/commit/3bdfa7507a91db66f176ba8221aa28dd546e464a), [`e770de9`](https://github.com/mastra-ai/mastra/commit/e770de941a287a49b1964d44db5a5763d19890a6), [`52e2716`](https://github.com/mastra-ai/mastra/commit/52e2716b42df6eff443de72360ae83e86ec23993), [`27b4040`](https://github.com/mastra-ai/mastra/commit/27b4040bfa1a95d92546f420a02a626b1419a1d6), [`610a70b`](https://github.com/mastra-ai/mastra/commit/610a70bdad282079f0c630e0d7bb284578f20151), [`8dc7f55`](https://github.com/mastra-ai/mastra/commit/8dc7f55900395771da851dc7d78d53ae84fe34ec), [`8379099`](https://github.com/mastra-ai/mastra/commit/8379099fc467af6bef54dd7f80c9bd75bf8bbddf), [`8c0ec25`](https://github.com/mastra-ai/mastra/commit/8c0ec25646c8a7df253ed1e5ff4863a0d3f1316c), [`ff4d9a6`](https://github.com/mastra-ai/mastra/commit/ff4d9a6704fc87b31a380a76ed22736fdedbba5a), [`69821ef`](https://github.com/mastra-ai/mastra/commit/69821ef806482e2c44e2197ac0b050c3fe3a5285), [`1ed5716`](https://github.com/mastra-ai/mastra/commit/1ed5716830867b3774c4a1b43cc0d82935f32b96), [`4186bdd`](https://github.com/mastra-ai/mastra/commit/4186bdd00731305726fa06adba0b076a1d50b49f), [`7aaf973`](https://github.com/mastra-ai/mastra/commit/7aaf973f83fbbe9521f1f9e7a4fd99b8de464617)]:
|
|
109
|
+
- @mastra/core@1.0.0-beta.22
|
|
110
|
+
|
|
3
111
|
## 1.0.0-beta.11
|
|
4
112
|
|
|
5
113
|
### Patch Changes
|
package/dist/docs/README.md
CHANGED
|
@@ -22,7 +22,7 @@ docs/
|
|
|
22
22
|
├── SKILL.md # Entry point
|
|
23
23
|
├── README.md # This file
|
|
24
24
|
├── SOURCE_MAP.json # Export index
|
|
25
|
-
├── agents/ (
|
|
25
|
+
├── agents/ (4 files)
|
|
26
26
|
├── core/ (3 files)
|
|
27
27
|
├── guides/ (1 files)
|
|
28
28
|
├── memory/ (6 files)
|
|
@@ -36,4 +36,4 @@ docs/
|
|
|
36
36
|
## Version
|
|
37
37
|
|
|
38
38
|
Package: @mastra/libsql
|
|
39
|
-
Version: 1.0.0-beta.
|
|
39
|
+
Version: 1.0.0-beta.12
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: Documentation for @mastra/libsql. Includes links to type definition
|
|
|
5
5
|
|
|
6
6
|
# @mastra/libsql Documentation
|
|
7
7
|
|
|
8
|
-
> **Version**: 1.0.0-beta.
|
|
8
|
+
> **Version**: 1.0.0-beta.12
|
|
9
9
|
> **Package**: @mastra/libsql
|
|
10
10
|
|
|
11
11
|
## Quick Navigation
|
|
@@ -29,7 +29,7 @@ See SOURCE_MAP.json for the complete list.
|
|
|
29
29
|
|
|
30
30
|
## Available Topics
|
|
31
31
|
|
|
32
|
-
- [Agents](agents/) -
|
|
32
|
+
- [Agents](agents/) - 4 file(s)
|
|
33
33
|
- [Core](core/) - 3 file(s)
|
|
34
34
|
- [Guides](guides/) - 1 file(s)
|
|
35
35
|
- [Memory](memory/) - 6 file(s)
|
|
@@ -228,6 +228,62 @@ tool-execution-end
|
|
|
228
228
|
network-execution-event-step-finish
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
+
## Structured output
|
|
232
|
+
|
|
233
|
+
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.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { z } from "zod";
|
|
237
|
+
|
|
238
|
+
const resultSchema = z.object({
|
|
239
|
+
summary: z.string().describe("A brief summary of the findings"),
|
|
240
|
+
recommendations: z.array(z.string()).describe("List of recommendations"),
|
|
241
|
+
confidence: z.number().min(0).max(1).describe("Confidence score"),
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const stream = await routingAgent.network("Research AI trends", {
|
|
245
|
+
structuredOutput: {
|
|
246
|
+
schema: resultSchema,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Consume the stream
|
|
251
|
+
for await (const chunk of stream) {
|
|
252
|
+
if (chunk.type === "network-object") {
|
|
253
|
+
// Partial object during generation
|
|
254
|
+
console.log("Partial:", chunk.payload.object);
|
|
255
|
+
}
|
|
256
|
+
if (chunk.type === "network-object-result") {
|
|
257
|
+
// Final structured object
|
|
258
|
+
console.log("Final:", chunk.payload.object);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Get the typed result
|
|
263
|
+
const result = await stream.object;
|
|
264
|
+
console.log(result?.summary);
|
|
265
|
+
console.log(result?.recommendations);
|
|
266
|
+
console.log(result?.confidence);
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Streaming partial objects
|
|
270
|
+
|
|
271
|
+
For real-time updates during structured output generation, use `objectStream`:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
const stream = await routingAgent.network("Analyze market data", {
|
|
275
|
+
structuredOutput: { schema: resultSchema },
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// Stream partial objects as they're generated
|
|
279
|
+
for await (const partial of stream.objectStream) {
|
|
280
|
+
console.log("Building result:", partial);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Get the final typed result
|
|
284
|
+
const final = await stream.object;
|
|
285
|
+
```
|
|
286
|
+
|
|
231
287
|
## Related
|
|
232
288
|
|
|
233
289
|
- [Agent Memory](./agent-memory)
|
|
@@ -85,8 +85,8 @@ export const testTool = createTool({
|
|
|
85
85
|
resumeSchema: z.object({
|
|
86
86
|
approved: z.boolean()
|
|
87
87
|
}),
|
|
88
|
-
execute: async (
|
|
89
|
-
const response = await fetch(`https://wttr.in/${location}?format=3`);
|
|
88
|
+
execute: async (inputData) => {
|
|
89
|
+
const response = await fetch(`https://wttr.in/${inputData.location}?format=3`);
|
|
90
90
|
const weather = await response.text();
|
|
91
91
|
|
|
92
92
|
return { weather };
|
|
@@ -121,7 +121,6 @@ const handleResume = async () => {
|
|
|
121
121
|
With this approach, neither the agent nor the tool uses `requireApproval`. Instead, the tool implementation calls `suspend` to pause execution and return context or confirmation prompts to the user.
|
|
122
122
|
|
|
123
123
|
```typescript
|
|
124
|
-
|
|
125
124
|
export const testToolB = createTool({
|
|
126
125
|
id: "test-tool-b",
|
|
127
126
|
description: "Fetches weather for a location",
|
|
@@ -137,14 +136,14 @@ export const testToolB = createTool({
|
|
|
137
136
|
suspendSchema: z.object({
|
|
138
137
|
reason: z.string()
|
|
139
138
|
}),
|
|
140
|
-
execute: async (
|
|
141
|
-
const { resumeData: { approved } = {}, suspend } = agent ?? {};
|
|
139
|
+
execute: async (inputData, context) => {
|
|
140
|
+
const { resumeData: { approved } = {}, suspend } = context?.agent ?? {};
|
|
142
141
|
|
|
143
142
|
if (!approved) {
|
|
144
143
|
return suspend?.({ reason: "Approval required." });
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
const response = await fetch(`https://wttr.in/${location}?format=3`);
|
|
146
|
+
const response = await fetch(`https://wttr.in/${inputData.location}?format=3`);
|
|
148
147
|
const weather = await response.text();
|
|
149
148
|
|
|
150
149
|
return { weather };
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
> Learn how to require approvals, suspend execution, and resume suspended networks while keeping humans in control of agent network workflows.
|
|
2
|
+
|
|
3
|
+
# Network Approval
|
|
4
|
+
|
|
5
|
+
Agent networks can require the same [human-in-the-loop](https://mastra.ai/docs/v1/workflows/human-in-the-loop) oversight used in individual agents and workflows. When a tool, sub-agent, 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.
|
|
6
|
+
|
|
7
|
+
## Storage
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
```typescript title="src/mastra/index.ts"
|
|
12
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
13
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
14
|
+
|
|
15
|
+
export const mastra = new Mastra({
|
|
16
|
+
storage: new LibSQLStore({
|
|
17
|
+
id: "mastra-storage",
|
|
18
|
+
url: ":memory:"
|
|
19
|
+
})
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Approving network tool calls
|
|
24
|
+
|
|
25
|
+
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`.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const stream = await routingAgent.network("Process this query", {
|
|
29
|
+
memory: {
|
|
30
|
+
thread: "user-123",
|
|
31
|
+
resource: "my-app"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
let runId: string;
|
|
36
|
+
|
|
37
|
+
for await (const chunk of stream) {
|
|
38
|
+
runId = stream.runId;
|
|
39
|
+
// if the requirApproval is in a tool inside a subAgent or the subAgent has requireToolApproval set to true
|
|
40
|
+
if (chunk.type === "agent-execution-approval") {
|
|
41
|
+
console.log("Tool requires approval:", chunk.payload);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// if the requirApproval is in a tool directly in the network agent
|
|
45
|
+
if (chunk.type === "tool-execution-approval") {
|
|
46
|
+
console.log("Tool requires approval:", chunk.payload);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Approve and resume execution
|
|
51
|
+
const approvedStream = await routingAgent.approveNetworkToolCall({
|
|
52
|
+
runId,
|
|
53
|
+
memory: {
|
|
54
|
+
thread: "user-123",
|
|
55
|
+
resource: "my-app"
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
for await (const chunk of approvedStream) {
|
|
60
|
+
if (chunk.type === "network-execution-event-step-finish") {
|
|
61
|
+
console.log(chunk.payload.result);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Declining network tool calls
|
|
67
|
+
|
|
68
|
+
To decline a pending tool call and prevent execution, call `declineNetworkToolCall`. The network continues without executing the tool.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const declinedStream = await routingAgent.declineNetworkToolCall({
|
|
72
|
+
runId,
|
|
73
|
+
memory: {
|
|
74
|
+
thread: "user-123",
|
|
75
|
+
resource: "my-app"
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
for await (const chunk of declinedStream) {
|
|
80
|
+
if (chunk.type === "network-execution-event-step-finish") {
|
|
81
|
+
console.log(chunk.payload.result);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Resuming suspended networks
|
|
87
|
+
|
|
88
|
+
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.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { createTool } from "@mastra/core/tools";
|
|
92
|
+
import { z } from "zod";
|
|
93
|
+
|
|
94
|
+
const confirmationTool = createTool({
|
|
95
|
+
id: "confirmation-tool",
|
|
96
|
+
description: "Requests user confirmation before proceeding",
|
|
97
|
+
inputSchema: z.object({
|
|
98
|
+
action: z.string()
|
|
99
|
+
}),
|
|
100
|
+
outputSchema: z.object({
|
|
101
|
+
confirmed: z.boolean(),
|
|
102
|
+
action: z.string()
|
|
103
|
+
}),
|
|
104
|
+
suspendSchema: z.object({
|
|
105
|
+
message: z.string(),
|
|
106
|
+
action: z.string()
|
|
107
|
+
}),
|
|
108
|
+
resumeSchema: z.object({
|
|
109
|
+
confirmed: z.boolean()
|
|
110
|
+
}),
|
|
111
|
+
execute: async (inputData, context) => {
|
|
112
|
+
const { resumeData, suspend } = context?.agent ?? {};
|
|
113
|
+
|
|
114
|
+
if (!resumeData?.confirmed) {
|
|
115
|
+
return suspend?.({
|
|
116
|
+
message: `Please confirm: ${inputData.action}`,
|
|
117
|
+
action: inputData.action
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return { confirmed: true, action: inputData.action };
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Handle the suspension and resume with user-provided data:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const stream = await routingAgent.network("Delete the old records", {
|
|
130
|
+
memory: {
|
|
131
|
+
thread: "user-123",
|
|
132
|
+
resource: "my-app"
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
for await (const chunk of stream) {
|
|
137
|
+
if (chunk.type === "workflow-execution-suspended") {
|
|
138
|
+
console.log(chunk.payload.suspendPayload);
|
|
139
|
+
// { message: "Please confirm: delete old records", action: "delete old records" }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Resume with user confirmation
|
|
144
|
+
const resumedStream = await routingAgent.resumeNetwork(
|
|
145
|
+
{ confirmed: true },
|
|
146
|
+
{
|
|
147
|
+
runId: stream.runId,
|
|
148
|
+
memory: {
|
|
149
|
+
thread: "user-123",
|
|
150
|
+
resource: "my-app"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
for await (const chunk of resumedStream) {
|
|
156
|
+
if (chunk.type === "network-execution-event-step-finish") {
|
|
157
|
+
console.log(chunk.payload.result);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Automatic primitive resumption
|
|
163
|
+
|
|
164
|
+
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.
|
|
165
|
+
|
|
166
|
+
### Enabling auto-resume
|
|
167
|
+
|
|
168
|
+
Set `autoResumeSuspendedTools` to `true` in the agent's `defaultNetworkOptions` or when calling `network()`:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { Agent } from "@mastra/core/agent";
|
|
172
|
+
import { Memory } from "@mastra/memory";
|
|
173
|
+
|
|
174
|
+
// Option 1: In agent configuration
|
|
175
|
+
const routingAgent = new Agent({
|
|
176
|
+
id: "routing-agent",
|
|
177
|
+
name: "Routing Agent",
|
|
178
|
+
instructions: "You coordinate tasks across multiple agents",
|
|
179
|
+
model: "openai/gpt-4o-mini",
|
|
180
|
+
tools: { confirmationTool },
|
|
181
|
+
memory: new Memory(),
|
|
182
|
+
defaultNetworkOptions: {
|
|
183
|
+
autoResumeSuspendedTools: true,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Option 2: Per-request
|
|
188
|
+
const stream = await routingAgent.network("Process this request", {
|
|
189
|
+
autoResumeSuspendedTools: true,
|
|
190
|
+
memory: {
|
|
191
|
+
thread: "user-123",
|
|
192
|
+
resource: "my-app"
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### How it works
|
|
198
|
+
|
|
199
|
+
When `autoResumeSuspendedTools` is enabled:
|
|
200
|
+
|
|
201
|
+
1. A primitive suspends execution by calling `suspend()` with a payload
|
|
202
|
+
2. The suspension is persisted to memory along with the conversation
|
|
203
|
+
3. When the user sends their next message on the same thread, the network:
|
|
204
|
+
- Detects the suspended primitive from message history
|
|
205
|
+
- Extracts `resumeData` from the user's message based on the tool's `resumeSchema`
|
|
206
|
+
- Automatically resumes the primitive with the extracted data
|
|
207
|
+
|
|
208
|
+
### Example
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
const stream = await routingAgent.network("Delete the old records", {
|
|
212
|
+
autoResumeSuspendedTools: true,
|
|
213
|
+
memory: {
|
|
214
|
+
thread: "user-123",
|
|
215
|
+
resource: "my-app"
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
for await (const chunk of stream) {
|
|
220
|
+
if (chunk.type === "workflow-execution-suspended") {
|
|
221
|
+
console.log(chunk.payload.suspendPayload);
|
|
222
|
+
// { message: "Please confirm: delete old records", action: "delete old records" }
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// User provides confirmation in their next message
|
|
227
|
+
const resumedStream = await routingAgent.network("Yes, confirmed", {
|
|
228
|
+
autoResumeSuspendedTools: true,
|
|
229
|
+
memory: {
|
|
230
|
+
thread: "user-123",
|
|
231
|
+
resource: "my-app"
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
for await (const chunk of resumedStream) {
|
|
236
|
+
if (chunk.type === "network-execution-event-step-finish") {
|
|
237
|
+
console.log(chunk.payload.result);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Conversation flow:**
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
User: "Delete the old records"
|
|
246
|
+
Agent: "Please confirm: delete old records"
|
|
247
|
+
|
|
248
|
+
User: "Yes, confirmed"
|
|
249
|
+
Agent: "Records deleted successfully"
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Requirements
|
|
253
|
+
|
|
254
|
+
For automatic tool resumption to work:
|
|
255
|
+
|
|
256
|
+
- **Memory configured**: The agent needs memory to track suspended tools across messages
|
|
257
|
+
- **Same thread**: The follow-up message must use the same memory thread and resource identifiers
|
|
258
|
+
- **`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
|
|
259
|
+
|
|
260
|
+
### Manual vs automatic resumption
|
|
261
|
+
|
|
262
|
+
| Approach | Use case |
|
|
263
|
+
|----------|----------|
|
|
264
|
+
| Manual (`resumeNetwork()`) | Programmatic control, webhooks, button clicks, external triggers |
|
|
265
|
+
| Automatic (`autoResumeSuspendedTools`) | Conversational flows where users provide resume data in natural language |
|
|
266
|
+
|
|
267
|
+
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.
|
|
268
|
+
|
|
269
|
+
## Related
|
|
270
|
+
|
|
271
|
+
- [Agent Networks](./networks)
|
|
272
|
+
- [Agent Approval](./agent-approval)
|
|
273
|
+
- [Human-in-the-Loop](https://mastra.ai/docs/v1/workflows/human-in-the-loop)
|
|
274
|
+
- [Agent Memory](./agent-memory)
|
|
@@ -9,12 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
> Documentation for the `Mastra` class in Mastra, the core entry point for managing agents, workflows, MCP servers, and server endpoints.
|
|
11
11
|
|
|
12
|
-
The `Mastra` class is the central orchestrator in any Mastra application, managing agents, workflows, storage, logging,
|
|
12
|
+
The `Mastra` class is the central orchestrator in any Mastra application, managing agents, workflows, storage, logging, observability, and more. Typically, you create a single instance of `Mastra` to coordinate your application.
|
|
13
13
|
|
|
14
|
-
Think of `Mastra` as a top-level registry
|
|
15
|
-
|
|
16
|
-
- Registering **integrations** makes them accessible to **agents**, **workflows**, and **tools** alike.
|
|
17
|
-
- **tools** aren’t registered on `Mastra` directly but are associated with agents and discovered automatically.
|
|
14
|
+
Think of `Mastra` as a top-level registry where you register agents, workflows, tools, and other components that need to be accessible throughout your application.
|
|
18
15
|
|
|
19
16
|
## Usage example
|
|
20
17
|
|
|
@@ -41,6 +38,8 @@ export const mastra = new Mastra({
|
|
|
41
38
|
|
|
42
39
|
## Constructor parameters
|
|
43
40
|
|
|
41
|
+
Visit the [Configuration reference](https://mastra.ai/reference/v1/configuration) for detailed documentation on all available configuration options.
|
|
42
|
+
|
|
44
43
|
---
|
|
45
44
|
|
|
46
45
|
## Reference: Mastra.getMemory()
|
|
@@ -73,7 +72,7 @@ import { Memory } from "@mastra/memory";
|
|
|
73
72
|
import { LibSQLStore } from "@mastra/libsql";
|
|
74
73
|
|
|
75
74
|
const conversationMemory = new Memory({
|
|
76
|
-
storage: new LibSQLStore({ url: ":memory:" }),
|
|
75
|
+
storage: new LibSQLStore({ id: 'conversation-store', url: ":memory:" }),
|
|
77
76
|
});
|
|
78
77
|
|
|
79
78
|
const mastra = new Mastra({
|
|
@@ -125,12 +124,12 @@ import { LibSQLStore } from "@mastra/libsql";
|
|
|
125
124
|
|
|
126
125
|
const conversationMemory = new Memory({
|
|
127
126
|
id: "conversation-memory",
|
|
128
|
-
storage: new LibSQLStore({ url: ":memory:" }),
|
|
127
|
+
storage: new LibSQLStore({ id: 'conversation-store', url: ":memory:" }),
|
|
129
128
|
});
|
|
130
129
|
|
|
131
130
|
const analyticsMemory = new Memory({
|
|
132
131
|
id: "analytics-memory",
|
|
133
|
-
storage: new LibSQLStore({ url: ":memory:" }),
|
|
132
|
+
storage: new LibSQLStore({ id: 'analytics-store', url: ":memory:" }),
|
|
134
133
|
});
|
|
135
134
|
|
|
136
135
|
const mastra = new Mastra({
|