@mastra/libsql 1.0.0-beta.10 → 1.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +184 -0
- package/dist/docs/README.md +39 -0
- package/dist/docs/SKILL.md +40 -0
- package/dist/docs/SOURCE_MAP.json +6 -0
- package/dist/docs/agents/01-agent-memory.md +160 -0
- package/dist/docs/agents/02-networks.md +292 -0
- package/dist/docs/agents/03-agent-approval.md +316 -0
- package/dist/docs/agents/04-network-approval.md +274 -0
- package/dist/docs/core/01-reference.md +151 -0
- package/dist/docs/guides/01-ai-sdk.md +141 -0
- package/dist/docs/memory/01-overview.md +76 -0
- package/dist/docs/memory/02-storage.md +215 -0
- package/dist/docs/memory/03-working-memory.md +390 -0
- package/dist/docs/memory/04-semantic-recall.md +233 -0
- package/dist/docs/memory/05-memory-processors.md +318 -0
- package/dist/docs/memory/06-reference.md +133 -0
- package/dist/docs/observability/01-overview.md +64 -0
- package/dist/docs/observability/02-default.md +177 -0
- package/dist/docs/rag/01-retrieval.md +548 -0
- package/dist/docs/storage/01-reference.md +542 -0
- package/dist/docs/vectors/01-reference.md +213 -0
- package/dist/docs/workflows/01-snapshots.md +240 -0
- package/dist/index.cjs +249 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +249 -60
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/utils.d.ts +16 -1
- package/dist/storage/db/utils.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +2 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +0 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +6 -2
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,189 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Changed JSON columns from TEXT to JSONB in `mastra_threads` and `mastra_workflow_snapshot` tables. ([#11853](https://github.com/mastra-ai/mastra/pull/11853))
|
|
8
|
+
|
|
9
|
+
**Why this change?**
|
|
10
|
+
|
|
11
|
+
These were the last remaining columns storing JSON as TEXT. This change aligns them with other tables that already use JSONB, enabling native JSON operators and improved performance. See [#8978](https://github.com/mastra-ai/mastra/issues/8978) for details.
|
|
12
|
+
|
|
13
|
+
**Columns Changed:**
|
|
14
|
+
- `mastra_threads.metadata` - Thread metadata
|
|
15
|
+
- `mastra_workflow_snapshot.snapshot` - Workflow run state
|
|
16
|
+
|
|
17
|
+
**PostgreSQL**
|
|
18
|
+
|
|
19
|
+
Migration Required - PostgreSQL enforces column types, so existing tables must be migrated. Note: Migration will fail if existing column values contain invalid JSON.
|
|
20
|
+
|
|
21
|
+
```sql
|
|
22
|
+
ALTER TABLE mastra_threads
|
|
23
|
+
ALTER COLUMN metadata TYPE jsonb
|
|
24
|
+
USING metadata::jsonb;
|
|
25
|
+
|
|
26
|
+
ALTER TABLE mastra_workflow_snapshot
|
|
27
|
+
ALTER COLUMN snapshot TYPE jsonb
|
|
28
|
+
USING snapshot::jsonb;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**LibSQL**
|
|
32
|
+
|
|
33
|
+
No Migration Required - LibSQL now uses native SQLite JSONB format (added in SQLite 3.45) for ~3x performance improvement on JSON operations. The changes are fully backwards compatible:
|
|
34
|
+
- Existing TEXT JSON data continues to work
|
|
35
|
+
- New data is stored in binary JSONB format
|
|
36
|
+
- Both formats can coexist in the same table
|
|
37
|
+
- All JSON functions (`json_extract`, etc.) work on both formats
|
|
38
|
+
|
|
39
|
+
New installations automatically use JSONB. Existing applications continue to work without any changes.
|
|
40
|
+
|
|
41
|
+
- Aligned vector store configuration with underlying library APIs, giving you access to all library options directly. ([#11742](https://github.com/mastra-ai/mastra/pull/11742))
|
|
42
|
+
|
|
43
|
+
**Why this change?**
|
|
44
|
+
|
|
45
|
+
Previously, each vector store defined its own configuration types that only exposed a subset of the underlying library's options. This meant users couldn't access advanced features like authentication, SSL, compression, or custom headers without creating their own client instances. Now, the configuration types extend the library types directly, so all options are available.
|
|
46
|
+
|
|
47
|
+
**@mastra/libsql** (Breaking)
|
|
48
|
+
|
|
49
|
+
Renamed `connectionUrl` to `url` to match the `@libsql/client` API and align with LibSQLStorage.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Before
|
|
53
|
+
new LibSQLVector({ id: 'my-vector', connectionUrl: 'file:./db.sqlite' });
|
|
54
|
+
|
|
55
|
+
// After
|
|
56
|
+
new LibSQLVector({ id: 'my-vector', url: 'file:./db.sqlite' });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**@mastra/opensearch** (Breaking)
|
|
60
|
+
|
|
61
|
+
Renamed `url` to `node` and added support for all OpenSearch `ClientOptions` including authentication, SSL, and compression.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Before
|
|
65
|
+
new OpenSearchVector({ id: 'my-vector', url: 'http://localhost:9200' });
|
|
66
|
+
|
|
67
|
+
// After
|
|
68
|
+
new OpenSearchVector({ id: 'my-vector', node: 'http://localhost:9200' });
|
|
69
|
+
|
|
70
|
+
// With authentication (now possible)
|
|
71
|
+
new OpenSearchVector({
|
|
72
|
+
id: 'my-vector',
|
|
73
|
+
node: 'https://localhost:9200',
|
|
74
|
+
auth: { username: 'admin', password: 'admin' },
|
|
75
|
+
ssl: { rejectUnauthorized: false },
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**@mastra/pinecone** (Breaking)
|
|
80
|
+
|
|
81
|
+
Removed `environment` parameter. Use `controllerHostUrl` instead (the actual Pinecone SDK field name). Added support for all `PineconeConfiguration` options.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Before
|
|
85
|
+
new PineconeVector({ id: 'my-vector', apiKey: '...', environment: '...' });
|
|
86
|
+
|
|
87
|
+
// After
|
|
88
|
+
new PineconeVector({ id: 'my-vector', apiKey: '...' });
|
|
89
|
+
|
|
90
|
+
// With custom controller host (if needed)
|
|
91
|
+
new PineconeVector({ id: 'my-vector', apiKey: '...', controllerHostUrl: '...' });
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**@mastra/clickhouse**
|
|
95
|
+
|
|
96
|
+
Added support for all `ClickHouseClientConfigOptions` like `request_timeout`, `compression`, `keep_alive`, and `database`. Existing configurations continue to work unchanged.
|
|
97
|
+
|
|
98
|
+
**@mastra/cloudflare, @mastra/cloudflare-d1, @mastra/lance, @mastra/libsql, @mastra/mongodb, @mastra/pg, @mastra/upstash**
|
|
99
|
+
|
|
100
|
+
Improved logging by replacing `console.warn` with structured logger in workflow storage domains.
|
|
101
|
+
|
|
102
|
+
**@mastra/deployer-cloud**
|
|
103
|
+
|
|
104
|
+
Updated internal LibSQLVector configuration for compatibility with the new API.
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- Updated dependencies [[`ebae12a`](https://github.com/mastra-ai/mastra/commit/ebae12a2dd0212e75478981053b148a2c246962d), [`c61a0a5`](https://github.com/mastra-ai/mastra/commit/c61a0a5de4904c88fd8b3718bc26d1be1c2ec6e7), [`69136e7`](https://github.com/mastra-ai/mastra/commit/69136e748e32f57297728a4e0f9a75988462f1a7), [`449aed2`](https://github.com/mastra-ai/mastra/commit/449aed2ba9d507b75bf93d427646ea94f734dfd1), [`eb648a2`](https://github.com/mastra-ai/mastra/commit/eb648a2cc1728f7678768dd70cd77619b448dab9), [`0131105`](https://github.com/mastra-ai/mastra/commit/0131105532e83bdcbb73352fc7d0879eebf140dc), [`9d5059e`](https://github.com/mastra-ai/mastra/commit/9d5059eae810829935fb08e81a9bb7ecd5b144a7), [`ef756c6`](https://github.com/mastra-ai/mastra/commit/ef756c65f82d16531c43f49a27290a416611e526), [`b00ccd3`](https://github.com/mastra-ai/mastra/commit/b00ccd325ebd5d9e37e34dd0a105caae67eb568f), [`3bdfa75`](https://github.com/mastra-ai/mastra/commit/3bdfa7507a91db66f176ba8221aa28dd546e464a), [`e770de9`](https://github.com/mastra-ai/mastra/commit/e770de941a287a49b1964d44db5a5763d19890a6), [`52e2716`](https://github.com/mastra-ai/mastra/commit/52e2716b42df6eff443de72360ae83e86ec23993), [`27b4040`](https://github.com/mastra-ai/mastra/commit/27b4040bfa1a95d92546f420a02a626b1419a1d6), [`610a70b`](https://github.com/mastra-ai/mastra/commit/610a70bdad282079f0c630e0d7bb284578f20151), [`8dc7f55`](https://github.com/mastra-ai/mastra/commit/8dc7f55900395771da851dc7d78d53ae84fe34ec), [`8379099`](https://github.com/mastra-ai/mastra/commit/8379099fc467af6bef54dd7f80c9bd75bf8bbddf), [`8c0ec25`](https://github.com/mastra-ai/mastra/commit/8c0ec25646c8a7df253ed1e5ff4863a0d3f1316c), [`ff4d9a6`](https://github.com/mastra-ai/mastra/commit/ff4d9a6704fc87b31a380a76ed22736fdedbba5a), [`69821ef`](https://github.com/mastra-ai/mastra/commit/69821ef806482e2c44e2197ac0b050c3fe3a5285), [`1ed5716`](https://github.com/mastra-ai/mastra/commit/1ed5716830867b3774c4a1b43cc0d82935f32b96), [`4186bdd`](https://github.com/mastra-ai/mastra/commit/4186bdd00731305726fa06adba0b076a1d50b49f), [`7aaf973`](https://github.com/mastra-ai/mastra/commit/7aaf973f83fbbe9521f1f9e7a4fd99b8de464617)]:
|
|
109
|
+
- @mastra/core@1.0.0-beta.22
|
|
110
|
+
|
|
111
|
+
## 1.0.0-beta.11
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- Add embedded documentation support for Mastra packages ([#11472](https://github.com/mastra-ai/mastra/pull/11472))
|
|
116
|
+
|
|
117
|
+
Mastra packages now include embedded documentation in the published npm package under `dist/docs/`. This enables coding agents and AI assistants to understand and use the framework by reading documentation directly from `node_modules`.
|
|
118
|
+
|
|
119
|
+
Each package includes:
|
|
120
|
+
- **SKILL.md** - Entry point explaining the package's purpose and capabilities
|
|
121
|
+
- **SOURCE_MAP.json** - Machine-readable index mapping exports to types and implementation files
|
|
122
|
+
- **Topic folders** - Conceptual documentation organized by feature area
|
|
123
|
+
|
|
124
|
+
Documentation is driven by the `packages` frontmatter field in MDX files, which maps docs to their corresponding packages. CI validation ensures all docs include this field.
|
|
125
|
+
|
|
126
|
+
- Added `startExclusive` and `endExclusive` options to `dateRange` filter for message queries. ([#11479](https://github.com/mastra-ai/mastra/pull/11479))
|
|
127
|
+
|
|
128
|
+
**What changed:** The `filter.dateRange` parameter in `listMessages()` and `Memory.recall()` now supports `startExclusive` and `endExclusive` boolean options. When set to `true`, messages with timestamps exactly matching the boundary are excluded from results.
|
|
129
|
+
|
|
130
|
+
**Why this matters:** Enables cursor-based pagination for chat applications. When new messages arrive during a session, offset-based pagination can skip or duplicate messages. Using `endExclusive: true` with the oldest message's timestamp as a cursor ensures consistent pagination without gaps or duplicates.
|
|
131
|
+
|
|
132
|
+
**Example:**
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Get first page
|
|
136
|
+
const page1 = await memory.recall({
|
|
137
|
+
threadId: 'thread-123',
|
|
138
|
+
perPage: 10,
|
|
139
|
+
orderBy: { field: 'createdAt', direction: 'DESC' },
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Get next page using cursor-based pagination
|
|
143
|
+
const oldestMessage = page1.messages[page1.messages.length - 1];
|
|
144
|
+
const page2 = await memory.recall({
|
|
145
|
+
threadId: 'thread-123',
|
|
146
|
+
perPage: 10,
|
|
147
|
+
orderBy: { field: 'createdAt', direction: 'DESC' },
|
|
148
|
+
filter: {
|
|
149
|
+
dateRange: {
|
|
150
|
+
end: oldestMessage.createdAt,
|
|
151
|
+
endExclusive: true, // Excludes the cursor message
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- Adds thread cloning to create independent copies of conversations that can diverge. ([#11517](https://github.com/mastra-ai/mastra/pull/11517))
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Clone a thread
|
|
161
|
+
const { thread, clonedMessages } = await memory.cloneThread({
|
|
162
|
+
sourceThreadId: 'thread-123',
|
|
163
|
+
title: 'My Clone',
|
|
164
|
+
options: {
|
|
165
|
+
messageLimit: 10, // optional: only copy last N messages
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Check if a thread is a clone
|
|
170
|
+
if (memory.isClone(thread)) {
|
|
171
|
+
const source = await memory.getSourceThread(thread.id);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// List all clones of a thread
|
|
175
|
+
const clones = await memory.listClones('thread-123');
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Includes:
|
|
179
|
+
- Storage implementations for InMemory, PostgreSQL, LibSQL, Upstash
|
|
180
|
+
- API endpoint: `POST /api/memory/threads/:threadId/clone`
|
|
181
|
+
- Embeddings created for cloned messages (semantic recall)
|
|
182
|
+
- Clone button in playground UI Memory tab
|
|
183
|
+
|
|
184
|
+
- Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
|
|
185
|
+
- @mastra/core@1.0.0-beta.20
|
|
186
|
+
|
|
3
187
|
## 1.0.0-beta.10
|
|
4
188
|
|
|
5
189
|
### Patch Changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @mastra/libsql Documentation
|
|
2
|
+
|
|
3
|
+
> Embedded documentation for coding agents
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Read the skill overview
|
|
9
|
+
cat docs/SKILL.md
|
|
10
|
+
|
|
11
|
+
# Get the source map
|
|
12
|
+
cat docs/SOURCE_MAP.json
|
|
13
|
+
|
|
14
|
+
# Read topic documentation
|
|
15
|
+
cat docs/<topic>/01-overview.md
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Structure
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
docs/
|
|
22
|
+
├── SKILL.md # Entry point
|
|
23
|
+
├── README.md # This file
|
|
24
|
+
├── SOURCE_MAP.json # Export index
|
|
25
|
+
├── agents/ (4 files)
|
|
26
|
+
├── core/ (3 files)
|
|
27
|
+
├── guides/ (1 files)
|
|
28
|
+
├── memory/ (6 files)
|
|
29
|
+
├── observability/ (2 files)
|
|
30
|
+
├── rag/ (1 files)
|
|
31
|
+
├── storage/ (3 files)
|
|
32
|
+
├── vectors/ (1 files)
|
|
33
|
+
├── workflows/ (1 files)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Version
|
|
37
|
+
|
|
38
|
+
Package: @mastra/libsql
|
|
39
|
+
Version: 1.0.0-beta.12
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mastra-libsql-docs
|
|
3
|
+
description: Documentation for @mastra/libsql. Includes links to type definitions and readable implementation code in dist/.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @mastra/libsql Documentation
|
|
7
|
+
|
|
8
|
+
> **Version**: 1.0.0-beta.12
|
|
9
|
+
> **Package**: @mastra/libsql
|
|
10
|
+
|
|
11
|
+
## Quick Navigation
|
|
12
|
+
|
|
13
|
+
Use SOURCE_MAP.json to find any export:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cat docs/SOURCE_MAP.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Each export maps to:
|
|
20
|
+
- **types**: `.d.ts` file with JSDoc and API signatures
|
|
21
|
+
- **implementation**: `.js` chunk file with readable source
|
|
22
|
+
- **docs**: Conceptual documentation in `docs/`
|
|
23
|
+
|
|
24
|
+
## Top Exports
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
See SOURCE_MAP.json for the complete list.
|
|
29
|
+
|
|
30
|
+
## Available Topics
|
|
31
|
+
|
|
32
|
+
- [Agents](agents/) - 4 file(s)
|
|
33
|
+
- [Core](core/) - 3 file(s)
|
|
34
|
+
- [Guides](guides/) - 1 file(s)
|
|
35
|
+
- [Memory](memory/) - 6 file(s)
|
|
36
|
+
- [Observability](observability/) - 2 file(s)
|
|
37
|
+
- [Rag](rag/) - 1 file(s)
|
|
38
|
+
- [Storage](storage/) - 3 file(s)
|
|
39
|
+
- [Vectors](vectors/) - 1 file(s)
|
|
40
|
+
- [Workflows](workflows/) - 1 file(s)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
> Learn how to add memory to agents to store message history and maintain context across interactions.
|
|
2
|
+
|
|
3
|
+
# Agent memory
|
|
4
|
+
|
|
5
|
+
Agents use memory to maintain context across interactions. LLMs are stateless and don't retain information between calls, so agents need memory to track message history and recall relevant information.
|
|
6
|
+
|
|
7
|
+
Mastra agents can be configured to store message history, with optional [working memory](../memory/working-memory) to maintain recent context or [semantic recall](../memory/semantic-recall) to retrieve past messages based on meaning.
|
|
8
|
+
|
|
9
|
+
## When to use memory
|
|
10
|
+
|
|
11
|
+
Use memory when your agent needs to maintain multi-turn conversations that reference prior exchanges, recall user preferences or facts from earlier in a session, or build context over time within a conversation thread. Skip memory for single-turn requests where each interaction is independent.
|
|
12
|
+
|
|
13
|
+
## Setting up memory
|
|
14
|
+
|
|
15
|
+
To enable memory in Mastra, install the `@mastra/memory` package along with a storage provider.
|
|
16
|
+
|
|
17
|
+
```bash npm2yarn
|
|
18
|
+
npm install @mastra/memory@beta @mastra/libsql@beta
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Storage providers
|
|
22
|
+
|
|
23
|
+
Memory requires a storage provider to persist message history, including user messages and agent responses. For more details on available providers and how storage works in Mastra, see the [Storage](https://mastra.ai/docs/v1/memory/storage) documentation.
|
|
24
|
+
|
|
25
|
+
## Configuring memory
|
|
26
|
+
|
|
27
|
+
### Step
|
|
28
|
+
|
|
29
|
+
Enable memory by creating a `Memory` instance and passing it to the agent’s `memory` option.
|
|
30
|
+
|
|
31
|
+
```typescript {7-11} title="src/mastra/agents/memory-agent.ts"
|
|
32
|
+
import { Agent } from "@mastra/core/agent";
|
|
33
|
+
import { Memory } from "@mastra/memory";
|
|
34
|
+
|
|
35
|
+
export const memoryAgent = new Agent({
|
|
36
|
+
id: 'memory-agent',
|
|
37
|
+
name: 'Memory Agent',
|
|
38
|
+
memory: new Memory({
|
|
39
|
+
options: {
|
|
40
|
+
lastMessages: 20,
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> **Note:**
|
|
47
|
+
|
|
48
|
+
Visit [Memory Class](https://mastra.ai/reference/v1/memory/memory-class) for a full list of configuration options.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Step
|
|
53
|
+
|
|
54
|
+
Add a storage provider to your main Mastra instance to enable memory across all configured agents.
|
|
55
|
+
|
|
56
|
+
```typescript {5-8} title="src/mastra/index.ts"
|
|
57
|
+
import { Mastra } from "@mastra/core";
|
|
58
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
59
|
+
|
|
60
|
+
export const mastra = new Mastra({
|
|
61
|
+
storage: new LibSQLStore({
|
|
62
|
+
id: 'mastra-storage',
|
|
63
|
+
url: ":memory:",
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
> **Note:**
|
|
69
|
+
|
|
70
|
+
Visit [libSQL Storage](https://mastra.ai/reference/v1/storage/libsql) for a full list of configuration options.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Alternatively, add storage directly to an agent’s memory to keep data separate or use different providers per agent.
|
|
75
|
+
|
|
76
|
+
```typescript {9-12} title="src/mastra/agents/memory-agent.ts"
|
|
77
|
+
import { Agent } from "@mastra/core/agent";
|
|
78
|
+
import { Memory } from "@mastra/memory";
|
|
79
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
80
|
+
|
|
81
|
+
export const memoryAgent = new Agent({
|
|
82
|
+
id: 'memory-agent',
|
|
83
|
+
name: 'Memory Agent',
|
|
84
|
+
memory: new Memory({
|
|
85
|
+
storage: new LibSQLStore({
|
|
86
|
+
id: 'mastra-storage',
|
|
87
|
+
url: ":memory:",
|
|
88
|
+
}),
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Message history
|
|
94
|
+
|
|
95
|
+
Include a `memory` object with both `resource` and `thread` to track message history during agent calls.
|
|
96
|
+
|
|
97
|
+
- `resource`: A stable identifier for the user or entity.
|
|
98
|
+
- `thread`: An ID that isolates a specific conversation or session.
|
|
99
|
+
|
|
100
|
+
These fields tell the agent where to store and retrieve context, enabling persistent, thread-aware memory across a conversation.
|
|
101
|
+
|
|
102
|
+
```typescript {4-7}
|
|
103
|
+
const response = await memoryAgent.generate(
|
|
104
|
+
"Remember my favorite color is blue.",
|
|
105
|
+
{
|
|
106
|
+
memory: {
|
|
107
|
+
resource: "user-123",
|
|
108
|
+
thread: "conversation-123",
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
To recall information stored in memory, call the agent with the same `resource` and `thread` values used in the original conversation.
|
|
115
|
+
|
|
116
|
+
```typescript {2-5}
|
|
117
|
+
const response = await memoryAgent.generate("What's my favorite color?", {
|
|
118
|
+
memory: {
|
|
119
|
+
resource: "user-123",
|
|
120
|
+
thread: "conversation-123",
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
To learn more about memory see the [Memory](../memory/overview) documentation.
|
|
126
|
+
|
|
127
|
+
## Using `RequestContext`
|
|
128
|
+
|
|
129
|
+
Use [RequestContext](https://mastra.ai/docs/v1/server/request-context) to access request-specific values. This lets you conditionally select different memory or storage configurations based on the context of the request.
|
|
130
|
+
|
|
131
|
+
```typescript title="src/mastra/agents/memory-agent.ts"
|
|
132
|
+
export type UserTier = {
|
|
133
|
+
"user-tier": "enterprise" | "pro";
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const premiumMemory = new Memory();
|
|
137
|
+
|
|
138
|
+
const standardMemory = new Memory();
|
|
139
|
+
|
|
140
|
+
export const memoryAgent = new Agent({
|
|
141
|
+
id: 'memory-agent',
|
|
142
|
+
name: 'Memory Agent',
|
|
143
|
+
memory: ({ requestContext }) => {
|
|
144
|
+
const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
|
|
145
|
+
|
|
146
|
+
return userTier === "enterprise" ? premiumMemory : standardMemory;
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
> **Note:**
|
|
152
|
+
|
|
153
|
+
Visit [Request Context](https://mastra.ai/docs/v1/server/request-context) for more information.
|
|
154
|
+
|
|
155
|
+
## Related
|
|
156
|
+
|
|
157
|
+
- [Working Memory](../memory/working-memory)
|
|
158
|
+
- [Semantic Recall](../memory/semantic-recall)
|
|
159
|
+
- [Storage](../memory/storage)
|
|
160
|
+
- [Request Context](https://mastra.ai/docs/v1/server/request-context)
|