@mastra/libsql 0.0.0-structured-output-issue-20260302184919 → 0.0.0-structured-output-errors-20260409185629
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 +344 -3
- package/LICENSE.md +15 -0
- package/dist/docs/SKILL.md +15 -19
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +136 -185
- package/dist/docs/references/docs-agents-networks.md +90 -207
- package/dist/docs/references/docs-memory-memory-processors.md +15 -15
- package/dist/docs/references/docs-memory-message-history.md +10 -8
- package/dist/docs/references/docs-memory-overview.md +219 -24
- package/dist/docs/references/docs-memory-semantic-recall.md +54 -29
- package/dist/docs/references/docs-memory-storage.md +14 -16
- package/dist/docs/references/docs-memory-working-memory.md +22 -22
- package/dist/docs/references/docs-rag-retrieval.md +16 -16
- package/dist/docs/references/docs-workflows-snapshots.md +1 -1
- package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +3 -3
- package/dist/docs/references/reference-core-getMemory.md +4 -5
- package/dist/docs/references/reference-core-listMemory.md +3 -4
- package/dist/docs/references/reference-core-mastra-class.md +18 -18
- package/dist/docs/references/reference-memory-memory-class.md +16 -18
- package/dist/docs/references/reference-storage-composite.md +19 -11
- package/dist/docs/references/reference-storage-dynamodb.md +16 -16
- package/dist/docs/references/reference-storage-libsql.md +3 -3
- package/dist/docs/references/reference-vectors-libsql.md +47 -47
- package/dist/index.cjs +512 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +513 -83
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +12 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts +3 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +5 -2
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/docs/references/docs-agents-agent-memory.md +0 -209
- package/dist/docs/references/docs-agents-network-approval.md +0 -275
- package/dist/docs/references/docs-observability-overview.md +0 -70
- package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -209
|
@@ -13,7 +13,7 @@ Working memory can persist at two different scopes:
|
|
|
13
13
|
|
|
14
14
|
**Important:** Switching between scopes means the agent won't see memory from the other scope - thread-scoped memory is completely separate from resource-scoped memory.
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## Quickstart
|
|
17
17
|
|
|
18
18
|
Here's a minimal example of setting up an agent with working memory:
|
|
19
19
|
|
|
@@ -26,7 +26,7 @@ const agent = new Agent({
|
|
|
26
26
|
id: 'personal-assistant',
|
|
27
27
|
name: 'PersonalAssistant',
|
|
28
28
|
instructions: 'You are a helpful personal assistant.',
|
|
29
|
-
model: 'openai/gpt-5.
|
|
29
|
+
model: 'openai/gpt-5.4',
|
|
30
30
|
memory: new Memory({
|
|
31
31
|
options: {
|
|
32
32
|
workingMemory: {
|
|
@@ -37,13 +37,13 @@ const agent = new Agent({
|
|
|
37
37
|
})
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
## How it
|
|
40
|
+
## How it works
|
|
41
41
|
|
|
42
42
|
Working memory is a block of Markdown text that the agent is able to update over time to store continuously relevant information:
|
|
43
43
|
|
|
44
44
|
[YouTube video player](https://www.youtube-nocookie.com/embed/UMy_JHLf1n8)
|
|
45
45
|
|
|
46
|
-
## Memory
|
|
46
|
+
## Memory persistence scopes
|
|
47
47
|
|
|
48
48
|
Working memory can operate in two different scopes, allowing you to choose how memory persists across conversations:
|
|
49
49
|
|
|
@@ -117,7 +117,7 @@ const memory = new Memory({
|
|
|
117
117
|
- Temporary or session-specific information
|
|
118
118
|
- Workflows where each thread needs working memory but threads are ephemeral and not related to each other
|
|
119
119
|
|
|
120
|
-
## Storage
|
|
120
|
+
## Storage adapter support
|
|
121
121
|
|
|
122
122
|
Resource-scoped working memory requires specific storage adapters that support the `mastra_resources` table:
|
|
123
123
|
|
|
@@ -128,7 +128,7 @@ Resource-scoped working memory requires specific storage adapters that support t
|
|
|
128
128
|
- **Upstash** (`@mastra/upstash`)
|
|
129
129
|
- **MongoDB** (`@mastra/mongodb`)
|
|
130
130
|
|
|
131
|
-
## Custom
|
|
131
|
+
## Custom templates
|
|
132
132
|
|
|
133
133
|
Templates guide the agent on what information to track and update in working memory. While a default template is used if none is provided, you'll typically want to define a custom template tailored to your agent's specific use case to ensure it remembers the most relevant information.
|
|
134
134
|
|
|
@@ -142,7 +142,7 @@ const memory = new Memory({
|
|
|
142
142
|
template: `
|
|
143
143
|
# User Profile
|
|
144
144
|
|
|
145
|
-
## Personal
|
|
145
|
+
## Personal info
|
|
146
146
|
|
|
147
147
|
- Name:
|
|
148
148
|
- Location:
|
|
@@ -156,7 +156,7 @@ const memory = new Memory({
|
|
|
156
156
|
- [Deadline 1]: [Date]
|
|
157
157
|
- [Deadline 2]: [Date]
|
|
158
158
|
|
|
159
|
-
## Session
|
|
159
|
+
## Session state
|
|
160
160
|
|
|
161
161
|
- Last Task Discussed:
|
|
162
162
|
- Open Questions:
|
|
@@ -168,13 +168,13 @@ const memory = new Memory({
|
|
|
168
168
|
})
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
## Designing
|
|
171
|
+
## Designing effective templates
|
|
172
172
|
|
|
173
|
-
A well-structured template keeps the information
|
|
173
|
+
A well-structured template keeps the information straightforward for the agent to parse and update. Treat the template as a short form that you want the assistant to keep up to date.
|
|
174
174
|
|
|
175
|
-
- **Short, focused labels.** Avoid paragraphs or very long headings. Keep labels brief (for example `## Personal Info` or `- Name:`) so updates are
|
|
175
|
+
- **Short, focused labels.** Avoid paragraphs or very long headings. Keep labels brief (for example `## Personal Info` or `- Name:`) so updates are readable and less likely to be truncated.
|
|
176
176
|
- **Use consistent casing.** Inconsistent capitalization (`Timezone:` vs `timezone:`) can cause messy updates. Stick to Title Case or lower case for headings and bullet labels.
|
|
177
|
-
- **Keep placeholder text
|
|
177
|
+
- **Keep placeholder text minimal.** Use hints such as `[e.g., Formal]` or `[Date]` to help the LLM fill in the correct spots.
|
|
178
178
|
- **Abbreviate very long values.** If you only need a short form, include guidance like `- Name: [First name or nickname]` or `- Address (short):` rather than the full legal text.
|
|
179
179
|
- **Mention update rules in `instructions`.** You can instruct how and when to fill or clear parts of the template directly in the agent's `instructions` field.
|
|
180
180
|
|
|
@@ -206,7 +206,7 @@ const paragraphMemory = new Memory({
|
|
|
206
206
|
})
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
-
## Structured
|
|
209
|
+
## Structured working memory
|
|
210
210
|
|
|
211
211
|
Working memory can also be defined using a structured schema instead of a Markdown template. This allows you to specify the exact fields and types that should be tracked, using a [Zod](https://zod.dev/) schema. When using a schema, the agent will see and update working memory as a JSON object matching your schema.
|
|
212
212
|
|
|
@@ -263,22 +263,22 @@ Schema-based working memory uses **merge semantics**, meaning the agent only nee
|
|
|
263
263
|
|
|
264
264
|
- **Object fields are deep merged:** Only provided fields are updated; others remain unchanged
|
|
265
265
|
- **Set a field to `null` to delete it:** This explicitly removes the field from memory
|
|
266
|
-
- **Arrays are replaced entirely:** When an array field is provided, it replaces the existing array (arrays
|
|
266
|
+
- **Arrays are replaced entirely:** When an array field is provided, it replaces the existing array (arrays aren't merged element-by-element)
|
|
267
267
|
|
|
268
|
-
## Choosing
|
|
268
|
+
## Choosing between template and schema
|
|
269
269
|
|
|
270
270
|
- Use a **template** (Markdown) if you want the agent to maintain memory as a free-form text block, such as a user profile or scratchpad. Templates use **replace semantics** — the agent must provide the complete memory content on each update.
|
|
271
|
-
- Use a **schema** if you need structured, type-safe data that can be validated and programmatically accessed as JSON. Schemas use **merge semantics** — the agent only provides fields to update, and existing fields are preserved.
|
|
272
|
-
- Only one mode can be active at a time: setting both `template` and `schema`
|
|
271
|
+
- Use a **schema** if you need structured, type-safe data that can be validated and programmatically accessed as JSON. The `workingMemory.schema` field accepts any `PublicSchema`-compatible schema (including Zod v3, Zod v4, JSON Schema, or already-standard schemas). Schemas use **merge semantics** — the agent only provides fields to update, and existing fields are preserved.
|
|
272
|
+
- Only one mode can be active at a time: setting both `template` and `schema` isn't supported.
|
|
273
273
|
|
|
274
|
-
## Example: Multi-step
|
|
274
|
+
## Example: Multi-step retention
|
|
275
275
|
|
|
276
276
|
Below is a simplified view of how the `User Profile` template updates across a short user conversation:
|
|
277
277
|
|
|
278
278
|
```nohighlight
|
|
279
279
|
# User Profile
|
|
280
280
|
|
|
281
|
-
## Personal
|
|
281
|
+
## Personal info
|
|
282
282
|
|
|
283
283
|
- Name:
|
|
284
284
|
- Location:
|
|
@@ -301,9 +301,9 @@ Below is a simplified view of how the `User Profile` template updates across a s
|
|
|
301
301
|
|
|
302
302
|
The agent can now refer to `Sam` or `Berlin` in later responses without requesting the information again because it has been stored in working memory.
|
|
303
303
|
|
|
304
|
-
If your agent
|
|
304
|
+
If your agent isn't properly updating working memory when you expect it to, you can add system instructions on _how_ and _when_ to use this template in your agent's `instructions` setting.
|
|
305
305
|
|
|
306
|
-
## Setting
|
|
306
|
+
## Setting initial working memory
|
|
307
307
|
|
|
308
308
|
While agents typically update working memory through the `updateWorkingMemory` tool, you can also set initial working memory programmatically when creating or updating threads. This is useful for injecting user data (like their name, preferences, or other info) that you want available to the agent without passing it in every request.
|
|
309
309
|
|
|
@@ -372,7 +372,7 @@ await memory.updateWorkingMemory({
|
|
|
372
372
|
})
|
|
373
373
|
```
|
|
374
374
|
|
|
375
|
-
## Read-
|
|
375
|
+
## Read-only working memory
|
|
376
376
|
|
|
377
377
|
In some scenarios, you may want an agent to have access to working memory data without the ability to modify it. This is useful for:
|
|
378
378
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Retrieval in RAG
|
|
1
|
+
# Retrieval in RAG systems
|
|
2
2
|
|
|
3
3
|
After storing embeddings, you need to retrieve relevant chunks to answer user queries.
|
|
4
4
|
|
|
5
5
|
Mastra provides flexible retrieval options with support for semantic search, filtering, and re-ranking.
|
|
6
6
|
|
|
7
|
-
## How
|
|
7
|
+
## How retrieval works
|
|
8
8
|
|
|
9
9
|
1. The user's query is converted to an embedding using the same model used for document embeddings
|
|
10
10
|
2. This embedding is compared to stored embeddings using vector similarity
|
|
@@ -14,7 +14,7 @@ Mastra provides flexible retrieval options with support for semantic search, fil
|
|
|
14
14
|
- Re-ranked for better relevance
|
|
15
15
|
- Processed through a knowledge graph
|
|
16
16
|
|
|
17
|
-
## Basic
|
|
17
|
+
## Basic retrieval
|
|
18
18
|
|
|
19
19
|
The simplest approach is direct semantic search. This method uses vector similarity to find chunks that are semantically similar to the query:
|
|
20
20
|
|
|
@@ -63,7 +63,7 @@ Results include both the text content and a similarity score:
|
|
|
63
63
|
]
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
## Advanced
|
|
66
|
+
## Advanced retrieval options
|
|
67
67
|
|
|
68
68
|
### Metadata Filtering
|
|
69
69
|
|
|
@@ -272,7 +272,7 @@ import { PGVECTOR_PROMPT } from '@mastra/pg'
|
|
|
272
272
|
export const ragAgent = new Agent({
|
|
273
273
|
id: 'rag-agent',
|
|
274
274
|
name: 'RAG Agent',
|
|
275
|
-
model: 'openai/gpt-5.
|
|
275
|
+
model: 'openai/gpt-5.4',
|
|
276
276
|
instructions: `
|
|
277
277
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
278
278
|
${PGVECTOR_PROMPT}
|
|
@@ -289,7 +289,7 @@ import { PINECONE_PROMPT } from '@mastra/pinecone'
|
|
|
289
289
|
export const ragAgent = new Agent({
|
|
290
290
|
id: 'rag-agent',
|
|
291
291
|
name: 'RAG Agent',
|
|
292
|
-
model: 'openai/gpt-5.
|
|
292
|
+
model: 'openai/gpt-5.4',
|
|
293
293
|
instructions: `
|
|
294
294
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
295
295
|
${PINECONE_PROMPT}
|
|
@@ -306,7 +306,7 @@ import { QDRANT_PROMPT } from '@mastra/qdrant'
|
|
|
306
306
|
export const ragAgent = new Agent({
|
|
307
307
|
id: 'rag-agent',
|
|
308
308
|
name: 'RAG Agent',
|
|
309
|
-
model: 'openai/gpt-5.
|
|
309
|
+
model: 'openai/gpt-5.4',
|
|
310
310
|
instructions: `
|
|
311
311
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
312
312
|
${QDRANT_PROMPT}
|
|
@@ -323,7 +323,7 @@ import { CHROMA_PROMPT } from '@mastra/chroma'
|
|
|
323
323
|
export const ragAgent = new Agent({
|
|
324
324
|
id: 'rag-agent',
|
|
325
325
|
name: 'RAG Agent',
|
|
326
|
-
model: 'openai/gpt-5.
|
|
326
|
+
model: 'openai/gpt-5.4',
|
|
327
327
|
instructions: `
|
|
328
328
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
329
329
|
${CHROMA_PROMPT}
|
|
@@ -340,7 +340,7 @@ import { ASTRA_PROMPT } from '@mastra/astra'
|
|
|
340
340
|
export const ragAgent = new Agent({
|
|
341
341
|
id: 'rag-agent',
|
|
342
342
|
name: 'RAG Agent',
|
|
343
|
-
model: 'openai/gpt-5.
|
|
343
|
+
model: 'openai/gpt-5.4',
|
|
344
344
|
instructions: `
|
|
345
345
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
346
346
|
${ASTRA_PROMPT}
|
|
@@ -357,7 +357,7 @@ import { LIBSQL_PROMPT } from '@mastra/libsql'
|
|
|
357
357
|
export const ragAgent = new Agent({
|
|
358
358
|
id: 'rag-agent',
|
|
359
359
|
name: 'RAG Agent',
|
|
360
|
-
model: 'openai/gpt-5.
|
|
360
|
+
model: 'openai/gpt-5.4',
|
|
361
361
|
instructions: `
|
|
362
362
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
363
363
|
${LIBSQL_PROMPT}
|
|
@@ -374,7 +374,7 @@ import { UPSTASH_PROMPT } from '@mastra/upstash'
|
|
|
374
374
|
export const ragAgent = new Agent({
|
|
375
375
|
id: 'rag-agent',
|
|
376
376
|
name: 'RAG Agent',
|
|
377
|
-
model: 'openai/gpt-5.
|
|
377
|
+
model: 'openai/gpt-5.4',
|
|
378
378
|
instructions: `
|
|
379
379
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
380
380
|
${UPSTASH_PROMPT}
|
|
@@ -391,7 +391,7 @@ import { VECTORIZE_PROMPT } from '@mastra/vectorize'
|
|
|
391
391
|
export const ragAgent = new Agent({
|
|
392
392
|
id: 'rag-agent',
|
|
393
393
|
name: 'RAG Agent',
|
|
394
|
-
model: 'openai/gpt-5.
|
|
394
|
+
model: 'openai/gpt-5.4',
|
|
395
395
|
instructions: `
|
|
396
396
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
397
397
|
${VECTORIZE_PROMPT}
|
|
@@ -408,7 +408,7 @@ import { MONGODB_PROMPT } from '@mastra/mongodb'
|
|
|
408
408
|
export const ragAgent = new Agent({
|
|
409
409
|
id: 'rag-agent',
|
|
410
410
|
name: 'RAG Agent',
|
|
411
|
-
model: 'openai/gpt-5.
|
|
411
|
+
model: 'openai/gpt-5.4',
|
|
412
412
|
instructions: `
|
|
413
413
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
414
414
|
${MONGODB_PROMPT}
|
|
@@ -425,7 +425,7 @@ import { OPENSEARCH_PROMPT } from '@mastra/opensearch'
|
|
|
425
425
|
export const ragAgent = new Agent({
|
|
426
426
|
id: 'rag-agent',
|
|
427
427
|
name: 'RAG Agent',
|
|
428
|
-
model: 'openai/gpt-5.
|
|
428
|
+
model: 'openai/gpt-5.4',
|
|
429
429
|
instructions: `
|
|
430
430
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
431
431
|
${OPENSEARCH_PROMPT}
|
|
@@ -442,7 +442,7 @@ import { S3VECTORS_PROMPT } from '@mastra/s3vectors'
|
|
|
442
442
|
export const ragAgent = new Agent({
|
|
443
443
|
id: 'rag-agent',
|
|
444
444
|
name: 'RAG Agent',
|
|
445
|
-
model: 'openai/gpt-5.
|
|
445
|
+
model: 'openai/gpt-5.4',
|
|
446
446
|
instructions: `
|
|
447
447
|
Process queries using the provided context. Structure responses to be concise and relevant.
|
|
448
448
|
${S3VECTORS_PROMPT}
|
|
@@ -472,7 +472,7 @@ const initialResults = await pgVector.query({
|
|
|
472
472
|
})
|
|
473
473
|
|
|
474
474
|
// Create a relevance scorer
|
|
475
|
-
const relevanceProvider = new MastraAgentRelevanceScorer('relevance-scorer', 'openai/gpt-5.
|
|
475
|
+
const relevanceProvider = new MastraAgentRelevanceScorer('relevance-scorer', 'openai/gpt-5.4')
|
|
476
476
|
|
|
477
477
|
// Re-rank the results
|
|
478
478
|
const rerankedResults = await rerank({
|
|
@@ -150,7 +150,7 @@ export const mastra = new Mastra({
|
|
|
150
150
|
1. **Ensure Serializability**: Any data that needs to be included in the snapshot must be serializable (convertible to JSON).
|
|
151
151
|
2. **Minimize Snapshot Size**: Avoid storing large data objects directly in the workflow context. Instead, store references to them (like IDs) and retrieve the data when needed.
|
|
152
152
|
3. **Handle Resume Context Carefully**: When resuming a workflow, carefully consider what context to provide. This will be merged with the existing snapshot data.
|
|
153
|
-
4. **Set Up Proper Monitoring**: Implement monitoring for suspended workflows, especially long-running ones, to ensure they
|
|
153
|
+
4. **Set Up Proper Monitoring**: Implement monitoring for suspended workflows, especially long-running ones, to ensure they're properly resumed.
|
|
154
154
|
5. **Consider Storage Scaling**: For applications with many suspended workflows, ensure your storage solution is appropriately scaled.
|
|
155
155
|
|
|
156
156
|
## Custom snapshot metadata
|
|
@@ -56,7 +56,7 @@ const loggingProcessor: Processor<'logger'> = {
|
|
|
56
56
|
},
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const model = withMastra(openai('gpt-
|
|
59
|
+
const model = withMastra(openai('gpt-5.4'), {
|
|
60
60
|
inputProcessors: [loggingProcessor],
|
|
61
61
|
outputProcessors: [loggingProcessor],
|
|
62
62
|
})
|
|
@@ -85,7 +85,7 @@ await storage.init()
|
|
|
85
85
|
|
|
86
86
|
const memoryStorage = await storage.getStore('memory')
|
|
87
87
|
|
|
88
|
-
const model = withMastra(openai('gpt-
|
|
88
|
+
const model = withMastra(openai('gpt-5.4'), {
|
|
89
89
|
memory: {
|
|
90
90
|
storage: memoryStorage!,
|
|
91
91
|
threadId: 'user-thread-123',
|
|
@@ -115,7 +115,7 @@ await storage.init()
|
|
|
115
115
|
|
|
116
116
|
const memoryStorage = await storage.getStore('memory')
|
|
117
117
|
|
|
118
|
-
const model = withMastra(openai('gpt-
|
|
118
|
+
const model = withMastra(openai('gpt-5.4'), {
|
|
119
119
|
inputProcessors: [myGuardProcessor],
|
|
120
120
|
outputProcessors: [myLoggingProcessor],
|
|
121
121
|
memory: {
|
|
@@ -16,13 +16,13 @@ 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
|
-
## Example: Registering and
|
|
25
|
+
## Example: Registering and retrieving memory
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
28
|
import { Mastra } from '@mastra/core'
|
|
@@ -46,5 +46,4 @@ const memory = mastra.getMemory('conversationMemory')
|
|
|
46
46
|
## Related
|
|
47
47
|
|
|
48
48
|
- [Mastra.listMemory()](https://mastra.ai/reference/core/listMemory)
|
|
49
|
-
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
50
|
-
- [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
|
|
49
|
+
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
@@ -18,9 +18,9 @@ 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
|
-
## Example: Checking
|
|
23
|
+
## Example: Checking registered memory
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { Mastra } from '@mastra/core'
|
|
@@ -52,5 +52,4 @@ console.log(Object.keys(allMemory)) // ["conversationMemory", "analyticsMemory"]
|
|
|
52
52
|
## Related
|
|
53
53
|
|
|
54
54
|
- [Mastra.getMemory()](https://mastra.ai/reference/core/getMemory)
|
|
55
|
-
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
56
|
-
- [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
|
|
55
|
+
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mastra
|
|
1
|
+
# Mastra class
|
|
2
2
|
|
|
3
3
|
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.
|
|
4
4
|
|
|
@@ -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** (`(context?: IdGeneratorContext) => string`): Custom ID generator function. Used by agents, workflows, memory, and other components to generate unique identifiers. Receives optional context such as idType, source, entityId, and threadId to support context-aware ID formats.
|
|
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, transpilePackages, and dynamicPackages. (Default: `{ externals: [], sourcemap: false, transpilePackages: [], dynamicPackages: [] }`)
|
|
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: `{}`)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Memory
|
|
1
|
+
# Memory class
|
|
2
2
|
|
|
3
3
|
The `Memory` class provides a robust system for managing conversation history and thread-based message storage in Mastra. It enables persistent storage of conversations, semantic search capabilities, and efficient message retrieval. You must configure a storage provider for conversation history, and if you enable semantic recall you will also need to provide a vector store and embedder.
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
11
11
|
export const agent = new Agent({
|
|
12
12
|
name: 'test-agent',
|
|
13
13
|
instructions: 'You are an agent with memory.',
|
|
14
|
-
model: 'openai/gpt-5.
|
|
14
|
+
model: 'openai/gpt-5.4',
|
|
15
15
|
memory: new Memory({
|
|
16
16
|
options: {
|
|
17
17
|
workingMemory: {
|
|
@@ -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
|
|
|
@@ -62,7 +60,7 @@ import { LibSQLStore, LibSQLVector } from '@mastra/libsql'
|
|
|
62
60
|
export const agent = new Agent({
|
|
63
61
|
name: 'test-agent',
|
|
64
62
|
instructions: 'You are an agent with memory.',
|
|
65
|
-
model: 'openai/gpt-5.
|
|
63
|
+
model: 'openai/gpt-5.4',
|
|
66
64
|
memory: new Memory({
|
|
67
65
|
storage: new LibSQLStore({
|
|
68
66
|
id: 'test-agent-storage',
|
|
@@ -99,7 +97,7 @@ import { PgStore, PgVector } from '@mastra/pg'
|
|
|
99
97
|
export const agent = new Agent({
|
|
100
98
|
name: 'pg-agent',
|
|
101
99
|
instructions: 'You are an agent with optimized PostgreSQL memory.',
|
|
102
|
-
model: 'openai/gpt-5.
|
|
100
|
+
model: 'openai/gpt-5.4',
|
|
103
101
|
memory: new Memory({
|
|
104
102
|
storage: new PgStore({
|
|
105
103
|
id: 'pg-agent-storage',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Composite
|
|
1
|
+
# Composite storage
|
|
2
2
|
|
|
3
3
|
`MastraCompositeStore` can compose storage domains from different providers. Use it when you need different databases for different purposes. For example, use LibSQL for memory and PostgreSQL for workflows.
|
|
4
4
|
|
|
@@ -58,7 +58,7 @@ bun add @mastra/pg@latest @mastra/libsql@latest
|
|
|
58
58
|
|
|
59
59
|
## Storage domains
|
|
60
60
|
|
|
61
|
-
Mastra organizes storage into
|
|
61
|
+
Mastra organizes storage into domains, each handling a specific type of data. Each domain can be backed by a different storage adapter, and domain classes are exported from each storage package.
|
|
62
62
|
|
|
63
63
|
| Domain | Description |
|
|
64
64
|
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -67,6 +67,10 @@ Mastra organizes storage into five specialized domains, each handling a specific
|
|
|
67
67
|
| `scores` | Evaluation results from Mastra's evals system. Scores and metrics are persisted here for analysis and comparison over time. |
|
|
68
68
|
| `observability` | Telemetry data including traces and spans. Agent interactions, tool calls, and LLM requests generate spans collected into traces for debugging and performance analysis. |
|
|
69
69
|
| `agents` | Agent configurations for stored agents. Enables agents to be defined and updated at runtime without code deployments. |
|
|
70
|
+
| `datasets` | Evaluation datasets used for experiment runs. Stores dataset definitions, schemas, and versioned items. |
|
|
71
|
+
| `experiments` | Experiment runs and per-item experiment results linked to datasets and targets. |
|
|
72
|
+
|
|
73
|
+
> **Note:** `MastraCompositeStore` accepts all of the domain keys above, but storage adapter support varies by package. You can mix adapters per domain, but only for domains implemented and exported by those adapters. For example, `memory: new MemoryLibSQL(...)` and `workflows: new WorkflowsPG(...)` is valid because both packages export those domain classes.
|
|
70
74
|
|
|
71
75
|
## Usage
|
|
72
76
|
|
|
@@ -120,23 +124,27 @@ export const mastra = new Mastra({
|
|
|
120
124
|
|
|
121
125
|
## Options
|
|
122
126
|
|
|
123
|
-
**id
|
|
127
|
+
**id** (`string`): Unique identifier for this storage instance.
|
|
128
|
+
|
|
129
|
+
**default** (`MastraCompositeStore`): Default storage adapter. Domains not explicitly specified in \`domains\` will use this storage's domains as fallbacks.
|
|
130
|
+
|
|
131
|
+
**disableInit** (`boolean`): When true, automatic initialization is disabled. You must call init() explicitly.
|
|
124
132
|
|
|
125
|
-
**
|
|
133
|
+
**domains** (`object`): Individual domain overrides. Each domain can come from a different storage adapter. These take precedence over both \`editor\` and \`default\` storage.
|
|
126
134
|
|
|
127
|
-
**domains
|
|
135
|
+
**domains.memory** (`MemoryStorage`): Storage for threads, messages, and resources.
|
|
128
136
|
|
|
129
|
-
**domains.
|
|
137
|
+
**domains.workflows** (`WorkflowsStorage`): Storage for workflow snapshots.
|
|
130
138
|
|
|
131
|
-
**domains.
|
|
139
|
+
**domains.scores** (`ScoresStorage`): Storage for evaluation scores.
|
|
132
140
|
|
|
133
|
-
**domains.
|
|
141
|
+
**domains.observability** (`ObservabilityStorage`): Storage for traces and spans.
|
|
134
142
|
|
|
135
|
-
**domains.
|
|
143
|
+
**domains.agents** (`AgentsStorage`): Storage for stored agent configurations.
|
|
136
144
|
|
|
137
|
-
**domains.
|
|
145
|
+
**domains.datasets** (`DatasetsStorage`): Storage for dataset metadata, dataset items, and dataset versions.
|
|
138
146
|
|
|
139
|
-
**
|
|
147
|
+
**domains.experiments** (`ExperimentsStorage`): Storage for experiment runs and per-item experiment results.
|
|
140
148
|
|
|
141
149
|
## Initialization
|
|
142
150
|
|