@mastra/mcp-docs-server 1.0.0-beta.5 → 1.0.0-beta.7

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 (163) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
  2. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +67 -67
  3. package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
  4. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +12 -12
  5. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +57 -57
  6. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +110 -110
  7. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +57 -57
  8. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +57 -57
  9. package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +60 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fcore.md +358 -358
  12. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +11 -11
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
  15. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +79 -79
  16. package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +57 -57
  18. package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +61 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
  20. package/.docs/organized/changelogs/%40mastra%2Flance.md +57 -57
  21. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +55 -55
  22. package/.docs/organized/changelogs/%40mastra%2Floggers.md +12 -12
  23. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
  24. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +125 -125
  25. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
  26. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +57 -57
  27. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +57 -57
  28. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
  29. package/.docs/organized/changelogs/%40mastra%2Fpg.md +59 -59
  30. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
  31. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +77 -77
  32. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
  33. package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
  34. package/.docs/organized/changelogs/%40mastra%2Freact.md +16 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fserver.md +113 -113
  38. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
  39. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +57 -57
  40. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
  42. package/.docs/organized/changelogs/create-mastra.md +15 -15
  43. package/.docs/organized/changelogs/mastra.md +30 -30
  44. package/.docs/organized/code-examples/agui.md +1 -0
  45. package/.docs/organized/code-examples/ai-elements.md +1 -1
  46. package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
  47. package/.docs/organized/code-examples/ai-sdk-v5.md +2 -1
  48. package/.docs/organized/code-examples/assistant-ui.md +1 -1
  49. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
  50. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
  51. package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
  52. package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
  53. package/.docs/organized/code-examples/server-app-access.md +342 -0
  54. package/.docs/organized/code-examples/server-express-adapter.md +87 -0
  55. package/.docs/organized/code-examples/server-hono-adapter.md +85 -0
  56. package/.docs/raw/agents/agent-approval.mdx +189 -0
  57. package/.docs/raw/agents/guardrails.mdx +13 -9
  58. package/.docs/raw/agents/networks.mdx +1 -0
  59. package/.docs/raw/agents/overview.mdx +8 -152
  60. package/.docs/raw/agents/processors.mdx +279 -0
  61. package/.docs/raw/agents/structured-output.mdx +224 -0
  62. package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
  63. package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
  64. package/.docs/raw/evals/running-in-ci.mdx +0 -2
  65. package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
  66. package/.docs/raw/getting-started/start.mdx +1 -1
  67. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
  68. package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
  69. package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
  70. package/.docs/raw/guides/index.mdx +3 -35
  71. package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
  72. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +37 -0
  73. package/.docs/raw/index.mdx +1 -1
  74. package/.docs/raw/memory/memory-processors.mdx +265 -79
  75. package/.docs/raw/memory/working-memory.mdx +11 -2
  76. package/.docs/raw/observability/overview.mdx +0 -1
  77. package/.docs/raw/observability/tracing/bridges/otel.mdx +200 -0
  78. package/.docs/raw/observability/tracing/exporters/arize.mdx +36 -0
  79. package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
  80. package/.docs/raw/observability/tracing/exporters/langfuse.mdx +83 -0
  81. package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
  82. package/.docs/raw/observability/tracing/exporters/otel.mdx +34 -22
  83. package/.docs/raw/observability/tracing/exporters/posthog.mdx +20 -0
  84. package/.docs/raw/observability/tracing/overview.mdx +76 -6
  85. package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
  86. package/.docs/raw/rag/retrieval.mdx +23 -6
  87. package/.docs/raw/rag/vector-databases.mdx +93 -2
  88. package/.docs/raw/reference/agents/generate.mdx +55 -6
  89. package/.docs/raw/reference/agents/network.mdx +44 -0
  90. package/.docs/raw/reference/client-js/memory.mdx +43 -0
  91. package/.docs/raw/reference/client-js/workflows.mdx +92 -63
  92. package/.docs/raw/reference/deployer/netlify.mdx +1 -2
  93. package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
  94. package/.docs/raw/reference/index.mdx +1 -0
  95. package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +177 -0
  96. package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
  97. package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +29 -0
  98. package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +43 -0
  99. package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
  100. package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +33 -43
  101. package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
  102. package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
  103. package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
  104. package/.docs/raw/reference/processors/language-detector.mdx +9 -2
  105. package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
  106. package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
  107. package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
  108. package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
  109. package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
  110. package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
  111. package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
  112. package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
  113. package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
  114. package/.docs/raw/reference/server/create-route.mdx +314 -0
  115. package/.docs/raw/reference/server/express-adapter.mdx +193 -0
  116. package/.docs/raw/reference/server/hono-adapter.mdx +174 -0
  117. package/.docs/raw/reference/server/mastra-server.mdx +316 -0
  118. package/.docs/raw/reference/server/routes.mdx +250 -0
  119. package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
  120. package/.docs/raw/reference/storage/convex.mdx +164 -0
  121. package/.docs/raw/reference/storage/lance.mdx +33 -0
  122. package/.docs/raw/reference/storage/libsql.mdx +37 -0
  123. package/.docs/raw/reference/storage/mongodb.mdx +39 -0
  124. package/.docs/raw/reference/storage/mssql.mdx +37 -0
  125. package/.docs/raw/reference/storage/postgresql.mdx +37 -0
  126. package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
  127. package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
  128. package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
  129. package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
  130. package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
  131. package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
  132. package/.docs/raw/reference/tools/mcp-client.mdx +128 -18
  133. package/.docs/raw/reference/vectors/convex.mdx +429 -0
  134. package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
  135. package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
  136. package/.docs/raw/reference/voice/google.mdx +159 -20
  137. package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
  138. package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
  139. package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
  140. package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
  141. package/.docs/raw/reference/workflows/run.mdx +27 -5
  142. package/.docs/raw/reference/workflows/step.mdx +13 -0
  143. package/.docs/raw/reference/workflows/workflow.mdx +19 -0
  144. package/.docs/raw/server-db/custom-adapters.mdx +380 -0
  145. package/.docs/raw/server-db/mastra-server.mdx +16 -8
  146. package/.docs/raw/server-db/request-context.mdx +0 -1
  147. package/.docs/raw/server-db/server-adapters.mdx +286 -0
  148. package/.docs/raw/server-db/storage.mdx +11 -0
  149. package/.docs/raw/streaming/overview.mdx +6 -6
  150. package/.docs/raw/streaming/tool-streaming.mdx +2 -2
  151. package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
  152. package/.docs/raw/workflows/error-handling.mdx +1 -0
  153. package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
  154. package/.docs/raw/workflows/overview.mdx +56 -44
  155. package/.docs/raw/workflows/snapshots.mdx +1 -0
  156. package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
  157. package/.docs/raw/workflows/time-travel.mdx +313 -0
  158. package/.docs/raw/workflows/workflow-state.mdx +191 -0
  159. package/CHANGELOG.md +16 -0
  160. package/package.json +4 -4
  161. package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
  162. package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
  163. package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
