@mastra/libsql 1.0.0 → 1.1.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 +77 -0
- package/dist/docs/README.md +2 -2
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/docs/agents/01-agent-memory.md +8 -8
- package/dist/docs/agents/02-networks.md +1 -1
- package/dist/docs/agents/03-agent-approval.md +2 -2
- package/dist/docs/agents/04-network-approval.md +2 -2
- package/dist/docs/core/01-reference.md +7 -7
- package/dist/docs/guides/01-ai-sdk.md +9 -30
- package/dist/docs/memory/01-overview.md +22 -53
- package/dist/docs/memory/02-storage.md +115 -87
- package/dist/docs/memory/03-message-history.md +249 -0
- package/dist/docs/memory/{03-working-memory.md → 04-working-memory.md} +22 -1
- package/dist/docs/memory/{04-semantic-recall.md → 05-semantic-recall.md} +45 -22
- package/dist/docs/memory/{05-memory-processors.md → 06-memory-processors.md} +4 -4
- package/dist/docs/memory/{06-reference.md → 07-reference.md} +11 -11
- package/dist/docs/observability/01-overview.md +13 -4
- package/dist/docs/observability/02-default.md +44 -7
- package/dist/docs/rag/01-retrieval.md +4 -4
- package/dist/docs/storage/01-reference.md +31 -17
- package/dist/docs/vectors/01-reference.md +4 -4
- package/dist/docs/workflows/01-snapshots.md +14 -14
- package/dist/index.cjs +271 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +272 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +10 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +2 -5
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,82 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.1.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added dynamic agent management with CRUD operations and version tracking ([#12038](https://github.com/mastra-ai/mastra/pull/12038))
|
|
8
|
+
|
|
9
|
+
**New Features:**
|
|
10
|
+
- Create, edit, and delete agents directly from the Mastra Studio UI
|
|
11
|
+
- Full version history for agents with compare and restore capabilities
|
|
12
|
+
- Visual diff viewer to compare agent configurations across versions
|
|
13
|
+
- Agent creation modal with comprehensive configuration options (model selection, instructions, tools, workflows, sub-agents, memory)
|
|
14
|
+
- AI-powered instruction enhancement
|
|
15
|
+
|
|
16
|
+
**Storage:**
|
|
17
|
+
- New storage interfaces for stored agents and agent versions
|
|
18
|
+
- PostgreSQL, LibSQL, and MongoDB implementations included
|
|
19
|
+
- In-memory storage for development and testing
|
|
20
|
+
|
|
21
|
+
**API:**
|
|
22
|
+
- RESTful endpoints for agent CRUD operations
|
|
23
|
+
- Version management endpoints (create, list, activate, restore, delete, compare)
|
|
24
|
+
- Automatic versioning on agent updates when enabled
|
|
25
|
+
|
|
26
|
+
**Client SDK:**
|
|
27
|
+
- JavaScript client with full support for stored agents and versions
|
|
28
|
+
- Type-safe methods for all CRUD and version operations
|
|
29
|
+
|
|
30
|
+
**Usage Example:**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
// Server-side: Configure storage
|
|
34
|
+
import { Mastra } from '@mastra/core';
|
|
35
|
+
import { PgAgentsStorage } from '@mastra/pg';
|
|
36
|
+
|
|
37
|
+
const mastra = new Mastra({
|
|
38
|
+
agents: { agentOne },
|
|
39
|
+
storage: {
|
|
40
|
+
agents: new PgAgentsStorage({
|
|
41
|
+
connectionString: process.env.DATABASE_URL,
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Client-side: Use the SDK
|
|
47
|
+
import { MastraClient } from '@mastra/client-js';
|
|
48
|
+
|
|
49
|
+
const client = new MastraClient({ baseUrl: 'http://localhost:3000' });
|
|
50
|
+
|
|
51
|
+
// Create a stored agent
|
|
52
|
+
const agent = await client.createStoredAgent({
|
|
53
|
+
name: 'Customer Support Agent',
|
|
54
|
+
description: 'Handles customer inquiries',
|
|
55
|
+
model: { provider: 'ANTHROPIC', name: 'claude-sonnet-4-5' },
|
|
56
|
+
instructions: 'You are a helpful customer support agent...',
|
|
57
|
+
tools: ['search', 'email'],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Create a version snapshot
|
|
61
|
+
await client.storedAgent(agent.id).createVersion({
|
|
62
|
+
name: 'v1.0 - Initial release',
|
|
63
|
+
changeMessage: 'First production version',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Compare versions
|
|
67
|
+
const diff = await client.storedAgent(agent.id).compareVersions('version-1', 'version-2');
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Why:**
|
|
71
|
+
This feature enables teams to manage agents dynamically without code changes, making it easier to iterate on agent configurations and maintain a complete audit trail of changes.
|
|
72
|
+
|
|
73
|
+
- Added `status` field to `listTraces` response. The status field indicates the trace state: `success` (completed without error), `error` (has error), or `running` (still in progress). This makes it easier to filter and display traces by their current state without having to derive it from the `error` and `endedAt` fields. ([#12213](https://github.com/mastra-ai/mastra/pull/12213))
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Updated dependencies [[`90fc0e5`](https://github.com/mastra-ai/mastra/commit/90fc0e5717cb280c2d4acf4f0410b510bb4c0a72), [`1cf5d2e`](https://github.com/mastra-ai/mastra/commit/1cf5d2ea1b085be23e34fb506c80c80a4e6d9c2b), [`833ae96`](https://github.com/mastra-ai/mastra/commit/833ae96c3e34370e58a1e979571c41f39a720592), [`943772b`](https://github.com/mastra-ai/mastra/commit/943772b4378f625f0f4e19ea2b7c392bd8e71786), [`b5c711b`](https://github.com/mastra-ai/mastra/commit/b5c711b281dd1fb81a399a766bc9f86c55efc13e), [`3efbe5a`](https://github.com/mastra-ai/mastra/commit/3efbe5ae20864c4f3143457f4f3ee7dc2fa5ca76), [`1e49e7a`](https://github.com/mastra-ai/mastra/commit/1e49e7ab5f173582154cb26b29d424de67d09aef), [`751eaab`](https://github.com/mastra-ai/mastra/commit/751eaab4e0d3820a94e4c3d39a2ff2663ded3d91), [`69d8156`](https://github.com/mastra-ai/mastra/commit/69d81568bcf062557c24471ce26812446bec465d), [`60d9d89`](https://github.com/mastra-ai/mastra/commit/60d9d899e44b35bc43f1bcd967a74e0ce010b1af), [`5c544c8`](https://github.com/mastra-ai/mastra/commit/5c544c8d12b08ab40d64d8f37b3c4215bee95b87), [`771ad96`](https://github.com/mastra-ai/mastra/commit/771ad962441996b5c43549391a3e6a02c6ddedc2), [`2b0936b`](https://github.com/mastra-ai/mastra/commit/2b0936b0c9a43eeed9bef63e614d7e02ee803f7e), [`3b04f30`](https://github.com/mastra-ai/mastra/commit/3b04f3010604f3cdfc8a0674731700ad66471cee), [`97e26de`](https://github.com/mastra-ai/mastra/commit/97e26deaebd9836647a67b96423281d66421ca07), [`10523f4`](https://github.com/mastra-ai/mastra/commit/10523f4882d9b874b40ce6e3715f66dbcd4947d2), [`cb72d20`](https://github.com/mastra-ai/mastra/commit/cb72d2069d7339bda8a0e76d4f35615debb07b84), [`42856b1`](https://github.com/mastra-ai/mastra/commit/42856b1c8aeea6371c9ee77ae2f5f5fe34400933), [`66f33ff`](https://github.com/mastra-ai/mastra/commit/66f33ff68620018513e499c394411d1d39b3aa5c), [`ab3c190`](https://github.com/mastra-ai/mastra/commit/ab3c1901980a99910ca9b96a7090c22e24060113), [`d4f06c8`](https://github.com/mastra-ai/mastra/commit/d4f06c85ffa5bb0da38fb82ebf3b040cc6b4ec4e), [`0350626`](https://github.com/mastra-ai/mastra/commit/03506267ec41b67add80d994c0c0fcce93bbc75f), [`bc9fa00`](https://github.com/mastra-ai/mastra/commit/bc9fa00859c5c4a796d53a0a5cae46ab4a3072e4), [`f46a478`](https://github.com/mastra-ai/mastra/commit/f46a4782f595949c696569e891f81c8d26338508), [`90fc0e5`](https://github.com/mastra-ai/mastra/commit/90fc0e5717cb280c2d4acf4f0410b510bb4c0a72), [`f05a3a5`](https://github.com/mastra-ai/mastra/commit/f05a3a5cf2b9a9c2d40c09cb8c762a4b6cd5d565), [`a291da9`](https://github.com/mastra-ai/mastra/commit/a291da9363efd92dafd8775dccb4f2d0511ece7a), [`c5d71da`](https://github.com/mastra-ai/mastra/commit/c5d71da1c680ce5640b1a7f8ca0e024a4ab1cfed), [`07042f9`](https://github.com/mastra-ai/mastra/commit/07042f9f89080f38b8f72713ba1c972d5b1905b8), [`0423442`](https://github.com/mastra-ai/mastra/commit/0423442b7be2dfacba95890bea8f4a810db4d603)]:
|
|
78
|
+
- @mastra/core@1.1.0-alpha.0
|
|
79
|
+
|
|
3
80
|
## 1.0.0
|
|
4
81
|
|
|
5
82
|
### Major Changes
|
package/dist/docs/README.md
CHANGED
|
@@ -25,7 +25,7 @@ docs/
|
|
|
25
25
|
├── agents/ (4 files)
|
|
26
26
|
├── core/ (3 files)
|
|
27
27
|
├── guides/ (1 files)
|
|
28
|
-
├── memory/ (
|
|
28
|
+
├── memory/ (7 files)
|
|
29
29
|
├── observability/ (2 files)
|
|
30
30
|
├── rag/ (1 files)
|
|
31
31
|
├── storage/ (3 files)
|
|
@@ -36,4 +36,4 @@ docs/
|
|
|
36
36
|
## Version
|
|
37
37
|
|
|
38
38
|
Package: @mastra/libsql
|
|
39
|
-
Version: 1.0.0
|
|
39
|
+
Version: 1.1.0-alpha.0
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: Documentation for @mastra/libsql. Includes links to type definition
|
|
|
5
5
|
|
|
6
6
|
# @mastra/libsql Documentation
|
|
7
7
|
|
|
8
|
-
> **Version**: 1.0.0
|
|
8
|
+
> **Version**: 1.1.0-alpha.0
|
|
9
9
|
> **Package**: @mastra/libsql
|
|
10
10
|
|
|
11
11
|
## Quick Navigation
|
|
@@ -32,7 +32,7 @@ See SOURCE_MAP.json for the complete list.
|
|
|
32
32
|
- [Agents](agents/) - 4 file(s)
|
|
33
33
|
- [Core](core/) - 3 file(s)
|
|
34
34
|
- [Guides](guides/) - 1 file(s)
|
|
35
|
-
- [Memory](memory/) -
|
|
35
|
+
- [Memory](memory/) - 7 file(s)
|
|
36
36
|
- [Observability](observability/) - 2 file(s)
|
|
37
37
|
- [Rag](rag/) - 1 file(s)
|
|
38
38
|
- [Storage](storage/) - 3 file(s)
|
|
@@ -15,12 +15,12 @@ Use memory when your agent needs to maintain multi-turn conversations that refer
|
|
|
15
15
|
To enable memory in Mastra, install the `@mastra/memory` package along with a storage provider.
|
|
16
16
|
|
|
17
17
|
```bash npm2yarn
|
|
18
|
-
npm install @mastra/memory@
|
|
18
|
+
npm install @mastra/memory@latest @mastra/libsql@latest
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Storage providers
|
|
22
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/
|
|
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/memory/storage) documentation.
|
|
24
24
|
|
|
25
25
|
## Configuring memory
|
|
26
26
|
|
|
@@ -45,7 +45,7 @@ export const memoryAgent = new Agent({
|
|
|
45
45
|
|
|
46
46
|
> **Note:**
|
|
47
47
|
|
|
48
|
-
Visit [Memory Class](https://mastra.ai/reference/
|
|
48
|
+
Visit [Memory Class](https://mastra.ai/reference/memory/memory-class) for a full list of configuration options.
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
|
|
@@ -67,7 +67,7 @@ export const mastra = new Mastra({
|
|
|
67
67
|
|
|
68
68
|
> **Note:**
|
|
69
69
|
|
|
70
|
-
Visit [libSQL Storage](https://mastra.ai/reference/
|
|
70
|
+
Visit [libSQL Storage](https://mastra.ai/reference/storage/libsql) for a full list of configuration options.
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
|
|
@@ -91,7 +91,7 @@ export const memoryAgent = new Agent({
|
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
> **Mastra Cloud Store limitation**
|
|
94
|
-
Agent-level storage is not supported when using [Mastra Cloud Store](https://mastra.ai/docs/
|
|
94
|
+
Agent-level storage is not supported when using [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment#using-mastra-cloud-store). If you use Mastra Cloud Store, configure storage on the Mastra instance instead. This limitation does not apply if you bring your own database.
|
|
95
95
|
|
|
96
96
|
## Message history
|
|
97
97
|
|
|
@@ -132,7 +132,7 @@ To learn more about memory see the [Memory](../memory/overview) documentation.
|
|
|
132
132
|
|
|
133
133
|
## Using `RequestContext`
|
|
134
134
|
|
|
135
|
-
Use [RequestContext](https://mastra.ai/docs/
|
|
135
|
+
Use [RequestContext](https://mastra.ai/docs/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.
|
|
136
136
|
|
|
137
137
|
```typescript title="src/mastra/agents/memory-agent.ts"
|
|
138
138
|
export type UserTier = {
|
|
@@ -156,11 +156,11 @@ export const memoryAgent = new Agent({
|
|
|
156
156
|
|
|
157
157
|
> **Note:**
|
|
158
158
|
|
|
159
|
-
Visit [Request Context](https://mastra.ai/docs/
|
|
159
|
+
Visit [Request Context](https://mastra.ai/docs/server/request-context) for more information.
|
|
160
160
|
|
|
161
161
|
## Related
|
|
162
162
|
|
|
163
163
|
- [Working Memory](../memory/working-memory)
|
|
164
164
|
- [Semantic Recall](../memory/semantic-recall)
|
|
165
165
|
- [Storage](../memory/storage)
|
|
166
|
-
- [Request Context](https://mastra.ai/docs/
|
|
166
|
+
- [Request Context](https://mastra.ai/docs/server/request-context)
|
|
@@ -288,5 +288,5 @@ const final = await stream.object;
|
|
|
288
288
|
|
|
289
289
|
- [Agent Memory](./agent-memory)
|
|
290
290
|
- [Workflows Overview](../workflows/overview)
|
|
291
|
-
- [Request Context](https://mastra.ai/docs/
|
|
291
|
+
- [Request Context](https://mastra.ai/docs/server/request-context)
|
|
292
292
|
- [Supervisor example](https://github.com/mastra-ai/mastra/tree/main/examples/supervisor-agent)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Agent Approval
|
|
4
4
|
|
|
5
|
-
Agents sometimes require the same [human-in-the-loop](https://mastra.ai/docs/
|
|
5
|
+
Agents sometimes require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in workflows when calling tools that handle sensitive operations, like deleting resources or performing running long processes. With agent approval you can suspend a tool call and provide feedback to the user, or approve or decline a tool call based on targeted application conditions.
|
|
6
6
|
|
|
7
7
|
## Tool call approval
|
|
8
8
|
|
|
@@ -374,4 +374,4 @@ Both approaches work with the same tool definitions. Automatic resumption trigge
|
|
|
374
374
|
- [Agent Overview](./overview)
|
|
375
375
|
- [Tools Overview](../mcp/overview)
|
|
376
376
|
- [Agent Memory](./agent-memory)
|
|
377
|
-
- [Request Context](https://mastra.ai/docs/
|
|
377
|
+
- [Request Context](https://mastra.ai/docs/server/request-context)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Network Approval
|
|
4
4
|
|
|
5
|
-
Agent networks can require the same [human-in-the-loop](https://mastra.ai/docs/
|
|
5
|
+
Agent networks can require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in individual agents and workflows. When a tool, sub-agent, or workflow within a network requires approval or suspends execution, the network pauses and emits events that allow your application to collect user input before resuming.
|
|
6
6
|
|
|
7
7
|
## Storage
|
|
8
8
|
|
|
@@ -270,5 +270,5 @@ Both approaches work with the same tool definitions. Automatic resumption trigge
|
|
|
270
270
|
|
|
271
271
|
- [Agent Networks](./networks)
|
|
272
272
|
- [Agent Approval](./agent-approval)
|
|
273
|
-
- [Human-in-the-Loop](https://mastra.ai/docs/
|
|
273
|
+
- [Human-in-the-Loop](https://mastra.ai/docs/workflows/human-in-the-loop)
|
|
274
274
|
- [Agent Memory](./agent-memory)
|
|
@@ -38,7 +38,7 @@ export const mastra = new Mastra({
|
|
|
38
38
|
|
|
39
39
|
## Constructor parameters
|
|
40
40
|
|
|
41
|
-
Visit the [Configuration reference](https://mastra.ai/reference/
|
|
41
|
+
Visit the [Configuration reference](https://mastra.ai/reference/configuration) for detailed documentation on all available configuration options.
|
|
42
42
|
|
|
43
43
|
---
|
|
44
44
|
|
|
@@ -87,9 +87,9 @@ const memory = mastra.getMemory("conversationMemory");
|
|
|
87
87
|
|
|
88
88
|
## Related
|
|
89
89
|
|
|
90
|
-
- [Mastra.listMemory()](https://mastra.ai/reference/
|
|
91
|
-
- [Memory overview](https://mastra.ai/docs/
|
|
92
|
-
- [Agent Memory](https://mastra.ai/docs/
|
|
90
|
+
- [Mastra.listMemory()](https://mastra.ai/reference/core/listMemory)
|
|
91
|
+
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
92
|
+
- [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
|
|
93
93
|
|
|
94
94
|
---
|
|
95
95
|
|
|
@@ -146,6 +146,6 @@ console.log(Object.keys(allMemory)); // ["conversationMemory", "analyticsMemory"
|
|
|
146
146
|
|
|
147
147
|
## Related
|
|
148
148
|
|
|
149
|
-
- [Mastra.getMemory()](https://mastra.ai/reference/
|
|
150
|
-
- [Memory overview](https://mastra.ai/docs/
|
|
151
|
-
- [Agent Memory](https://mastra.ai/docs/
|
|
149
|
+
- [Mastra.getMemory()](https://mastra.ai/reference/core/getMemory)
|
|
150
|
+
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
151
|
+
- [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
|
|
@@ -2,40 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
# AI SDK
|
|
4
4
|
|
|
5
|
-
If you're already using the [Vercel AI SDK](https://sdk.vercel.ai) directly and want to add Mastra capabilities like [processors](https://mastra.ai/docs/
|
|
5
|
+
If you're already using the [Vercel AI SDK](https://sdk.vercel.ai) directly and want to add Mastra capabilities like [processors](https://mastra.ai/docs/agents/processors) or [memory](https://mastra.ai/docs/memory/memory-processors) without switching to the full Mastra agent API, [`withMastra()`](https://mastra.ai/reference/ai-sdk/with-mastra) lets you wrap any AI SDK model with these features. This is useful when you want to keep your existing AI SDK code but add input/output processing, conversation persistence, or content filtering.
|
|
6
6
|
|
|
7
7
|
> **Note:**
|
|
8
8
|
|
|
9
|
-
If you want to use Mastra together with AI SDK UI (e.g. `useChat()`), visit the [AI SDK UI guide](https://mastra.ai/guides/
|
|
9
|
+
If you want to use Mastra together with AI SDK UI (e.g. `useChat()`), visit the [AI SDK UI guide](https://mastra.ai/guides/build-your-ui/ai-sdk-ui).
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
Install `@mastra/ai-sdk` to begin using the `withMastra()` function.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
npm install @mastra/ai-sdk@beta
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
**pnpm:**
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
pnpm add @mastra/ai-sdk@beta
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**yarn:**
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
yarn add @mastra/ai-sdk@beta
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
**bun:**
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
bun add @mastra/ai-sdk@beta
|
|
37
|
-
```
|
|
38
|
-
|
|
15
|
+
```bash npm2yarn
|
|
16
|
+
npm install @mastra/ai-sdk@latest
|
|
17
|
+
```
|
|
39
18
|
|
|
40
19
|
## Examples
|
|
41
20
|
|
|
@@ -135,7 +114,7 @@ const { text } = await generateText({
|
|
|
135
114
|
|
|
136
115
|
## Related
|
|
137
116
|
|
|
138
|
-
- [`withMastra()`](https://mastra.ai/reference/
|
|
139
|
-
- [Processors](https://mastra.ai/docs/
|
|
140
|
-
- [Memory](https://mastra.ai/docs/
|
|
141
|
-
- [AI SDK UI](https://mastra.ai/guides/
|
|
117
|
+
- [`withMastra()`](https://mastra.ai/reference/ai-sdk/with-mastra) - API reference for `withMastra()`
|
|
118
|
+
- [Processors](https://mastra.ai/docs/agents/processors) - Learn about input and output processors
|
|
119
|
+
- [Memory](https://mastra.ai/docs/memory/overview) - Overview of Mastra's memory system
|
|
120
|
+
- [AI SDK UI](https://mastra.ai/guides/build-your-ui/ai-sdk-ui) - Using AI SDK UI hooks with Mastra agents, workflows, and networks
|
|
@@ -2,75 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
# Memory
|
|
4
4
|
|
|
5
|
-
Memory
|
|
5
|
+
Memory enables your agent to remember user messages, agent replies, and tool results across interactions, giving it the context it needs to stay consistent, maintain conversation flow, and produce better answers over time.
|
|
6
6
|
|
|
7
|
-
Mastra
|
|
7
|
+
Mastra supports three complementary memory types:
|
|
8
8
|
|
|
9
|
-
- [**Message history**](https://mastra.ai/docs/
|
|
10
|
-
- [**Working memory**](https://mastra.ai/docs/
|
|
11
|
-
- [**Semantic recall**](https://mastra.ai/docs/
|
|
9
|
+
- [**Message history**](https://mastra.ai/docs/memory/message-history) - keeps recent messages from the current conversation so they can be rendered in the UI and used to maintain short-term continuity within the exchange.
|
|
10
|
+
- [**Working memory**](https://mastra.ai/docs/memory/working-memory) - stores persistent, structured user data such as names, preferences, and goals.
|
|
11
|
+
- [**Semantic recall**](https://mastra.ai/docs/memory/semantic-recall) - retrieves relevant messages from older conversations based on semantic meaning rather than exact keywords, mirroring how humans recall information by association. Requires a [vector database](https://mastra.ai/docs/memory/semantic-recall#storage-configuration) and an [embedding model](https://mastra.ai/docs/memory/semantic-recall#embedder-configuration).
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
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.
|
|
14
14
|
|
|
15
15
|
## Getting started
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Choose a memory option to get started:
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Add the storage adapter to the main Mastra instance:
|
|
24
|
-
|
|
25
|
-
```typescript title="src/mastra/index.ts"
|
|
26
|
-
import { Mastra } from "@mastra/core";
|
|
27
|
-
import { LibSQLStore } from "@mastra/libsql";
|
|
28
|
-
|
|
29
|
-
export const mastra = new Mastra({
|
|
30
|
-
storage: new LibSQLStore({
|
|
31
|
-
id: 'mastra-storage',
|
|
32
|
-
url: ":memory:",
|
|
33
|
-
}),
|
|
34
|
-
});
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
Enable memory by passing a `Memory` instance to your agent:
|
|
38
|
-
|
|
39
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
40
|
-
import { Memory } from "@mastra/memory";
|
|
41
|
-
import { Agent } from "@mastra/core/agent";
|
|
42
|
-
|
|
43
|
-
export const testAgent = new Agent({
|
|
44
|
-
id: "test-agent",
|
|
45
|
-
memory: new Memory({
|
|
46
|
-
options: {
|
|
47
|
-
lastMessages: 20,
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
When you send a new message, the model can now "see" the previous 20 messages, which gives it better context for the conversation and leads to more coherent, accurate replies.
|
|
53
|
-
|
|
54
|
-
This example configures basic [message history](https://mastra.ai/docs/v1/memory/message-history). You can also enable [working memory](https://mastra.ai/docs/v1/memory/working-memory) and [semantic recall](https://mastra.ai/docs/v1/memory/semantic-recall) by passing additional options to `Memory`.
|
|
19
|
+
- [Message history](https://mastra.ai/docs/memory/message-history)
|
|
20
|
+
- [Working memory](https://mastra.ai/docs/memory/working-memory)
|
|
21
|
+
- [Semantic recall](https://mastra.ai/docs/memory/semantic-recall)
|
|
55
22
|
|
|
56
23
|
## Storage
|
|
57
24
|
|
|
58
|
-
Before enabling memory, you must first configure a storage adapter. Mastra supports
|
|
25
|
+
Before enabling memory, you must first configure a storage adapter. Mastra supports several databases including PostgreSQL, MongoDB, libSQL, and [more](https://mastra.ai/docs/memory/storage#supported-providers).
|
|
26
|
+
|
|
27
|
+
Storage can be configured at the [instance level](https://mastra.ai/docs/memory/storage#instance-level-storage) (shared across all agents) or at the [agent level](https://mastra.ai/docs/memory/storage#agent-level-storage) (dedicated per agent).
|
|
59
28
|
|
|
60
|
-
|
|
29
|
+
For semantic recall, you can use a separate vector database like Pinecone alongside your primary storage.
|
|
61
30
|
|
|
62
|
-
See the [Storage](https://mastra.ai/docs/
|
|
31
|
+
See the [Storage](https://mastra.ai/docs/memory/storage) documentation for configuration options, supported providers, and examples.
|
|
63
32
|
|
|
64
33
|
## Debugging memory
|
|
65
34
|
|
|
66
|
-
When tracing is enabled, you can inspect exactly which messages the agent uses for context in each request. The trace output shows all memory included in the agent's context window - both recent message history and messages recalled via semantic recall.
|
|
35
|
+
When [tracing](https://mastra.ai/docs/observability/tracing/overview) is enabled, you can inspect exactly which messages the agent uses for context in each request. The trace output shows all memory included in the agent's context window - both recent message history and messages recalled via semantic recall.
|
|
67
36
|
|
|
68
|
-
|
|
37
|
+

|
|
69
38
|
|
|
70
|
-
|
|
39
|
+
This visibility helps you understand why an agent made specific decisions and verify that memory retrieval is working as expected.
|
|
71
40
|
|
|
72
|
-
## Next
|
|
41
|
+
## Next steps
|
|
73
42
|
|
|
74
|
-
- Learn more about [Storage](https://mastra.ai/docs/
|
|
75
|
-
- Add [Message
|
|
76
|
-
- Visit [Memory configuration reference](https://mastra.ai/reference/
|
|
43
|
+
- Learn more about [Storage](https://mastra.ai/docs/memory/storage) providers and configuration options
|
|
44
|
+
- Add [Message history](https://mastra.ai/docs/memory/message-history), [Working memory](https://mastra.ai/docs/memory/working-memory), or [Semantic recall](https://mastra.ai/docs/memory/semantic-recall)
|
|
45
|
+
- Visit [Memory configuration reference](https://mastra.ai/reference/memory/memory-class) for all available options
|