@mastra/libsql 0.0.0-working-memory-undefined-20260212204651 → 0.0.0-workshop-yj-20260903030708
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/LICENSE.md +17 -0
- package/README.md +13 -107
- package/dist/docs/SKILL.md +30 -27
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-human-in-the-loop.md +682 -0
- package/dist/docs/references/docs-agents-networks.md +109 -213
- package/dist/docs/references/docs-deployment-workers.md +394 -0
- package/dist/docs/references/docs-memory-memory-processors.md +162 -91
- package/dist/docs/references/docs-memory-message-history.md +160 -70
- package/dist/docs/references/docs-memory-multi-user-threads.md +210 -0
- package/dist/docs/references/docs-memory-overview.md +248 -25
- package/dist/docs/references/docs-memory-semantic-recall.md +228 -79
- package/dist/docs/references/docs-memory-working-memory.md +104 -70
- package/dist/docs/references/docs-storage.md +222 -0
- package/dist/docs/references/docs-studio-editor.md +353 -0
- package/dist/docs/references/docs-workflows-snapshots.md +51 -45
- package/dist/docs/references/integrations-channels-github.md +152 -0
- package/dist/docs/references/{reference-storage-dynamodb.md → integrations-databases-dynamodb.md} +48 -44
- package/dist/docs/references/{reference-storage-libsql.md → integrations-databases-libsql.md} +54 -28
- package/dist/docs/references/{guides-agent-frameworks-ai-sdk.md → reference-ai-sdk-overview.md} +42 -38
- package/dist/docs/references/reference-core-getMemory.md +19 -16
- package/dist/docs/references/reference-core-listMemory.md +21 -18
- package/dist/docs/references/reference-core-mastra-class.md +119 -28
- package/dist/docs/references/reference-file-based-agents-memory.md +62 -0
- package/dist/docs/references/reference-file-based-agents-storage.md +34 -0
- package/dist/docs/references/reference-memory-memory-class.md +48 -44
- package/dist/docs/references/{docs-rag-retrieval.md → reference-rag-retrieval.md} +286 -152
- package/dist/docs/references/reference-storage-composite.md +223 -59
- package/dist/docs/references/reference-storage-retention.md +250 -0
- package/dist/docs/references/reference-vectors-libsql.md +77 -73
- package/dist/index.cjs +14255 -7157
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14222 -7140
- package/dist/index.js.map +1 -1
- package/dist/storage/db/client.d.ts +31 -0
- package/dist/storage/db/client.d.ts.map +1 -0
- package/dist/storage/db/index.d.ts +86 -2
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/utils.d.ts +17 -1
- package/dist/storage/db/utils.d.ts.map +1 -1
- package/dist/storage/db/write-lock.d.ts +8 -0
- package/dist/storage/db/write-lock.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +1 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +29 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
- package/dist/storage/domains/blobs/index.d.ts +17 -0
- package/dist/storage/domains/blobs/index.d.ts.map +1 -0
- package/dist/storage/domains/channels/index.d.ts +20 -0
- package/dist/storage/domains/channels/index.d.ts.map +1 -0
- package/dist/storage/domains/datasets/index.d.ts +43 -0
- package/dist/storage/domains/datasets/index.d.ts.map +1 -0
- package/dist/storage/domains/experiments/index.d.ts +55 -0
- package/dist/storage/domains/experiments/index.d.ts.map +1 -0
- package/dist/storage/domains/favorites/index.d.ts +17 -0
- package/dist/storage/domains/favorites/index.d.ts.map +1 -0
- package/dist/storage/domains/harness/index.d.ts +17 -0
- package/dist/storage/domains/harness/index.d.ts.map +1 -0
- package/dist/storage/domains/knowledge/index.d.ts +81 -0
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -1
- package/dist/storage/domains/mcp-servers/index.d.ts +26 -0
- package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +30 -5
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/notifications/index.d.ts +23 -0
- package/dist/storage/domains/notifications/index.d.ts.map +1 -0
- package/dist/storage/domains/observability/index.d.ts +9 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +27 -0
- package/dist/storage/domains/schedules/index.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +15 -5
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/skills/index.d.ts +27 -0
- package/dist/storage/domains/skills/index.d.ts.map +1 -0
- package/dist/storage/domains/thread-state/index.d.ts +38 -0
- package/dist/storage/domains/thread-state/index.d.ts.map +1 -0
- package/dist/storage/domains/tool-provider-connections/index.d.ts +14 -0
- package/dist/storage/domains/tool-provider-connections/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +34 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflow-definitions/index.d.ts +14 -0
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +9 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/domains/workspaces/index.d.ts +26 -0
- package/dist/storage/domains/workspaces/index.d.ts.map +1 -0
- package/dist/storage/factory-storage.d.ts +28 -0
- package/dist/storage/factory-storage.d.ts.map +1 -0
- package/dist/storage/index.d.ts +85 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/retention.d.ts +77 -0
- package/dist/storage/retention.d.ts.map +1 -0
- package/dist/vector/filter.d.ts.map +1 -1
- package/dist/vector/index.d.ts +26 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/sql-builder.d.ts.map +1 -1
- package/dist/vector/write-lock.d.ts +7 -0
- package/dist/vector/write-lock.d.ts.map +1 -0
- package/package.json +20 -19
- package/CHANGELOG.md +0 -3696
- package/dist/docs/references/docs-agents-agent-approval.md +0 -377
- package/dist/docs/references/docs-agents-agent-memory.md +0 -212
- package/dist/docs/references/docs-agents-network-approval.md +0 -275
- package/dist/docs/references/docs-memory-storage.md +0 -261
- package/dist/docs/references/docs-observability-overview.md +0 -70
- package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -211
|
@@ -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,261 +0,0 @@
|
|
|
1
|
-
# Storage
|
|
2
|
-
|
|
3
|
-
For agents to remember previous interactions, Mastra needs a database. Use a storage adapter for one of the [supported databases](#supported-providers) and pass it to your Mastra instance.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import { Mastra } from "@mastra/core";
|
|
7
|
-
import { LibSQLStore } from "@mastra/libsql";
|
|
8
|
-
|
|
9
|
-
export const mastra = new Mastra({
|
|
10
|
-
storage: new LibSQLStore({
|
|
11
|
-
id: 'mastra-storage',
|
|
12
|
-
url: "file:./mastra.db",
|
|
13
|
-
}),
|
|
14
|
-
});
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
> **Sharing the database with Mastra Studio:** When running `mastra dev` alongside your application (e.g., Next.js), use an absolute path to ensure both processes access the same database:
|
|
18
|
-
>
|
|
19
|
-
> ```typescript
|
|
20
|
-
> url: "file:/absolute/path/to/your/project/mastra.db"
|
|
21
|
-
> ```
|
|
22
|
-
>
|
|
23
|
-
> Relative paths like `file:./mastra.db` resolve based on each process's working directory, which may differ.
|
|
24
|
-
|
|
25
|
-
This configures instance-level storage, which all agents share by default. You can also configure [agent-level storage](#agent-level-storage) for isolated data boundaries.
|
|
26
|
-
|
|
27
|
-
Mastra automatically creates the necessary tables on first interaction. See the [core schema](https://mastra.ai/reference/storage/overview) for details on what gets created, including tables for messages, threads, resources, workflows, traces, and evaluation datasets.
|
|
28
|
-
|
|
29
|
-
## Supported providers
|
|
30
|
-
|
|
31
|
-
Each provider page includes installation instructions, configuration parameters, and usage examples:
|
|
32
|
-
|
|
33
|
-
- [libSQL](https://mastra.ai/reference/storage/libsql)
|
|
34
|
-
- [PostgreSQL](https://mastra.ai/reference/storage/postgresql)
|
|
35
|
-
- [MongoDB](https://mastra.ai/reference/storage/mongodb)
|
|
36
|
-
- [Upstash](https://mastra.ai/reference/storage/upstash)
|
|
37
|
-
- [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
|
|
38
|
-
- [Cloudflare Durable Objects](https://mastra.ai/reference/storage/cloudflare)
|
|
39
|
-
- [Convex](https://mastra.ai/reference/storage/convex)
|
|
40
|
-
- [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
|
|
41
|
-
- [LanceDB](https://mastra.ai/reference/storage/lance)
|
|
42
|
-
- [Microsoft SQL Server](https://mastra.ai/reference/storage/mssql)
|
|
43
|
-
|
|
44
|
-
> **Tip:** libSQL is the easiest way to get started because it doesn’t require running a separate database server.
|
|
45
|
-
|
|
46
|
-
## Configuration scope
|
|
47
|
-
|
|
48
|
-
Storage can be configured at the instance level (shared by all agents) or at the agent level (isolated to a specific agent).
|
|
49
|
-
|
|
50
|
-
### Instance-level storage
|
|
51
|
-
|
|
52
|
-
Add storage to your Mastra instance so all agents, workflows, observability traces and scores share the same memory provider:
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
import { Mastra } from "@mastra/core";
|
|
56
|
-
import { PostgresStore } from "@mastra/pg";
|
|
57
|
-
|
|
58
|
-
export const mastra = new Mastra({
|
|
59
|
-
storage: new PostgresStore({
|
|
60
|
-
id: 'mastra-storage',
|
|
61
|
-
connectionString: process.env.DATABASE_URL,
|
|
62
|
-
}),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// Both agents inherit storage from the Mastra instance above
|
|
66
|
-
const agent1 = new Agent({ id: "agent-1", memory: new Memory() });
|
|
67
|
-
const agent2 = new Agent({ id: "agent-2", memory: new Memory() });
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
This is useful when all primitives share the same storage backend and have similar performance, scaling, and operational requirements.
|
|
71
|
-
|
|
72
|
-
#### Composite storage
|
|
73
|
-
|
|
74
|
-
[Composite storage](https://mastra.ai/reference/storage/composite) is an alternative way to configure instance-level storage. Use `MastraCompositeStore` to set the `memory` domain (and any other [domains](https://mastra.ai/reference/storage/composite) you need) to different storage providers.
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
import { Mastra } from "@mastra/core";
|
|
78
|
-
import { MastraCompositeStore } from "@mastra/core/storage";
|
|
79
|
-
import { MemoryLibSQL } from "@mastra/libsql";
|
|
80
|
-
import { WorkflowsPG } from "@mastra/pg";
|
|
81
|
-
import { ObservabilityStorageClickhouse } from "@mastra/clickhouse";
|
|
82
|
-
|
|
83
|
-
export const mastra = new Mastra({
|
|
84
|
-
storage: new MastraCompositeStore({
|
|
85
|
-
id: "composite",
|
|
86
|
-
domains: {
|
|
87
|
-
memory: new MemoryLibSQL({ url: "file:./memory.db" }),
|
|
88
|
-
workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
|
|
89
|
-
observability: new ObservabilityStorageClickhouse({
|
|
90
|
-
url: process.env.CLICKHOUSE_URL,
|
|
91
|
-
username: process.env.CLICKHOUSE_USERNAME,
|
|
92
|
-
password: process.env.CLICKHOUSE_PASSWORD,
|
|
93
|
-
}),
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
|
-
});
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
This is useful when different types of data have different performance or operational requirements, such as low-latency storage for memory, durable storage for workflows, and high-throughput storage for observability.
|
|
100
|
-
|
|
101
|
-
### Agent-level storage
|
|
102
|
-
|
|
103
|
-
Agent-level storage overrides storage configured at the instance level. Add storage to a specific agent when you need data boundaries or compliance requirements:
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
import { Agent } from "@mastra/core/agent";
|
|
107
|
-
import { Memory } from "@mastra/memory";
|
|
108
|
-
import { PostgresStore } from "@mastra/pg";
|
|
109
|
-
|
|
110
|
-
export const agent = new Agent({
|
|
111
|
-
id: "agent",
|
|
112
|
-
memory: new Memory({
|
|
113
|
-
storage: new PostgresStore({
|
|
114
|
-
id: 'agent-storage',
|
|
115
|
-
connectionString: process.env.AGENT_DATABASE_URL,
|
|
116
|
-
}),
|
|
117
|
-
}),
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
> **Warning:** [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment) doesn't support agent-level storage.
|
|
122
|
-
|
|
123
|
-
## Threads and resources
|
|
124
|
-
|
|
125
|
-
Mastra organizes conversations using two identifiers:
|
|
126
|
-
|
|
127
|
-
- **Thread** - a conversation session containing a sequence of messages.
|
|
128
|
-
- **Resource** - the entity that owns the thread, such as a user, organization, project, or any other domain entity in your application.
|
|
129
|
-
|
|
130
|
-
Both identifiers are required for agents to store information:
|
|
131
|
-
|
|
132
|
-
**Generate**:
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
const response = await agent.generate("hello", {
|
|
136
|
-
memory: {
|
|
137
|
-
thread: "conversation-abc-123",
|
|
138
|
-
resource: "user_123",
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
**Stream**:
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
const stream = await agent.stream("hello", {
|
|
147
|
-
memory: {
|
|
148
|
-
thread: "conversation-abc-123",
|
|
149
|
-
resource: "user_123",
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
> **Note:** [Studio](https://mastra.ai/docs/getting-started/studio) automatically generates a thread and resource ID for you. When calling `stream()` or `generate()` yourself, remember to provide these identifiers explicitly.
|
|
155
|
-
|
|
156
|
-
### Thread title generation
|
|
157
|
-
|
|
158
|
-
Mastra can automatically generate descriptive thread titles based on the user's first message when `generateTitle` is enabled.
|
|
159
|
-
|
|
160
|
-
Use this option when implementing a ChatGPT-style chat interface to render a title alongside each thread in the conversation list (for example, in a sidebar) derived from the thread’s initial user message.
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
export const agent = new Agent({
|
|
164
|
-
id: "agent",
|
|
165
|
-
memory: new Memory({
|
|
166
|
-
options: {
|
|
167
|
-
generateTitle: true,
|
|
168
|
-
},
|
|
169
|
-
}),
|
|
170
|
-
});
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Title generation runs asynchronously after the agent responds and does not affect response time.
|
|
174
|
-
|
|
175
|
-
To optimize cost or behavior, provide a smaller [`model`](https://mastra.ai/models) and custom `instructions`:
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
export const agent = new Agent({
|
|
179
|
-
id: "agent",
|
|
180
|
-
memory: new Memory({
|
|
181
|
-
options: {
|
|
182
|
-
generateTitle: {
|
|
183
|
-
model: "openai/gpt-4o-mini",
|
|
184
|
-
instructions: "Generate a 1 word title",
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
}),
|
|
188
|
-
});
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Semantic recall
|
|
192
|
-
|
|
193
|
-
Semantic recall has different storage requirements - it needs a vector database in addition to the standard storage adapter. See [Semantic recall](https://mastra.ai/docs/memory/semantic-recall) for setup and supported vector providers.
|
|
194
|
-
|
|
195
|
-
## Handling large attachments
|
|
196
|
-
|
|
197
|
-
Some storage providers enforce record size limits that base64-encoded file attachments (such as images) can exceed:
|
|
198
|
-
|
|
199
|
-
| Provider | Record size limit |
|
|
200
|
-
| ------------------------------------------------------------------ | ----------------- |
|
|
201
|
-
| [DynamoDB](https://mastra.ai/reference/storage/dynamodb) | 400 KB |
|
|
202
|
-
| [Convex](https://mastra.ai/reference/storage/convex) | 1 MiB |
|
|
203
|
-
| [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1) | 1 MiB |
|
|
204
|
-
|
|
205
|
-
PostgreSQL, MongoDB, and libSQL have higher limits and are generally unaffected.
|
|
206
|
-
|
|
207
|
-
To avoid this, use an input processor to upload attachments to external storage (S3, R2, GCS, [Convex file storage](https://docs.convex.dev/file-storage), etc.) and replace them with URL references before persistence.
|
|
208
|
-
|
|
209
|
-
```typescript
|
|
210
|
-
import type { Processor } from "@mastra/core/processors";
|
|
211
|
-
import type { MastraDBMessage } from "@mastra/core/memory";
|
|
212
|
-
|
|
213
|
-
export class AttachmentUploader implements Processor {
|
|
214
|
-
id = "attachment-uploader";
|
|
215
|
-
|
|
216
|
-
async processInput({ messages }: { messages: MastraDBMessage[] }) {
|
|
217
|
-
return Promise.all(messages.map((msg) => this.processMessage(msg)));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
async processMessage(msg: MastraDBMessage) {
|
|
221
|
-
const attachments = msg.content.experimental_attachments;
|
|
222
|
-
if (!attachments?.length) return msg;
|
|
223
|
-
|
|
224
|
-
const uploaded = await Promise.all(
|
|
225
|
-
attachments.map(async (att) => {
|
|
226
|
-
// Skip if already a URL
|
|
227
|
-
if (!att.url?.startsWith("data:")) return att;
|
|
228
|
-
|
|
229
|
-
// Upload base64 data and replace with URL
|
|
230
|
-
const url = await this.upload(att.url, att.contentType);
|
|
231
|
-
return { ...att, url };
|
|
232
|
-
})
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
return { ...msg, content: { ...msg.content, experimental_attachments: uploaded } };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
async upload(dataUri: string, contentType?: string): Promise<string> {
|
|
239
|
-
const base64 = dataUri.split(",")[1];
|
|
240
|
-
const buffer = Buffer.from(base64, "base64");
|
|
241
|
-
|
|
242
|
-
// Replace with your storage provider (S3, R2, GCS, Convex, etc.)
|
|
243
|
-
// return await s3.upload(buffer, contentType);
|
|
244
|
-
throw new Error("Implement upload() with your storage provider");
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
Use the processor with your agent:
|
|
250
|
-
|
|
251
|
-
```typescript
|
|
252
|
-
import { Agent } from "@mastra/core/agent";
|
|
253
|
-
import { Memory } from "@mastra/memory";
|
|
254
|
-
import { AttachmentUploader } from "./processors/attachment-uploader";
|
|
255
|
-
|
|
256
|
-
const agent = new Agent({
|
|
257
|
-
id: "my-agent",
|
|
258
|
-
memory: new Memory({ storage: yourStorage }),
|
|
259
|
-
inputProcessors: [new AttachmentUploader()],
|
|
260
|
-
});
|
|
261
|
-
```
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Observability Overview
|
|
2
|
-
|
|
3
|
-
Mastra provides observability features for AI applications. Monitor LLM operations, trace agent decisions, and debug complex workflows with tools that understand AI-specific patterns.
|
|
4
|
-
|
|
5
|
-
## Key Features
|
|
6
|
-
|
|
7
|
-
### Tracing
|
|
8
|
-
|
|
9
|
-
Specialized tracing for AI operations that captures:
|
|
10
|
-
|
|
11
|
-
- **Model interactions**: Token usage, latency, prompts, and completions
|
|
12
|
-
- **Agent execution**: Decision paths, tool calls, and memory operations
|
|
13
|
-
- **Workflow steps**: Branching logic, parallel execution, and step outputs
|
|
14
|
-
- **Automatic instrumentation**: Tracing with decorators
|
|
15
|
-
|
|
16
|
-
## Storage Requirements
|
|
17
|
-
|
|
18
|
-
The `DefaultExporter` persists traces to your configured storage backend. Not all storage providers support observability—for the full list, see [Storage Provider Support](https://mastra.ai/docs/observability/tracing/exporters/default).
|
|
19
|
-
|
|
20
|
-
For production environments with high traffic, we recommend using **ClickHouse** for the observability domain via [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](https://mastra.ai/docs/observability/tracing/exporters/default) for details.
|
|
21
|
-
|
|
22
|
-
## Quick Start
|
|
23
|
-
|
|
24
|
-
Configure Observability in your Mastra instance:
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
import { Mastra } from "@mastra/core";
|
|
28
|
-
import { PinoLogger } from "@mastra/loggers";
|
|
29
|
-
import { LibSQLStore } from "@mastra/libsql";
|
|
30
|
-
import {
|
|
31
|
-
Observability,
|
|
32
|
-
DefaultExporter,
|
|
33
|
-
CloudExporter,
|
|
34
|
-
SensitiveDataFilter,
|
|
35
|
-
} from "@mastra/observability";
|
|
36
|
-
|
|
37
|
-
export const mastra = new Mastra({
|
|
38
|
-
logger: new PinoLogger(),
|
|
39
|
-
storage: new LibSQLStore({
|
|
40
|
-
id: 'mastra-storage',
|
|
41
|
-
url: "file:./mastra.db", // Storage is required for tracing
|
|
42
|
-
}),
|
|
43
|
-
observability: new Observability({
|
|
44
|
-
configs: {
|
|
45
|
-
default: {
|
|
46
|
-
serviceName: "mastra",
|
|
47
|
-
exporters: [
|
|
48
|
-
new DefaultExporter(), // Persists traces to storage for Mastra Studio
|
|
49
|
-
new CloudExporter(), // Sends traces to Mastra Cloud (if MASTRA_CLOUD_ACCESS_TOKEN is set)
|
|
50
|
-
],
|
|
51
|
-
spanOutputProcessors: [
|
|
52
|
-
new SensitiveDataFilter(), // Redacts sensitive data like passwords, tokens, keys
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
}),
|
|
57
|
-
});
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
> **Serverless environments:** The `file:./mastra.db` storage URL uses the local filesystem, which doesn't work in serverless environments like Vercel, AWS Lambda, or Cloudflare Workers. For serverless deployments, use external storage. See the [Vercel deployment guide](https://mastra.ai/guides/deployment/vercel) for a complete example.
|
|
61
|
-
|
|
62
|
-
With this basic setup, you will see Traces and Logs in both Studio and in Mastra Cloud.
|
|
63
|
-
|
|
64
|
-
We also support various external tracing providers like MLflow, Langfuse, Braintrust, and any OpenTelemetry-compatible platform (Datadog, New Relic, SigNoz, etc.). See more about this in the [Tracing](https://mastra.ai/docs/observability/tracing/overview) documentation.
|
|
65
|
-
|
|
66
|
-
## What's Next?
|
|
67
|
-
|
|
68
|
-
- **[Set up Tracing](https://mastra.ai/docs/observability/tracing/overview)**: Configure tracing for your application
|
|
69
|
-
- **[Configure Logging](https://mastra.ai/docs/observability/logging)**: Add structured logging
|
|
70
|
-
- **[API Reference](https://mastra.ai/reference/observability/tracing/instances)**: Detailed configuration options
|