@mastra/libsql 1.6.3-alpha.0 → 1.6.4-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 +20 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +61 -31
- package/dist/docs/references/docs-memory-semantic-recall.md +17 -1
- package/dist/docs/references/reference-core-getMemory.md +2 -2
- package/dist/docs/references/reference-core-listMemory.md +1 -1
- package/dist/docs/references/reference-core-mastra-class.md +17 -17
- package/dist/docs/references/reference-memory-memory-class.md +12 -14
- package/dist/docs/references/reference-storage-composite.md +9 -9
- package/dist/docs/references/reference-storage-dynamodb.md +9 -9
- package/dist/docs/references/reference-storage-libsql.md +2 -2
- package/dist/docs/references/reference-vectors-libsql.md +31 -31
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.6.4-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- - Fixed experiment pending count showing negative values when experiments are triggered from the Studio ([#13831](https://github.com/mastra-ai/mastra/pull/13831))
|
|
8
|
+
- Fixed scorer prompt metadata (analysis context, generated prompts) being lost when saving experiment scores
|
|
9
|
+
- Updated dependencies [[`41e48c1`](https://github.com/mastra-ai/mastra/commit/41e48c198eee846478e60c02ec432c19d322a517), [`82469d3`](https://github.com/mastra-ai/mastra/commit/82469d3135d5a49dd8dc8feec0ff398b4e0225a0), [`33e2fd5`](https://github.com/mastra-ai/mastra/commit/33e2fd5088f83666df17401e2da68c943dbc0448), [`7ef6e2c`](https://github.com/mastra-ai/mastra/commit/7ef6e2c61be5a42e26f55d15b5902866fc76634f), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`fa37d39`](https://github.com/mastra-ai/mastra/commit/fa37d39910421feaf8847716292e3d65dd4f30c2), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`71c38bf`](https://github.com/mastra-ai/mastra/commit/71c38bf905905148ecd0e75c07c1f9825d299b76), [`f993c38`](https://github.com/mastra-ai/mastra/commit/f993c3848c97479b813231be872443bedeced6ab), [`f51849a`](https://github.com/mastra-ai/mastra/commit/f51849a568935122b5100b7ee69704e6d680cf7b), [`9bf3a0d`](https://github.com/mastra-ai/mastra/commit/9bf3a0dac602787925f1762f1f0387d7b4a59620), [`cafa045`](https://github.com/mastra-ai/mastra/commit/cafa0453c9de141ad50c09a13894622dffdd9978), [`1fd9ddb`](https://github.com/mastra-ai/mastra/commit/1fd9ddbb3fe83b281b12bd2e27e426ae86288266), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443), [`d9d228c`](https://github.com/mastra-ai/mastra/commit/d9d228c0c6ae82ae6ce3b540a3a56b2b1c2b8d98), [`5576507`](https://github.com/mastra-ai/mastra/commit/55765071e360fb97e443aa0a91ccf7e1cd8d92aa), [`79d69c9`](https://github.com/mastra-ai/mastra/commit/79d69c9d5f842ff1c31352fb6026f04c1f6190f3), [`94f44b8`](https://github.com/mastra-ai/mastra/commit/94f44b827ce57b179e50f4916a84c0fa6e7f3b8c), [`13187db`](https://github.com/mastra-ai/mastra/commit/13187dbac880174232dedc5a501ff6c5d0fe59bc), [`2ae5311`](https://github.com/mastra-ai/mastra/commit/2ae531185fff66a80fa165c0999e3d801900e89d), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443)]:
|
|
10
|
+
- @mastra/core@1.10.0-alpha.0
|
|
11
|
+
|
|
12
|
+
## 1.6.3
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Added atomic `updateWorkflowResults` and `updateWorkflowState` to safely merge concurrent step results into workflow snapshots. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
|
|
17
|
+
|
|
18
|
+
- Added `insertObservationalMemoryRecord()` to PostgreSQL, LibSQL, MongoDB, and Upstash adapters for OM cloning support. ([#13569](https://github.com/mastra-ai/mastra/pull/13569))
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
|
|
21
|
+
- @mastra/core@1.9.0
|
|
22
|
+
|
|
3
23
|
## 1.6.3-alpha.0
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
# Agent
|
|
1
|
+
# Agent approval
|
|
2
2
|
|
|
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
|
|
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
|
-
##
|
|
5
|
+
## How approval works
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Mastra offers two distinct mechanisms for pausing tool calls: **pre-execution approval** and **runtime suspension**.
|
|
8
|
+
|
|
9
|
+
### Pre-execution approval
|
|
10
|
+
|
|
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.
|
|
12
|
+
|
|
13
|
+
Two flags control this, combined with OR logic. If _either_ is `true`, the call pauses:
|
|
14
|
+
|
|
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** |
|
|
19
|
+
|
|
20
|
+
The stream emits a `tool-call-approval` chunk when a call is paused this way. You then call `approveToolCall()` or `declineToolCall()` to continue.
|
|
21
|
+
|
|
22
|
+
### Runtime suspension with `suspend()`
|
|
23
|
+
|
|
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.
|
|
25
|
+
|
|
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`.
|
|
8
27
|
|
|
9
28
|
### Storage
|
|
10
29
|
|
|
@@ -24,7 +43,7 @@ export const mastra = new Mastra({
|
|
|
24
43
|
|
|
25
44
|
## Agent-level approval
|
|
26
45
|
|
|
27
|
-
|
|
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.
|
|
28
47
|
|
|
29
48
|
```typescript
|
|
30
49
|
const stream = await agent.stream("What's the weather in London?", {
|
|
@@ -32,9 +51,20 @@ const stream = await agent.stream("What's the weather in London?", {
|
|
|
32
51
|
})
|
|
33
52
|
```
|
|
34
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
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
for await (const chunk of stream.fullStream) {
|
|
58
|
+
if (chunk.type === 'tool-call-approval') {
|
|
59
|
+
console.log('Tool:', chunk.payload.toolName)
|
|
60
|
+
console.log('Args:', chunk.payload.args)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
35
65
|
### Approving tool calls
|
|
36
66
|
|
|
37
|
-
|
|
67
|
+
Call `approveToolCall()` on the agent with the `runId` of the stream to resume the suspended tool call and let it execute:
|
|
38
68
|
|
|
39
69
|
```typescript
|
|
40
70
|
const handleApproval = async () => {
|
|
@@ -49,7 +79,7 @@ const handleApproval = async () => {
|
|
|
49
79
|
|
|
50
80
|
### Declining tool calls
|
|
51
81
|
|
|
52
|
-
|
|
82
|
+
Call `declineToolCall()` on the agent to skip the tool call. The agent continues without executing the tool and responds accordingly:
|
|
53
83
|
|
|
54
84
|
```typescript
|
|
55
85
|
const handleDecline = async () => {
|
|
@@ -64,19 +94,19 @@ const handleDecline = async () => {
|
|
|
64
94
|
|
|
65
95
|
## Tool approval with generate()
|
|
66
96
|
|
|
67
|
-
Tool approval also works with the `generate()` method for non-streaming use cases. When
|
|
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.
|
|
68
98
|
|
|
69
99
|
### How it works
|
|
70
100
|
|
|
71
101
|
When a tool requires approval during a `generate()` call, the response includes:
|
|
72
102
|
|
|
73
|
-
- `finishReason: 'suspended'
|
|
74
|
-
- `suspendPayload
|
|
75
|
-
- `runId
|
|
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
|
|
76
106
|
|
|
77
107
|
### Approving tool calls
|
|
78
108
|
|
|
79
|
-
|
|
109
|
+
Use `approveToolCallGenerate()` to approve the tool call and get the final result:
|
|
80
110
|
|
|
81
111
|
```typescript
|
|
82
112
|
const output = await agent.generate('Find user John', {
|
|
@@ -99,7 +129,7 @@ if (output.finishReason === 'suspended') {
|
|
|
99
129
|
|
|
100
130
|
### Declining tool calls
|
|
101
131
|
|
|
102
|
-
|
|
132
|
+
Use `declineToolCallGenerate()` to skip the tool call:
|
|
103
133
|
|
|
104
134
|
```typescript
|
|
105
135
|
if (output.finishReason === 'suspended') {
|
|
@@ -108,12 +138,12 @@ if (output.finishReason === 'suspended') {
|
|
|
108
138
|
toolCallId: output.suspendPayload.toolCallId,
|
|
109
139
|
})
|
|
110
140
|
|
|
111
|
-
// Agent
|
|
141
|
+
// Agent responds acknowledging the declined tool
|
|
112
142
|
console.log(result.text)
|
|
113
143
|
}
|
|
114
144
|
```
|
|
115
145
|
|
|
116
|
-
### Stream vs
|
|
146
|
+
### Stream vs generate comparison
|
|
117
147
|
|
|
118
148
|
| Aspect | `stream()` | `generate()` |
|
|
119
149
|
| ------------------ | ---------------------------- | ------------------------------------------------ |
|
|
@@ -125,11 +155,11 @@ if (output.finishReason === 'suspended') {
|
|
|
125
155
|
|
|
126
156
|
## Tool-level approval
|
|
127
157
|
|
|
128
|
-
|
|
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.
|
|
129
159
|
|
|
130
|
-
###
|
|
160
|
+
### Approval using `requireApproval`
|
|
131
161
|
|
|
132
|
-
|
|
162
|
+
Set `requireApproval: true` on a tool definition. The tool pauses before execution regardless of whether `requireToolApproval` is set on the agent:
|
|
133
163
|
|
|
134
164
|
```typescript
|
|
135
165
|
export const testTool = createTool({
|
|
@@ -154,30 +184,30 @@ export const testTool = createTool({
|
|
|
154
184
|
})
|
|
155
185
|
```
|
|
156
186
|
|
|
157
|
-
When `requireApproval` is true
|
|
187
|
+
When `requireApproval` is `true`, the stream emits `tool-call-approval` chunks the same way agent-level approval does. Use `approveToolCall()` or `declineToolCall()` to continue:
|
|
158
188
|
|
|
159
189
|
```typescript
|
|
160
190
|
const stream = await agent.stream("What's the weather in London?")
|
|
161
191
|
|
|
162
192
|
for await (const chunk of stream.fullStream) {
|
|
163
193
|
if (chunk.type === 'tool-call-approval') {
|
|
164
|
-
console.log('Approval required.
|
|
194
|
+
console.log('Approval required for:', chunk.payload.toolName)
|
|
165
195
|
}
|
|
166
196
|
}
|
|
167
197
|
|
|
168
|
-
const
|
|
169
|
-
const
|
|
198
|
+
const handleApproval = async () => {
|
|
199
|
+
const approvedStream = await agent.approveToolCall({ runId: stream.runId })
|
|
170
200
|
|
|
171
|
-
for await (const chunk of
|
|
201
|
+
for await (const chunk of approvedStream.textStream) {
|
|
172
202
|
process.stdout.write(chunk)
|
|
173
203
|
}
|
|
174
204
|
process.stdout.write('\n')
|
|
175
205
|
}
|
|
176
206
|
```
|
|
177
207
|
|
|
178
|
-
###
|
|
208
|
+
### Approval using `suspend`
|
|
179
209
|
|
|
180
|
-
With this approach, neither the agent nor the tool uses `requireApproval`. Instead, the tool
|
|
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.
|
|
181
211
|
|
|
182
212
|
```typescript
|
|
183
213
|
export const testToolB = createTool({
|
|
@@ -210,7 +240,7 @@ export const testToolB = createTool({
|
|
|
210
240
|
})
|
|
211
241
|
```
|
|
212
242
|
|
|
213
|
-
With this approach the stream
|
|
243
|
+
With this approach the stream includes a `tool-call-suspended` chunk, and the `suspendPayload` contains the `reason` defined by the tool's `suspendSchema`. Call `resumeStream` with the `resumeSchema` data and `runId` to continue:
|
|
214
244
|
|
|
215
245
|
```typescript
|
|
216
246
|
const stream = await agent.stream("What's the weather in London?")
|
|
@@ -349,7 +379,7 @@ User: "San Francisco"
|
|
|
349
379
|
Agent: "The weather in San Francisco is: San Francisco: ☀️ +72°F"
|
|
350
380
|
```
|
|
351
381
|
|
|
352
|
-
The second message automatically resumes the suspended tool
|
|
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`.
|
|
353
383
|
|
|
354
384
|
### Requirements
|
|
355
385
|
|
|
@@ -370,7 +400,7 @@ Both approaches work with the same tool definitions. Automatic resumption trigge
|
|
|
370
400
|
|
|
371
401
|
## Tool approval: Supervisor pattern
|
|
372
402
|
|
|
373
|
-
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
|
|
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.
|
|
374
404
|
|
|
375
405
|
### How it works
|
|
376
406
|
|
|
@@ -453,7 +483,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
453
483
|
|
|
454
484
|
### Declining tool calls in supervisor pattern
|
|
455
485
|
|
|
456
|
-
|
|
486
|
+
Decline tool calls at the supervisor level by calling `declineToolCall`. The supervisor responds acknowledging the declined tool without executing it:
|
|
457
487
|
|
|
458
488
|
```typescript
|
|
459
489
|
for await (const chunk of stream.fullStream) {
|
|
@@ -466,7 +496,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
466
496
|
toolCallId: chunk.payload.toolCallId,
|
|
467
497
|
})
|
|
468
498
|
|
|
469
|
-
// The supervisor
|
|
499
|
+
// The supervisor responds acknowledging the declined tool
|
|
470
500
|
for await (const declineChunk of declineStream.textStream) {
|
|
471
501
|
process.stdout.write(declineChunk)
|
|
472
502
|
}
|
|
@@ -476,7 +506,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
476
506
|
|
|
477
507
|
### Using suspend() in supervisor pattern
|
|
478
508
|
|
|
479
|
-
Tools can also use [`suspend()`](#
|
|
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:
|
|
480
510
|
|
|
481
511
|
```typescript
|
|
482
512
|
const conditionalTool = createTool({
|
|
@@ -147,8 +147,24 @@ Supported embedding models:
|
|
|
147
147
|
|
|
148
148
|
- **OpenAI**: `text-embedding-3-small`, `text-embedding-3-large`, `text-embedding-ada-002`
|
|
149
149
|
- **Google**: `gemini-embedding-001`
|
|
150
|
+
- **OpenRouter**: Access embedding models from various providers
|
|
150
151
|
|
|
151
|
-
|
|
152
|
+
```ts
|
|
153
|
+
import { Agent } from '@mastra/core/agent'
|
|
154
|
+
import { Memory } from '@mastra/memory'
|
|
155
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
156
|
+
|
|
157
|
+
const agent = new Agent({
|
|
158
|
+
memory: new Memory({
|
|
159
|
+
embedder: new ModelRouterEmbeddingModel({
|
|
160
|
+
providerId: 'openrouter',
|
|
161
|
+
modelId: 'openai/text-embedding-3-small',
|
|
162
|
+
}),
|
|
163
|
+
}),
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The model router automatically handles API key detection from environment variables (`OPENAI_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`, `OPENROUTER_API_KEY`).
|
|
152
168
|
|
|
153
169
|
### Using AI SDK Packages
|
|
154
170
|
|
|
@@ -16,11 +16,11 @@ const thread = await memory.createThread({
|
|
|
16
16
|
|
|
17
17
|
## Parameters
|
|
18
18
|
|
|
19
|
-
**key
|
|
19
|
+
**key** (`TMemoryKey extends keyof TMemory`): The registry key of the memory instance to retrieve. Must match a key used when registering memory in the Mastra constructor.
|
|
20
20
|
|
|
21
21
|
## Returns
|
|
22
22
|
|
|
23
|
-
**memory
|
|
23
|
+
**memory** (`TMemory[TMemoryKey]`): The memory instance with the specified key. Throws an error if the memory is not found.
|
|
24
24
|
|
|
25
25
|
## Example: Registering and Retrieving Memory
|
|
26
26
|
|
|
@@ -18,7 +18,7 @@ This method takes no parameters.
|
|
|
18
18
|
|
|
19
19
|
## Returns
|
|
20
20
|
|
|
21
|
-
**memory
|
|
21
|
+
**memory** (`Record<string, MastraMemory>`): An object containing all registered memory instances, keyed by their registry keys.
|
|
22
22
|
|
|
23
23
|
## Example: Checking Registered Memory
|
|
24
24
|
|
|
@@ -31,36 +31,36 @@ export const mastra = new Mastra({
|
|
|
31
31
|
|
|
32
32
|
Visit the [Configuration reference](https://mastra.ai/reference/configuration) for detailed documentation on all available configuration options.
|
|
33
33
|
|
|
34
|
-
**agents
|
|
34
|
+
**agents** (`Record<string, Agent>`): Agent instances to register, keyed by name (Default: `{}`)
|
|
35
35
|
|
|
36
|
-
**tools
|
|
36
|
+
**tools** (`Record<string, ToolApi>`): Custom tools to register. Structured as a key-value pair, with keys being the tool name and values being the tool function. (Default: `{}`)
|
|
37
37
|
|
|
38
|
-
**storage
|
|
38
|
+
**storage** (`MastraCompositeStore`): Storage engine instance for persisting data
|
|
39
39
|
|
|
40
|
-
**vectors
|
|
40
|
+
**vectors** (`Record<string, MastraVector>`): Vector store instance, used for semantic search and vector-based tools (eg Pinecone, PgVector or Qdrant)
|
|
41
41
|
|
|
42
|
-
**logger
|
|
42
|
+
**logger** (`Logger`): Logger instance created with new PinoLogger() (Default: `Console logger with INFO level`)
|
|
43
43
|
|
|
44
|
-
**idGenerator
|
|
44
|
+
**idGenerator** (`() => string`): Custom ID generator function. Used by agents, workflows, memory, and other components to generate unique identifiers.
|
|
45
45
|
|
|
46
|
-
**workflows
|
|
46
|
+
**workflows** (`Record<string, Workflow>`): Workflows to register. Structured as a key-value pair, with keys being the workflow name and values being the workflow instance. (Default: `{}`)
|
|
47
47
|
|
|
48
|
-
**tts
|
|
48
|
+
**tts** (`Record<string, MastraVoice>`): Text-to-speech providers for voice synthesis
|
|
49
49
|
|
|
50
|
-
**observability
|
|
50
|
+
**observability** (`ObservabilityEntrypoint`): Observability configuration for tracing and monitoring
|
|
51
51
|
|
|
52
|
-
**deployer
|
|
52
|
+
**deployer** (`MastraDeployer`): An instance of a MastraDeployer for managing deployments.
|
|
53
53
|
|
|
54
|
-
**server
|
|
54
|
+
**server** (`ServerConfig`): Server configuration including port, host, timeout, API routes, middleware, CORS settings, and build options for Swagger UI, API request logging, and OpenAPI docs.
|
|
55
55
|
|
|
56
|
-
**mcpServers
|
|
56
|
+
**mcpServers** (`Record<string, MCPServerBase>`): An object where keys are registry keys (used for getMCPServer()) and values are instances of MCPServer or classes extending MCPServerBase. Each MCPServer must have an id property. Servers can be retrieved by registry key using getMCPServer() or by their intrinsic id using getMCPServerById().
|
|
57
57
|
|
|
58
|
-
**bundler
|
|
58
|
+
**bundler** (`BundlerConfig`): Configuration for the asset bundler with options for externals, sourcemap, and transpilePackages.
|
|
59
59
|
|
|
60
|
-
**scorers
|
|
60
|
+
**scorers** (`Record<string, Scorer>`): Scorers for evaluating agent responses and workflow outputs (Default: `{}`)
|
|
61
61
|
|
|
62
|
-
**processors
|
|
62
|
+
**processors** (`Record<string, Processor>`): Input/output processors for transforming agent inputs and outputs (Default: `{}`)
|
|
63
63
|
|
|
64
|
-
**gateways
|
|
64
|
+
**gateways** (`Record<string, MastraModelGateway>`): Custom model gateways to register for accessing AI models through alternative providers or private deployments. Structured as a key-value pair, with keys being the registry key (used for getGateway()) and values being gateway instances. (Default: `{}`)
|
|
65
65
|
|
|
66
|
-
**memory
|
|
66
|
+
**memory** (`Record<string, MastraMemory>`): Memory instances to register. These can be referenced by stored agents and resolved at runtime. Structured as a key-value pair, with keys being the registry key and values being memory instances. (Default: `{}`)
|
|
@@ -22,35 +22,33 @@ export const agent = new Agent({
|
|
|
22
22
|
})
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
> To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](https://mastra.ai/reference/core/mastra-class) for more information.
|
|
25
|
+
> **Note:** To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](https://mastra.ai/reference/core/mastra-class) for more information.
|
|
26
26
|
|
|
27
27
|
## Constructor parameters
|
|
28
28
|
|
|
29
|
-
**storage
|
|
29
|
+
**storage** (`MastraCompositeStore`): Storage implementation for persisting memory data. Defaults to \`new DefaultStorage({ config: { url: "file:memory.db" } })\` if not provided.
|
|
30
30
|
|
|
31
|
-
**vector
|
|
31
|
+
**vector** (`MastraVector | false`): Vector store for semantic search capabilities. Set to \`false\` to disable vector operations.
|
|
32
32
|
|
|
33
|
-
**embedder
|
|
33
|
+
**embedder** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder instance for vector embeddings. Required when semantic recall is enabled.
|
|
34
34
|
|
|
35
|
-
**options
|
|
35
|
+
**options** (`MemoryConfig`): Memory configuration options.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
**options.lastMessages** (`number | false`): Number of most recent messages to include in context. Set to \`false\` to disable loading conversation history into context. Use \`Number.MAX\_SAFE\_INTEGER\` to retrieve all messages with no limit. To prevent saving new messages, use the \`readOnly\` option instead.
|
|
38
38
|
|
|
39
|
-
**
|
|
39
|
+
**options.readOnly** (`boolean`): When true, prevents memory from saving new messages and provides working memory as read-only context (without the updateWorkingMemory tool). Useful for read-only operations like previews, internal routing agents, or sub agents that should reference but not modify memory.
|
|
40
40
|
|
|
41
|
-
**
|
|
41
|
+
**options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires both vector store and embedder to be configured. Default topK is 4, default messageRange is {before: 1, after: 1}.
|
|
42
42
|
|
|
43
|
-
**
|
|
43
|
+
**options.workingMemory** (`WorkingMemory`): Configuration for working memory feature. Can be \`{ enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' }\` or \`{ enabled: boolean }\` to disable.
|
|
44
44
|
|
|
45
|
-
**
|
|
45
|
+
**options.observationalMemory** (`boolean | ObservationalMemoryOptions`): Enable Observational Memory for long-context agentic memory. Set to \`true\` for defaults, or pass a config object to customize token budgets, models, and scope. See \[Observational Memory reference]\(/reference/memory/observational-memory) for configuration details.
|
|
46
46
|
|
|
47
|
-
**
|
|
48
|
-
|
|
49
|
-
**generateTitle?:** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the user's first message. Can be a boolean or an object with custom model and instructions. (Default: `false`)
|
|
47
|
+
**options.generateTitle** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the user's first message. Can be a boolean or an object with custom model and instructions.
|
|
50
48
|
|
|
51
49
|
## Returns
|
|
52
50
|
|
|
53
|
-
**memory
|
|
51
|
+
**memory** (`Memory`): A new Memory instance with the specified configuration.
|
|
54
52
|
|
|
55
53
|
## Extended usage example
|
|
56
54
|
|
|
@@ -120,23 +120,23 @@ export const mastra = new Mastra({
|
|
|
120
120
|
|
|
121
121
|
## Options
|
|
122
122
|
|
|
123
|
-
**id
|
|
123
|
+
**id** (`string`): Unique identifier for this storage instance.
|
|
124
124
|
|
|
125
|
-
**default
|
|
125
|
+
**default** (`MastraCompositeStore`): Default storage adapter. Domains not explicitly specified in \`domains\` will use this storage's domains as fallbacks.
|
|
126
126
|
|
|
127
|
-
**domains
|
|
127
|
+
**domains** (`object`): Individual domain overrides. Each domain can come from a different storage adapter. These take precedence over the default storage.
|
|
128
128
|
|
|
129
|
-
**domains.memory
|
|
129
|
+
**domains.memory** (`MemoryStorage`): Storage for threads, messages, and resources.
|
|
130
130
|
|
|
131
|
-
**domains.workflows
|
|
131
|
+
**domains.workflows** (`WorkflowsStorage`): Storage for workflow snapshots.
|
|
132
132
|
|
|
133
|
-
**domains.scores
|
|
133
|
+
**domains.scores** (`ScoresStorage`): Storage for evaluation scores.
|
|
134
134
|
|
|
135
|
-
**domains.observability
|
|
135
|
+
**domains.observability** (`ObservabilityStorage`): Storage for traces and spans.
|
|
136
136
|
|
|
137
|
-
**domains.agents
|
|
137
|
+
**domains.agents** (`AgentsStorage`): Storage for stored agent configurations.
|
|
138
138
|
|
|
139
|
-
**disableInit
|
|
139
|
+
**disableInit** (`boolean`): When true, automatic initialization is disabled. You must call init() explicitly.
|
|
140
140
|
|
|
141
141
|
## Initialization
|
|
142
142
|
|
|
@@ -108,17 +108,17 @@ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/
|
|
|
108
108
|
|
|
109
109
|
## Parameters
|
|
110
110
|
|
|
111
|
-
**id
|
|
111
|
+
**id** (`string`): Unique identifier for this storage instance.
|
|
112
112
|
|
|
113
|
-
**config.tableName
|
|
113
|
+
**config.tableName** (`string`): The name of your DynamoDB table.
|
|
114
114
|
|
|
115
|
-
**config.region
|
|
115
|
+
**config.region** (`string`): AWS region. Defaults to 'us-east-1'. For local development, can be set to 'localhost' or similar.
|
|
116
116
|
|
|
117
|
-
**config.endpoint
|
|
117
|
+
**config.endpoint** (`string`): Custom endpoint for DynamoDB (e.g., 'http\://localhost:8000' for local development).
|
|
118
118
|
|
|
119
|
-
**config.credentials
|
|
119
|
+
**config.credentials** (`object`): AWS credentials object with \`accessKeyId\` and \`secretAccessKey\`. If not provided, the AWS SDK will attempt to source credentials from environment variables, IAM roles (e.g., for EC2/Lambda), or the shared AWS credentials file.
|
|
120
120
|
|
|
121
|
-
**config.ttl
|
|
121
|
+
**config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow\_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
|
|
122
122
|
|
|
123
123
|
## TTL (Time To Live) Configuration
|
|
124
124
|
|
|
@@ -188,11 +188,11 @@ TTL can be configured for these entity types:
|
|
|
188
188
|
|
|
189
189
|
Each entity type accepts the following configuration:
|
|
190
190
|
|
|
191
|
-
**enabled
|
|
191
|
+
**enabled** (`boolean`): Whether TTL is enabled for this entity type.
|
|
192
192
|
|
|
193
|
-
**attributeName
|
|
193
|
+
**attributeName** (`string`): The DynamoDB attribute name to use for TTL. Must match the TTL attribute configured on your DynamoDB table. Defaults to 'ttl'.
|
|
194
194
|
|
|
195
|
-
**defaultTtlSeconds
|
|
195
|
+
**defaultTtlSeconds** (`number`): Default TTL in seconds from item creation time. Items will be automatically deleted by DynamoDB after this duration.
|
|
196
196
|
|
|
197
197
|
### Enabling TTL on Your DynamoDB Table
|
|
198
198
|
|
|
@@ -89,9 +89,9 @@ storage: new LibSQLStore({
|
|
|
89
89
|
|
|
90
90
|
## Options
|
|
91
91
|
|
|
92
|
-
**url
|
|
92
|
+
**url** (`string`): Database URL. Use \`:memory:\` for in-memory database, \`file:filename.db\` for a file database, or a libSQL connection string (e.g., \`libsql://your-database.turso.io\`) for remote storage.
|
|
93
93
|
|
|
94
|
-
**authToken
|
|
94
|
+
**authToken** (`string`): Authentication token for remote libSQL databases.
|
|
95
95
|
|
|
96
96
|
## Initialization
|
|
97
97
|
|