@mastra/libsql 1.15.1-alpha.0 → 1.16.0-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 +22 -0
- package/dist/docs/SKILL.md +4 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agent-builder-overview.md +4 -3
- package/dist/docs/references/docs-agents-agent-approval.md +25 -2
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +67 -0
- package/dist/docs/references/docs-memory-message-history.md +56 -2
- package/dist/docs/references/docs-memory-overview.md +5 -3
- package/dist/docs/references/docs-memory-semantic-recall.md +36 -2
- package/dist/docs/references/docs-memory-working-memory.md +3 -3
- package/dist/docs/references/docs-storage-overview.md +214 -0
- package/dist/docs/references/docs-workflows-snapshots.md +1 -1
- package/dist/docs/references/reference-core-mastra-class.md +1 -1
- package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
- package/dist/docs/references/reference-file-based-agents-storage.md +30 -0
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-storage-composite.md +64 -6
- package/dist/docs/references/reference-storage-dynamodb.md +1 -1
- package/dist/docs/references/reference-storage-retention.md +74 -6
- package/dist/index.cjs +25 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/dist/vector/index.d.ts +12 -0
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/docs/references/docs-memory-storage.md +0 -267
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.16.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `LibSQLVector.close()` to release the underlying libsql client. For local file databases it checkpoints the WAL and switches back to `journal_mode=DELETE` before closing (mirroring `LibSQLStore.close()`), so the `-wal`/`-shm` sidecar files and OS handles are released promptly. Safe to call more than once. ([#19059](https://github.com/mastra-ai/mastra/pull/19059))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`e955965`](https://github.com/mastra-ai/mastra/commit/e955965dce575a903e37cf054d28ea99aa48785e), [`860ef7e`](https://github.com/mastra-ai/mastra/commit/860ef7e77d92b63469cbe5857aa1e626197e43e9), [`17e818c`](https://github.com/mastra-ai/mastra/commit/17e818c51a958ba90641b1a959dc38faf8c034e9), [`4451dfe`](https://github.com/mastra-ai/mastra/commit/4451dfe857428e7abcc0261a507a2e186dae6d47), [`1d39058`](https://github.com/mastra-ai/mastra/commit/1d39058e548efd691799985d5c8af2737f1c3bd2)]:
|
|
12
|
+
- @mastra/core@1.51.0-alpha.2
|
|
13
|
+
|
|
14
|
+
## 1.15.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Update `@mastra/core` peer dependency for the unified schedules API ([#18874](https://github.com/mastra-ai/mastra/pull/18874))
|
|
19
|
+
|
|
20
|
+
- Schedule rows persisted with the legacy `target.type: 'heartbeat'` are now normalized to `target.type: 'agent'` when read, so existing agent schedules keep firing after the heartbeats-to-schedules rename in `@mastra/core`. ([#18874](https://github.com/mastra-ai/mastra/pull/18874))
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`b291760`](https://github.com/mastra-ai/mastra/commit/b291760df9d6c7e4fc72606c8f0a4af2cf6e946c), [`3ffb8b7`](https://github.com/mastra-ai/mastra/commit/3ffb8b720e90f5e6977129ec1f6707d43c2bebe0), [`6ef59fe`](https://github.com/mastra-ai/mastra/commit/6ef59fef1da52ed8da5fbb2a892c71cf4fb6c739), [`4039488`](https://github.com/mastra-ai/mastra/commit/403948898af7293198d9e8b3e7fb47f623c78b94), [`29b7ea6`](https://github.com/mastra-ai/mastra/commit/29b7ea64e72b5523d5bdcbd34ee03d2b854d54e1), [`b2c9d70`](https://github.com/mastra-ai/mastra/commit/b2c9d70757207fb01a9069549e69b6f0d73a6636), [`a51c63d`](https://github.com/mastra-ai/mastra/commit/a51c63d8ee639e4daeba2a0be093efa6a1b5e52f), [`252f63d`](https://github.com/mastra-ai/mastra/commit/252f63d8fec723955adb2202be2f01a75ad0e69c), [`5ea76a7`](https://github.com/mastra-ai/mastra/commit/5ea76a723d966c72da9aa3ab30ae20276e049765), [`6445560`](https://github.com/mastra-ai/mastra/commit/6445560327045d20b239585fc63fed72e9ce36ec), [`e2b9f33`](https://github.com/mastra-ai/mastra/commit/e2b9f33456fd638eca555f9466c6519d8d049666), [`10959d5`](https://github.com/mastra-ai/mastra/commit/10959d509d824f682d40ff96e05ee044aec3b0e5), [`c547a77`](https://github.com/mastra-ai/mastra/commit/c547a7729bdf64dfc2df29c965046c0712a18f10), [`a0085fa`](https://github.com/mastra-ai/mastra/commit/a0085fa0934e52c37c8c8b3d75a6bb5cd199af36), [`a2ba369`](https://github.com/mastra-ai/mastra/commit/a2ba369e796dfab610f41c6875965b488272fa55), [`ffc3c17`](https://github.com/mastra-ai/mastra/commit/ffc3c17274ea17c11aa6f73d3140649cd7fc8abc), [`81542c1`](https://github.com/mastra-ai/mastra/commit/81542c1835c35bc32f2ce4fa9136ee11993cd299), [`3908e53`](https://github.com/mastra-ai/mastra/commit/3908e53ce04bbea04f5e0c097d7aa298c35fabee), [`cb24ce7`](https://github.com/mastra-ai/mastra/commit/cb24ce76bd16ca88eb6a963f6277f8780e703029), [`02705fd`](https://github.com/mastra-ai/mastra/commit/02705fd2f5a9062210d64ea061adeeb10dc9452e), [`ae51e81`](https://github.com/mastra-ai/mastra/commit/ae51e818825582d42500338dfc1929a082eff0ba), [`6f304ef`](https://github.com/mastra-ai/mastra/commit/6f304ef319e99725e884bdb8d3193c001b6e5964), [`5f9858f`](https://github.com/mastra-ai/mastra/commit/5f9858f791f1137ca7d52d23559fb4568f7a9026)]:
|
|
23
|
+
- @mastra/core@1.50.0
|
|
24
|
+
|
|
3
25
|
## 1.15.1-alpha.0
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-libsql
|
|
|
3
3
|
description: Documentation for @mastra/libsql. Use when working with @mastra/libsql APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/libsql"
|
|
6
|
-
version: "1.
|
|
6
|
+
version: "1.16.0-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -25,9 +25,9 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
25
25
|
- [Multi-user threads](references/docs-memory-multi-user-threads.md) - Share one Mastra thread between multiple users by carrying speaker identity in the message body.
|
|
26
26
|
- [Memory overview](references/docs-memory-overview.md) - Learn how Mastra's memory system works with working memory, message history, semantic recall, and observational memory.
|
|
27
27
|
- [Semantic recall](references/docs-memory-semantic-recall.md) - Learn how to use semantic recall in Mastra to retrieve relevant messages from past conversations using vector search and embeddings.
|
|
28
|
-
- [Storage](references/docs-memory-storage.md) - Configure storage for Mastra to persist conversations and other runtime state.
|
|
29
28
|
- [Working memory](references/docs-memory-working-memory.md) - Learn how to configure working memory in Mastra to store persistent user data, preferences.
|
|
30
29
|
- [Retrieval, semantic search, reranking](references/docs-rag-retrieval.md) - Guide on retrieval processes in Mastra's RAG systems, including semantic search, filtering, and re-ranking.
|
|
30
|
+
- [Storage overview](references/docs-storage-overview.md) - Configure storage for Mastra to persist runtime state across agents, workflows, observability, evals, schedules, and memory.
|
|
31
31
|
- [Snapshots](references/docs-workflows-snapshots.md) - Learn how to save and resume workflow execution state with snapshots in Mastra
|
|
32
32
|
|
|
33
33
|
### Guides
|
|
@@ -39,6 +39,8 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
39
39
|
- [Reference: Mastra.getMemory()](references/reference-core-getMemory.md) - Documentation for the `Mastra.getMemory()` method in Mastra, which retrieves a registered memory instance by its registry key.
|
|
40
40
|
- [Reference: Mastra.listMemory()](references/reference-core-listMemory.md) - Documentation for the `Mastra.listMemory()` method in Mastra, which returns all registered memory instances.
|
|
41
41
|
- [Reference: Mastra class](references/reference-core-mastra-class.md) - Documentation for the `Mastra` class in Mastra, the core entry point for managing agents, workflows, MCP servers, and server endpoints.
|
|
42
|
+
- [Memory](references/reference-file-based-agents-memory.md) - Give a file-based agent persistent memory with a memory.ts module.
|
|
43
|
+
- [Storage](references/reference-file-based-agents-storage.md) - Set the default Mastra store by file convention with storage.ts.
|
|
42
44
|
- [Reference: Memory class](references/reference-memory-memory-class.md) - Documentation for the `Memory` class in Mastra, which provides a robust system for managing conversation history and thread-based message storage.
|
|
43
45
|
- [Reference: Composite storage](references/reference-storage-composite.md) - Documentation for combining multiple storage backends in Mastra.
|
|
44
46
|
- [Reference: DynamoDB storage](references/reference-storage-dynamodb.md) - Documentation for the DynamoDB storage implementation in Mastra, using a single-table design with ElectroDB.
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
> **Note:** The Agent Builder is part of the Mastra Enterprise Edition. Production deployments require a valid EE license. [Contact sales](https://mastra.ai/contact) for more information.
|
|
6
6
|
|
|
7
|
-
[YouTube video player](https://www.youtube-nocookie.com/embed/AbdgIu4Z07I)
|
|
8
|
-
|
|
9
7
|
The Agent Builder lets you build, configure, and operate Mastra agents all within the UI. It runs inside your Mastra server, persists everything to `Mastra.storage`, and supports multi-tenant agent workflows with RBAC and channel integrations.
|
|
10
8
|
|
|
9
|
+
> **📹 Watch:** Watch [Mastra Agent Builder overview](https://www.youtube.com/watch?v=AbdgIu4Z07I) to see how teams create and configure agents from the UI.
|
|
10
|
+
|
|
11
11
|
- [**Configuration**](https://mastra.ai/docs/agent-builder/configuration): Toggle UI sections and pin admin-controlled defaults for every new agent.
|
|
12
12
|
- [**Model policy**](https://mastra.ai/docs/agent-builder/model-policy): Restrict which providers and models the Builder exposes, and pin a default.
|
|
13
13
|
- [**Memory**](https://mastra.ai/docs/agent-builder/memory): Configure the default memory shape for every Builder-created agent.
|
|
@@ -108,4 +108,5 @@ Omitting the `builder` field has the same effect.
|
|
|
108
108
|
|
|
109
109
|
- [Configuration](https://mastra.ai/docs/agent-builder/configuration): Toggle Builder surfaces and pin defaults for new agents.
|
|
110
110
|
- [Access control](https://mastra.ai/docs/agent-builder/access-control): Gate the Builder with authentication and role-based access control.
|
|
111
|
-
- [Deploying](https://mastra.ai/docs/agent-builder/deploying): Replace local development primitives with production-ready storage, filesystems, and sandboxes.
|
|
111
|
+
- [Deploying](https://mastra.ai/docs/agent-builder/deploying): Replace local development primitives with production-ready storage, filesystems, and sandboxes.
|
|
112
|
+
- 📹 [Mastra Agent Builder workshop](https://www.youtube.com/watch?v=p2p_wb-rUPg\&t=666s)
|
|
@@ -48,7 +48,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
> **Note:** Agent approval uses snapshots to capture request state. Configure a [storage provider](https://mastra.ai/docs/
|
|
51
|
+
> **Note:** Agent approval uses snapshots to capture request state. Configure a [storage provider](https://mastra.ai/docs/storage/overview) on your Mastra instance or you'll see a "snapshot not found" error.
|
|
52
52
|
>
|
|
53
53
|
> Snapshots for agent runs are minimal resume artifacts: they hold only what's needed to resume the suspended run and are deleted once the run finishes. Use [tracing](https://mastra.ai/docs/observability/overview) for the execution record and [memory](https://mastra.ai/docs/memory/overview) for the conversation history.
|
|
54
54
|
|
|
@@ -110,6 +110,29 @@ A tool can also pause _during_ its `execute` function by calling `suspend()`. Th
|
|
|
110
110
|
|
|
111
111
|
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`.
|
|
112
112
|
|
|
113
|
+
```typescript
|
|
114
|
+
const weatherTool = createTool({
|
|
115
|
+
id: 'get-weather',
|
|
116
|
+
inputSchema: z.object({
|
|
117
|
+
location: z.string().optional(),
|
|
118
|
+
}),
|
|
119
|
+
suspendSchema: z.object({
|
|
120
|
+
question: z.string(),
|
|
121
|
+
}),
|
|
122
|
+
resumeSchema: z.object({
|
|
123
|
+
location: z.string(),
|
|
124
|
+
}),
|
|
125
|
+
execute: async ({ location }, context) => {
|
|
126
|
+
if (!location) {
|
|
127
|
+
return await context?.agent?.suspend({
|
|
128
|
+
question: 'Which city would you like the weather for?',
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
return await fetchWeather(location)
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
113
136
|
> **Note:** `suspend()` doesn't throw — return immediately after calling it (e.g. `return await suspend({ ... })`). Code after `await suspend(...)` still runs before the tool pauses.
|
|
114
137
|
|
|
115
138
|
## Tool approval with `generate()`
|
|
@@ -397,7 +420,7 @@ Each returned run includes the suspended tool calls (`toolCallId`, `toolName`, `
|
|
|
397
420
|
|
|
398
421
|
The same discovery is available over HTTP as `GET /agents/:agentId/suspended-runs` and in the client SDK as [`agent.listSuspendedRuns()`](https://mastra.ai/reference/client-js/agents), so browser-based approval UIs can rediscover pending runs directly.
|
|
399
422
|
|
|
400
|
-
> **Note:** Suspended runs only survive restarts when your Mastra instance is configured with a persistent [storage provider](https://mastra.ai/docs/
|
|
423
|
+
> **Note:** Suspended runs only survive restarts when your Mastra instance is configured with a persistent [storage provider](https://mastra.ai/docs/storage/overview). The default in-memory store loses snapshots when the process exits.
|
|
401
424
|
|
|
402
425
|
## Tool approval: Supervisor agents
|
|
403
426
|
|
|
@@ -95,7 +95,7 @@ console.log(final?.summary)
|
|
|
95
95
|
|
|
96
96
|
When a primitive requires approval, the stream emits an `agent-execution-approval` or `tool-execution-approval` chunk. Use `approveNetworkToolCall()` or `declineNetworkToolCall()` to respond.
|
|
97
97
|
|
|
98
|
-
Network approval uses snapshots to capture execution state. Ensure a [storage provider](https://mastra.ai/docs/
|
|
98
|
+
Network approval uses snapshots to capture execution state. Ensure a [storage provider](https://mastra.ai/docs/storage/overview) is enabled in your Mastra instance.
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
101
|
const stream = await routingAgent.network('Perform some sensitive action', {
|
|
@@ -309,6 +309,73 @@ const agent = new Agent({
|
|
|
309
309
|
|
|
310
310
|
Both scenarios are safe - guardrails prevent inappropriate content from being persisted to memory
|
|
311
311
|
|
|
312
|
+
## Handling large attachments
|
|
313
|
+
|
|
314
|
+
Some storage providers enforce record size limits that base64-encoded file attachments can exceed:
|
|
315
|
+
|
|
316
|
+
| Provider | Record size limit |
|
|
317
|
+
| ------------------------------------------------------------------ | ----------------- |
|
|
318
|
+
| [DynamoDB](https://mastra.ai/reference/storage/dynamodb) | 400 KB |
|
|
319
|
+
| [Convex](https://mastra.ai/reference/storage/convex) | 1 MiB |
|
|
320
|
+
| [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1) | 1 MiB |
|
|
321
|
+
|
|
322
|
+
PostgreSQL, MongoDB, and libSQL have higher limits and are usually unaffected.
|
|
323
|
+
|
|
324
|
+
Use an input processor to upload attachments to external storage, then replace them with URL references before messages are persisted.
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import type { Processor } from '@mastra/core/processors'
|
|
328
|
+
import type { MastraDBMessage } from '@mastra/core/memory'
|
|
329
|
+
|
|
330
|
+
export class AttachmentUploader implements Processor {
|
|
331
|
+
id = 'attachment-uploader'
|
|
332
|
+
|
|
333
|
+
async processInput({ messages }: { messages: MastraDBMessage[] }) {
|
|
334
|
+
return Promise.all(messages.map(message => this.processMessage(message)))
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async processMessage(message: MastraDBMessage) {
|
|
338
|
+
const attachments = message.content.experimental_attachments
|
|
339
|
+
if (!attachments?.length) return message
|
|
340
|
+
|
|
341
|
+
const uploaded = await Promise.all(
|
|
342
|
+
attachments.map(async attachment => {
|
|
343
|
+
if (!attachment.url?.startsWith('data:')) return attachment
|
|
344
|
+
|
|
345
|
+
const url = await this.upload(attachment.url, attachment.contentType)
|
|
346
|
+
return { ...attachment, url }
|
|
347
|
+
}),
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
return { ...message, content: { ...message.content, experimental_attachments: uploaded } }
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async upload(dataUri: string, contentType?: string): Promise<string> {
|
|
354
|
+
const base64 = dataUri.split(',')[1]
|
|
355
|
+
const buffer = Buffer.from(base64, 'base64')
|
|
356
|
+
|
|
357
|
+
throw new Error('Implement upload() with your storage provider')
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Use the processor with your agent:
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
import { Agent } from '@mastra/core/agent'
|
|
366
|
+
import { Memory } from '@mastra/memory'
|
|
367
|
+
import { AttachmentUploader } from '../processors/attachment-uploader'
|
|
368
|
+
|
|
369
|
+
export const supportAgent = new Agent({
|
|
370
|
+
id: 'support-agent',
|
|
371
|
+
name: 'Support agent',
|
|
372
|
+
instructions: 'Answer customer support questions.',
|
|
373
|
+
model: 'openai/gpt-5.5',
|
|
374
|
+
memory: new Memory({ lastMessages: 10 }),
|
|
375
|
+
inputProcessors: [new AttachmentUploader()],
|
|
376
|
+
})
|
|
377
|
+
```
|
|
378
|
+
|
|
312
379
|
## Related documentation
|
|
313
380
|
|
|
314
381
|
- [Processors](https://mastra.ai/docs/agents/processors): General processor concepts and custom processor creation
|
|
@@ -6,7 +6,7 @@ Message history is the most basic and important form of memory. It gives the LLM
|
|
|
6
6
|
|
|
7
7
|
You can also retrieve message history to display past conversations in your UI.
|
|
8
8
|
|
|
9
|
-
> **Info:** Each message belongs to a thread (the conversation) and a resource (the user or entity it's associated with). See [Threads and resources](
|
|
9
|
+
> **Info:** Each message belongs to a thread (the conversation) and a resource (the user or entity it's associated with). See [Threads and resources](#threads-and-resources) for more detail.
|
|
10
10
|
|
|
11
11
|
> **Warning:** When you use memory with a client application, send **only the new message** from the client instead of the full conversation history.
|
|
12
12
|
>
|
|
@@ -14,9 +14,18 @@ You can also retrieve message history to display past conversations in your UI.
|
|
|
14
14
|
>
|
|
15
15
|
> For an AI SDK example, see [Using Mastra Memory](https://mastra.ai/guides/build-your-ui/ai-sdk-ui).
|
|
16
16
|
|
|
17
|
+
## Threads and resources
|
|
18
|
+
|
|
19
|
+
Mastra organizes conversations using two identifiers:
|
|
20
|
+
|
|
21
|
+
- **Thread**: A conversation session containing a sequence of messages.
|
|
22
|
+
- **Resource**: The entity that owns the thread, such as a user, organization, project, or another domain entity in your application.
|
|
23
|
+
|
|
24
|
+
Studio automatically generates a thread and resource ID for you. When calling `stream()` or `generate()` yourself, provide these identifiers explicitly.
|
|
25
|
+
|
|
17
26
|
## Getting started
|
|
18
27
|
|
|
19
|
-
Install the Mastra memory module along with a [storage adapter](https://mastra.ai/docs/
|
|
28
|
+
Install the Mastra memory module along with a [storage adapter](https://mastra.ai/docs/storage/overview) for your database. The examples below use `@mastra/libsql`, which stores data locally in a `mastra.db` file.
|
|
20
29
|
|
|
21
30
|
**npm**:
|
|
22
31
|
|
|
@@ -113,6 +122,51 @@ You can use this history in two ways:
|
|
|
113
122
|
|
|
114
123
|
> **Tip:** When memory is enabled, [Studio](https://mastra.ai/docs/studio/overview) uses message history to display past conversations in the chat sidebar.
|
|
115
124
|
|
|
125
|
+
## Thread title generation
|
|
126
|
+
|
|
127
|
+
Mastra can automatically generate descriptive thread titles based on the user's first message when `generateTitle` is enabled. Use this option when you build a chat interface that renders conversation titles in a thread list or sidebar.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { Agent } from '@mastra/core/agent'
|
|
131
|
+
import { Memory } from '@mastra/memory'
|
|
132
|
+
|
|
133
|
+
export const supportAgent = new Agent({
|
|
134
|
+
id: 'support-agent',
|
|
135
|
+
name: 'Support agent',
|
|
136
|
+
instructions: 'Answer customer support questions.',
|
|
137
|
+
model: 'openai/gpt-5.5',
|
|
138
|
+
memory: new Memory({
|
|
139
|
+
options: {
|
|
140
|
+
generateTitle: true,
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Title generation runs asynchronously after the agent responds and doesn't affect response time.
|
|
147
|
+
|
|
148
|
+
To optimize cost or behavior, provide a smaller [`model`](https://mastra.ai/models) and custom `instructions`:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { Agent } from '@mastra/core/agent'
|
|
152
|
+
import { Memory } from '@mastra/memory'
|
|
153
|
+
|
|
154
|
+
export const supportAgent = new Agent({
|
|
155
|
+
id: 'support-agent',
|
|
156
|
+
name: 'Support agent',
|
|
157
|
+
instructions: 'Answer customer support questions.',
|
|
158
|
+
model: 'openai/gpt-5.5',
|
|
159
|
+
memory: new Memory({
|
|
160
|
+
options: {
|
|
161
|
+
generateTitle: {
|
|
162
|
+
model: 'openai/gpt-5-mini',
|
|
163
|
+
instructions: 'Generate a one-word title.',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
}),
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
116
170
|
## Accessing memory
|
|
117
171
|
|
|
118
172
|
To access memory functions for querying, cloning, or deleting threads and messages, call `getMemory()` on an agent:
|
|
@@ -13,7 +13,9 @@ Mastra agents can be configured to store [message history](https://mastra.ai/doc
|
|
|
13
13
|
|
|
14
14
|
If the combined memory exceeds the model's context limit, [memory processors](https://mastra.ai/docs/memory/memory-processors) can filter, trim, or prioritize content so the most relevant information is preserved.
|
|
15
15
|
|
|
16
|
-
Memory results will be stored in one or more of your configured [storage providers](https://mastra.ai/docs/
|
|
16
|
+
Memory results will be stored in one or more of your configured [storage providers](https://mastra.ai/docs/storage/overview).
|
|
17
|
+
|
|
18
|
+
> **📹 Watch:** Watch [Mastra memory concepts](https://www.youtube.com/watch?v=18iIHQtIPmc) for a conceptual overview of the memory layers agents can use.
|
|
17
19
|
|
|
18
20
|
## When to use memory
|
|
19
21
|
|
|
@@ -75,7 +77,7 @@ Use memory when your agent needs to maintain multi-turn conversations that refer
|
|
|
75
77
|
bun add @mastra/libsql@latest
|
|
76
78
|
```
|
|
77
79
|
|
|
78
|
-
> **Note:** For more details on available providers and how storage works in Mastra, visit the [storage](https://mastra.ai/docs/
|
|
80
|
+
> **Note:** For more details on available providers and how storage works in Mastra, visit the [storage](https://mastra.ai/docs/storage/overview) documentation.
|
|
79
81
|
|
|
80
82
|
3. Add the storage provider to your main Mastra instance to enable memory across all configured agents.
|
|
81
83
|
|
|
@@ -178,7 +180,7 @@ Each delegation creates a fresh `threadId` and a deterministic `resourceId` for
|
|
|
178
180
|
- **Resource ID**: Derived as `{parentResourceId}-{agentName}`. Because the resource ID is stable across delegations, resource-scoped memory persists between calls. A subagent remembers facts from previous delegations by the same user.
|
|
179
181
|
- **Memory instance**: If a subagent has no memory configured, it inherits the supervisor's `Memory` instance, including all of its options. If the subagent defines its own, that takes precedence.
|
|
180
182
|
|
|
181
|
-
> **Note:** Title generation (`generateTitle`) is a top-level thread concern and
|
|
183
|
+
> **Note:** Title generation (`generateTitle`) is a top-level thread concern and **isn't** applied to inherited subagent threads. Because each delegation creates an ephemeral thread that no one sees, running title generation for it would waste an LLM call per delegation. To generate titles for a subagent's own threads, give that subagent its own memory configuration.
|
|
182
184
|
|
|
183
185
|
The supervisor forwards its conversation context to the subagent so it has enough background to complete the task. Only the delegation prompt and the subagent's response are saved — the full parent conversation isn't stored. You can control which messages reach the subagent with the [`messageFilter`](https://mastra.ai/docs/agents/supervisor-agents) callback.
|
|
184
186
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
If you ask your friend what they did last weekend, they will search in their memory for events associated with "last weekend" and then tell you what they did. That's sort of like how semantic recall works in Mastra.
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> **📹 Watch:** Watch [Mastra semantic recall](https://www.youtube.com/watch?v=UVZtK8cK8xQ\&pp=ygUVbWFzdHJhIHdvcmtpbmcgbWVtb3J5) to see how agents retrieve relevant messages from past conversations.
|
|
8
8
|
|
|
9
9
|
## How semantic recall works
|
|
10
10
|
|
|
@@ -22,6 +22,8 @@ After getting a response from the LLM, all new messages (user, assistant, and to
|
|
|
22
22
|
|
|
23
23
|
Semantic recall is disabled by default. To enable it, set `semanticRecall: true` in `options` and provide a `vector` store and `embedder`:
|
|
24
24
|
|
|
25
|
+
**LibSQL**:
|
|
26
|
+
|
|
25
27
|
```typescript
|
|
26
28
|
import { Agent } from '@mastra/core/agent'
|
|
27
29
|
import { Memory } from '@mastra/memory'
|
|
@@ -50,6 +52,38 @@ const agent = new Agent({
|
|
|
50
52
|
})
|
|
51
53
|
```
|
|
52
54
|
|
|
55
|
+
**MongoDB**:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { Agent } from '@mastra/core/agent'
|
|
59
|
+
import { Memory } from '@mastra/memory'
|
|
60
|
+
import { MongoDBStore, MongoDBVector } from '@mastra/mongodb'
|
|
61
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
62
|
+
|
|
63
|
+
const agent = new Agent({
|
|
64
|
+
id: 'support-agent',
|
|
65
|
+
name: 'SupportAgent',
|
|
66
|
+
instructions: 'You are a helpful support agent.',
|
|
67
|
+
model: 'openai/gpt-5.5',
|
|
68
|
+
memory: new Memory({
|
|
69
|
+
storage: new MongoDBStore({
|
|
70
|
+
id: 'agent-storage',
|
|
71
|
+
uri: process.env.MONGODB_URI,
|
|
72
|
+
dbName: process.env.MONGODB_DB_NAME,
|
|
73
|
+
}),
|
|
74
|
+
vector: new MongoDBVector({
|
|
75
|
+
id: 'agent-vector',
|
|
76
|
+
uri: process.env.MONGODB_URI,
|
|
77
|
+
dbName: process.env.MONGODB_DB_NAME,
|
|
78
|
+
}),
|
|
79
|
+
embedder: new ModelRouterEmbeddingModel('openai/text-embedding-3-small'),
|
|
80
|
+
options: {
|
|
81
|
+
semanticRecall: true,
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
53
87
|
## Using the `recall()` method
|
|
54
88
|
|
|
55
89
|
While `listMessages` retrieves messages by thread ID with basic pagination, [`recall()`](https://mastra.ai/reference/memory/recall) adds support for **semantic search**. When you need to find messages by meaning rather than recency, use `recall()` with a `vectorSearchString`:
|
|
@@ -146,7 +180,7 @@ const agent = new Agent({
|
|
|
146
180
|
})
|
|
147
181
|
```
|
|
148
182
|
|
|
149
|
-
> **Note:** `scope: 'resource'` is supported by the LibSQL, PostgreSQL, and Upstash storage adapters.
|
|
183
|
+
> **Note:** `scope: 'resource'` is supported by the LibSQL, PostgreSQL, MongoDB, and Upstash storage adapters.
|
|
150
184
|
|
|
151
185
|
### Metadata filtering
|
|
152
186
|
|
|
@@ -10,6 +10,8 @@ This is useful for maintaining ongoing state that's always relevant and should a
|
|
|
10
10
|
|
|
11
11
|
If you use [Observational Memory](https://mastra.ai/docs/memory/observational-memory), `observationalMemory.observation.manageWorkingMemory` lets OM update working memory for the agent.
|
|
12
12
|
|
|
13
|
+
> **📹 Watch:** Watch [Mastra working memory](https://www.youtube.com/watch?v=UMy_JHLf1n8\&pp=ygUVbWFzdHJhIHdvcmtpbmcgbWVtb3J5) to see how agents keep persistent user context available across interactions.
|
|
14
|
+
|
|
13
15
|
Working memory can persist at two different scopes:
|
|
14
16
|
|
|
15
17
|
- **Resource-scoped** (default): Memory persists across all conversation threads for the same user
|
|
@@ -43,9 +45,7 @@ const agent = new Agent({
|
|
|
43
45
|
|
|
44
46
|
## How it works
|
|
45
47
|
|
|
46
|
-
Working memory is a block of Markdown text that the agent is able to update over time to store continuously relevant information
|
|
47
|
-
|
|
48
|
-
[YouTube video player](https://www.youtube-nocookie.com/embed/UMy_JHLf1n8)
|
|
48
|
+
Working memory is a block of Markdown text that the agent is able to update over time to store continuously relevant information.
|
|
49
49
|
|
|
50
50
|
## Memory persistence scopes
|
|
51
51
|
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Storage overview
|
|
4
|
+
|
|
5
|
+
Storage is the persistence layer for the Mastra runtime. It keeps memory, workflow state, observability data, eval results, schedules, and long-running agent state available after a process restarts.
|
|
6
|
+
|
|
7
|
+
Storage powers:
|
|
8
|
+
|
|
9
|
+
- [Memory](https://mastra.ai/docs/memory/overview): Message history, threads, resources, and working memory.
|
|
10
|
+
- [Workflows](https://mastra.ai/docs/workflows/overview): Durable snapshots for suspended and resumed workflow runs.
|
|
11
|
+
- [Observability](https://mastra.ai/docs/observability/overview): Traces, spans, metrics, logs, and feedback.
|
|
12
|
+
- [Evals](https://mastra.ai/docs/evals/overview): Scores, datasets, experiments, and evaluation results.
|
|
13
|
+
- [Long-running agents](https://mastra.ai/docs/long-running-agents/durable-agents): Background tasks, schedules, goals, and thread state.
|
|
14
|
+
|
|
15
|
+
## When to configure storage
|
|
16
|
+
|
|
17
|
+
Configure a persistent storage adapter when state must survive restarts, be shared across processes, or be visible in Studio across sessions. The default in-memory store is useful for tests and short local experiments, but it loses data when the process exits.
|
|
18
|
+
|
|
19
|
+
Use storage when your application needs any of these behaviors:
|
|
20
|
+
|
|
21
|
+
- Agents remember past messages or user facts.
|
|
22
|
+
- Workflows suspend and resume after a restart.
|
|
23
|
+
- Traces, metrics, logs, scores, or feedback stay available for analysis.
|
|
24
|
+
- Schedules and background tasks continue across deployments.
|
|
25
|
+
- Multiple runtime processes read and write the same state.
|
|
26
|
+
|
|
27
|
+
## How storage works
|
|
28
|
+
|
|
29
|
+
Mastra storage is organized into **domains**. A domain owns one type of runtime data, and a storage adapter implements one or more domains.
|
|
30
|
+
|
|
31
|
+
| Domain | What it stores |
|
|
32
|
+
| ----------------- | --------------------------------------------------------------------------- |
|
|
33
|
+
| `memory` | Threads, messages, resources, working memory, and other agent memory state. |
|
|
34
|
+
| `workflows` | Workflow snapshots used to suspend and resume runs. |
|
|
35
|
+
| `observability` | Traces, spans, metrics, logs, and feedback. |
|
|
36
|
+
| `scores` | Eval score records. |
|
|
37
|
+
| `datasets` | Dataset records and dataset items used by evals and experiments. |
|
|
38
|
+
| `experiments` | Experiment runs and per-item experiment results. |
|
|
39
|
+
| `backgroundTasks` | Background task records and execution state. |
|
|
40
|
+
| `schedules` | Schedule definitions and trigger history. |
|
|
41
|
+
| `threadState` | Durable task, goal, and thread state. |
|
|
42
|
+
|
|
43
|
+
Adapter support varies by domain. For the full domain list and built-in schemas, see the [storage overview reference](https://mastra.ai/reference/storage/overview).
|
|
44
|
+
|
|
45
|
+
## Choose a backend by data shape
|
|
46
|
+
|
|
47
|
+
Different domains write and query different kinds of data. Pick a backend based on the domain's access pattern:
|
|
48
|
+
|
|
49
|
+
- `memory`: Reads and writes rows during every remembered agent call. Use a transactional database such as libSQL, PostgreSQL, or MongoDB.
|
|
50
|
+
- `observability`: Writes high-volume telemetry and often queries aggregations. Use a dedicated observability store or an online analytical processing (OLAP) backend such as ClickHouse or DuckDB.
|
|
51
|
+
- `workflows`: Stores durable snapshots that must be available when a run resumes. Use a reliable persistent database.
|
|
52
|
+
- `scores`, `datasets`, and `experiments`: Store lower-frequency evaluation data that's often read later for analysis.
|
|
53
|
+
- `schedules`: Stores schedule definitions and fire history. Use an adapter that implements the schedules domain.
|
|
54
|
+
|
|
55
|
+
When domains have different operational needs, use [composite storage](#composite-storage) to route each domain to the right backend.
|
|
56
|
+
|
|
57
|
+
## Get started locally
|
|
58
|
+
|
|
59
|
+
For local development, use libSQL with a file-backed database. It doesn't require a separate database server and persists state between restarts.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { Mastra } from '@mastra/core'
|
|
63
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
64
|
+
|
|
65
|
+
export const mastra = new Mastra({
|
|
66
|
+
storage: new LibSQLStore({
|
|
67
|
+
id: 'mastra-storage',
|
|
68
|
+
url: 'file:./mastra.db',
|
|
69
|
+
}),
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
> **Sharing the database with Studio:** When running `mastra dev` alongside your application, use an absolute path so both processes access the same database:
|
|
74
|
+
>
|
|
75
|
+
> ```typescript
|
|
76
|
+
> url: 'file:/absolute/path/to/your/project/mastra.db'
|
|
77
|
+
> ```
|
|
78
|
+
>
|
|
79
|
+
> Relative paths like `file:./mastra.db` resolve based on each process's working directory, which may differ.
|
|
80
|
+
|
|
81
|
+
Mastra initializes the required storage structures on first use.
|
|
82
|
+
|
|
83
|
+
## Configure for production
|
|
84
|
+
|
|
85
|
+
For production, use a persistent managed database. PostgreSQL is a good default for most teams because it works well for transactional runtime state and is widely available as a managed service.
|
|
86
|
+
|
|
87
|
+
Production guidance:
|
|
88
|
+
|
|
89
|
+
- Use a managed database with backups, monitoring, and connection pooling.
|
|
90
|
+
- Keep local file databases such as `file:./mastra.db` out of multi-process production deployments.
|
|
91
|
+
- Route high-volume domains, especially `observability`, to a dedicated backend with [composite storage](#composite-storage).
|
|
92
|
+
- Configure [retention](https://mastra.ai/reference/storage/retention) policies on the storage adapter or composite store, then call `storage.prune()` from a scheduler or maintenance job.
|
|
93
|
+
- Choose providers based on the domains your application uses. For example, schedules require an adapter that implements the `schedules` domain.
|
|
94
|
+
|
|
95
|
+
## Configuration scope
|
|
96
|
+
|
|
97
|
+
Storage can be configured at the Mastra instance level or at the agent level.
|
|
98
|
+
|
|
99
|
+
### Instance-level storage
|
|
100
|
+
|
|
101
|
+
Instance-level storage is shared by agents, workflows, observability, evals, schedules, and other runtime features registered on the same Mastra instance.
|
|
102
|
+
|
|
103
|
+
**PostgreSQL**:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { Mastra } from '@mastra/core'
|
|
107
|
+
import { PostgresStore } from '@mastra/pg'
|
|
108
|
+
|
|
109
|
+
export const mastra = new Mastra({
|
|
110
|
+
storage: new PostgresStore({
|
|
111
|
+
id: 'mastra-storage',
|
|
112
|
+
connectionString: process.env.DATABASE_URL,
|
|
113
|
+
}),
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**MongoDB**:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { Mastra } from '@mastra/core'
|
|
121
|
+
import { MongoDBStore } from '@mastra/mongodb'
|
|
122
|
+
|
|
123
|
+
export const mastra = new Mastra({
|
|
124
|
+
storage: new MongoDBStore({
|
|
125
|
+
id: 'mastra-storage',
|
|
126
|
+
uri: process.env.MONGODB_URI,
|
|
127
|
+
dbName: process.env.MONGODB_DB_NAME,
|
|
128
|
+
}),
|
|
129
|
+
})
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Use instance-level storage when most runtime domains can share the same database.
|
|
133
|
+
|
|
134
|
+
### Agent-level storage
|
|
135
|
+
|
|
136
|
+
Agent-level storage is configured on a `Memory` instance. It overrides instance-level storage for that agent's memory data only.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { Agent } from '@mastra/core/agent'
|
|
140
|
+
import { Memory } from '@mastra/memory'
|
|
141
|
+
import { PostgresStore } from '@mastra/pg'
|
|
142
|
+
|
|
143
|
+
export const supportAgent = new Agent({
|
|
144
|
+
id: 'support-agent',
|
|
145
|
+
name: 'Support agent',
|
|
146
|
+
instructions: 'Answer customer support questions.',
|
|
147
|
+
model: 'openai/gpt-5.5',
|
|
148
|
+
memory: new Memory({
|
|
149
|
+
storage: new PostgresStore({
|
|
150
|
+
id: 'support-agent-storage',
|
|
151
|
+
connectionString: process.env.SUPPORT_AGENT_DATABASE_URL,
|
|
152
|
+
}),
|
|
153
|
+
}),
|
|
154
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Use agent-level storage when an agent needs an isolated memory boundary or a different memory backend.
|
|
158
|
+
|
|
159
|
+
## Composite storage
|
|
160
|
+
|
|
161
|
+
[`MastraCompositeStore`](https://mastra.ai/reference/storage/composite) routes domains to different backends. Use it when one database isn't the right fit for every domain.
|
|
162
|
+
|
|
163
|
+
The following example uses libSQL as the default store and routes workflow state to PostgreSQL:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { Mastra } from '@mastra/core'
|
|
167
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
168
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
169
|
+
import { WorkflowsPG } from '@mastra/pg'
|
|
170
|
+
|
|
171
|
+
export const mastra = new Mastra({
|
|
172
|
+
storage: new MastraCompositeStore({
|
|
173
|
+
id: 'composite-storage',
|
|
174
|
+
default: new LibSQLStore({
|
|
175
|
+
id: 'default-storage',
|
|
176
|
+
url: 'file:./mastra.db',
|
|
177
|
+
}),
|
|
178
|
+
domains: {
|
|
179
|
+
workflows: new WorkflowsPG({
|
|
180
|
+
connectionString: process.env.DATABASE_URL,
|
|
181
|
+
}),
|
|
182
|
+
},
|
|
183
|
+
}),
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
You can also route `observability` to a dedicated analytics backend. See [observability storage](https://mastra.ai/docs/observability/storage) for an observability-specific example.
|
|
188
|
+
|
|
189
|
+
## Supported providers
|
|
190
|
+
|
|
191
|
+
Each provider page includes installation instructions, configuration parameters, and usage examples:
|
|
192
|
+
|
|
193
|
+
- [libSQL](https://mastra.ai/reference/storage/libsql)
|
|
194
|
+
- [PostgreSQL](https://mastra.ai/reference/storage/postgresql)
|
|
195
|
+
- [MongoDB](https://mastra.ai/reference/storage/mongodb)
|
|
196
|
+
- [Upstash](https://mastra.ai/reference/storage/upstash)
|
|
197
|
+
- [Redis](https://mastra.ai/reference/storage/redis)
|
|
198
|
+
- [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
|
|
199
|
+
- [Cloudflare KV & Durable Objects](https://mastra.ai/reference/storage/cloudflare)
|
|
200
|
+
- [Convex](https://mastra.ai/reference/storage/convex)
|
|
201
|
+
- [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
|
|
202
|
+
- [LanceDB](https://mastra.ai/reference/storage/lance)
|
|
203
|
+
- [Microsoft SQL Server](https://mastra.ai/reference/storage/mssql)
|
|
204
|
+
- [Google Cloud Spanner](https://mastra.ai/reference/storage/spanner)
|
|
205
|
+
|
|
206
|
+
> **Tip:** libSQL is the fastest path for local development because it doesn't require running a separate database server.
|
|
207
|
+
|
|
208
|
+
## Next steps
|
|
209
|
+
|
|
210
|
+
- [Composite storage](https://mastra.ai/reference/storage/composite)
|
|
211
|
+
- [Storage retention](https://mastra.ai/reference/storage/retention)
|
|
212
|
+
- [Storage schemas](https://mastra.ai/reference/storage/overview)
|
|
213
|
+
- [Memory](https://mastra.ai/docs/memory/overview)
|
|
214
|
+
- [Observability storage](https://mastra.ai/docs/observability/storage)
|
|
@@ -145,7 +145,7 @@ export const mastra = new Mastra({
|
|
|
145
145
|
- [Upstash Storage](https://mastra.ai/reference/storage/upstash)
|
|
146
146
|
- [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
|
|
147
147
|
- [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
|
|
148
|
-
- [More storage providers](https://mastra.ai/docs/
|
|
148
|
+
- [More storage providers](https://mastra.ai/docs/storage/overview)
|
|
149
149
|
|
|
150
150
|
## Best practices
|
|
151
151
|
|