@mastra/libsql 1.2.0 → 1.3.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 +87 -0
- package/dist/docs/SKILL.md +36 -26
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
- package/dist/docs/{agents/03-agent-approval.md → references/docs-agents-agent-approval.md} +19 -19
- package/dist/docs/references/docs-agents-agent-memory.md +212 -0
- package/dist/docs/{agents/04-network-approval.md → references/docs-agents-network-approval.md} +13 -12
- package/dist/docs/{agents/02-networks.md → references/docs-agents-networks.md} +10 -12
- package/dist/docs/{memory/06-memory-processors.md → references/docs-memory-memory-processors.md} +6 -8
- package/dist/docs/{memory/03-message-history.md → references/docs-memory-message-history.md} +31 -20
- package/dist/docs/{memory/01-overview.md → references/docs-memory-overview.md} +8 -8
- package/dist/docs/{memory/05-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
- package/dist/docs/{memory/02-storage.md → references/docs-memory-storage.md} +29 -39
- package/dist/docs/{memory/04-working-memory.md → references/docs-memory-working-memory.md} +16 -27
- package/dist/docs/{observability/01-overview.md → references/docs-observability-overview.md} +4 -7
- package/dist/docs/{observability/02-default.md → references/docs-observability-tracing-exporters-default.md} +11 -14
- package/dist/docs/{rag/01-retrieval.md → references/docs-rag-retrieval.md} +26 -53
- package/dist/docs/{workflows/01-snapshots.md → references/docs-workflows-snapshots.md} +3 -5
- package/dist/docs/{guides/01-ai-sdk.md → references/guides-agent-frameworks-ai-sdk.md} +25 -9
- package/dist/docs/references/reference-core-getMemory.md +50 -0
- package/dist/docs/references/reference-core-listMemory.md +56 -0
- package/dist/docs/references/reference-core-mastra-class.md +66 -0
- package/dist/docs/{memory/07-reference.md → references/reference-memory-memory-class.md} +28 -14
- package/dist/docs/references/reference-storage-composite.md +235 -0
- package/dist/docs/references/reference-storage-dynamodb.md +282 -0
- package/dist/docs/references/reference-storage-libsql.md +135 -0
- package/dist/docs/{vectors/01-reference.md → references/reference-vectors-libsql.md} +105 -13
- package/dist/index.cjs +1676 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1676 -196
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +9 -12
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +7 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts +25 -0
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts +26 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +3 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -4
- package/dist/docs/README.md +0 -39
- package/dist/docs/agents/01-agent-memory.md +0 -166
- package/dist/docs/core/01-reference.md +0 -151
- package/dist/docs/storage/01-reference.md +0 -556
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
> Store traces locally for development and debugging
|
|
2
|
-
|
|
3
1
|
# Default Exporter
|
|
4
2
|
|
|
5
3
|
The `DefaultExporter` persists traces to your configured storage backend, making them accessible through Studio. It's automatically enabled when using the default observability configuration and requires no external services.
|
|
6
4
|
|
|
7
|
-
> **Production Observability**
|
|
8
|
-
Observability data can quickly overwhelm general-purpose databases in production. For high-traffic applications, we recommend using **ClickHouse** for the observability storage domain via [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](#production-recommendations) for details.
|
|
5
|
+
> **Production Observability:** Observability data can quickly overwhelm general-purpose databases in production. For high-traffic applications, we recommend using **ClickHouse** for the observability storage domain via [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](#production-recommendations) for details.
|
|
9
6
|
|
|
10
7
|
## Configuration
|
|
11
8
|
|
|
@@ -16,7 +13,7 @@ Observability data can quickly overwhelm general-purpose databases in production
|
|
|
16
13
|
|
|
17
14
|
### Basic Setup
|
|
18
15
|
|
|
19
|
-
```typescript
|
|
16
|
+
```typescript
|
|
20
17
|
import { Mastra } from "@mastra/core";
|
|
21
18
|
import { Observability, DefaultExporter } from "@mastra/observability";
|
|
22
19
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -119,13 +116,13 @@ If you set the strategy to `'auto'`, the `DefaultExporter` automatically selects
|
|
|
119
116
|
|
|
120
117
|
### Providers with Observability Support
|
|
121
118
|
|
|
122
|
-
| Storage Provider
|
|
123
|
-
|
|
|
124
|
-
| **ClickHouse** (`@mastra/clickhouse`)
|
|
125
|
-
| **[PostgreSQL](https://mastra.ai/reference/storage/postgresql)** | batch-with-updates | batch-with-updates, insert-only
|
|
126
|
-
| **[MSSQL](https://mastra.ai/reference/storage/mssql)** | batch-with-updates | batch-with-updates, insert-only
|
|
127
|
-
| **[MongoDB](https://mastra.ai/reference/storage/mongodb)** | batch-with-updates | batch-with-updates, insert-only
|
|
128
|
-
| **[libSQL](https://mastra.ai/reference/storage/libsql)** | batch-with-updates | batch-with-updates, insert-only
|
|
119
|
+
| Storage Provider | Preferred Strategy | Supported Strategies | Recommended Use |
|
|
120
|
+
| ---------------------------------------------------------------- | ------------------ | ------------------------------- | ------------------------------------- |
|
|
121
|
+
| **ClickHouse** (`@mastra/clickhouse`) | insert-only | insert-only | Production (high-volume) |
|
|
122
|
+
| **[PostgreSQL](https://mastra.ai/reference/storage/postgresql)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
123
|
+
| **[MSSQL](https://mastra.ai/reference/storage/mssql)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
124
|
+
| **[MongoDB](https://mastra.ai/reference/storage/mongodb)** | batch-with-updates | batch-with-updates, insert-only | Production (low volume) |
|
|
125
|
+
| **[libSQL](https://mastra.ai/reference/storage/libsql)** | batch-with-updates | batch-with-updates, insert-only | Default storage, good for development |
|
|
129
126
|
|
|
130
127
|
### Providers without Observability Support
|
|
131
128
|
|
|
@@ -150,7 +147,7 @@ Observability data grows quickly in production environments. A single agent inte
|
|
|
150
147
|
|
|
151
148
|
### Recommended: ClickHouse for High-Volume Production
|
|
152
149
|
|
|
153
|
-
[ClickHouse](https://mastra.ai/reference/storage/composite
|
|
150
|
+
[ClickHouse](https://mastra.ai/reference/storage/composite) is a columnar database designed for high-volume analytics workloads. It's the recommended choice for production observability because:
|
|
154
151
|
|
|
155
152
|
- **Optimized for writes**: Handles millions of inserts per second
|
|
156
153
|
- **Efficient compression**: Reduces storage costs for trace data
|
|
@@ -159,7 +156,7 @@ Observability data grows quickly in production environments. A single agent inte
|
|
|
159
156
|
|
|
160
157
|
### Using Composite Storage
|
|
161
158
|
|
|
162
|
-
If you're using a provider without observability support (like Convex or DynamoDB) or want to optimize performance, use [composite storage](https://mastra.ai/reference/storage/composite
|
|
159
|
+
If you're using a provider without observability support (like Convex or DynamoDB) or want to optimize performance, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to ClickHouse while keeping other data in your primary database.
|
|
163
160
|
|
|
164
161
|
## Batching Behavior
|
|
165
162
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
> Guide on retrieval processes in Mastra
|
|
2
|
-
|
|
3
1
|
# Retrieval in RAG Systems
|
|
4
2
|
|
|
5
3
|
After storing embeddings, you need to retrieve relevant chunks to answer user queries.
|
|
@@ -168,10 +166,9 @@ This is particularly useful when:
|
|
|
168
166
|
|
|
169
167
|
The Vector Query Tool supports database-specific configurations that enable you to leverage unique features and optimizations of different vector stores.
|
|
170
168
|
|
|
171
|
-
> **Note:**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
Connection credentials (URLs, auth tokens) are configured when you instantiate the vector store class (e.g., `new LibSQLVector({ url: '...' })`).
|
|
169
|
+
> **Note:** These configurations are for **query-time options** like namespaces, performance tuning, and filtering—not for database connection setup.
|
|
170
|
+
>
|
|
171
|
+
> Connection credentials (URLs, auth tokens) are configured when you instantiate the vector store class (e.g., `new LibSQLVector({ url: '...' })`).
|
|
175
172
|
|
|
176
173
|
```ts
|
|
177
174
|
import { createVectorQueryTool } from "@mastra/rag";
|
|
@@ -268,10 +265,9 @@ For detailed configuration options and advanced usage, see the [Vector Query Too
|
|
|
268
265
|
|
|
269
266
|
### Vector Store Prompts
|
|
270
267
|
|
|
271
|
-
Vector store prompts define query patterns and filtering capabilities for each vector database implementation.
|
|
272
|
-
When implementing filtering, these prompts are required in the agent's instructions to specify valid operators and syntax for each vector store implementation.
|
|
268
|
+
Vector store prompts define query patterns and filtering capabilities for each vector database implementation. When implementing filtering, these prompts are required in the agent's instructions to specify valid operators and syntax for each vector store implementation.
|
|
273
269
|
|
|
274
|
-
|
|
270
|
+
**pgVector**:
|
|
275
271
|
|
|
276
272
|
```ts
|
|
277
273
|
import { PGVECTOR_PROMPT } from "@mastra/pg";
|
|
@@ -288,11 +284,9 @@ export const ragAgent = new Agent({
|
|
|
288
284
|
});
|
|
289
285
|
```
|
|
290
286
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
**pinecone:**
|
|
287
|
+
**Pinecone**:
|
|
294
288
|
|
|
295
|
-
```ts
|
|
289
|
+
```ts
|
|
296
290
|
import { PINECONE_PROMPT } from "@mastra/pinecone";
|
|
297
291
|
|
|
298
292
|
export const ragAgent = new Agent({
|
|
@@ -307,11 +301,9 @@ export const ragAgent = new Agent({
|
|
|
307
301
|
});
|
|
308
302
|
```
|
|
309
303
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
**qdrant:**
|
|
304
|
+
**Qdrant**:
|
|
313
305
|
|
|
314
|
-
```ts
|
|
306
|
+
```ts
|
|
315
307
|
import { QDRANT_PROMPT } from "@mastra/qdrant";
|
|
316
308
|
|
|
317
309
|
export const ragAgent = new Agent({
|
|
@@ -326,11 +318,9 @@ export const ragAgent = new Agent({
|
|
|
326
318
|
});
|
|
327
319
|
```
|
|
328
320
|
|
|
329
|
-
|
|
321
|
+
**Chroma**:
|
|
330
322
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
```ts title="vector-store.ts"
|
|
323
|
+
```ts
|
|
334
324
|
import { CHROMA_PROMPT } from "@mastra/chroma";
|
|
335
325
|
|
|
336
326
|
export const ragAgent = new Agent({
|
|
@@ -345,11 +335,9 @@ export const ragAgent = new Agent({
|
|
|
345
335
|
});
|
|
346
336
|
```
|
|
347
337
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
**astra:**
|
|
338
|
+
**Astra**:
|
|
351
339
|
|
|
352
|
-
```ts
|
|
340
|
+
```ts
|
|
353
341
|
import { ASTRA_PROMPT } from "@mastra/astra";
|
|
354
342
|
|
|
355
343
|
export const ragAgent = new Agent({
|
|
@@ -364,11 +352,9 @@ export const ragAgent = new Agent({
|
|
|
364
352
|
});
|
|
365
353
|
```
|
|
366
354
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
**libsql:**
|
|
355
|
+
**libSQL**:
|
|
370
356
|
|
|
371
|
-
```ts
|
|
357
|
+
```ts
|
|
372
358
|
import { LIBSQL_PROMPT } from "@mastra/libsql";
|
|
373
359
|
|
|
374
360
|
export const ragAgent = new Agent({
|
|
@@ -383,11 +369,9 @@ export const ragAgent = new Agent({
|
|
|
383
369
|
});
|
|
384
370
|
```
|
|
385
371
|
|
|
386
|
-
|
|
372
|
+
**Upstash**:
|
|
387
373
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
```ts title="vector-store.ts"
|
|
374
|
+
```ts
|
|
391
375
|
import { UPSTASH_PROMPT } from "@mastra/upstash";
|
|
392
376
|
|
|
393
377
|
export const ragAgent = new Agent({
|
|
@@ -402,11 +386,9 @@ export const ragAgent = new Agent({
|
|
|
402
386
|
});
|
|
403
387
|
```
|
|
404
388
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
**vectorize:**
|
|
389
|
+
**Vectorize**:
|
|
408
390
|
|
|
409
|
-
```ts
|
|
391
|
+
```ts
|
|
410
392
|
import { VECTORIZE_PROMPT } from "@mastra/vectorize";
|
|
411
393
|
|
|
412
394
|
export const ragAgent = new Agent({
|
|
@@ -421,11 +403,9 @@ export const ragAgent = new Agent({
|
|
|
421
403
|
});
|
|
422
404
|
```
|
|
423
405
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
**mongodb:**
|
|
406
|
+
**MongoDB**:
|
|
427
407
|
|
|
428
|
-
```ts
|
|
408
|
+
```ts
|
|
429
409
|
import { MONGODB_PROMPT } from "@mastra/mongodb";
|
|
430
410
|
|
|
431
411
|
export const ragAgent = new Agent({
|
|
@@ -440,11 +420,9 @@ export const ragAgent = new Agent({
|
|
|
440
420
|
});
|
|
441
421
|
```
|
|
442
422
|
|
|
443
|
-
|
|
423
|
+
**OpenSearch**:
|
|
444
424
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
```ts title="vector-store.ts"
|
|
425
|
+
```ts
|
|
448
426
|
import { OPENSEARCH_PROMPT } from "@mastra/opensearch";
|
|
449
427
|
|
|
450
428
|
export const ragAgent = new Agent({
|
|
@@ -459,11 +437,9 @@ export const ragAgent = new Agent({
|
|
|
459
437
|
});
|
|
460
438
|
```
|
|
461
439
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
**s3vectors:**
|
|
440
|
+
**S3Vectors**:
|
|
465
441
|
|
|
466
|
-
```ts
|
|
442
|
+
```ts
|
|
467
443
|
import { S3VECTORS_PROMPT } from "@mastra/s3vectors";
|
|
468
444
|
|
|
469
445
|
export const ragAgent = new Agent({
|
|
@@ -478,8 +454,6 @@ export const ragAgent = new Agent({
|
|
|
478
454
|
});
|
|
479
455
|
```
|
|
480
456
|
|
|
481
|
-
|
|
482
|
-
|
|
483
457
|
### Re-ranking
|
|
484
458
|
|
|
485
459
|
Initial vector similarity search can sometimes miss nuanced relevance. Re-ranking is a more computationally expensive process, but more accurate algorithm that improves results by:
|
|
@@ -528,8 +502,7 @@ The weights control how different factors influence the final ranking:
|
|
|
528
502
|
- `vector`: Higher values favor the original vector similarity scores
|
|
529
503
|
- `position`: Higher values help maintain the original ordering of results
|
|
530
504
|
|
|
531
|
-
> **Note:**
|
|
532
|
-
For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
505
|
+
> **Note:** For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
533
506
|
|
|
534
507
|
You can also use other relevance score providers like Cohere or ZeroEntropy:
|
|
535
508
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
> Learn how to save and resume workflow execution state with snapshots in Mastra
|
|
2
|
-
|
|
3
1
|
# Snapshots
|
|
4
2
|
|
|
5
3
|
In Mastra, a snapshot is a serializable representation of a workflow's complete execution state at a specific point in time. Snapshots capture all the information needed to resume a workflow from exactly where it left off, including:
|
|
@@ -125,7 +123,7 @@ console.log(snapshot);
|
|
|
125
123
|
|
|
126
124
|
Snapshots are persisted using a `storage` instance configured on the `Mastra` class. This storage layer is shared across all workflows registered to that instance. Mastra supports multiple storage options for flexibility in different environments.
|
|
127
125
|
|
|
128
|
-
```typescript
|
|
126
|
+
```typescript
|
|
129
127
|
import { Mastra } from "@mastra/core";
|
|
130
128
|
import { LibSQLStore } from "@mastra/libsql";
|
|
131
129
|
import { approvalWorkflow } from "./workflows";
|
|
@@ -159,7 +157,7 @@ export const mastra = new Mastra({
|
|
|
159
157
|
|
|
160
158
|
You can attach custom metadata when suspending a workflow by defining a `suspendSchema`. This metadata is stored in the snapshot and made available when the workflow is resumed.
|
|
161
159
|
|
|
162
|
-
```typescript
|
|
160
|
+
```typescript
|
|
163
161
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
164
162
|
import { z } from "zod";
|
|
165
163
|
|
|
@@ -208,7 +206,7 @@ const approvalStep = createStep({
|
|
|
208
206
|
|
|
209
207
|
Use `resumeData` to pass structured input when resuming a suspended step. It must match the step’s `resumeSchema`.
|
|
210
208
|
|
|
211
|
-
```typescript
|
|
209
|
+
```typescript
|
|
212
210
|
const workflow = mastra.getWorkflow("approvalWorkflow");
|
|
213
211
|
|
|
214
212
|
const run = await workflow.createRun();
|
|
@@ -1,28 +1,44 @@
|
|
|
1
|
-
> Use Mastra processors and memory with the Vercel AI SDK
|
|
2
|
-
|
|
3
1
|
# AI SDK
|
|
4
2
|
|
|
5
3
|
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
4
|
|
|
7
|
-
> **
|
|
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/build-your-ui/ai-sdk-ui).
|
|
5
|
+
> **Tip:** 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
6
|
|
|
11
7
|
## Installation
|
|
12
8
|
|
|
13
9
|
Install `@mastra/ai-sdk` to begin using the `withMastra()` function.
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
**npm**:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
16
14
|
npm install @mastra/ai-sdk@latest
|
|
17
15
|
```
|
|
18
16
|
|
|
17
|
+
**pnpm**:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @mastra/ai-sdk@latest
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Yarn**:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @mastra/ai-sdk@latest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Bun**:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @mastra/ai-sdk@latest
|
|
33
|
+
```
|
|
34
|
+
|
|
19
35
|
## Examples
|
|
20
36
|
|
|
21
37
|
### With Processors
|
|
22
38
|
|
|
23
39
|
Processors let you transform messages before they're sent to the model (`processInput`) and after responses are received (`processOutputResult`). This example creates a logging processor that logs message counts at each stage, then wraps an OpenAI model with it.
|
|
24
40
|
|
|
25
|
-
```typescript
|
|
41
|
+
```typescript
|
|
26
42
|
import { openai } from '@ai-sdk/openai';
|
|
27
43
|
import { generateText } from 'ai';
|
|
28
44
|
import { withMastra } from '@mastra/ai-sdk';
|
|
@@ -55,7 +71,7 @@ const { text } = await generateText({
|
|
|
55
71
|
|
|
56
72
|
Memory automatically loads previous messages from storage before the LLM call and saves new messages after. This example configures a libSQL storage backend to persist conversation history, loading the last 10 messages for context.
|
|
57
73
|
|
|
58
|
-
```typescript
|
|
74
|
+
```typescript
|
|
59
75
|
import { openai } from '@ai-sdk/openai';
|
|
60
76
|
import { generateText } from 'ai';
|
|
61
77
|
import { withMastra } from '@mastra/ai-sdk';
|
|
@@ -86,7 +102,7 @@ const { text } = await generateText({
|
|
|
86
102
|
|
|
87
103
|
You can combine processors and memory together. Input processors run after memory loads historical messages, and output processors run before memory saves the response.
|
|
88
104
|
|
|
89
|
-
```typescript
|
|
105
|
+
```typescript
|
|
90
106
|
import { openai } from '@ai-sdk/openai';
|
|
91
107
|
import { generateText } from 'ai';
|
|
92
108
|
import { withMastra } from '@mastra/ai-sdk';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Mastra.getMemory()
|
|
2
|
+
|
|
3
|
+
The `.getMemory()` method retrieves a memory instance from the Mastra registry by its key. Memory instances are registered in the Mastra constructor and can be referenced by stored agents.
|
|
4
|
+
|
|
5
|
+
## Usage example
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
const memory = mastra.getMemory("conversationMemory");
|
|
9
|
+
|
|
10
|
+
// Use the memory instance
|
|
11
|
+
const thread = await memory.createThread({
|
|
12
|
+
resourceId: "user-123",
|
|
13
|
+
title: "New Conversation",
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Parameters
|
|
18
|
+
|
|
19
|
+
**key:** (`TMemoryKey extends keyof TMemory`): The registry key of the memory instance to retrieve. Must match a key used when registering memory in the Mastra constructor.
|
|
20
|
+
|
|
21
|
+
## Returns
|
|
22
|
+
|
|
23
|
+
**memory:** (`TMemory[TMemoryKey]`): The memory instance with the specified key. Throws an error if the memory is not found.
|
|
24
|
+
|
|
25
|
+
## Example: Registering and Retrieving Memory
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Mastra } from "@mastra/core";
|
|
29
|
+
import { Memory } from "@mastra/memory";
|
|
30
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
31
|
+
|
|
32
|
+
const conversationMemory = new Memory({
|
|
33
|
+
storage: new LibSQLStore({ id: 'conversation-store', url: ":memory:" }),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const mastra = new Mastra({
|
|
37
|
+
memory: {
|
|
38
|
+
conversationMemory,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Later, retrieve the memory instance
|
|
43
|
+
const memory = mastra.getMemory("conversationMemory");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Related
|
|
47
|
+
|
|
48
|
+
- [Mastra.listMemory()](https://mastra.ai/reference/core/listMemory)
|
|
49
|
+
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
50
|
+
- [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Mastra.listMemory()
|
|
2
|
+
|
|
3
|
+
The `.listMemory()` method returns all memory instances registered with the Mastra instance.
|
|
4
|
+
|
|
5
|
+
## Usage example
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
const memoryInstances = mastra.listMemory();
|
|
9
|
+
|
|
10
|
+
for (const [key, memory] of Object.entries(memoryInstances)) {
|
|
11
|
+
console.log(`Memory "${key}": ${memory.id}`);
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
This method takes no parameters.
|
|
18
|
+
|
|
19
|
+
## Returns
|
|
20
|
+
|
|
21
|
+
**memory:** (`Record<string, MastraMemory>`): An object containing all registered memory instances, keyed by their registry keys.
|
|
22
|
+
|
|
23
|
+
## Example: Checking Registered Memory
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Mastra } from "@mastra/core";
|
|
27
|
+
import { Memory } from "@mastra/memory";
|
|
28
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
29
|
+
|
|
30
|
+
const conversationMemory = new Memory({
|
|
31
|
+
id: "conversation-memory",
|
|
32
|
+
storage: new LibSQLStore({ id: 'conversation-store', url: ":memory:" }),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const analyticsMemory = new Memory({
|
|
36
|
+
id: "analytics-memory",
|
|
37
|
+
storage: new LibSQLStore({ id: 'analytics-store', url: ":memory:" }),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const mastra = new Mastra({
|
|
41
|
+
memory: {
|
|
42
|
+
conversationMemory,
|
|
43
|
+
analyticsMemory,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// List all registered memory instances
|
|
48
|
+
const allMemory = mastra.listMemory();
|
|
49
|
+
console.log(Object.keys(allMemory)); // ["conversationMemory", "analyticsMemory"]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Related
|
|
53
|
+
|
|
54
|
+
- [Mastra.getMemory()](https://mastra.ai/reference/core/getMemory)
|
|
55
|
+
- [Memory overview](https://mastra.ai/docs/memory/overview)
|
|
56
|
+
- [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Mastra Class
|
|
2
|
+
|
|
3
|
+
The `Mastra` class is the central orchestrator in any Mastra application, managing agents, workflows, storage, logging, observability, and more. Typically, you create a single instance of `Mastra` to coordinate your application.
|
|
4
|
+
|
|
5
|
+
Think of `Mastra` as a top-level registry where you register agents, workflows, tools, and other components that need to be accessible throughout your application.
|
|
6
|
+
|
|
7
|
+
## Usage example
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Mastra } from "@mastra/core";
|
|
11
|
+
import { PinoLogger } from "@mastra/loggers";
|
|
12
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
13
|
+
import { weatherWorkflow } from "./workflows/weather-workflow";
|
|
14
|
+
import { weatherAgent } from "./agents/weather-agent";
|
|
15
|
+
|
|
16
|
+
export const mastra = new Mastra({
|
|
17
|
+
workflows: { weatherWorkflow },
|
|
18
|
+
agents: { weatherAgent },
|
|
19
|
+
storage: new LibSQLStore({
|
|
20
|
+
id: 'mastra-storage',
|
|
21
|
+
url: ":memory:",
|
|
22
|
+
}),
|
|
23
|
+
logger: new PinoLogger({
|
|
24
|
+
name: "Mastra",
|
|
25
|
+
level: "info",
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Constructor parameters
|
|
31
|
+
|
|
32
|
+
Visit the [Configuration reference](https://mastra.ai/reference/configuration) for detailed documentation on all available configuration options.
|
|
33
|
+
|
|
34
|
+
**agents?:** (`Record<string, Agent>`): Agent instances to register, keyed by name (Default: `{}`)
|
|
35
|
+
|
|
36
|
+
**tools?:** (`Record<string, ToolApi>`): Custom tools to register. Structured as a key-value pair, with keys being the tool name and values being the tool function. (Default: `{}`)
|
|
37
|
+
|
|
38
|
+
**storage?:** (`MastraCompositeStore`): Storage engine instance for persisting data
|
|
39
|
+
|
|
40
|
+
**vectors?:** (`Record<string, MastraVector>`): Vector store instance, used for semantic search and vector-based tools (eg Pinecone, PgVector or Qdrant)
|
|
41
|
+
|
|
42
|
+
**logger?:** (`Logger`): Logger instance created with new PinoLogger() (Default: `Console logger with INFO level`)
|
|
43
|
+
|
|
44
|
+
**idGenerator?:** (`() => string`): Custom ID generator function. Used by agents, workflows, memory, and other components to generate unique identifiers.
|
|
45
|
+
|
|
46
|
+
**workflows?:** (`Record<string, Workflow>`): Workflows to register. Structured as a key-value pair, with keys being the workflow name and values being the workflow instance. (Default: `{}`)
|
|
47
|
+
|
|
48
|
+
**tts?:** (`Record<string, MastraVoice>`): Text-to-speech providers for voice synthesis
|
|
49
|
+
|
|
50
|
+
**observability?:** (`ObservabilityEntrypoint`): Observability configuration for tracing and monitoring
|
|
51
|
+
|
|
52
|
+
**deployer?:** (`MastraDeployer`): An instance of a MastraDeployer for managing deployments.
|
|
53
|
+
|
|
54
|
+
**server?:** (`ServerConfig`): Server configuration including port, host, timeout, API routes, middleware, CORS settings, and build options for Swagger UI, API request logging, and OpenAPI docs.
|
|
55
|
+
|
|
56
|
+
**mcpServers?:** (`Record<string, MCPServerBase>`): An object where keys are registry keys (used for getMCPServer()) and values are instances of MCPServer or classes extending MCPServerBase. Each MCPServer must have an id property. Servers can be retrieved by registry key using getMCPServer() or by their intrinsic id using getMCPServerById().
|
|
57
|
+
|
|
58
|
+
**bundler?:** (`BundlerConfig`): Configuration for the asset bundler with options for externals, sourcemap, and transpilePackages.
|
|
59
|
+
|
|
60
|
+
**scorers?:** (`Record<string, Scorer>`): Scorers for evaluating agent responses and workflow outputs (Default: `{}`)
|
|
61
|
+
|
|
62
|
+
**processors?:** (`Record<string, Processor>`): Input/output processors for transforming agent inputs and outputs (Default: `{}`)
|
|
63
|
+
|
|
64
|
+
**gateways?:** (`Record<string, MastraModelGateway>`): Custom model gateways to register for accessing AI models through alternative providers or private deployments. Structured as a key-value pair, with keys being the registry key (used for getGateway()) and values being gateway instances. (Default: `{}`)
|
|
65
|
+
|
|
66
|
+
**memory?:** (`Record<string, MastraMemory>`): Memory instances to register. These can be referenced by stored agents and resolved at runtime. Structured as a key-value pair, with keys being the registry key and values being memory instances. (Default: `{}`)
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
# Memory
|
|
2
|
-
|
|
3
|
-
> API reference for memory - 1 entries
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Reference: Memory Class
|
|
9
|
-
|
|
10
|
-
> Documentation for the `Memory` class in Mastra, which provides a robust system for managing conversation history and thread-based message storage.
|
|
1
|
+
# Memory Class
|
|
11
2
|
|
|
12
3
|
The `Memory` class provides a robust system for managing conversation history and thread-based message storage in Mastra. It enables persistent storage of conversations, semantic search capabilities, and efficient message retrieval. You must configure a storage provider for conversation history, and if you enable semantic recall you will also need to provide a vector store and embedder.
|
|
13
4
|
|
|
14
5
|
## Usage example
|
|
15
6
|
|
|
16
|
-
```typescript
|
|
7
|
+
```typescript
|
|
17
8
|
import { Memory } from "@mastra/memory";
|
|
18
9
|
import { Agent } from "@mastra/core/agent";
|
|
19
10
|
|
|
@@ -31,17 +22,39 @@ export const agent = new Agent({
|
|
|
31
22
|
});
|
|
32
23
|
```
|
|
33
24
|
|
|
34
|
-
> To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](
|
|
25
|
+
> To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](https://mastra.ai/reference/core/mastra-class) for more information.
|
|
35
26
|
|
|
36
27
|
## Constructor parameters
|
|
37
28
|
|
|
29
|
+
**storage?:** (`MastraCompositeStore`): Storage implementation for persisting memory data. Defaults to \`new DefaultStorage({ config: { url: "file:memory.db" } })\` if not provided.
|
|
30
|
+
|
|
31
|
+
**vector?:** (`MastraVector | false`): Vector store for semantic search capabilities. Set to \`false\` to disable vector operations.
|
|
32
|
+
|
|
33
|
+
**embedder?:** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder instance for vector embeddings. Required when semantic recall is enabled.
|
|
34
|
+
|
|
35
|
+
**options?:** (`MemoryConfig`): Memory configuration options.
|
|
36
|
+
|
|
38
37
|
### Options parameters
|
|
39
38
|
|
|
39
|
+
**lastMessages?:** (`number | false`): Number of most recent messages to retrieve. Set to false to disable. (Default: `10`)
|
|
40
|
+
|
|
41
|
+
**readOnly?:** (`boolean`): When true, prevents memory from saving new messages and provides working memory as read-only context (without the updateWorkingMemory tool). Useful for read-only operations like previews, internal routing agents, or sub agents that should reference but not modify memory. (Default: `false`)
|
|
42
|
+
|
|
43
|
+
**semanticRecall?:** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires both vector store and embedder to be configured. Default topK is 4, default messageRange is {before: 1, after: 1}. (Default: `false`)
|
|
44
|
+
|
|
45
|
+
**workingMemory?:** (`WorkingMemory`): Configuration for working memory feature. Can be \`{ enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' }\` or \`{ enabled: boolean }\` to disable. (Default: `{ enabled: false, template: '# User Information\n- **First Name**:\n- **Last Name**:\n...' }`)
|
|
46
|
+
|
|
47
|
+
**observationalMemory?:** (`boolean | ObservationalMemoryOptions`): Enable Observational Memory for long-context agentic memory. Set to \`true\` for defaults, or pass a config object to customize token budgets, models, and scope. See \[Observational Memory reference]\(/reference/memory/observational-memory) for configuration details. (Default: `false`)
|
|
48
|
+
|
|
49
|
+
**generateTitle?:** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the user's first message. Can be a boolean or an object with custom model and instructions. (Default: `false`)
|
|
50
|
+
|
|
40
51
|
## Returns
|
|
41
52
|
|
|
53
|
+
**memory:** (`Memory`): A new Memory instance with the specified configuration.
|
|
54
|
+
|
|
42
55
|
## Extended usage example
|
|
43
56
|
|
|
44
|
-
```typescript
|
|
57
|
+
```typescript
|
|
45
58
|
import { Memory } from "@mastra/memory";
|
|
46
59
|
import { Agent } from "@mastra/core/agent";
|
|
47
60
|
import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
|
|
@@ -77,7 +90,7 @@ export const agent = new Agent({
|
|
|
77
90
|
|
|
78
91
|
## PostgreSQL with index configuration
|
|
79
92
|
|
|
80
|
-
```typescript
|
|
93
|
+
```typescript
|
|
81
94
|
import { Memory } from "@mastra/memory";
|
|
82
95
|
import { Agent } from "@mastra/core/agent";
|
|
83
96
|
import { ModelRouterEmbeddingModel } from "@mastra/core/llm";
|
|
@@ -123,6 +136,7 @@ export const agent = new Agent({
|
|
|
123
136
|
- [Getting Started with Memory](https://mastra.ai/docs/memory/overview)
|
|
124
137
|
- [Semantic Recall](https://mastra.ai/docs/memory/semantic-recall)
|
|
125
138
|
- [Working Memory](https://mastra.ai/docs/memory/working-memory)
|
|
139
|
+
- [Observational Memory](https://mastra.ai/docs/memory/observational-memory)
|
|
126
140
|
- [Memory Processors](https://mastra.ai/docs/memory/memory-processors)
|
|
127
141
|
- [createThread](https://mastra.ai/reference/memory/createThread)
|
|
128
142
|
- [recall](https://mastra.ai/reference/memory/recall)
|