@mastra/pinecone 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256

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.
@@ -0,0 +1,314 @@
1
+ # Memory Processors
2
+
3
+ Memory processors transform and filter messages as they pass through an agent with memory enabled. They manage context window limits, remove unnecessary content, and optimize the information sent to the language model.
4
+
5
+ When memory is enabled on an agent, Mastra adds memory processors to the agent's processor pipeline. These processors retrieve message history, working memory, and semantically relevant messages, then persist new messages after the model responds.
6
+
7
+ Memory processors are [processors](https://mastra.ai/docs/agents/processors) that operate specifically on memory-related messages and state.
8
+
9
+ ## Built-in Memory Processors
10
+
11
+ Mastra automatically adds these processors when memory is enabled:
12
+
13
+ ### MessageHistory
14
+
15
+ Retrieves message history and persists new messages.
16
+
17
+ **When you configure:**
18
+
19
+ ```typescript
20
+ memory: new Memory({
21
+ lastMessages: 10,
22
+ })
23
+ ```
24
+
25
+ **Mastra internally:**
26
+
27
+ 1. Creates a `MessageHistory` processor with `limit: 10`
28
+ 2. Adds it to the agent's input processors (runs before the LLM)
29
+ 3. Adds it to the agent's output processors (runs after the LLM)
30
+
31
+ **What it does:**
32
+
33
+ - **Input**: Fetches the last 10 messages from storage and prepends them to the conversation
34
+ - **Output**: Persists new messages to storage after the model responds
35
+
36
+ **Example:**
37
+
38
+ ```typescript
39
+ import { Agent } from '@mastra/core/agent'
40
+ import { Memory } from '@mastra/memory'
41
+ import { LibSQLStore } from '@mastra/libsql'
42
+ import { openai } from '@ai-sdk/openai'
43
+
44
+ const agent = new Agent({
45
+ id: 'test-agent',
46
+ name: 'Test Agent',
47
+ instructions: 'You are a helpful assistant',
48
+ model: 'openai/gpt-4o',
49
+ memory: new Memory({
50
+ storage: new LibSQLStore({
51
+ id: 'memory-store',
52
+ url: 'file:memory.db',
53
+ }),
54
+ lastMessages: 10, // MessageHistory processor automatically added
55
+ }),
56
+ })
57
+ ```
58
+
59
+ ### SemanticRecall
60
+
61
+ Retrieves semantically relevant messages based on the current input and creates embeddings for new messages.
62
+
63
+ **When you configure:**
64
+
65
+ ```typescript
66
+ memory: new Memory({
67
+ semanticRecall: { enabled: true },
68
+ vector: myVectorStore,
69
+ embedder: myEmbedder,
70
+ })
71
+ ```
72
+
73
+ **Mastra internally:**
74
+
75
+ 1. Creates a `SemanticRecall` processor
76
+ 2. Adds it to the agent's input processors (runs before the LLM)
77
+ 3. Adds it to the agent's output processors (runs after the LLM)
78
+ 4. Requires both a vector store and embedder to be configured
79
+
80
+ **What it does:**
81
+
82
+ - **Input**: Performs vector similarity search to find relevant past messages and prepends them to the conversation
83
+ - **Output**: Creates embeddings for new messages and stores them in the vector store for future retrieval
84
+
85
+ **Example:**
86
+
87
+ ```typescript
88
+ import { Agent } from '@mastra/core/agent'
89
+ import { Memory } from '@mastra/memory'
90
+ import { LibSQLStore } from '@mastra/libsql'
91
+ import { PineconeVector } from '@mastra/pinecone'
92
+ import { OpenAIEmbedder } from '@mastra/openai'
93
+ import { openai } from '@ai-sdk/openai'
94
+
95
+ const agent = new Agent({
96
+ name: 'semantic-agent',
97
+ instructions: 'You are a helpful assistant with semantic memory',
98
+ model: 'openai/gpt-4o',
99
+ memory: new Memory({
100
+ storage: new LibSQLStore({
101
+ id: 'memory-store',
102
+ url: 'file:memory.db',
103
+ }),
104
+ vector: new PineconeVector({
105
+ id: 'memory-vector',
106
+ apiKey: process.env.PINECONE_API_KEY!,
107
+ }),
108
+ embedder: new OpenAIEmbedder({
109
+ model: 'text-embedding-3-small',
110
+ apiKey: process.env.OPENAI_API_KEY!,
111
+ }),
112
+ semanticRecall: { enabled: true }, // SemanticRecall processor automatically added
113
+ }),
114
+ })
115
+ ```
116
+
117
+ ### WorkingMemory
118
+
119
+ Manages working memory state across conversations.
120
+
121
+ **When you configure:**
122
+
123
+ ```typescript
124
+ memory: new Memory({
125
+ workingMemory: { enabled: true },
126
+ })
127
+ ```
128
+
129
+ **Mastra internally:**
130
+
131
+ 1. Creates a `WorkingMemory` processor
132
+ 2. Adds it to the agent's input processors (runs before the LLM)
133
+ 3. Requires a storage adapter to be configured
134
+
135
+ **What it does:**
136
+
137
+ - **Input**: Retrieves working memory state for the current thread and prepends it to the conversation
138
+ - **Output**: No output processing
139
+
140
+ **Example:**
141
+
142
+ ```typescript
143
+ import { Agent } from '@mastra/core/agent'
144
+ import { Memory } from '@mastra/memory'
145
+ import { LibSQLStore } from '@mastra/libsql'
146
+ import { openai } from '@ai-sdk/openai'
147
+
148
+ const agent = new Agent({
149
+ name: 'working-memory-agent',
150
+ instructions: 'You are an assistant with working memory',
151
+ model: 'openai/gpt-4o',
152
+ memory: new Memory({
153
+ storage: new LibSQLStore({
154
+ id: 'memory-store',
155
+ url: 'file:memory.db',
156
+ }),
157
+ workingMemory: { enabled: true }, // WorkingMemory processor automatically added
158
+ }),
159
+ })
160
+ ```
161
+
162
+ ## Manual Control and Deduplication
163
+
164
+ If you manually add a memory processor to `inputProcessors` or `outputProcessors`, Mastra will **not** automatically add it. This gives you full control over processor ordering:
165
+
166
+ ```typescript
167
+ import { Agent } from '@mastra/core/agent'
168
+ import { Memory } from '@mastra/memory'
169
+ import { MessageHistory } from '@mastra/core/processors'
170
+ import { TokenLimiter } from '@mastra/core/processors'
171
+ import { LibSQLStore } from '@mastra/libsql'
172
+ import { openai } from '@ai-sdk/openai'
173
+
174
+ // Custom MessageHistory with different configuration
175
+ const customMessageHistory = new MessageHistory({
176
+ storage: new LibSQLStore({ id: 'memory-store', url: 'file:memory.db' }),
177
+ lastMessages: 20,
178
+ })
179
+
180
+ const agent = new Agent({
181
+ name: 'custom-memory-agent',
182
+ instructions: 'You are a helpful assistant',
183
+ model: 'openai/gpt-4o',
184
+ memory: new Memory({
185
+ storage: new LibSQLStore({ id: 'memory-store', url: 'file:memory.db' }),
186
+ lastMessages: 10, // This would normally add MessageHistory(10)
187
+ }),
188
+ inputProcessors: [
189
+ customMessageHistory, // Your custom one is used instead
190
+ new TokenLimiter({ limit: 4000 }), // Runs after your custom MessageHistory
191
+ ],
192
+ })
193
+ ```
194
+
195
+ ## Processor Execution Order
196
+
197
+ Understanding the execution order is important when combining guardrails with memory:
198
+
199
+ ### Input Processors
200
+
201
+ ```text
202
+ [Memory Processors] → [Your inputProcessors]
203
+ ```
204
+
205
+ 1. **Memory processors run FIRST**: `WorkingMemory`, `MessageHistory`, `SemanticRecall`
206
+ 2. **Your input processors run AFTER**: guardrails, filters, validators
207
+
208
+ This means memory loads message history before your processors can validate or filter the input.
209
+
210
+ ### Output Processors
211
+
212
+ ```text
213
+ [Your outputProcessors] → [Memory Processors]
214
+ ```
215
+
216
+ 1. **Your output processors run FIRST**: guardrails, filters, validators
217
+ 2. **Memory processors run AFTER**: `SemanticRecall` (embeddings), `MessageHistory` (persistence)
218
+
219
+ This ordering is designed to be **safe by default**: if your output guardrail calls `abort()`, the memory processors never run and **no messages are saved**.
220
+
221
+ ## Guardrails and Memory
222
+
223
+ The default execution order provides safe guardrail behavior:
224
+
225
+ ### Output guardrails (recommended)
226
+
227
+ Output guardrails run **before** memory processors save messages. If a guardrail aborts:
228
+
229
+ - The tripwire is triggered
230
+ - Memory processors are skipped
231
+ - **No messages are persisted to storage**
232
+
233
+ ```typescript
234
+ import { Agent } from '@mastra/core/agent'
235
+ import { Memory } from '@mastra/memory'
236
+ import { openai } from '@ai-sdk/openai'
237
+
238
+ // Output guardrail that blocks inappropriate content
239
+ const contentBlocker = {
240
+ id: 'content-blocker',
241
+ processOutputResult: async ({ messages, abort }) => {
242
+ const hasInappropriateContent = messages.some(msg => containsBadContent(msg))
243
+ if (hasInappropriateContent) {
244
+ abort('Content blocked by guardrail')
245
+ }
246
+ return messages
247
+ },
248
+ }
249
+
250
+ const agent = new Agent({
251
+ name: 'safe-agent',
252
+ instructions: 'You are a helpful assistant',
253
+ model: 'openai/gpt-4o',
254
+ memory: new Memory({ lastMessages: 10 }),
255
+ // Your guardrail runs BEFORE memory saves
256
+ outputProcessors: [contentBlocker],
257
+ })
258
+
259
+ // If the guardrail aborts, nothing is saved to memory
260
+ const result = await agent.generate('Hello')
261
+ if (result.tripwire) {
262
+ console.log('Blocked:', result.tripwire.reason)
263
+ // Memory is empty - no messages were persisted
264
+ }
265
+ ```
266
+
267
+ ### Input guardrails
268
+
269
+ Input guardrails run **after** memory processors load history. If a guardrail aborts:
270
+
271
+ - The tripwire is triggered
272
+ - The LLM is never called
273
+ - Output processors (including memory persistence) are skipped
274
+ - **No messages are persisted to storage**
275
+
276
+ ```typescript
277
+ // Input guardrail that validates user input
278
+ const inputValidator = {
279
+ id: 'input-validator',
280
+ processInput: async ({ messages, abort }) => {
281
+ const lastUserMessage = messages.findLast(m => m.role === 'user')
282
+ if (isInvalidInput(lastUserMessage)) {
283
+ abort('Invalid input detected')
284
+ }
285
+ return messages
286
+ },
287
+ }
288
+
289
+ const agent = new Agent({
290
+ name: 'validated-agent',
291
+ instructions: 'You are a helpful assistant',
292
+ model: 'openai/gpt-4o',
293
+ memory: new Memory({ lastMessages: 10 }),
294
+ // Your guardrail runs AFTER memory loads history
295
+ inputProcessors: [inputValidator],
296
+ })
297
+ ```
298
+
299
+ ### Summary
300
+
301
+ | Guardrail Type | When it runs | If it aborts |
302
+ | -------------- | -------------------------- | ----------------------------- |
303
+ | Input | After memory loads history | LLM not called, nothing saved |
304
+ | Output | Before memory saves | Nothing saved to storage |
305
+
306
+ Both scenarios are safe - guardrails prevent inappropriate content from being persisted to memory
307
+
308
+ ## Related documentation
309
+
310
+ - [Processors](https://mastra.ai/docs/agents/processors) - General processor concepts and custom processor creation
311
+ - [Guardrails](https://mastra.ai/docs/agents/guardrails) - Security and validation processors
312
+ - [Memory Overview](https://mastra.ai/docs/memory/overview) - Memory types and configuration
313
+
314
+ When creating custom processors avoid mutating the input `messages` array or its objects directly.
@@ -0,0 +1,261 @@
1
+ # Storage
2
+
3
+ For agents to remember previous interactions, Mastra needs a database. Use a storage adapter for one of the [supported databases](#supported-providers) and pass it to your Mastra instance.
4
+
5
+ ```typescript
6
+ import { Mastra } from '@mastra/core'
7
+ import { LibSQLStore } from '@mastra/libsql'
8
+
9
+ export const mastra = new Mastra({
10
+ storage: new LibSQLStore({
11
+ id: 'mastra-storage',
12
+ url: 'file:./mastra.db',
13
+ }),
14
+ })
15
+ ```
16
+
17
+ > **Sharing the database with Mastra Studio:** When running `mastra dev` alongside your application (e.g., Next.js), use an absolute path to ensure both processes access the same database:
18
+ >
19
+ > ```typescript
20
+ > url: 'file:/absolute/path/to/your/project/mastra.db'
21
+ > ```
22
+ >
23
+ > Relative paths like `file:./mastra.db` resolve based on each process's working directory, which may differ.
24
+
25
+ This configures instance-level storage, which all agents share by default. You can also configure [agent-level storage](#agent-level-storage) for isolated data boundaries.
26
+
27
+ Mastra automatically creates the necessary tables on first interaction. See the [core schema](https://mastra.ai/reference/storage/overview) for details on what gets created, including tables for messages, threads, resources, workflows, traces, and evaluation datasets.
28
+
29
+ ## Supported providers
30
+
31
+ Each provider page includes installation instructions, configuration parameters, and usage examples:
32
+
33
+ - [libSQL](https://mastra.ai/reference/storage/libsql)
34
+ - [PostgreSQL](https://mastra.ai/reference/storage/postgresql)
35
+ - [MongoDB](https://mastra.ai/reference/storage/mongodb)
36
+ - [Upstash](https://mastra.ai/reference/storage/upstash)
37
+ - [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
38
+ - [Cloudflare Durable Objects](https://mastra.ai/reference/storage/cloudflare)
39
+ - [Convex](https://mastra.ai/reference/storage/convex)
40
+ - [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
41
+ - [LanceDB](https://mastra.ai/reference/storage/lance)
42
+ - [Microsoft SQL Server](https://mastra.ai/reference/storage/mssql)
43
+
44
+ > **Tip:** libSQL is the easiest way to get started because it doesn’t require running a separate database server.
45
+
46
+ ## Configuration scope
47
+
48
+ Storage can be configured at the instance level (shared by all agents) or at the agent level (isolated to a specific agent).
49
+
50
+ ### Instance-level storage
51
+
52
+ Add storage to your Mastra instance so all agents, workflows, observability traces and scores share the same memory provider:
53
+
54
+ ```typescript
55
+ import { Mastra } from '@mastra/core'
56
+ import { PostgresStore } from '@mastra/pg'
57
+
58
+ export const mastra = new Mastra({
59
+ storage: new PostgresStore({
60
+ id: 'mastra-storage',
61
+ connectionString: process.env.DATABASE_URL,
62
+ }),
63
+ })
64
+
65
+ // Both agents inherit storage from the Mastra instance above
66
+ const agent1 = new Agent({ id: 'agent-1', memory: new Memory() })
67
+ const agent2 = new Agent({ id: 'agent-2', memory: new Memory() })
68
+ ```
69
+
70
+ This is useful when all primitives share the same storage backend and have similar performance, scaling, and operational requirements.
71
+
72
+ #### Composite storage
73
+
74
+ [Composite storage](https://mastra.ai/reference/storage/composite) is an alternative way to configure instance-level storage. Use `MastraCompositeStore` to set the `memory` domain (and any other [domains](https://mastra.ai/reference/storage/composite) you need) to different storage providers.
75
+
76
+ ```typescript
77
+ import { Mastra } from '@mastra/core'
78
+ import { MastraCompositeStore } from '@mastra/core/storage'
79
+ import { MemoryLibSQL } from '@mastra/libsql'
80
+ import { WorkflowsPG } from '@mastra/pg'
81
+ import { ObservabilityStorageClickhouse } from '@mastra/clickhouse'
82
+
83
+ export const mastra = new Mastra({
84
+ storage: new MastraCompositeStore({
85
+ id: 'composite',
86
+ domains: {
87
+ memory: new MemoryLibSQL({ url: 'file:./memory.db' }),
88
+ workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
89
+ observability: new ObservabilityStorageClickhouse({
90
+ url: process.env.CLICKHOUSE_URL,
91
+ username: process.env.CLICKHOUSE_USERNAME,
92
+ password: process.env.CLICKHOUSE_PASSWORD,
93
+ }),
94
+ },
95
+ }),
96
+ })
97
+ ```
98
+
99
+ This is useful when different types of data have different performance or operational requirements, such as low-latency storage for memory, durable storage for workflows, and high-throughput storage for observability.
100
+
101
+ ### Agent-level storage
102
+
103
+ Agent-level storage overrides storage configured at the instance level. Add storage to a specific agent when you need data boundaries or compliance requirements:
104
+
105
+ ```typescript
106
+ import { Agent } from '@mastra/core/agent'
107
+ import { Memory } from '@mastra/memory'
108
+ import { PostgresStore } from '@mastra/pg'
109
+
110
+ export const agent = new Agent({
111
+ id: 'agent',
112
+ memory: new Memory({
113
+ storage: new PostgresStore({
114
+ id: 'agent-storage',
115
+ connectionString: process.env.AGENT_DATABASE_URL,
116
+ }),
117
+ }),
118
+ })
119
+ ```
120
+
121
+ > **Warning:** [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment) doesn't support agent-level storage.
122
+
123
+ ## Threads and resources
124
+
125
+ Mastra organizes conversations using two identifiers:
126
+
127
+ - **Thread** - a conversation session containing a sequence of messages.
128
+ - **Resource** - the entity that owns the thread, such as a user, organization, project, or any other domain entity in your application.
129
+
130
+ Both identifiers are required for agents to store information:
131
+
132
+ **Generate**:
133
+
134
+ ```typescript
135
+ const response = await agent.generate('hello', {
136
+ memory: {
137
+ thread: 'conversation-abc-123',
138
+ resource: 'user_123',
139
+ },
140
+ })
141
+ ```
142
+
143
+ **Stream**:
144
+
145
+ ```typescript
146
+ const stream = await agent.stream('hello', {
147
+ memory: {
148
+ thread: 'conversation-abc-123',
149
+ resource: 'user_123',
150
+ },
151
+ })
152
+ ```
153
+
154
+ > **Note:** [Studio](https://mastra.ai/docs/getting-started/studio) automatically generates a thread and resource ID for you. When calling `stream()` or `generate()` yourself, remember to provide these identifiers explicitly.
155
+
156
+ ### Thread title generation
157
+
158
+ Mastra can automatically generate descriptive thread titles based on the user's first message when `generateTitle` is enabled.
159
+
160
+ Use this option when implementing a ChatGPT-style chat interface to render a title alongside each thread in the conversation list (for example, in a sidebar) derived from the thread’s initial user message.
161
+
162
+ ```typescript
163
+ export const agent = new Agent({
164
+ id: 'agent',
165
+ memory: new Memory({
166
+ options: {
167
+ generateTitle: true,
168
+ },
169
+ }),
170
+ })
171
+ ```
172
+
173
+ Title generation runs asynchronously after the agent responds and does not affect response time.
174
+
175
+ To optimize cost or behavior, provide a smaller [`model`](https://mastra.ai/models) and custom `instructions`:
176
+
177
+ ```typescript
178
+ export const agent = new Agent({
179
+ id: 'agent',
180
+ memory: new Memory({
181
+ options: {
182
+ generateTitle: {
183
+ model: 'openai/gpt-4o-mini',
184
+ instructions: 'Generate a 1 word title',
185
+ },
186
+ },
187
+ }),
188
+ })
189
+ ```
190
+
191
+ ## Semantic recall
192
+
193
+ Semantic recall has different storage requirements - it needs a vector database in addition to the standard storage adapter. See [Semantic recall](https://mastra.ai/docs/memory/semantic-recall) for setup and supported vector providers.
194
+
195
+ ## Handling large attachments
196
+
197
+ Some storage providers enforce record size limits that base64-encoded file attachments (such as images) can exceed:
198
+
199
+ | Provider | Record size limit |
200
+ | ------------------------------------------------------------------ | ----------------- |
201
+ | [DynamoDB](https://mastra.ai/reference/storage/dynamodb) | 400 KB |
202
+ | [Convex](https://mastra.ai/reference/storage/convex) | 1 MiB |
203
+ | [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1) | 1 MiB |
204
+
205
+ PostgreSQL, MongoDB, and libSQL have higher limits and are generally unaffected.
206
+
207
+ To avoid this, use an input processor to upload attachments to external storage (S3, R2, GCS, [Convex file storage](https://docs.convex.dev/file-storage), etc.) and replace them with URL references before persistence.
208
+
209
+ ```typescript
210
+ import type { Processor } from '@mastra/core/processors'
211
+ import type { MastraDBMessage } from '@mastra/core/memory'
212
+
213
+ export class AttachmentUploader implements Processor {
214
+ id = 'attachment-uploader'
215
+
216
+ async processInput({ messages }: { messages: MastraDBMessage[] }) {
217
+ return Promise.all(messages.map(msg => this.processMessage(msg)))
218
+ }
219
+
220
+ async processMessage(msg: MastraDBMessage) {
221
+ const attachments = msg.content.experimental_attachments
222
+ if (!attachments?.length) return msg
223
+
224
+ const uploaded = await Promise.all(
225
+ attachments.map(async att => {
226
+ // Skip if already a URL
227
+ if (!att.url?.startsWith('data:')) return att
228
+
229
+ // Upload base64 data and replace with URL
230
+ const url = await this.upload(att.url, att.contentType)
231
+ return { ...att, url }
232
+ }),
233
+ )
234
+
235
+ return { ...msg, content: { ...msg.content, experimental_attachments: uploaded } }
236
+ }
237
+
238
+ async upload(dataUri: string, contentType?: string): Promise<string> {
239
+ const base64 = dataUri.split(',')[1]
240
+ const buffer = Buffer.from(base64, 'base64')
241
+
242
+ // Replace with your storage provider (S3, R2, GCS, Convex, etc.)
243
+ // return await s3.upload(buffer, contentType);
244
+ throw new Error('Implement upload() with your storage provider')
245
+ }
246
+ }
247
+ ```
248
+
249
+ Use the processor with your agent:
250
+
251
+ ```typescript
252
+ import { Agent } from '@mastra/core/agent'
253
+ import { Memory } from '@mastra/memory'
254
+ import { AttachmentUploader } from './processors/attachment-uploader'
255
+
256
+ const agent = new Agent({
257
+ id: 'my-agent',
258
+ memory: new Memory({ storage: yourStorage }),
259
+ inputProcessors: [new AttachmentUploader()],
260
+ })
261
+ ```