@mastra/memory 1.5.0 → 1.5.1

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/{chunk-DF7NDDSM.js → chunk-6PKWQ3GH.js} +28 -11
  3. package/dist/chunk-6PKWQ3GH.js.map +1 -0
  4. package/dist/{chunk-LLTHE64H.cjs → chunk-6XVTMLW4.cjs} +28 -11
  5. package/dist/chunk-6XVTMLW4.cjs.map +1 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/{observational-memory-ZNTAIUGT.js → observational-memory-AJWSMZVP.js} +3 -3
  9. package/dist/{observational-memory-ZNTAIUGT.js.map → observational-memory-AJWSMZVP.js.map} +1 -1
  10. package/dist/{observational-memory-4PCXEZIS.cjs → observational-memory-Q5TO525O.cjs} +17 -17
  11. package/dist/{observational-memory-4PCXEZIS.cjs.map → observational-memory-Q5TO525O.cjs.map} +1 -1
  12. package/dist/processors/index.cjs +15 -15
  13. package/dist/processors/index.js +1 -1
  14. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  15. package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
  16. package/package.json +7 -7
  17. package/dist/chunk-DF7NDDSM.js.map +0 -1
  18. package/dist/chunk-LLTHE64H.cjs.map +0 -1
  19. package/dist/docs/SKILL.md +0 -54
  20. package/dist/docs/assets/SOURCE_MAP.json +0 -103
  21. package/dist/docs/references/docs-agents-agent-approval.md +0 -377
  22. package/dist/docs/references/docs-agents-agent-memory.md +0 -212
  23. package/dist/docs/references/docs-agents-network-approval.md +0 -275
  24. package/dist/docs/references/docs-agents-networks.md +0 -290
  25. package/dist/docs/references/docs-memory-memory-processors.md +0 -316
  26. package/dist/docs/references/docs-memory-message-history.md +0 -260
  27. package/dist/docs/references/docs-memory-observational-memory.md +0 -246
  28. package/dist/docs/references/docs-memory-overview.md +0 -45
  29. package/dist/docs/references/docs-memory-semantic-recall.md +0 -272
  30. package/dist/docs/references/docs-memory-storage.md +0 -261
  31. package/dist/docs/references/docs-memory-working-memory.md +0 -400
  32. package/dist/docs/references/reference-core-getMemory.md +0 -50
  33. package/dist/docs/references/reference-core-listMemory.md +0 -56
  34. package/dist/docs/references/reference-memory-clone-utilities.md +0 -199
  35. package/dist/docs/references/reference-memory-cloneThread.md +0 -130
  36. package/dist/docs/references/reference-memory-createThread.md +0 -68
  37. package/dist/docs/references/reference-memory-getThreadById.md +0 -24
  38. package/dist/docs/references/reference-memory-listThreads.md +0 -145
  39. package/dist/docs/references/reference-memory-memory-class.md +0 -147
  40. package/dist/docs/references/reference-memory-observational-memory.md +0 -565
  41. package/dist/docs/references/reference-processors-token-limiter-processor.md +0 -113
  42. package/dist/docs/references/reference-storage-dynamodb.md +0 -282
  43. package/dist/docs/references/reference-storage-libsql.md +0 -135
  44. package/dist/docs/references/reference-storage-mongodb.md +0 -262
  45. package/dist/docs/references/reference-storage-postgresql.md +0 -529
  46. package/dist/docs/references/reference-storage-upstash.md +0 -160
  47. package/dist/docs/references/reference-vectors-libsql.md +0 -305
  48. package/dist/docs/references/reference-vectors-mongodb.md +0 -295
  49. package/dist/docs/references/reference-vectors-pg.md +0 -408
  50. package/dist/docs/references/reference-vectors-upstash.md +0 -294
