@mastra/mcp-docs-server 1.2.7-alpha.1 → 1.2.7-alpha.12

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 (206) hide show
  1. package/.docs/docs/agent-builder/integrations.md +45 -3
  2. package/.docs/docs/agent-builder/overview.md +4 -3
  3. package/.docs/docs/agent-builder/skill-registries.md +1 -3
  4. package/.docs/docs/agent-controller/modes.md +1 -1
  5. package/.docs/docs/agent-controller/overview.md +4 -3
  6. package/.docs/docs/agent-controller/session.md +3 -5
  7. package/.docs/docs/agents/a2a.md +2 -1
  8. package/.docs/docs/agents/agent-approval.md +2 -2
  9. package/.docs/docs/agents/code-mode.md +1 -1
  10. package/.docs/docs/agents/guardrails.md +10 -9
  11. package/.docs/docs/agents/networks.md +1 -1
  12. package/.docs/docs/agents/overview.md +5 -5
  13. package/.docs/docs/agents/skills.md +3 -5
  14. package/.docs/docs/agents/structured-output.md +1 -1
  15. package/.docs/docs/agents/supervisor-agents.md +3 -4
  16. package/.docs/docs/agents/using-tools.md +2 -4
  17. package/.docs/docs/browser/agent-browser.md +1 -3
  18. package/.docs/docs/browser/browser-viewer.md +1 -3
  19. package/.docs/docs/browser/overview.md +2 -1
  20. package/.docs/docs/browser/recording.md +1 -1
  21. package/.docs/docs/browser/stagehand.md +1 -1
  22. package/.docs/docs/capabilities/channels/discord.md +98 -0
  23. package/.docs/docs/capabilities/channels/other-adapters.md +68 -0
  24. package/.docs/docs/capabilities/channels/overview.md +255 -0
  25. package/.docs/docs/capabilities/channels/slack.md +225 -0
  26. package/.docs/docs/capabilities/channels/teams.md +100 -0
  27. package/.docs/docs/capabilities/channels/telegram.md +98 -0
  28. package/.docs/docs/capabilities/channels/whatsapp.md +99 -0
  29. package/.docs/docs/deployment/mastra-server.md +2 -4
  30. package/.docs/docs/editor/overview.md +2 -6
  31. package/.docs/docs/editor/prompts.md +1 -1
  32. package/.docs/docs/editor/tools.md +3 -5
  33. package/.docs/docs/evals/built-in-scorers.md +2 -2
  34. package/.docs/docs/evals/custom-scorers.md +1 -3
  35. package/.docs/docs/evals/datasets/overview.md +4 -5
  36. package/.docs/docs/evals/datasets/running-experiments.md +10 -8
  37. package/.docs/docs/evals/evals-with-memory.md +1 -3
  38. package/.docs/docs/evals/gates-and-verdicts.md +2 -4
  39. package/.docs/docs/evals/overview.md +4 -1
  40. package/.docs/docs/evals/quick-checks.md +3 -5
  41. package/.docs/docs/getting-started/file-based-agents.md +116 -0
  42. package/.docs/docs/getting-started/manual-install.md +17 -4
  43. package/.docs/docs/index.md +1 -1
  44. package/.docs/docs/long-running-agents/background-tasks.md +3 -3
  45. package/.docs/docs/long-running-agents/durable-agents.md +5 -7
  46. package/.docs/docs/long-running-agents/goals.md +5 -7
  47. package/.docs/docs/long-running-agents/schedules.md +1 -1
  48. package/.docs/docs/long-running-agents/signal-providers.md +1 -3
  49. package/.docs/docs/long-running-agents/signals.md +12 -23
  50. package/.docs/docs/mastra-platform/database.md +2 -2
  51. package/.docs/docs/mastra-platform/github.md +1 -1
  52. package/.docs/docs/mastra-platform/observability.md +5 -1
  53. package/.docs/docs/mcp/mcp-apps.md +3 -3
  54. package/.docs/docs/mcp/overview.md +6 -10
  55. package/.docs/docs/memory/memory-processors.md +67 -0
  56. package/.docs/docs/memory/message-history.md +56 -2
  57. package/.docs/docs/memory/observational-memory.md +5 -4
  58. package/.docs/docs/memory/overview.md +8 -6
  59. package/.docs/docs/memory/semantic-recall.md +36 -2
  60. package/.docs/docs/memory/working-memory.md +3 -3
  61. package/.docs/docs/observability/integrations/exporters/mastra-platform.md +1 -3
  62. package/.docs/docs/observability/integrations/exporters/mastra-storage.md +1 -1
  63. package/.docs/docs/observability/logging.md +1 -1
  64. package/.docs/docs/observability/tracing/overview.md +1 -1
  65. package/.docs/docs/rag/vector-databases.md +7 -2
  66. package/.docs/docs/server/auth/auth0.md +1 -1
  67. package/.docs/docs/server/auth/better-auth.md +2 -2
  68. package/.docs/docs/server/auth/clerk.md +1 -1
  69. package/.docs/docs/server/auth/firebase.md +1 -1
  70. package/.docs/docs/server/auth/google.md +3 -3
  71. package/.docs/docs/server/auth/jwt.md +2 -2
  72. package/.docs/docs/server/auth/okta.md +2 -2
  73. package/.docs/docs/server/auth/workos.md +1 -1
  74. package/.docs/docs/server/mastra-client.md +1 -1
  75. package/.docs/docs/server/mastra-server.md +1 -1
  76. package/.docs/docs/server/pubsub.md +1 -1
  77. package/.docs/docs/server/request-context.md +4 -4
  78. package/.docs/docs/server/server-adapters.md +8 -8
  79. package/.docs/docs/storage/overview.md +214 -0
  80. package/.docs/docs/studio/auth.md +1 -3
  81. package/.docs/docs/studio/overview.md +1 -1
  82. package/.docs/docs/voice/livekit.md +101 -4
  83. package/.docs/docs/workflows/agents-and-tools.md +3 -5
  84. package/.docs/docs/workflows/control-flow.md +1 -3
  85. package/.docs/docs/workflows/overview.md +6 -7
  86. package/.docs/docs/workflows/snapshots.md +1 -1
  87. package/.docs/docs/workspace/overview.md +2 -1
  88. package/.docs/docs/workspace/sandbox.md +2 -0
  89. package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
  90. package/.docs/guides/build-your-ui/copilotkit/channels.md +1 -1
  91. package/.docs/guides/build-your-ui/copilotkit/generative-ui.md +2 -2
  92. package/.docs/guides/build-your-ui/copilotkit/overview.md +1 -1
  93. package/.docs/guides/concepts/streaming.md +3 -3
  94. package/.docs/guides/getting-started/quickstart.md +4 -2
  95. package/.docs/guides/guide/chef-michel.md +0 -2
  96. package/.docs/guides/guide/slack-assistant.md +2 -2
  97. package/.docs/guides/guide/stock-agent.md +0 -2
  98. package/.docs/models/embeddings.md +119 -0
  99. package/.docs/models/environment-variables.md +7 -0
  100. package/.docs/models/gateways/netlify.md +4 -1
  101. package/.docs/models/gateways/openrouter.md +10 -7
  102. package/.docs/models/gateways/vercel.md +8 -1
  103. package/.docs/models/index.md +1 -1
  104. package/.docs/models/providers/abacus.md +44 -14
  105. package/.docs/models/providers/crossmodel.md +109 -0
  106. package/.docs/models/providers/empiriolabs.md +106 -0
  107. package/.docs/models/providers/google.md +2 -1
  108. package/.docs/models/providers/llmgateway.md +185 -181
  109. package/.docs/models/providers/meta.md +101 -0
  110. package/.docs/models/providers/model-oracle-ai.md +87 -0
  111. package/.docs/models/providers/nano-gpt.md +2 -2
  112. package/.docs/models/providers/neon.md +40 -29
  113. package/.docs/models/providers/nvidia.md +1 -3
  114. package/.docs/models/providers/openai.md +6 -1
  115. package/.docs/models/providers/opencode.md +6 -2
  116. package/.docs/models/providers/pioneer.md +148 -0
  117. package/.docs/models/providers/poolside.md +6 -5
  118. package/.docs/models/providers/routing-run.md +23 -34
  119. package/.docs/models/providers/the-grid-ai.md +3 -3
  120. package/.docs/models/providers/unorouter.md +95 -0
  121. package/.docs/models/providers/wandb.md +21 -14
  122. package/.docs/models/providers/xai.md +2 -1
  123. package/.docs/models/providers/zenifra.md +73 -0
  124. package/.docs/models/providers.md +7 -0
  125. package/.docs/reference/agent-controller/agent-controller-class.md +3 -3
  126. package/.docs/reference/agent-controller/session.md +4 -4
  127. package/.docs/reference/agents/agent.md +1 -1
  128. package/.docs/reference/agents/channels.md +2 -2
  129. package/.docs/reference/agents/inngest-agent.md +1 -1
  130. package/.docs/reference/agents/listSkills.md +1 -1
  131. package/.docs/reference/agents/listSuspendedRuns.md +3 -3
  132. package/.docs/reference/auth/google.md +5 -5
  133. package/.docs/reference/channels/channel-provider.md +1 -1
  134. package/.docs/reference/channels/slack-provider.md +3 -3
  135. package/.docs/reference/cli/mastra.md +119 -12
  136. package/.docs/reference/code-sdk/mount-agent-controller.md +76 -0
  137. package/.docs/reference/coding-agent/create-coding-agent.md +1 -1
  138. package/.docs/reference/configuration.md +1 -1
  139. package/.docs/reference/evals/checks.md +4 -4
  140. package/.docs/reference/evals/create-scorer.md +8 -0
  141. package/.docs/reference/file-based-agents/config.md +97 -0
  142. package/.docs/reference/file-based-agents/instructions.md +54 -0
  143. package/.docs/reference/file-based-agents/logger.md +26 -0
  144. package/.docs/reference/file-based-agents/memory.md +58 -0
  145. package/.docs/reference/file-based-agents/observability.md +32 -0
  146. package/.docs/reference/file-based-agents/processors.md +56 -0
  147. package/.docs/reference/file-based-agents/scorers.md +54 -0
  148. package/.docs/reference/file-based-agents/server.md +37 -0
  149. package/.docs/reference/file-based-agents/skills.md +56 -0
  150. package/.docs/reference/file-based-agents/storage.md +30 -0
  151. package/.docs/reference/file-based-agents/studio.md +56 -0
  152. package/.docs/reference/file-based-agents/subagents.md +123 -0
  153. package/.docs/reference/file-based-agents/tools.md +63 -0
  154. package/.docs/reference/file-based-agents/workflows.md +52 -0
  155. package/.docs/reference/file-based-agents/workspace.md +74 -0
  156. package/.docs/reference/index.md +18 -0
  157. package/.docs/reference/memory/memory-class.md +1 -1
  158. package/.docs/reference/memory/observational-memory.md +1 -1
  159. package/.docs/reference/memory/serialized-memory-config.md +1 -1
  160. package/.docs/reference/memory/summarizeConversation.md +99 -0
  161. package/.docs/reference/memory/summarizeThread.md +93 -0
  162. package/.docs/{docs/getting-started → reference}/project-structure.md +3 -10
  163. package/.docs/reference/pubsub/lease-provider.md +5 -5
  164. package/.docs/reference/server/express-adapter.md +1 -3
  165. package/.docs/reference/server/fastify-adapter.md +1 -3
  166. package/.docs/reference/server/hono-adapter.md +1 -3
  167. package/.docs/reference/server/koa-adapter.md +1 -3
  168. package/.docs/reference/server/nestjs-adapter.md +1 -3
  169. package/.docs/reference/signals/task-signal-provider.md +1 -1
  170. package/.docs/reference/storage/clickhouse.md +34 -2
  171. package/.docs/reference/storage/cloudflare-d1.md +1 -1
  172. package/.docs/reference/storage/composite.md +64 -6
  173. package/.docs/reference/storage/convex.md +1 -1
  174. package/.docs/reference/storage/dynamodb.md +1 -1
  175. package/.docs/reference/storage/mongodb.md +46 -46
  176. package/.docs/reference/storage/retention.md +74 -6
  177. package/.docs/reference/tools/create-tool.md +2 -2
  178. package/.docs/reference/tools/mcp-client.md +22 -0
  179. package/.docs/reference/tools/mcp-server.md +161 -4
  180. package/.docs/reference/vectors/mongodb.md +93 -4
  181. package/.docs/reference/voice/livekit.md +272 -8
  182. package/.docs/reference/workspace/agentcore-runtime-sandbox.md +1 -3
  183. package/.docs/reference/workspace/agentfs-filesystem.md +1 -3
  184. package/.docs/reference/workspace/apple-container-sandbox.md +6 -8
  185. package/.docs/reference/workspace/archil-filesystem.md +1 -3
  186. package/.docs/reference/workspace/azure-blob-filesystem.md +1 -3
  187. package/.docs/reference/workspace/blaxel-sandbox.md +1 -3
  188. package/.docs/reference/workspace/daytona-sandbox.md +1 -3
  189. package/.docs/reference/workspace/docker-sandbox.md +1 -3
  190. package/.docs/reference/workspace/e2b-sandbox.md +1 -3
  191. package/.docs/reference/workspace/files-sdk-filesystem.md +1 -3
  192. package/.docs/reference/workspace/gcs-filesystem.md +1 -3
  193. package/.docs/reference/workspace/google-drive-filesystem.md +1 -3
  194. package/.docs/reference/workspace/local-filesystem.md +1 -3
  195. package/.docs/reference/workspace/local-sandbox.md +1 -3
  196. package/.docs/reference/workspace/mesa-filesystem.md +4 -4
  197. package/.docs/reference/workspace/modal-sandbox.md +1 -3
  198. package/.docs/reference/workspace/railway-sandbox.md +2 -4
  199. package/.docs/reference/workspace/s3-filesystem.md +1 -3
  200. package/.docs/reference/workspace/vercel-sandbox.md +5 -7
  201. package/.docs/reference/workspace/vercel-serverless.md +2 -4
  202. package/CHANGELOG.md +36 -0
  203. package/package.json +5 -5
  204. package/.docs/docs/agents/channels.md +0 -225
  205. package/.docs/docs/agents/file-based-agents.md +0 -297
  206. package/.docs/docs/memory/storage.md +0 -267
