@mastra/mcp-docs-server 1.2.7-alpha.4 → 1.2.7-alpha.6
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/overview.md +4 -3
- package/.docs/docs/agent-controller/overview.md +2 -1
- package/.docs/docs/agents/a2a.md +2 -1
- package/.docs/docs/agents/guardrails.md +2 -1
- package/.docs/docs/agents/overview.md +2 -2
- package/.docs/docs/agents/skills.md +1 -1
- package/.docs/docs/agents/supervisor-agents.md +2 -1
- package/.docs/docs/browser/overview.md +2 -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 +257 -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/evals/datasets/overview.md +2 -1
- package/.docs/docs/evals/datasets/running-experiments.md +2 -0
- package/.docs/docs/evals/overview.md +4 -1
- package/.docs/docs/getting-started/file-based-agents.md +114 -0
- package/.docs/docs/long-running-agents/signals.md +4 -1
- package/.docs/docs/mastra-platform/observability.md +5 -1
- package/.docs/docs/memory/observational-memory.md +2 -1
- package/.docs/docs/memory/overview.md +2 -0
- package/.docs/docs/memory/semantic-recall.md +1 -1
- package/.docs/docs/memory/working-memory.md +3 -3
- package/.docs/docs/studio/overview.md +1 -1
- package/.docs/docs/workflows/control-flow.md +0 -2
- package/.docs/docs/workflows/overview.md +2 -3
- package/.docs/docs/workspace/overview.md +2 -1
- package/.docs/docs/workspace/sandbox.md +2 -0
- package/.docs/guides/getting-started/quickstart.md +3 -1
- 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/gateways/openrouter.md +1 -2
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/llmgateway.md +180 -181
- package/.docs/models/providers/neon.md +40 -29
- package/.docs/reference/agents/channels.md +2 -2
- package/.docs/reference/channels/channel-provider.md +1 -1
- package/.docs/reference/channels/slack-provider.md +2 -2
- package/.docs/reference/cli/mastra.md +1 -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/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/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 +13 -0
- package/.docs/reference/memory/memory-class.md +1 -1
- package/.docs/reference/memory/serialized-memory-config.md +1 -1
- package/.docs/reference/project-structure.md +1 -1
- package/.docs/reference/pubsub/lease-provider.md +1 -1
- package/.docs/reference/storage/clickhouse.md +32 -0
- package/.docs/reference/storage/composite.md +27 -1
- package/.docs/reference/storage/retention.md +11 -0
- package/CHANGELOG.md +7 -0
- package/package.json +4 -4
- package/.docs/docs/agents/channels.md +0 -225
- package/.docs/docs/agents/file-based-agents.md +0 -297
|
@@ -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's 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)
|