@@ -0,0 +1,197 @@
1
+ ---
2
+ title: "Reference: Semantic Recall Processor | Processors"
3
+ description: "Documentation for the SemanticRecall processor in Mastra, which enables semantic search over conversation history using vector embeddings."
4
+ ---
5
+
6
+ # SemanticRecall
7
+
8
+ The `SemanticRecall` is a **hybrid processor** that enables semantic search over conversation history using vector embeddings. On input, it performs semantic search to find relevant historical messages. On output, it creates embeddings for new messages to enable future semantic retrieval.
9
+
10
+ ## Usage example
11
+
12
+ ```typescript copy
13
+ import { SemanticRecall } from "@mastra/core/processors";
14
+ import { openai } from "@ai-sdk/openai";
15
+
16
+ const processor = new SemanticRecall({
17
+ storage: memoryStorage,
18
+ vector: vectorStore,
19
+ embedder: openai.embedding("text-embedding-3-small"),
20
+ topK: 5,
21
+ messageRange: 2,
22
+ scope: "resource",
23
+ });
24
+ ```
25
+
26
+ ## Constructor parameters
27
+
28
+ <PropertiesTable
29
+ content={[
30
+ {
31
+ name: "options",
32
+ type: "SemanticRecallOptions",
33
+ description: "Configuration options for the semantic recall processor",
34
+ isOptional: false,
35
+ },
36
+ ]}
37
+ />
38
+
39
+ ### Options
40
+
41
+ <PropertiesTable
42
+ content={[
43
+ {
44
+ name: "storage",
45
+ type: "MemoryStorage",
46
+ description: "Storage instance for retrieving messages",
47
+ isOptional: false,
48
+ },
49
+ {
50
+ name: "vector",
51
+ type: "MastraVector",
52
+ description: "Vector store for semantic search",
53
+ isOptional: false,
54
+ },
55
+ {
56
+ name: "embedder",
57
+ type: "MastraEmbeddingModel<string>",
58
+ description: "Embedder for generating query embeddings",
59
+ isOptional: false,
60
+ },
61
+ {
62
+ name: "topK",
63
+ type: "number",
64
+ description: "Number of most similar messages to retrieve",
65
+ isOptional: true,
66
+ default: "4",
67
+ },
68
+ {
69
+ name: "messageRange",
70
+ type: "number | { before: number; after: number }",
71
+ description: "Number of context messages to include before/after each match. Can be a single number (same for both) or an object with separate values",
72
+ isOptional: true,
73
+ default: "1",
74
+ },
75
+ {
76
+ name: "scope",
77
+ type: "'thread' | 'resource'",
78
+ description: "Scope of semantic search. 'thread' searches within the current thread only. 'resource' searches across all threads for the resource",
79
+ isOptional: true,
80
+ default: "'resource'",
81
+ },
82
+ {
83
+ name: "threshold",
84
+ type: "number",
85
+ description: "Minimum similarity score threshold (0-1). Messages below this threshold are filtered out",
86
+ isOptional: true,
87
+ },
88
+ {
89
+ name: "indexName",
90
+ type: "string",
91
+ description: "Index name for the vector store. If not provided, auto-generated based on embedder model",
92
+ isOptional: true,
93
+ },
94
+ {
95
+ name: "logger",
96
+ type: "IMastraLogger",
97
+ description: "Optional logger instance for structured logging",
98
+ isOptional: true,
99
+ },
100
+ ]}
101
+ />
102
+
103
+ ## Returns
104
+
105
+ <PropertiesTable
106
+ content={[
107
+ {
108
+ name: "id",
109
+ type: "string",
110
+ description: "Processor identifier set to 'semantic-recall'",
111
+ isOptional: false,
112
+ },
113
+ {
114
+ name: "name",
115
+ type: "string",
116
+ description: "Processor display name set to 'SemanticRecall'",
117
+ isOptional: false,
118
+ },
119
+ {
120
+ name: "processInput",
121
+ type: "(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>",
122
+ description: "Performs semantic search on historical messages and adds relevant context to the message list",
123
+ isOptional: false,
124
+ },
125
+ {
126
+ name: "processOutputResult",
127
+ type: "(args: { messages: MastraDBMessage[]; messageList?: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>",
128
+ description: "Creates embeddings for new messages to enable future semantic search",
129
+ isOptional: false,
130
+ },
131
+ ]}
132
+ />
133
+
134
+ ## Extended usage example
135
+
136
+ ```typescript title="src/mastra/agents/semantic-memory-agent.ts" showLineNumbers copy
137
+ import { Agent } from "@mastra/core/agent";
138
+ import { SemanticRecall, MessageHistory } from "@mastra/core/processors";
139
+ import { PostgresStorage } from "@mastra/pg";
140
+ import { PgVector } from "@mastra/pg";
141
+ import { openai } from "@ai-sdk/openai";
142
+
143
+ const storage = new PostgresStorage({
144
+ connectionString: process.env.DATABASE_URL,
145
+ });
146
+
147
+ const vector = new PgVector({
148
+ connectionString: process.env.DATABASE_URL,
149
+ });
150
+
151
+ const semanticRecall = new SemanticRecall({
152
+ storage,
153
+ vector,
154
+ embedder: openai.embedding("text-embedding-3-small"),
155
+ topK: 5,
156
+ messageRange: { before: 2, after: 1 },
157
+ scope: "resource",
158
+ threshold: 0.7,
159
+ });
160
+
161
+ export const agent = new Agent({
162
+ name: "semantic-memory-agent",
163
+ instructions: "You are a helpful assistant with semantic memory recall",
164
+ model: "openai:gpt-4o",
165
+ inputProcessors: [
166
+ semanticRecall,
167
+ new MessageHistory({ storage, lastMessages: 50 }),
168
+ ],
169
+ outputProcessors: [
170
+ semanticRecall,
171
+ new MessageHistory({ storage }),
172
+ ],
173
+ });
174
+ ```
175
+
176
+ ## Behavior
177
+
178
+ ### Input processing
179
+ 1. Extracts the user query from the last user message
180
+ 2. Generates embeddings for the query
181
+ 3. Performs vector search to find semantically similar messages
182
+ 4. Retrieves matched messages along with surrounding context (based on `messageRange`)
183
+ 5. For `scope: 'resource'`, formats cross-thread messages as a system message with timestamps
184
+ 6. Adds recalled messages with `source: 'memory'` tag
185
+
186
+ ### Output processing
187
+ 1. Extracts text content from new user and assistant messages
188
+ 2. Generates embeddings for each message
189
+ 3. Stores embeddings in the vector store with metadata (message ID, thread ID, resource ID, role, content, timestamp)
190
+ 4. Uses LRU caching for embeddings to avoid redundant API calls
191
+
192
+ ### Cross-thread recall
193
+ When `scope` is set to `'resource'`, the processor can recall messages from other threads. These cross-thread messages are formatted as a system message with timestamps and conversation labels to provide context about when and where the conversation occurred.
194
+
195
+ ## Related
196
+
197
+ - [Guardrails](/docs/v1/agents/guardrails)
@@ -13,7 +13,7 @@ The `SystemPromptScrubber` is an **output processor** that detects and handles s
13
13
  import { SystemPromptScrubber } from "@mastra/core/processors";