@@ -1,297 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # File-based agents
4
-
5
- **Added in:** `@mastra/core@1.48.0`
6
-
7
- > **Beta:** This feature is in beta. Breaking changes may occur without a major version bump until the API is stable.
8
-
9
- You can define an agent by file convention instead of constructing it in code. Mastra discovers a directory under `src/mastra/agents/<name>/`, assembles an [`Agent`](https://mastra.ai/reference/agents/agent), and registers it on your [`Mastra`](https://mastra.ai/reference/core/mastra-class) instance.
10
-
11
- ## When to use file-based agents
12
-
13
- Use file-based agents when you want one directory per agent, with configuration, instructions, tools, skills, workspace files, and subagents grouped together.
14
-
15
- Keep using [`new Agent()`](https://mastra.ai/reference/agents/agent) in code when you need dynamic configuration, programmatic registration, or a shared agent instance across modules. Both approaches can coexist: code-registered agents are always present, and the bundler adds file-based agents when you run through the Mastra CLI.
16
-
17
- ## Quickstart
18
-
19
- Create a directory for the agent and add a `config.ts`. Use `agentConfig` so the partial config is typed while sibling files supply the rest.
20
-
21
- ```typescript
22
- import { agentConfig } from '@mastra/core/agent'
23
-
24
- export default agentConfig({
25
- model: 'openai/gpt-5.5',
26
- // instructions omitted -> taken from instructions.md
27
- // tools omitted -> taken from tools/*.ts
28
- })
29
- ```
30
-
31
- Add the agent instructions:
32
-
33
- ```markdown
34
- You are a helpful weather assistant. Answer questions about current conditions and forecasts.
35
- ```
36
-
37
- Add a tool. The filename becomes the tool key, so this file is exposed as `get_weather`.
38
-
39
- ```typescript
40
- import { createTool } from '@mastra/core/tools'
41
- import { z } from 'zod'
42
-
43
- export default createTool({
44
- id: 'get_weather',
45
- description: 'Get the current weather for a city',
46
- inputSchema: z.object({ city: z.string() }),
47
- execute: async ({ context }) => ({ city: context.city, tempC: 21 }),
48
- })
49
- ```
50
-
51
- Your `src/mastra/index.ts` stays the same. The discovered agent is registered automatically when you run the app through `mastra dev` or `mastra build`.
52
-
53
- ```typescript
54
- import { Mastra } from '@mastra/core'
55
- import { Agent } from '@mastra/core/agent'
56
-
57
- const supportAgent = new Agent({
58
- id: 'support',
59
- name: 'support',
60
- instructions: 'You are a support agent.',
61
- model: 'openai/gpt-5.5',
62
- })
63
-
64
- // `support` is registered in code; `weather` is discovered from the filesystem.
65
- export const mastra = new Mastra({
66
- agents: { support: supportAgent },
67
- })
68
- ```
69
-
70
- Start the app through the Mastra CLI:
71
-
72
- **npm**:
73
-
74
- ```bash
75
- npx mastra dev
76
- ```
77
-
78
- **pnpm**:
79
-
80
- ```bash
81
- pnpm dlx mastra dev
82
- ```
83
-
84
- **Yarn**:
85
-
86
- ```bash
87
- yarn dlx mastra dev
88
- ```
89
-
90
- **Bun**:
91
-
92
- ```bash
93
- bun x mastra dev
94
- ```
95
-
96
- ## Folder structure
97
-
98
- The following table shows the supported file-based agent surface:
99
-
100
- | File / directory | Maps to |
101
- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
102
- | `agents/<name>/config.ts` | Default export merged into the agent config. `id` and `name` default to `<name>`. |
103
- | `agents/<name>/instructions.md` | The agent `instructions`. The file contents are inlined into generated code. |
104
- | `agents/<name>/tools/*.ts` | Each default-exported [`createTool()`](https://mastra.ai/reference/tools/create-tool). The tool key defaults to the filename. |
105
- | `agents/<name>/skills/*.ts` | Each default-exported [`createSkill()`](https://mastra.ai/reference/agents/createSkill), added to the agent `skills`. |
106
- | `agents/<name>/skills/<skill>/SKILL.md` | A packaged skill. Frontmatter supplies `name` and `description`, the body is the instructions, and files under `references/` are inlined. |
107
- | `agents/<name>/skills/<skill>.md` | A flat skill. The filename is the skill name and the body is the instructions. |
108
- | `agents/<name>/memory.ts` | Default export: a [`Memory`](https://mastra.ai/reference/memory/memory-class) instance used as the agent `memory`. |
109
- | `agents/<name>/workspace.ts` | Default export: a [`Workspace`](https://mastra.ai/reference/workspace/workspace-class) for the agent. |
110
- | `agents/<name>/workspace/` | Seed files mirrored into the agent's default workspace at build time. |
111
- | `agents/<name>/subagents/<childId>/` | A declared subagent with the same layout as an agent directory. Wired into the parent as a delegation tool named `<childId>`. |
112
-
113
- Test files named `*.test.ts`, `*.spec.ts`, `*.test.js`, and `*.spec.js` are ignored during tool and skill discovery.
114
-
115
- ## Add skills
116
-
117
- Add skills to a file-based agent by placing them under `agents/<name>/skills/`. Three layouts are supported, and they're inlined into the bundle at build time so the deployed agent doesn't read them from disk at runtime.
118
-
119
- - A `.ts` file can default-export `createSkill()`:
120
-
121
- ```typescript
122
- import { createSkill } from '@mastra/core/skills'
123
-
124
- export default createSkill({
125
- name: 'forecasting',
126
- description: 'Use when the user asks about multi-day forecasts.',
127
- instructions: 'Summarize the forecast day by day and call out precipitation.',
128
- })
129
- ```
130
-
131
- > **Note:** Visit [`createSkill()` reference](https://mastra.ai/reference/agents/createSkill) for the full API.
132
-
133
- - A packaged `SKILL.md` directory uses frontmatter for the name and description. Files under `references/` are inlined with the skill.
134
-
135
- ```markdown
136
- ---
137
- name: severe-weather
138
- description: Use when conditions include storms, flooding, or other hazards.
139
- ---
140
-
141
- Lead with the active alert, then give safety guidance.
142
- ```
143
-
144
- - A flat `<skill>.md` file uses the filename as the skill name:
145
-
146
- ```markdown
147
- Always report temperatures in both Celsius and Fahrenheit.
148
- ```
149
-
150
- Discovered skills merge with any `skills` in `config.ts`. On a name collision, `config.skills` wins and a warning is logged. If `config.skills` is a function, discovered skills are ignored with a warning because they can't be statically merged.
151
-
152
- ## Add memory
153
-
154
- Give a file-based agent [memory](https://mastra.ai/docs/memory/overview) by adding a `memory.ts` that default-exports a [`Memory`](https://mastra.ai/reference/memory/memory-class) instance:
155
-
156
- ```typescript
157
- import { Memory } from '@mastra/memory'
158
-
159
- export default new Memory()
160
- ```
161
-
162
- The exported instance becomes the agent's `memory`. You can also set `memory` directly in `config.ts`. `config.memory` wins over `memory.ts`, and a warning is logged when both are present. If neither is present, the agent has no memory, which is the default.
163
-
164
- ## Add a workspace
165
-
166
- When a file-based agent is discovered through `mastra dev` or `mastra build`, it gets a default workspace unless `config.workspace` or `workspace.ts` supplies one. The default workspace uses a contained filesystem and shell sandbox rooted at a per-agent `workspace/` directory in the bundle.
167
-
168
- To customize it, add a `workspace.ts` that default-exports a [`Workspace`](https://mastra.ai/reference/workspace/workspace-class):
169
-
170
- ```typescript
171
- import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
172
-
173
- export default new Workspace({
174
- name: 'weather-workspace',
175
- filesystem: new LocalFilesystem({ basePath: './data/weather' }),
176
- sandbox: new LocalSandbox({ workingDirectory: './data/weather' }),
177
- })
178
- ```
179
-
180
- You can also set `workspace` directly in `config.ts`. `config.workspace` wins over `workspace.ts`, and `workspace.ts` wins over the default workspace.
181
-
182
- ### Seed files
183
-
184
- Add a `workspace/` directory to ship files with the agent. Mastra mirrors every file under it into the agent's default workspace at build time, so the agent starts with those files on disk:
185
-
186
- ```text
187
- src/mastra/agents/weather/
188
- config.ts
189
- workspace/
190
- README.md
191
- data/cities.json
192
- ```
193
-
194
- Seed files are copied into the bundle next to the running server. Commit the starting files alongside the agent that uses them.
195
-
196
- ## Add subagents
197
-
198
- A file-based agent can declare **subagents**, specialist child agents it can delegate to. Add a `subagents/` directory under the agent, with one directory per subagent. Each subagent directory has the same layout as a top-level agent: `config.ts`, `instructions.md`, `tools/`, `skills/`, `memory.ts`, `workspace.ts`, and `workspace/`.
199
-
200
- ```text
201
- src/mastra/agents/
202
- supervisor/
203
- config.ts
204
- instructions.md
205
- subagents/
206
- researcher/
207
- config.ts
208
- instructions.md
209
- tools/
210
- search.ts
211
- ```
212
-
213
- Each subagent is assembled as its own agent and wired into the parent's `agents` map. The agent loop lowers it into a model-visible delegation tool. The tool name is the bare directory name, so the example above exposes `researcher` to the supervisor.
214
-
215
- A subagent's `config.ts` must set a non-empty `description`. The description is what the model sees when deciding whether to delegate, so the build fails if it's missing.
216
-
217
- ```typescript
218
- import { agentConfig } from '@mastra/core/agent'
219
-
220
- export default agentConfig({
221
- model: 'openai/gpt-5.5',
222
- description: 'Researches a topic and returns cited findings.',
223
- })
224
- ```
225
-
226
- Subagents are isolated. A subagent inherits nothing from its parent. Its tools, skills, and workspace come only from its own directory, and any absent slot falls back to the same framework defaults as a top-level agent.
227
-
228
- Subagents can declare their own `subagents/` directories, nesting up to three levels below the top-level agent. A `subagents/` directory deeper than that is ignored with a warning.
229
-
230
- ```text
231
- src/mastra/agents/
232
- supervisor/ # depth 0
233
- subagents/
234
- researcher/ # depth 1
235
- subagents/
236
- summarizer/ # depth 2
237
- ```
238
-
239
- Naming rules:
240
-
241
- - A subagent id that collides with one of the parent's tool keys is a build error.
242
- - A duplicate subagent id under the same parent is a build error.
243
- - If a subagent id also exists in the parent's `config.agents`, the `config.agents` entry wins and logs a warning.
244
- - If `config.agents` is a function, discovered subagents are ignored with a warning because they can't be statically merged.
245
-
246
- ## Precedence rules
247
-
248
- File-based and code-based agents coexist with deterministic rules:
249
-
250
- - **Code wins on name collisions:** If an agent name exists in both code and the filesystem, the code-registered agent is kept and a warning is logged.
251
- - **A folder can hold a code agent:** If `config.ts` exports a configured `new Agent({ id: 'file-based-agent', ... })`, that instance is used as-is. Sibling `instructions.md`, `tools/`, `skills/`, `memory.ts`, `workspace.ts`, and `subagents/` entries are ignored with warnings.
252
- - **Instructions:** Dynamic function instructions in `config.ts` win over `instructions.md`. Otherwise, `instructions.md` wins over a static `instructions` string. If neither is present, the build fails for that agent.
253
- - **Model:** A missing `model` fails the build and names the agent directory.
254
- - **Tools:** Tools from `tools/*.ts` merge with `config.tools`. On a key collision, `config.tools` wins and a warning is logged. If `config.tools` is a function, discovered tools are ignored with a warning.
255
- - **Skills:** Skills from `skills/` merge with `config.skills`. On a name collision, `config.skills` wins and a warning is logged. If `config.skills` is a function, discovered skills are ignored with a warning.
256
- - **Memory:** `config.memory` wins over `memory.ts`, and a warning is logged when both are present. If neither is set, the agent has no memory.
257
- - **Workspace:** `config.workspace` wins over `workspace.ts`, which wins over the default workspace.
258
- - **Subagents:** Subagents from `subagents/` merge with `config.agents`. On an id collision, `config.agents` wins and a warning is logged. A subagent id that collides with a tool key, or a duplicate subagent id, is a build error.
259
-
260
- ## What happens at build time
261
-
262
- File-based agents are discovered by the Mastra **bundler**, the step that runs under `mastra dev` and `mastra build`.
263
-
264
- File-based agents are registered only when your app runs through the Mastra CLI. If you import your `mastra` instance directly, `agents/<name>/` directories aren't discovered.
265
-
266
- When you consume Mastra as a library, register those agents in code instead of relying on file discovery:
267
-
268
- ```typescript
269
- import { Mastra } from '@mastra/core'
270
- import { Agent } from '@mastra/core/agent'
271
-
272
- const weather = new Agent({
273
- id: 'weather',
274
- name: 'weather',
275
- instructions: 'You are a helpful weather assistant.',
276
- model: 'openai/gpt-5.5',
277
- })
278
-
279
- export const mastra = new Mastra({
280
- agents: { weather },
281
- })
282
- ```
283
-
284
- ## Related
285
-
286
- - [Agents overview](https://mastra.ai/docs/agents/overview)
287
- - [Tools](https://mastra.ai/docs/agents/using-tools)
288
- - [Skills](https://mastra.ai/docs/agents/skills)
289
- - [Memory](https://mastra.ai/docs/memory/overview)
290
- - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
291
- - [Workspace](https://mastra.ai/docs/workspace/overview)
292
- - [Studio overview](https://mastra.ai/docs/studio/overview)
293
- - [`Agent` reference](https://mastra.ai/reference/agents/agent)
294
- - [`createTool()` reference](https://mastra.ai/reference/tools/create-tool)
295
- - [`createSkill()` reference](https://mastra.ai/reference/agents/createSkill)
296
- - [`Memory` reference](https://mastra.ai/reference/memory/memory-class)
297
- - [`Workspace` reference](https://mastra.ai/reference/workspace/workspace-class)
@@ -1,267 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Storage
4
-
5
- For agents to remember previous interactions, Mastra needs a storage adapter. Use one of the [supported providers](#supported-providers) and pass it to your Mastra instance.
6
-
7
- ```typescript
8
- import { Mastra } from '@mastra/core'
9
- import { LibSQLStore } from '@mastra/libsql'
10
-
11
- export const mastra = new Mastra({
12
- storage: new LibSQLStore({
13
- id: 'mastra-storage',
14
- url: 'file:./mastra.db',
15
- }),
16
- })
17
- ```
18
-
19
- > **Sharing the database with Studio:** When running `mastra dev` alongside your application (e.g., Next.js), use an absolute path to ensure both processes access the same database:
20
- >
21
- > ```typescript
22
- > url: 'file:/absolute/path/to/your/project/mastra.db'
23
- > ```
24
- >
25
- > Relative paths like `file:./mastra.db` resolve based on each process's working directory, which may differ.
26
-
27
- 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.
28
-
29
- Mastra automatically initializes the necessary storage structures on first interaction. See [Storage Overview](https://mastra.ai/reference/storage/overview) for domain coverage and the schema used by the built-in database-backed domains.
30
-
31
- ## Supported providers
32
-
33
- Each provider page includes installation instructions, configuration parameters, and usage examples:
34
-
35
- - [libSQL](https://mastra.ai/reference/storage/libsql)
36
- - [PostgreSQL](https://mastra.ai/reference/storage/postgresql)
37
- - [MongoDB](https://mastra.ai/reference/storage/mongodb)
38
- - [Upstash](https://mastra.ai/reference/storage/upstash)
39
- - [Redis](https://mastra.ai/reference/storage/redis)
40
- - [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
41
- - [Cloudflare KV & Durable Objects](https://mastra.ai/reference/storage/cloudflare)
42
- - [Convex](https://mastra.ai/reference/storage/convex)
43
- - [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
44
- - [LanceDB](https://mastra.ai/reference/storage/lance)
45
- - [Microsoft SQL Server](https://mastra.ai/reference/storage/mssql)
46
- - [Google Cloud Spanner](https://mastra.ai/reference/storage/spanner)
47
-
48
- > **Tip:** libSQL is the easiest way to get started because it doesn’t require running a separate database server.
49
-
50
- ## Configuration scope
51
-
52
- Storage can be configured at the instance level (shared by all agents) or at the agent level (isolated to a specific agent).
53
-
54
- ### Instance-level storage
55
-
56
- Add storage to your Mastra instance so all agents, workflows, observability traces, and scores share the same storage backend:
57
-
58
- ```typescript
59
- import { Mastra } from '@mastra/core'
60
- import { PostgresStore } from '@mastra/pg'
61
-
62
- export const mastra = new Mastra({
63
- storage: new PostgresStore({
64
- id: 'mastra-storage',
65
- connectionString: process.env.DATABASE_URL,
66
- }),
67
- })
68
-
69
- // Both agents inherit storage from the Mastra instance above
70
- const agent1 = new Agent({ id: 'agent-1', memory: new Memory() })
71
- const agent2 = new Agent({ id: 'agent-2', memory: new Memory() })
72
- ```
73
-
74
- This is useful when all primitives share the same storage backend and have similar performance, scaling, and operational requirements.
75
-
76
- #### Composite storage
77
-
78
- [Composite storage](https://mastra.ai/reference/storage/composite) is an alternative way to configure instance-level storage. Use `MastraCompositeStore` to route `memory` and any other [supported domains](https://mastra.ai/reference/storage/composite) to different storage providers.
79
-
80
- ```typescript
81
- import { Mastra } from '@mastra/core'
82
- import { MastraCompositeStore } from '@mastra/core/storage'
83
- import { MemoryLibSQL } from '@mastra/libsql'
84
- import { WorkflowsPG } from '@mastra/pg'
85
- import { ObservabilityStorageClickhouse } from '@mastra/clickhouse'
86
-
87
- export const mastra = new Mastra({
88
- storage: new MastraCompositeStore({
89
- id: 'composite',
90
- domains: {
91
- memory: new MemoryLibSQL({ url: 'file:./memory.db' }),
92
- workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
93
- observability: new ObservabilityStorageClickhouse({
94
- url: process.env.CLICKHOUSE_URL,
95
- username: process.env.CLICKHOUSE_USERNAME,
96
- password: process.env.CLICKHOUSE_PASSWORD,
97
- }),
98
- },
99
- }),
100
- })
101
- ```
102
-
103
- 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.
104
-
105
- #### Retention
106
-
107
- Storage grows without bound by default. To cap growth, declare per-table `maxAge` policies in the `retention` config and call `storage.prune()` from your own scheduler to delete old rows. Anything you don't configure is kept forever. See [Storage retention](https://mastra.ai/reference/storage/retention) for `prune()` and the full config shape.
108
-
109
- ### Agent-level storage
110
-
111
- Agent-level storage overrides storage configured at the instance level. Add storage to a specific agent when you need to keep data separate or use different providers per agent.
112
-
113
- ```typescript
114
- import { Agent } from '@mastra/core/agent'
115
- import { Memory } from '@mastra/memory'
116
- import { PostgresStore } from '@mastra/pg'
117
-
118
- export const agent = new Agent({
119
- id: 'agent',
120
- memory: new Memory({
121
- storage: new PostgresStore({
122
- id: 'agent-storage',
123
- connectionString: process.env.AGENT_DATABASE_URL,
124
- }),
125
- }),
126
- })
127
- ```
128
-
129
- ## Threads and resources
130
-
131
- Mastra organizes conversations using two identifiers:
132
-
133
- - **Thread**: A conversation session containing a sequence of messages.
134
- - **Resource**: The entity that owns the thread, such as a user, organization, project, or any other domain entity in your application.
135
-
136
- Both identifiers are required for agents to store information:
137
-
138
- **.generate()**:
139
-
140
- ```typescript
141
- const response = await agent.generate('hello', {
142
- memory: {
143
- thread: 'conversation-abc-123',
144
- resource: 'user_123',
145
- },
146
- })
147
- ```
148
-
149
- **.stream()**:
150
-
151
- ```typescript
152
- const stream = await agent.stream('hello', {
153
- memory: {
154
- thread: 'conversation-abc-123',
155
- resource: 'user_123',
156
- },
157
- })
158
- ```
159
-
160
- > **Note:** [Studio](https://mastra.ai/docs/studio/overview) automatically generates a thread and resource ID for you. When calling `stream()` or `generate()` yourself, remember to provide these identifiers explicitly.
161
-
162
- ### Thread title generation
163
-
164
- Mastra can automatically generate descriptive thread titles based on the user's first message when `generateTitle` is enabled.
165
-
166
- 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.
167
-
168
- ```typescript
169
- export const agent = new Agent({
170
- id: 'agent',
171
- memory: new Memory({
172
- options: {
173
- generateTitle: true,
174
- },
175
- }),
176
- })
177
- ```
178
-
179
- Title generation runs asynchronously after the agent responds and doesn't affect response time.
180
-
181
- To optimize cost or behavior, provide a smaller [`model`](https://mastra.ai/models) and custom `instructions`:
182
-
183
- ```typescript
184
- export const agent = new Agent({
185
- id: 'agent',
186
- memory: new Memory({
187
- options: {
188
- generateTitle: {
189
- model: 'openai/gpt-5-mini',
190
- instructions: 'Generate a 1 word title',
191
- },
192
- },
193
- }),
194
- })
195
- ```
196
-
197
- ## Semantic recall
198
-
199
- 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.
200
-
201
- ## Handling large attachments
202
-
203
- Some storage providers enforce record size limits that base64-encoded file attachments (such as images) can exceed:
204
-
205
- | Provider | Record size limit |
206
- | ------------------------------------------------------------------ | ----------------- |
207
- | [DynamoDB](https://mastra.ai/reference/storage/dynamodb) | 400 KB |
208
- | [Convex](https://mastra.ai/reference/storage/convex) | 1 MiB |
209
- | [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1) | 1 MiB |
210
-
211
- PostgreSQL, MongoDB, and libSQL have higher limits and are generally unaffected.
212
-
213
- 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.
214
-
215
- ```typescript
216
- import type { Processor } from '@mastra/core/processors'
217
- import type { MastraDBMessage } from '@mastra/core/memory'
218
-
219
- export class AttachmentUploader implements Processor {
220
- id = 'attachment-uploader'
221
-
222
- async processInput({ messages }: { messages: MastraDBMessage[] }) {
223
- return Promise.all(messages.map(msg => this.processMessage(msg)))
224
- }
225
-
226
- async processMessage(msg: MastraDBMessage) {
227
- const attachments = msg.content.experimental_attachments
228
- if (!attachments?.length) return msg
229
-
230
- const uploaded = await Promise.all(
231
- attachments.map(async att => {
232
- // Skip if already a URL
233
- if (!att.url?.startsWith('data:')) return att
234
-
235
- // Upload base64 data and replace with URL
236
- const url = await this.upload(att.url, att.contentType)
237
- return { ...att, url }
238
- }),
239
- )
240
-
241
- return { ...msg, content: { ...msg.content, experimental_attachments: uploaded } }
242
- }
243
-
244
- async upload(dataUri: string, contentType?: string): Promise<string> {
245
- const base64 = dataUri.split(',')[1]
246
- const buffer = Buffer.from(base64, 'base64')
247
-
248
- // Replace with your storage provider (S3, R2, GCS, Convex, etc.)
249
- // return await s3.upload(buffer, contentType);
250
- throw new Error('Implement upload() with your storage provider')
251
- }
252
- }
253
- ```
254
-
255
- Use the processor with your agent:
256
-
257
- ```typescript
258
- import { Agent } from '@mastra/core/agent'
259
- import { Memory } from '@mastra/memory'
260
- import { AttachmentUploader } from './processors/attachment-uploader'
261
-
262
- const agent = new Agent({
263
- id: 'my-agent',
264
- memory: new Memory({ storage: yourStorage }),
265
- inputProcessors: [new AttachmentUploader()],
266
- })
267
- ```