@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.
- package/.docs/docs/agent-builder/integrations.md +45 -3
- package/.docs/docs/agent-builder/overview.md +4 -3
- package/.docs/docs/agent-builder/skill-registries.md +1 -3
- package/.docs/docs/agent-controller/modes.md +1 -1
- package/.docs/docs/agent-controller/overview.md +4 -3
- package/.docs/docs/agent-controller/session.md +3 -5
- package/.docs/docs/agents/a2a.md +2 -1
- package/.docs/docs/agents/agent-approval.md +2 -2
- package/.docs/docs/agents/code-mode.md +1 -1
- package/.docs/docs/agents/guardrails.md +10 -9
- package/.docs/docs/agents/networks.md +1 -1
- package/.docs/docs/agents/overview.md +5 -5
- package/.docs/docs/agents/skills.md +3 -5
- package/.docs/docs/agents/structured-output.md +1 -1
- package/.docs/docs/agents/supervisor-agents.md +3 -4
- package/.docs/docs/agents/using-tools.md +2 -4
- package/.docs/docs/browser/agent-browser.md +1 -3
- package/.docs/docs/browser/browser-viewer.md +1 -3
- package/.docs/docs/browser/overview.md +2 -1
- package/.docs/docs/browser/recording.md +1 -1
- package/.docs/docs/browser/stagehand.md +1 -1
- package/.docs/docs/capabilities/channels/discord.md +98 -0
- package/.docs/docs/capabilities/channels/other-adapters.md +68 -0
- package/.docs/docs/capabilities/channels/overview.md +255 -0
- package/.docs/docs/capabilities/channels/slack.md +225 -0
- package/.docs/docs/capabilities/channels/teams.md +100 -0
- package/.docs/docs/capabilities/channels/telegram.md +98 -0
- package/.docs/docs/capabilities/channels/whatsapp.md +99 -0
- package/.docs/docs/deployment/mastra-server.md +2 -4
- package/.docs/docs/editor/overview.md +2 -6
- package/.docs/docs/editor/prompts.md +1 -1
- package/.docs/docs/editor/tools.md +3 -5
- package/.docs/docs/evals/built-in-scorers.md +2 -2
- package/.docs/docs/evals/custom-scorers.md +1 -3
- package/.docs/docs/evals/datasets/overview.md +4 -5
- package/.docs/docs/evals/datasets/running-experiments.md +10 -8
- package/.docs/docs/evals/evals-with-memory.md +1 -3
- package/.docs/docs/evals/gates-and-verdicts.md +2 -4
- package/.docs/docs/evals/overview.md +4 -1
- package/.docs/docs/evals/quick-checks.md +3 -5
- package/.docs/docs/getting-started/file-based-agents.md +116 -0
- package/.docs/docs/getting-started/manual-install.md +17 -4
- package/.docs/docs/index.md +1 -1
- package/.docs/docs/long-running-agents/background-tasks.md +3 -3
- package/.docs/docs/long-running-agents/durable-agents.md +5 -7
- package/.docs/docs/long-running-agents/goals.md +5 -7
- package/.docs/docs/long-running-agents/schedules.md +1 -1
- package/.docs/docs/long-running-agents/signal-providers.md +1 -3
- package/.docs/docs/long-running-agents/signals.md +12 -23
- package/.docs/docs/mastra-platform/database.md +2 -2
- package/.docs/docs/mastra-platform/github.md +1 -1
- package/.docs/docs/mastra-platform/observability.md +5 -1
- package/.docs/docs/mcp/mcp-apps.md +3 -3
- package/.docs/docs/mcp/overview.md +6 -10
- package/.docs/docs/memory/memory-processors.md +67 -0
- package/.docs/docs/memory/message-history.md +56 -2
- package/.docs/docs/memory/observational-memory.md +5 -4
- package/.docs/docs/memory/overview.md +8 -6
- package/.docs/docs/memory/semantic-recall.md +36 -2
- package/.docs/docs/memory/working-memory.md +3 -3
- package/.docs/docs/observability/integrations/exporters/mastra-platform.md +1 -3
- package/.docs/docs/observability/integrations/exporters/mastra-storage.md +1 -1
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/tracing/overview.md +1 -1
- package/.docs/docs/rag/vector-databases.md +7 -2
- package/.docs/docs/server/auth/auth0.md +1 -1
- package/.docs/docs/server/auth/better-auth.md +2 -2
- package/.docs/docs/server/auth/clerk.md +1 -1
- package/.docs/docs/server/auth/firebase.md +1 -1
- package/.docs/docs/server/auth/google.md +3 -3
- package/.docs/docs/server/auth/jwt.md +2 -2
- package/.docs/docs/server/auth/okta.md +2 -2
- package/.docs/docs/server/auth/workos.md +1 -1
- package/.docs/docs/server/mastra-client.md +1 -1
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/server/pubsub.md +1 -1
- package/.docs/docs/server/request-context.md +4 -4
- package/.docs/docs/server/server-adapters.md +8 -8
- package/.docs/docs/storage/overview.md +214 -0
- package/.docs/docs/studio/auth.md +1 -3
- package/.docs/docs/studio/overview.md +1 -1
- package/.docs/docs/voice/livekit.md +101 -4
- package/.docs/docs/workflows/agents-and-tools.md +3 -5
- package/.docs/docs/workflows/control-flow.md +1 -3
- package/.docs/docs/workflows/overview.md +6 -7
- package/.docs/docs/workflows/snapshots.md +1 -1
- package/.docs/docs/workspace/overview.md +2 -1
- package/.docs/docs/workspace/sandbox.md +2 -0
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/guides/build-your-ui/copilotkit/channels.md +1 -1
- package/.docs/guides/build-your-ui/copilotkit/generative-ui.md +2 -2
- package/.docs/guides/build-your-ui/copilotkit/overview.md +1 -1
- package/.docs/guides/concepts/streaming.md +3 -3
- package/.docs/guides/getting-started/quickstart.md +4 -2
- package/.docs/guides/guide/chef-michel.md +0 -2
- package/.docs/guides/guide/slack-assistant.md +2 -2
- package/.docs/guides/guide/stock-agent.md +0 -2
- package/.docs/models/embeddings.md +119 -0
- package/.docs/models/environment-variables.md +7 -0
- package/.docs/models/gateways/netlify.md +4 -1
- package/.docs/models/gateways/openrouter.md +10 -7
- package/.docs/models/gateways/vercel.md +8 -1
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/abacus.md +44 -14
- package/.docs/models/providers/crossmodel.md +109 -0
- package/.docs/models/providers/empiriolabs.md +106 -0
- package/.docs/models/providers/google.md +2 -1
- package/.docs/models/providers/llmgateway.md +185 -181
- package/.docs/models/providers/meta.md +101 -0
- package/.docs/models/providers/model-oracle-ai.md +87 -0
- package/.docs/models/providers/nano-gpt.md +2 -2
- package/.docs/models/providers/neon.md +40 -29
- package/.docs/models/providers/nvidia.md +1 -3
- package/.docs/models/providers/openai.md +6 -1
- package/.docs/models/providers/opencode.md +6 -2
- package/.docs/models/providers/pioneer.md +148 -0
- package/.docs/models/providers/poolside.md +6 -5
- package/.docs/models/providers/routing-run.md +23 -34
- package/.docs/models/providers/the-grid-ai.md +3 -3
- package/.docs/models/providers/unorouter.md +95 -0
- package/.docs/models/providers/wandb.md +21 -14
- package/.docs/models/providers/xai.md +2 -1
- package/.docs/models/providers/zenifra.md +73 -0
- package/.docs/models/providers.md +7 -0
- package/.docs/reference/agent-controller/agent-controller-class.md +3 -3
- package/.docs/reference/agent-controller/session.md +4 -4
- package/.docs/reference/agents/agent.md +1 -1
- package/.docs/reference/agents/channels.md +2 -2
- package/.docs/reference/agents/inngest-agent.md +1 -1
- package/.docs/reference/agents/listSkills.md +1 -1
- package/.docs/reference/agents/listSuspendedRuns.md +3 -3
- package/.docs/reference/auth/google.md +5 -5
- package/.docs/reference/channels/channel-provider.md +1 -1
- package/.docs/reference/channels/slack-provider.md +3 -3
- package/.docs/reference/cli/mastra.md +119 -12
- package/.docs/reference/code-sdk/mount-agent-controller.md +76 -0
- package/.docs/reference/coding-agent/create-coding-agent.md +1 -1
- package/.docs/reference/configuration.md +1 -1
- package/.docs/reference/evals/checks.md +4 -4
- package/.docs/reference/evals/create-scorer.md +8 -0
- package/.docs/reference/file-based-agents/config.md +97 -0
- package/.docs/reference/file-based-agents/instructions.md +54 -0
- package/.docs/reference/file-based-agents/logger.md +26 -0
- package/.docs/reference/file-based-agents/memory.md +58 -0
- package/.docs/reference/file-based-agents/observability.md +32 -0
- package/.docs/reference/file-based-agents/processors.md +56 -0
- package/.docs/reference/file-based-agents/scorers.md +54 -0
- package/.docs/reference/file-based-agents/server.md +37 -0
- package/.docs/reference/file-based-agents/skills.md +56 -0
- package/.docs/reference/file-based-agents/storage.md +30 -0
- package/.docs/reference/file-based-agents/studio.md +56 -0
- package/.docs/reference/file-based-agents/subagents.md +123 -0
- package/.docs/reference/file-based-agents/tools.md +63 -0
- package/.docs/reference/file-based-agents/workflows.md +52 -0
- package/.docs/reference/file-based-agents/workspace.md +74 -0
- package/.docs/reference/index.md +18 -0
- package/.docs/reference/memory/memory-class.md +1 -1
- package/.docs/reference/memory/observational-memory.md +1 -1
- package/.docs/reference/memory/serialized-memory-config.md +1 -1
- package/.docs/reference/memory/summarizeConversation.md +99 -0
- package/.docs/reference/memory/summarizeThread.md +93 -0
- package/.docs/{docs/getting-started → reference}/project-structure.md +3 -10
- package/.docs/reference/pubsub/lease-provider.md +5 -5
- package/.docs/reference/server/express-adapter.md +1 -3
- package/.docs/reference/server/fastify-adapter.md +1 -3
- package/.docs/reference/server/hono-adapter.md +1 -3
- package/.docs/reference/server/koa-adapter.md +1 -3
- package/.docs/reference/server/nestjs-adapter.md +1 -3
- package/.docs/reference/signals/task-signal-provider.md +1 -1
- package/.docs/reference/storage/clickhouse.md +34 -2
- package/.docs/reference/storage/cloudflare-d1.md +1 -1
- package/.docs/reference/storage/composite.md +64 -6
- package/.docs/reference/storage/convex.md +1 -1
- package/.docs/reference/storage/dynamodb.md +1 -1
- package/.docs/reference/storage/mongodb.md +46 -46
- package/.docs/reference/storage/retention.md +74 -6
- package/.docs/reference/tools/create-tool.md +2 -2
- package/.docs/reference/tools/mcp-client.md +22 -0
- package/.docs/reference/tools/mcp-server.md +161 -4
- package/.docs/reference/vectors/mongodb.md +93 -4
- package/.docs/reference/voice/livekit.md +272 -8
- package/.docs/reference/workspace/agentcore-runtime-sandbox.md +1 -3
- package/.docs/reference/workspace/agentfs-filesystem.md +1 -3
- package/.docs/reference/workspace/apple-container-sandbox.md +6 -8
- package/.docs/reference/workspace/archil-filesystem.md +1 -3
- package/.docs/reference/workspace/azure-blob-filesystem.md +1 -3
- package/.docs/reference/workspace/blaxel-sandbox.md +1 -3
- package/.docs/reference/workspace/daytona-sandbox.md +1 -3
- package/.docs/reference/workspace/docker-sandbox.md +1 -3
- package/.docs/reference/workspace/e2b-sandbox.md +1 -3
- package/.docs/reference/workspace/files-sdk-filesystem.md +1 -3
- package/.docs/reference/workspace/gcs-filesystem.md +1 -3
- package/.docs/reference/workspace/google-drive-filesystem.md +1 -3
- package/.docs/reference/workspace/local-filesystem.md +1 -3
- package/.docs/reference/workspace/local-sandbox.md +1 -3
- package/.docs/reference/workspace/mesa-filesystem.md +4 -4
- package/.docs/reference/workspace/modal-sandbox.md +1 -3
- package/.docs/reference/workspace/railway-sandbox.md +2 -4
- package/.docs/reference/workspace/s3-filesystem.md +1 -3
- package/.docs/reference/workspace/vercel-sandbox.md +5 -7
- package/.docs/reference/workspace/vercel-serverless.md +2 -4
- package/CHANGELOG.md +36 -0
- package/package.json +5 -5
- package/.docs/docs/agents/channels.md +0 -225
- package/.docs/docs/agents/file-based-agents.md +0 -297
- 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
|
-
```
|