14
14
 
15
15
  const processor = new SystemPromptScrubber({
16
- model: "openai/gpt-4.1-nano",
16
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
17
17
  strategy: "redact",
18
18
  redactionMethod: "mask",
19
19
  includeDetections: true
@@ -138,7 +138,7 @@ export const agent = new Agent({
138
138
  }),
139
139
  // Then apply system prompt detection on batched content
140
140
  new SystemPromptScrubber({
141
- model: "openai/gpt-4.1-nano",
141
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
142
142
  strategy: "redact",
143
143
  customPatterns: ["system prompt", "internal instructions"],
144
144
  includeDetections: true,
@@ -0,0 +1,125 @@
1
+ ---
2
+ title: "Reference: Tool Call Filter | Processors"
3
+ description: "Documentation for the ToolCallFilter processor in Mastra, which filters out tool calls and results from messages."
4
+ ---
5
+
6
+ # ToolCallFilter
7
+
8
+ The `ToolCallFilter` is an **input processor** that filters out tool calls and their results from the message history before sending to the model. This is useful when you want to exclude specific tool interactions from context or remove all tool calls entirely.
9
+
10
+ ## Usage example
11
+
12
+ ```typescript copy
13
+ import { ToolCallFilter } from "@mastra/core/processors";
14
+
15
+ // Exclude all tool calls
16
+ const filterAll = new ToolCallFilter();
17
+
18
+ // Exclude specific tools by name
19
+ const filterSpecific = new ToolCallFilter({
20
+ exclude: ["searchDatabase", "sendEmail"],
21
+ });
22
+ ```
23
+
24
+ ## Constructor parameters
25
+
26
+ <PropertiesTable
27
+ content={[
28
+ {
29
+ name: "options",
30
+ type: "Options",
31
+ description: "Configuration options for the tool call filter",
32
+ isOptional: true,
33
+ },
34
+ ]}
35
+ />
36
+
37
+ ### Options
38
+
39
+ <PropertiesTable
40
+ content={[
41
+ {
42
+ name: "exclude",
43
+ type: "string[]",
44
+ description: "List of specific tool names to exclude. If not provided or undefined, all tool calls are excluded",
45
+ isOptional: true,
46
+ },
47
+ ]}
48
+ />
49
+
50
+ ## Returns
51
+
52
+ <PropertiesTable
53
+ content={[
54
+ {
55
+ name: "id",
56
+ type: "string",
57
+ description: "Processor identifier set to 'tool-call-filter'",
58
+ isOptional: false,
59
+ },
60
+ {
61
+ name: "name",
62
+ type: "string",
63
+ description: "Processor display name set to 'ToolCallFilter'",
64
+ isOptional: false,
65
+ },
66
+ {
67
+ name: "processInput",
68
+ type: "(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>",
69
+ description: "Processes input messages to filter out tool calls and their results based on configuration",
70
+ isOptional: false,
71
+ },
72
+ ]}
73
+ />
74
+
75
+ ## Extended usage example
76
+
77
+ ```typescript title="src/mastra/agents/filtered-agent.ts" showLineNumbers copy
78
+ import { Agent } from "@mastra/core/agent";
79
+ import { ToolCallFilter } from "@mastra/core/processors";
80
+
81
+ export const agent = new Agent({
82
+ name: "filtered-agent",
83
+ instructions: "You are a helpful assistant",
84
+ model: "openai:gpt-4o",
85
+ tools: {
86
+ searchDatabase,
87
+ sendEmail,
88
+ getWeather,
89
+ },
90
+ inputProcessors: [
91
+ // Filter out database search tool calls from context
92
+ // to reduce token usage while keeping other tool interactions
93
+ new ToolCallFilter({
94
+ exclude: ["searchDatabase"],
95
+ }),
96
+ ],
97
+ });
98
+ ```
99
+
100
+ ## Filtering all tool calls
101
+
102
+ ```typescript copy
103
+ import { Agent } from "@mastra/core/agent";
104
+ import { ToolCallFilter } from "@mastra/core/processors";
105
+
106
+ export const agent = new Agent({
107
+ name: "no-tools-context-agent",
108
+ instructions: "You are a helpful assistant",
109
+ model: "openai:gpt-4o",
110
+ tools: {
111
+ searchDatabase,
112
+ sendEmail,
113
+ },
114
+ inputProcessors: [
115
+ // Remove all tool calls from the message history
116
+ // The agent can still use tools, but previous tool interactions
117
+ // won't be included in the context
118
+ new ToolCallFilter(),
119
+ ],
120
+ });
121
+ ```
122
+
123
+ ## Related
124
+
125
+ - [Guardrails](/docs/v1/agents/guardrails)
@@ -0,0 +1,221 @@
1
+ ---
2
+ title: "Reference: Working Memory Processor | Processors"
3
+ description: "Documentation for the WorkingMemory processor in Mastra, which injects persistent user/context data as system instructions."
4
+ ---
5
+
6
+ # WorkingMemory
7
+
8
+ The `WorkingMemory` is an **input processor** that injects working memory data as a system message. It retrieves persistent information from storage and formats it as instructions for the LLM, enabling the agent to maintain context about users across conversations.
9
+
10
+ ## Usage example
11
+
12
+ ```typescript copy
13
+ import { WorkingMemory } from "@mastra/core/processors";
14
+
15
+ const processor = new WorkingMemory({
16
+ storage: memoryStorage,
17
+ scope: "resource",
18
+ template: {
19
+ format: "markdown",
20
+ content: `# User Profile
21
+ - **Name**:
22
+ - **Preferences**:
23
+ - **Goals**:
24
+ `,
25
+ },
26
+ });
27
+ ```
28
+
29
+ ## Constructor parameters
30
+
31
+ <PropertiesTable
32
+ content={[
33
+ {
34
+ name: "options",
35
+ type: "Options",
36
+ description: "Configuration options for the working memory processor",
37
+ isOptional: false,
38
+ },
39
+ ]}
40
+ />
41
+
42
+ ### Options
43
+
44
+ <PropertiesTable
45
+ content={[
46
+ {
47
+ name: "storage",
48
+ type: "MemoryStorage",
49
+ description: "Storage instance for retrieving working memory data",
50
+ isOptional: false,
51
+ },
52
+ {
53
+ name: "template",
54
+ type: "WorkingMemoryTemplate",
55
+ description: "Template defining the format and structure of working memory",
56
+ isOptional: true,
57
+ },
58
+ {
59
+ name: "scope",
60
+ type: "'thread' | 'resource'",
61
+ description: "Scope of working memory. 'thread' scopes to current thread, 'resource' shares across all threads for the resource",
62
+ isOptional: true,
63
+ default: "'resource'",
64
+ },
65
+ {
66
+ name: "useVNext",
67
+ type: "boolean",
68
+ description: "Use the next-generation instruction format with improved guidelines",
69
+ isOptional: true,
70
+ },
71
+ {
72
+ name: "templateProvider",
73
+ type: "{ getWorkingMemoryTemplate(args: { memoryConfig?: MemoryConfig }): Promise<WorkingMemoryTemplate | null> }",
74
+ description: "Dynamic template provider for runtime template resolution",
75
+ isOptional: true,
76
+ },
77
+ {
78
+ name: "logger",
79
+ type: "IMastraLogger",
80
+ description: "Optional logger instance for structured logging",
81
+ isOptional: true,
82
+ },
83
+ ]}
84
+ />
85
+
86
+ ### WorkingMemoryTemplate
87
+
88
+ <PropertiesTable
89
+ content={[
90
+ {
91
+ name: "format",
92
+ type: "'markdown' | 'json'",
93
+ description: "Format of the working memory content",
94
+ isOptional: false,
95
+ },
96
+ {
97
+ name: "content",
98
+ type: "string",
99
+ description: "Template content defining the structure of working memory data",
100
+ isOptional: false,
101
+ },
102
+ ]}
103
+ />
104
+
105
+ ## Returns
106
+
107
+ <PropertiesTable
108
+ content={[
109
+ {
110
+ name: "id",
111
+ type: "string",
112
+ description: "Processor identifier set to 'working-memory'",
113
+ isOptional: false,
114
+ },
115
+ {
116
+ name: "name",
117
+ type: "string",
118
+ description: "Processor display name set to 'WorkingMemory'",
119
+ isOptional: false,
120
+ },
121
+ {
122
+ name: "defaultWorkingMemoryTemplate",
123
+ type: "string",
124
+ description: "The default markdown template used when no custom template is provided",
125
+ isOptional: false,
126
+ },
127
+ {
128
+ name: "processInput",
129
+ type: "(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>",
130
+ description: "Retrieves working memory and adds it as a system message to the message list",
131
+ isOptional: false,
132
+ },
133
+ ]}
134
+ />
135
+
136
+ ## Extended usage example
137
+
138
+ ```typescript title="src/mastra/agents/personalized-agent.ts" showLineNumbers copy
139
+ import { Agent } from "@mastra/core/agent";
140
+ import { WorkingMemory, MessageHistory } from "@mastra/core/processors";
141
+ import { PostgresStorage } from "@mastra/pg";
142
+
143
+ const storage = new PostgresStorage({
144
+ connectionString: process.env.DATABASE_URL,
145
+ });
146
+
147
+ export const agent = new Agent({
148
+ name: "personalized-agent",
149
+ instructions: "You are a helpful assistant that remembers user preferences",
150
+ model: "openai:gpt-4o",
151
+ inputProcessors: [
152
+ new WorkingMemory({
153
+ storage,
154
+ scope: "resource",
155
+ template: {
156
+ format: "markdown",
157
+ content: `# User Information
158
+ - **Name**:
159
+ - **Location**:
160
+ - **Preferences**:
161
+ - **Communication Style**:
162
+ - **Current Projects**:
163
+ `,
164
+ },
165
+ }),
166
+ new MessageHistory({ storage, lastMessages: 50 }),
167
+ ],
168
+ outputProcessors: [
169
+ new MessageHistory({ storage }),
170
+ ],
171
+ });
172
+ ```
173
+
174
+ ## JSON format example
175
+
176
+ ```typescript copy
177
+ import { WorkingMemory } from "@mastra/core/processors";
178
+
179
+ const processor = new WorkingMemory({
180
+ storage: memoryStorage,
181
+ scope: "resource",
182
+ template: {
183
+ format: "json",
184
+ content: JSON.stringify({
185
+ user: {
186
+ name: { type: "string" },
187
+ preferences: { type: "object" },
188
+ goals: { type: "array" },
189
+ },
190
+ }),
191
+ },
192
+ });
193
+ ```
194
+
195
+ ## Behavior
196
+
197
+ ### Input processing
198
+ 1. Retrieves `threadId` and `resourceId` from the request context
199
+ 2. Based on scope, fetches working memory from either:
200
+ - Thread metadata (`scope: 'thread'`)
201
+ - Resource record (`scope: 'resource'`)
202
+ 3. Resolves the template (from provider, options, or default)
203
+ 4. Generates system instructions that include:
204
+ - Guidelines for the LLM on storing and updating information
205
+ - The template structure
206
+ - Current working memory data
207
+ 5. Adds the instruction as a system message with `source: 'memory'` tag
208
+
209
+ ### Working memory updates
210
+ Working memory updates happen through the `updateWorkingMemory` tool provided by the Memory class, not through this processor. The processor only handles injecting the current working memory state into conversations.
211
+
212
+ ### Default template
213
+ If no template is provided, the processor uses a default markdown template with fields for:
214
+ - First Name, Last Name
215
+ - Location, Occupation
216
+ - Interests, Goals
217
+ - Events, Facts, Projects
218
+
219
+ ## Related
220
+
221
+ - [Guardrails](/docs/v1/agents/guardrails)