@@ -1,290 +0,0 @@
1
- # Agent Networks
2
-
3
- Agent networks in Mastra coordinate multiple agents, workflows, and tools to handle tasks that aren't clearly defined upfront but can be inferred from the user's message or context. A top-level **routing agent** (a Mastra agent with other agents, workflows, and tools configured) uses an LLM to interpret the request and decide which primitives (subagents, workflows, or tools) to call, in what order, and with what data.
4
-
5
- ## When to use networks
6
-
7
- Use networks for complex tasks that require coordination across multiple primitives. Unlike workflows, which follow a predefined sequence, networks rely on LLM reasoning to interpret the request and decide what to run.
8
-
9
- ## Core principles
10
-
11
- Mastra agent networks operate using these principles:
12
-
13
- - Memory is required when using `.network()` and is used to store task history and determine when a task is complete.
14
- - Primitives are selected based on their descriptions. Clear, specific descriptions improve routing. For workflows and tools, the input schema helps determine the right inputs at runtime.
15
- - If multiple primitives have overlapping functionality, the agent favors the more specific one, using a combination of schema and descriptions to decide which to run.
16
-
17
- ## Creating an agent network
18
-
19
- An agent network is built around a top-level routing agent that delegates tasks to subagents, workflows, and tools defined in its configuration. Memory is configured on the routing agent using the `memory` option, and `instructions` define the agent's routing behavior.
20
-
21
- ```typescript
22
- import { Agent } from "@mastra/core/agent";
23
- import { Memory } from "@mastra/memory";
24
- import { LibSQLStore } from "@mastra/libsql";
25
-
26
- import { researchAgent } from "./research-agent";
27
- import { writingAgent } from "./writing-agent";
28
-
29
- import { cityWorkflow } from "../workflows/city-workflow";
30
- import { weatherTool } from "../tools/weather-tool";
31
-
32
- export const routingAgent = new Agent({
33
- id: "routing-agent",
34
- name: "Routing Agent",
35
- instructions: `
36
- You are a network of writers and researchers.
37
- The user will ask you to research a topic.
38
- Always respond with a complete report—no bullet points.
39
- Write in full paragraphs, like a blog post.
40
- Do not answer with incomplete or uncertain information.`,
41
- model: "openai/gpt-5.1",
42
- agents: {
43
- researchAgent,
44
- writingAgent,
45
- },
46
- workflows: {
47
- cityWorkflow,
48
- },
49
- tools: {
50
- weatherTool,
51
- },
52
- memory: new Memory({
53
- storage: new LibSQLStore({
54
- id: 'mastra-storage',
55
- url: "file:../mastra.db",
56
- }),
57
- }),
58
- });
59
- ```
60
-
61
- ### Writing descriptions for network primitives
62
-
63
- When configuring a Mastra agent network, each primitive (agent, workflow, or tool) needs a clear description to help the routing agent decide which to use. The routing agent uses each primitive's description and schema to determine what it does and how to use it. Clear descriptions and well-defined input and output schemas improve routing accuracy.
64
-
65
- #### Agent descriptions
66
-
67
- Each subagent in a network should include a clear `description` that explains what the agent does.
68
-
69
- ```typescript
70
- export const researchAgent = new Agent({
71
- id: "research-agent",
72
- name: "Research Agent",
73
- description: `This agent gathers concise research insights in bullet-point form.
74
- It's designed to extract key facts without generating full
75
- responses or narrative content.`,
76
- });
77
- ```
78
-
79
- ```typescript
80
- export const writingAgent = new Agent({
81
- id: "writing-agent",
82
- name: "Writing Agent",
83
- description: `This agent turns researched material into well-structured
84
- written content. It produces full-paragraph reports with no bullet points,
85
- suitable for use in articles, summaries, or blog posts.`,
86
- });
87
- ```
88
-
89
- #### Workflow descriptions
90
-
91
- Workflows in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
92
-
93
- ```typescript
94
- export const cityWorkflow = createWorkflow({
95
- id: "city-workflow",
96
- description: `This workflow handles city-specific research tasks.
97
- It first gathers factual information about the city, then synthesizes
98
- that research into a full written report. Use it when the user input
99
- includes a city to be researched.`,
100
- inputSchema: z.object({
101
- city: z.string(),
102
- }),
103
- outputSchema: z.object({
104
- text: z.string(),
105
- }),
106
- });
107
- ```
108
-
109
- #### Tool descriptions
110
-
111
- Tools in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
112
-
113
- ```typescript
114
- export const weatherTool = createTool({
115
- id: "weather-tool",
116
- description: ` Retrieves current weather information using the wttr.in API.
117
- Accepts a city or location name as input and returns a short weather summary.
118
- Use this tool whenever up-to-date weather data is requested.
119
- `,
120
- inputSchema: z.object({
121
- location: z.string(),
122
- }),
123
- outputSchema: z.object({
124
- weather: z.string(),
125
- }),
126
- });
127
- ```
128
-
129
- ## Calling agent networks
130
-
131
- Call a Mastra agent network using `.network()` with a user message. The method returns a stream of events that you can iterate over to track execution progress and retrieve the final result.
132
-
133
- ### Agent example
134
-
135
- In this example, the network interprets the message and would route the request to both the `researchAgent` and `writingAgent` to generate a complete response.
136
-
137
- ```typescript
138
- const result = await routingAgent.network(
139
- "Tell me three cool ways to use Mastra",
140
- );
141
-
142
- for await (const chunk of result) {
143
- console.log(chunk.type);
144
- if (chunk.type === "network-execution-event-step-finish") {
145
- console.log(chunk.payload.result);
146
- }
147
- }
148
- ```
149
-
150
- #### Agent output
151
-
152
- The following `chunk.type` events are emitted during this request:
153
-
154
- ```text
155
- routing-agent-start
156
- routing-agent-end
157
- agent-execution-start
158
- agent-execution-event-start
159
- agent-execution-event-step-start
160
- agent-execution-event-text-start
161
- agent-execution-event-text-delta
162
- agent-execution-event-text-end
163
- agent-execution-event-step-finish
164
- agent-execution-event-finish
165
- agent-execution-end
166
- network-execution-event-step-finish
167
- ```
168
-
169
- ## Workflow example
170
-
171
- In this example, the routing agent recognizes the city name in the message and runs the `cityWorkflow`. The workflow defines steps that call the `researchAgent` to gather facts, then the `writingAgent` to generate the final text.
172
-
173
- ```typescript
174
- const result = await routingAgent.network(
175
- "Tell me some historical facts about London",
176
- );
177
-
178
- for await (const chunk of result) {
179
- console.log(chunk.type);
180
- if (chunk.type === "network-execution-event-step-finish") {
181
- console.log(chunk.payload.result);
182
- }
183
- }
184
- ```
185
-
186
- #### Workflow output
187
-
188
- The following `chunk.type` events are emitted during this request:
189
-
190
- ```text
191
- routing-agent-end
192
- workflow-execution-start
193
- workflow-execution-event-workflow-start
194
- workflow-execution-event-workflow-step-start
195
- workflow-execution-event-workflow-step-result
196
- workflow-execution-event-workflow-finish
197
- workflow-execution-end
198
- routing-agent-start
199
- network-execution-event-step-finish
200
- ```
201
-
202
- ### Tool example
203
-
204
- In this example, the routing agent skips the `researchAgent`, `writingAgent`, and `cityWorkflow`, and calls the `weatherTool` directly to complete the task.
205
-
206
- ```typescript
207
- const result = await routingAgent.network("What's the weather in London?");
208
-
209
- for await (const chunk of result) {
210
- console.log(chunk.type);
211
- if (chunk.type === "network-execution-event-step-finish") {
212
- console.log(chunk.payload.result);
213
- }
214
- }
215
- ```
216
-
217
- #### Tool output
218
-
219
- The following `chunk.type` events are emitted during this request:
220
-
221
- ```text
222
- routing-agent-start
223
- routing-agent-end
224
- tool-execution-start
225
- tool-execution-end
226
- network-execution-event-step-finish
227
- ```
228
-
229
- ## Structured output
230
-
231
- When you need typed, validated results from a network, use the `structuredOutput` option. After the network completes its task, it generates a structured response matching your schema.
232
-
233
- ```typescript
234
- import { z } from "zod";
235
-
236
- const resultSchema = z.object({
237
- summary: z.string().describe("A brief summary of the findings"),
238
- recommendations: z.array(z.string()).describe("List of recommendations"),
239
- confidence: z.number().min(0).max(1).describe("Confidence score"),
240
- });
241
-
242
- const stream = await routingAgent.network("Research AI trends", {
243
- structuredOutput: {
244
- schema: resultSchema,
245
- },
246
- });
247
-
248
- // Consume the stream
249
- for await (const chunk of stream) {
250
- if (chunk.type === "network-object") {
251
- // Partial object during generation
252
- console.log("Partial:", chunk.payload.object);
253
- }
254
- if (chunk.type === "network-object-result") {
255
- // Final structured object
256
- console.log("Final:", chunk.payload.object);
257
- }
258
- }
259
-
260
- // Get the typed result
261
- const result = await stream.object;
262
- console.log(result?.summary);
263
- console.log(result?.recommendations);
264
- console.log(result?.confidence);
265
- ```
266
-
267
- ### Streaming partial objects
268
-
269
- For real-time updates during structured output generation, use `objectStream`:
270
-
271
- ```typescript
272
- const stream = await routingAgent.network("Analyze market data", {
273
- structuredOutput: { schema: resultSchema },
274
- });
275
-
276
- // Stream partial objects as they're generated
277
- for await (const partial of stream.objectStream) {
278
- console.log("Building result:", partial);
279
- }
280
-
281
- // Get the final typed result
282
- const final = await stream.object;
283
- ```
284
-
285
- ## Related
286
-
287
- - [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
288
- - [Workflows Overview](https://mastra.ai/docs/workflows/overview)
289
- - [Request Context](https://mastra.ai/docs/server/request-context)
290
- - [Supervisor example](https://github.com/mastra-ai/mastra/tree/main/examples/supervisor-agent)
@@ -1,316 +0,0 @@
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) =>
243
- containsBadContent(msg)
244
- );
245
- if (hasInappropriateContent) {
246
- abort("Content blocked by guardrail");
247
- }
248
- return messages;
249
- },
250
- };
251
-
252
- const agent = new Agent({
253
- name: "safe-agent",
254
- instructions: "You are a helpful assistant",
255
- model: 'openai/gpt-4o',
256
- memory: new Memory({ lastMessages: 10 }),
257
- // Your guardrail runs BEFORE memory saves
258
- outputProcessors: [contentBlocker],
259
- });
260
-
261
- // If the guardrail aborts, nothing is saved to memory
262
- const result = await agent.generate("Hello");
263
- if (result.tripwire) {
264
- console.log("Blocked:", result.tripwire.reason);
265
- // Memory is empty - no messages were persisted
266
- }
267
- ```
268
-
269
- ### Input guardrails
270
-
271
- Input guardrails run **after** memory processors load history. If a guardrail aborts:
272
-
273
- - The tripwire is triggered
274
- - The LLM is never called
275
- - Output processors (including memory persistence) are skipped
276
- - **No messages are persisted to storage**
277
-
278
- ```typescript
279
- // Input guardrail that validates user input
280
- const inputValidator = {
281
- id: "input-validator",
282
- processInput: async ({ messages, abort }) => {
283
- const lastUserMessage = messages.findLast((m) => m.role === "user");
284
- if (isInvalidInput(lastUserMessage)) {
285
- abort("Invalid input detected");
286
- }
287
- return messages;
288
- },
289
- };
290
-
291
- const agent = new Agent({
292
- name: "validated-agent",
293
- instructions: "You are a helpful assistant",
294
- model: 'openai/gpt-4o',
295
- memory: new Memory({ lastMessages: 10 }),
296
- // Your guardrail runs AFTER memory loads history
297
- inputProcessors: [inputValidator],
298
- });
299
- ```
300
-
301
- ### Summary
302
-
303
- | Guardrail Type | When it runs | If it aborts |
304
- | -------------- | -------------------------- | ----------------------------- |
305
- | Input | After memory loads history | LLM not called, nothing saved |
306
- | Output | Before memory saves | Nothing saved to storage |
307
-
308
- Both scenarios are safe - guardrails prevent inappropriate content from being persisted to memory
309
-
310
- ## Related documentation
311
-
312
- - [Processors](https://mastra.ai/docs/agents/processors) - General processor concepts and custom processor creation
313
- - [Guardrails](https://mastra.ai/docs/agents/guardrails) - Security and validation processors
314
- - [Memory Overview](https://mastra.ai/docs/memory/overview) - Memory types and configuration
315
-
316
- When creating custom processors avoid mutating the input `messages` array or its objects directly.