@mastra/mcp-docs-server 1.2.14 → 1.2.15-alpha.10
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/agents/a2a.md +75 -2
- package/.docs/docs/agents/processors.md +2 -0
- package/.docs/docs/agents/skills.md +15 -1
- package/.docs/docs/capabilities/channels/overview.md +19 -0
- package/.docs/docs/capabilities/subagents.md +23 -5
- package/.docs/docs/connections/overview.md +94 -0
- package/.docs/docs/datasets/running-experiments.md +18 -0
- package/.docs/docs/evals/overview.md +16 -4
- package/.docs/docs/harness/agent-controller.md +6 -0
- package/.docs/docs/harness/overview.md +26 -0
- package/.docs/docs/index.md +1 -1
- package/.docs/docs/mcp/overview.md +10 -0
- package/.docs/docs/memory/multi-user-threads.md +1 -1
- package/.docs/docs/memory/observational-memory.md +1 -1
- package/.docs/docs/memory/semantic-recall.md +2 -1
- package/.docs/docs/memory/working-memory.md +1 -0
- package/.docs/docs/observability/feedback.md +16 -0
- package/.docs/docs/observability/integrations/exporters/mastra-storage.md +1 -0
- package/.docs/docs/server/auth.md +2 -0
- package/.docs/docs/server/mastra-client.md +11 -11
- package/.docs/docs/storage/overview.md +1 -0
- package/.docs/docs/workflows/agents-and-tools.md +2 -2
- package/.docs/docs/workflows/{stored-workflows.md → dynamic-workflows.md} +23 -23
- package/.docs/docs/workflows/snapshots.md +3 -1
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +25 -14
- package/.docs/guides/getting-started/quickstart.md +1 -1
- package/.docs/guides/rag/overview.md +1 -1
- package/.docs/guides/rag/retrieval.md +17 -0
- package/.docs/guides/rag/vector-databases.md +41 -0
- package/.docs/guides/voice/realtime-voice.md +28 -2
- package/.docs/models/gateways/neon.md +20 -14
- package/.docs/models/gateways/netlify.md +1 -2
- package/.docs/models/gateways/openrouter.md +4 -2
- package/.docs/models/gateways/vercel.md +10 -3
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/anthropic.md +2 -2
- package/.docs/models/providers/cortecs.md +2 -1
- package/.docs/models/providers/deepinfra.md +6 -3
- package/.docs/models/providers/digitalocean.md +6 -5
- package/.docs/models/providers/empiriolabs.md +6 -4
- package/.docs/models/providers/friendli.md +8 -9
- package/.docs/models/providers/huggingface.md +4 -1
- package/.docs/models/providers/hyper.md +5 -6
- package/.docs/models/providers/kilo.md +11 -9
- package/.docs/models/providers/llmgateway.md +3 -3
- package/.docs/models/providers/meta.md +7 -5
- package/.docs/models/providers/minimax.md +25 -23
- package/.docs/models/providers/nano-gpt.md +7 -4
- package/.docs/models/providers/neuralwatt.md +2 -1
- package/.docs/models/providers/ofox.md +74 -16
- package/.docs/models/providers/openai.md +28 -26
- package/.docs/models/providers/opencode-go.md +1 -1
- package/.docs/models/providers/opencode.md +2 -3
- package/.docs/models/providers/perplexity-agent.md +24 -24
- package/.docs/models/providers/pioneer.md +27 -1
- package/.docs/models/providers/regolo-ai.md +25 -20
- package/.docs/models/providers/upstage.md +3 -2
- package/.docs/models/providers/vivgrid.md +4 -2
- package/.docs/models/providers/wandb.md +1 -1
- package/.docs/reference/agents/channels.md +22 -1
- package/.docs/reference/agents/generate.md +1 -1
- package/.docs/reference/ai-sdk/chat-route.md +2 -0
- package/.docs/reference/browser/agent-browser.md +1 -1
- package/.docs/reference/browser/mastra-browser.md +1 -1
- package/.docs/reference/browser/stagehand-browser.md +1 -1
- package/.docs/reference/channels/slack-provider.md +2 -0
- package/.docs/reference/client-js/observability.md +22 -0
- package/.docs/reference/client-js/workflows.md +32 -19
- package/.docs/reference/configuration.md +26 -1
- package/.docs/reference/core/{addStoredWorkflow.md → addDynamicWorkflow.md} +10 -10
- package/.docs/reference/core/{addStoredWorkflows.md → addDynamicWorkflows.md} +9 -9
- package/.docs/reference/editor/tool-provider.md +26 -1
- package/.docs/reference/file-based-agents/config.md +22 -21
- package/.docs/reference/file-based-agents/instructions.md +42 -17
- package/.docs/reference/file-based-agents/schedules.md +232 -0
- package/.docs/reference/index.md +7 -3
- package/.docs/reference/observability/metrics/automatic-metrics.md +10 -8
- package/.docs/reference/rag/metadata-filters.md +13 -4
- package/.docs/reference/server/register-api-route.md +2 -0
- package/.docs/reference/server/routes.md +38 -24
- package/.docs/reference/storage/composite.md +58 -0
- package/.docs/reference/storage/oracledb.md +239 -0
- package/.docs/reference/storage/overview.md +9 -9
- package/.docs/reference/storage/retention.md +1 -1
- package/.docs/reference/streaming/agents/stream.md +1 -1
- package/.docs/reference/tools/bedrock-kb-tool.md +117 -0
- package/.docs/reference/tools/mcp-client.md +54 -0
- package/.docs/reference/vectors/oracledb.md +347 -0
- package/.docs/reference/voice/google.md +19 -3
- package/.docs/reference/workflows/{stored-workflow-definition.md → dynamic-workflow-definition.md} +7 -7
- package/.docs/reference/workflows/step.md +40 -0
- package/.docs/reference/workflows/workflow-methods/agent.md +3 -3
- package/.docs/reference/workflows/workflow-methods/tool.md +3 -3
- package/.docs/reference/workspace/daytona-sandbox.md +21 -0
- package/.docs/reference/workspace/workspace-class.md +2 -0
- package/CHANGELOG.md +51 -0
- package/package.json +6 -6
|
@@ -12,6 +12,19 @@ Retrieve a list of all available workflows:
|
|
|
12
12
|
const workflows = await mastraClient.listWorkflows()
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Getting workflow run counts
|
|
16
|
+
|
|
17
|
+
Retrieve per-workflow counts of `running` and [`suspended`](https://mastra.ai/docs/workflows/suspend-and-resume) runs in a single request. The counts are computed on the server and keyed by the workflow's registry key — the key used when registering the workflow in the Mastra config, which can differ from the workflow's own `id`:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const runCounts = await mastraClient.listWorkflowRunCounts()
|
|
21
|
+
// { "cityWorkflow": { running: 2, suspended: 1 }, ... }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Returns: `Record<string, { running: number; suspended: number }>`
|
|
25
|
+
|
|
26
|
+
The server may cache the counts for a few seconds between requests. Servers that predate this endpoint respond with `404 Not Found` — handle the error when the client can talk to older deployments.
|
|
27
|
+
|
|
15
28
|
## Working with a specific workflow
|
|
16
29
|
|
|
17
30
|
Get an instance of a specific workflow by its ID:
|
|
@@ -212,28 +225,28 @@ A workflow run result yields the following:
|
|
|
212
225
|
|
|
213
226
|
**payload** (`object`): Contains currentStep (id, status, output, payload) and workflowState (status, steps record)
|
|
214
227
|
|
|
215
|
-
##
|
|
228
|
+
## Dynamic workflows
|
|
216
229
|
|
|
217
|
-
> **Beta:**
|
|
230
|
+
> **Beta:** Dynamic workflows are in beta. Breaking changes may occur without a major version bump until the API is stable.
|
|
218
231
|
|
|
219
|
-
|
|
232
|
+
Dynamic workflows are workflow definitions expressed as JSON. The server persists each definition and registers it as a runnable workflow. See [Dynamic workflows](https://mastra.ai/docs/workflows/dynamic-workflows) for the definition format.
|
|
220
233
|
|
|
221
|
-
### `
|
|
234
|
+
### `listDynamicWorkflows()`
|
|
222
235
|
|
|
223
|
-
List
|
|
236
|
+
List dynamic workflow definitions, optionally filtered by `status` (`'active' | 'archived'`) and `authorId`:
|
|
224
237
|
|
|
225
238
|
```typescript
|
|
226
|
-
const { definitions, total } = await mastraClient.
|
|
239
|
+
const { definitions, total } = await mastraClient.listDynamicWorkflows({
|
|
227
240
|
status: 'active',
|
|
228
241
|
})
|
|
229
242
|
```
|
|
230
243
|
|
|
231
|
-
### `
|
|
244
|
+
### `upsertDynamicWorkflow()`
|
|
232
245
|
|
|
233
|
-
Create or replace a
|
|
246
|
+
Create or replace a dynamic workflow definition. The server validates the definition, persists it, and live-registers it for execution:
|
|
234
247
|
|
|
235
248
|
```typescript
|
|
236
|
-
const stored = await mastraClient.
|
|
249
|
+
const stored = await mastraClient.upsertDynamicWorkflow({
|
|
237
250
|
id: 'greeting-workflow',
|
|
238
251
|
description: 'Returns a greeting for the supplied name',
|
|
239
252
|
inputSchema: {
|
|
@@ -261,7 +274,7 @@ const stored = await mastraClient.upsertStoredWorkflow({
|
|
|
261
274
|
When the root definition nests helper workflows that don't exist yet, pass them in the same request through `dependencies`. The server validates and registers the bundle as a unit and echoes the helper ids back as `dependencyIds`:
|
|
262
275
|
|
|
263
276
|
```typescript
|
|
264
|
-
const stored = await mastraClient.
|
|
277
|
+
const stored = await mastraClient.upsertDynamicWorkflow({
|
|
265
278
|
id: 'root-workflow',
|
|
266
279
|
// ...schemas and graph referencing 'helper-workflow'...
|
|
267
280
|
dependencies: [helperDefinition],
|
|
@@ -270,33 +283,33 @@ const stored = await mastraClient.upsertStoredWorkflow({
|
|
|
270
283
|
console.log(stored.dependencyIds) // ['helper-workflow']
|
|
271
284
|
```
|
|
272
285
|
|
|
273
|
-
### `
|
|
286
|
+
### `getDynamicWorkflow()`
|
|
274
287
|
|
|
275
|
-
Get a
|
|
288
|
+
Get a dynamic workflow instance for definition management. To execute a dynamic workflow, use `getWorkflow(id).createRun()` like any other workflow:
|
|
276
289
|
|
|
277
290
|
```typescript
|
|
278
|
-
const
|
|
291
|
+
const dynamicWorkflow = mastraClient.getDynamicWorkflow('greeting-workflow')
|
|
279
292
|
```
|
|
280
293
|
|
|
281
|
-
### `
|
|
294
|
+
### `dynamicWorkflow.details()`
|
|
282
295
|
|
|
283
296
|
Retrieve the persisted definition, including schemas, graph, status, and timestamps:
|
|
284
297
|
|
|
285
298
|
```typescript
|
|
286
|
-
const definition = await
|
|
299
|
+
const definition = await dynamicWorkflow.details()
|
|
287
300
|
```
|
|
288
301
|
|
|
289
|
-
### `
|
|
302
|
+
### `dynamicWorkflow.delete()`
|
|
290
303
|
|
|
291
304
|
Delete the stored definition and unregister the live workflow:
|
|
292
305
|
|
|
293
306
|
```typescript
|
|
294
|
-
await
|
|
307
|
+
await dynamicWorkflow.delete()
|
|
295
308
|
```
|
|
296
309
|
|
|
297
|
-
### Executing a
|
|
310
|
+
### Executing a dynamic workflow
|
|
298
311
|
|
|
299
|
-
Once registered, a
|
|
312
|
+
Once registered, a dynamic workflow runs through the ordinary workflow API:
|
|
300
313
|
|
|
301
314
|
```typescript
|
|
302
315
|
const workflow = mastraClient.getWorkflow('greeting-workflow')
|
|
@@ -438,7 +438,7 @@ export const mastra = new Mastra({
|
|
|
438
438
|
|
|
439
439
|
**Type:** `Record<string, MastraVector>`
|
|
440
440
|
|
|
441
|
-
Vector stores for semantic search and embeddings. Used in RAG pipelines, similarity search, and other embedding-based features. Mastra supports multiple vector databases including Pinecone, PostgreSQL with pgvector, MongoDB, and more.
|
|
441
|
+
Vector stores for semantic search and embeddings. Used in RAG pipelines, similarity search, and other embedding-based features. Mastra supports multiple vector databases including Pinecone, PostgreSQL with pgvector, OracleDB, MongoDB, and more.
|
|
442
442
|
|
|
443
443
|
Visit the [RAG documentation](https://mastra.ai/guides/rag/overview) to learn more.
|
|
444
444
|
|
|
@@ -500,6 +500,31 @@ const mastra = new Mastra({
|
|
|
500
500
|
|
|
501
501
|
## Bundler options
|
|
502
502
|
|
|
503
|
+
### bundler.entries
|
|
504
|
+
|
|
505
|
+
**Type:** `Record<string, string>`\
|
|
506
|
+
**Default:** `{}`
|
|
507
|
+
|
|
508
|
+
Additional process entries to emit alongside the server bundle, as a map of output name to source path relative to your Mastra directory. Each entry becomes its own `<name>.mjs` in `.mastra/output`.
|
|
509
|
+
|
|
510
|
+
Use this for long-running processes that run beside your Mastra server rather than inside it, such as a [LiveKit voice worker](https://mastra.ai/guides/voice/realtime-voice). The entry shares the output directory, `package.json`, and installed dependencies with the server, so one `mastra build` produces one deployable artifact you can start with different commands.
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
import { Mastra } from '@mastra/core'
|
|
514
|
+
|
|
515
|
+
export const mastra = new Mastra({
|
|
516
|
+
bundler: {
|
|
517
|
+
entries: { 'voice-worker': './voice-worker.ts' },
|
|
518
|
+
},
|
|
519
|
+
})
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
This emits `.mastra/output/voice-worker.mjs` next to `.mastra/output/index.mjs`. Dependencies imported only by the extra entry are analyzed too, so they're installed into the output.
|
|
523
|
+
|
|
524
|
+
Entry names can contain `/` to nest the output. They can't be `index`, which is the server bundle, `tools`, which is the tool aggregator, or start with `tools/`, which is reserved for tool bundles.
|
|
525
|
+
|
|
526
|
+
> **Note:** `mastra build` applies the [`bundler.externals`](#bundlerexternals) default of `true` only when you set no bundler options at all. Once you set `entries`, set `externals` explicitly as well if your extra entry depends on packages that can't be bundled, such as native modules.
|
|
527
|
+
|
|
503
528
|
### bundler.externals
|
|
504
529
|
|
|
505
530
|
**Type:** `boolean | string[]`\
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
2
|
|
|
3
|
-
# Mastra.
|
|
3
|
+
# Mastra.addDynamicWorkflow()
|
|
4
4
|
|
|
5
|
-
> **Beta:**
|
|
5
|
+
> **Beta:** Dynamic workflows are in beta. Breaking changes may occur without a major version bump until the API is stable.
|
|
6
6
|
|
|
7
|
-
The `.
|
|
7
|
+
The `.addDynamicWorkflow()` method validates a dynamic workflow definition and registers it as a live workflow on the instance, persisting it through the `workflowDefinitions` storage domain. Once registered, the workflow runs like any other workflow via [`getWorkflow()`](https://mastra.ai/reference/core/getWorkflow).
|
|
8
8
|
|
|
9
|
-
See [
|
|
9
|
+
See [Dynamic workflows](https://mastra.ai/docs/workflows/dynamic-workflows) for a complete setup example and the [dynamic workflow definition reference](https://mastra.ai/reference/workflows/dynamic-workflow-definition) for the accepted fields and graph entries.
|
|
10
10
|
|
|
11
11
|
## Usage example
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
await mastra.
|
|
14
|
+
await mastra.addDynamicWorkflow({
|
|
15
15
|
id: 'greeting-workflow',
|
|
16
16
|
description: 'Returns a greeting for the supplied name',
|
|
17
17
|
inputSchema: {
|
|
@@ -41,7 +41,7 @@ const result = await run.start({ inputData: { name: 'Ada' } })
|
|
|
41
41
|
|
|
42
42
|
## Parameters
|
|
43
43
|
|
|
44
|
-
**def** (`
|
|
44
|
+
**def** (`DynamicWorkflowGraph`): The workflow definition: id, optional description and metadata, JSON Schema input/output schemas, optional state and request-context schemas, and the step graph.
|
|
45
45
|
|
|
46
46
|
## Returns
|
|
47
47
|
|
|
@@ -52,11 +52,11 @@ A promise that resolves once the definition is validated, registered, and persis
|
|
|
52
52
|
- The definition is fully validated (structure, references, schema flow) before anything is mutated. Agents, tools, and workflows referenced by the graph must already be registered on the instance.
|
|
53
53
|
- Adding a definition with an existing ID replaces both the stored definition and the live registration. In-flight runs keep the graph they started with.
|
|
54
54
|
- Without a storage adapter that supports the `workflowDefinitions` domain, the workflow is still validated and registered in memory, but the definition is lost on restart.
|
|
55
|
-
- To add a root workflow together with helper workflows it nests, use [`
|
|
55
|
+
- To add a root workflow together with helper workflows it nests, use [`addDynamicWorkflows()`](https://mastra.ai/reference/core/addDynamicWorkflows).
|
|
56
56
|
|
|
57
57
|
## Related
|
|
58
58
|
|
|
59
|
-
- [Mastra.
|
|
59
|
+
- [Mastra.addDynamicWorkflows()](https://mastra.ai/reference/core/addDynamicWorkflows): Add a dependency-ordered bundle of definitions
|
|
60
60
|
- [Mastra.getWorkflow()](https://mastra.ai/reference/core/getWorkflow): Retrieve a registered workflow
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
61
|
+
- [Dynamic workflows](https://mastra.ai/docs/workflows/dynamic-workflows): Set up and use dynamic workflows
|
|
62
|
+
- [Dynamic workflow definition](https://mastra.ai/reference/workflows/dynamic-workflow-definition): Definition fields and graph entries
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
2
|
|
|
3
|
-
# Mastra.
|
|
3
|
+
# Mastra.addDynamicWorkflows()
|
|
4
4
|
|
|
5
|
-
> **Beta:**
|
|
5
|
+
> **Beta:** Dynamic workflows are in beta. Breaking changes may occur without a major version bump until the API is stable.
|
|
6
6
|
|
|
7
|
-
The `.
|
|
7
|
+
The `.addDynamicWorkflows()` method adds a bundle of dynamic workflow definitions that may reference each other. The typical case is a root workflow plus helper workflows it nests, where none of the definitions exist yet.
|
|
8
8
|
|
|
9
9
|
The whole bundle is validated up front. Members are then registered in dependency order, so a helper is always in place before the workflow that nests it.
|
|
10
10
|
|
|
11
|
-
[`
|
|
11
|
+
[`addDynamicWorkflow()`](https://mastra.ai/reference/core/addDynamicWorkflow) is the single-member case.
|
|
12
12
|
|
|
13
13
|
## Usage example
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
await mastra.
|
|
16
|
+
await mastra.addDynamicWorkflows([
|
|
17
17
|
helperDefinition, // nested by the root — order in the array doesn't matter
|
|
18
18
|
rootDefinition, // graph contains { type: 'workflow', workflowId: helperDefinition.id }
|
|
19
19
|
])
|
|
@@ -21,7 +21,7 @@ await mastra.addStoredWorkflows([
|
|
|
21
21
|
|
|
22
22
|
## Parameters
|
|
23
23
|
|
|
24
|
-
**defs** (`readonly
|
|
24
|
+
**defs** (`readonly DynamicWorkflowGraph[]`): The workflow definitions to add. Nested-workflow references may resolve against the live registries or against other members of the same bundle.
|
|
25
25
|
|
|
26
26
|
## Returns
|
|
27
27
|
|
|
@@ -35,6 +35,6 @@ A promise that resolves once every member is validated, registered, and persiste
|
|
|
35
35
|
|
|
36
36
|
## Related
|
|
37
37
|
|
|
38
|
-
- [Mastra.
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
38
|
+
- [Mastra.addDynamicWorkflow()](https://mastra.ai/reference/core/addDynamicWorkflow): Add a single definition
|
|
39
|
+
- [Dynamic workflows](https://mastra.ai/docs/workflows/dynamic-workflows): Set up and use dynamic workflows
|
|
40
|
+
- [Dynamic workflow definition](https://mastra.ai/reference/workflows/dynamic-workflow-definition): Definition fields and graph entries
|
|
@@ -83,7 +83,32 @@ Composio tools use uppercase slug format: `GITHUB_CREATE_ISSUE`, `SLACK_SEND_MES
|
|
|
83
83
|
|
|
84
84
|
### Authentication
|
|
85
85
|
|
|
86
|
-
Connections use per-author scope by default. Set `defaultScope: 'caller-supplied'` to bucket authorization by the caller identity resolved from request context.
|
|
86
|
+
Connections use per-author scope by default. Set `defaultScope: 'caller-supplied'` to bucket authorization by the caller identity resolved from `MASTRA_RESOURCE_ID_KEY` in request context. Ensure each authenticated request provides a stable, unique resource ID. When using `MastraAuthWorkos`, configure `mapUserToResourceId` to set this value from the authenticated user.
|
|
87
|
+
|
|
88
|
+
### Connection management tools
|
|
89
|
+
|
|
90
|
+
Composio provides tools for starting and monitoring authorization from an agent chat. When `allowedToolkits` is set, include `composio` to make these tools available:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
const editor = new MastraEditor({
|
|
94
|
+
toolProviders: {
|
|
95
|
+
composio: new ComposioToolProvider({
|
|
96
|
+
apiKey: process.env.COMPOSIO_API_KEY!,
|
|
97
|
+
allowedToolkits: ['composio', 'gmail'],
|
|
98
|
+
defaultScope: 'caller-supplied',
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Add only the connection management tools that the agent needs:
|
|
105
|
+
|
|
106
|
+
| Tool | Behavior |
|
|
107
|
+
| ------------------------------- | ---------------------------------------------------------------------------- |
|
|
108
|
+
| `COMPOSIO_MANAGE_CONNECTIONS` | Creates an authorization link in chat through a session owned by the caller. |
|
|
109
|
+
| `COMPOSIO_WAIT_FOR_CONNECTIONS` | Waits for the caller to finish authorization before the agent continues. |
|
|
110
|
+
|
|
111
|
+
`COMPOSIO_WAIT_FOR_CONNECTIONS` is optional. Without it, complete authorization and return to the chat. Then ask the agent to continue. The connected account remains associated with the caller resource ID for later requests.
|
|
87
112
|
|
|
88
113
|
***
|
|
89
114
|
|
|
@@ -69,32 +69,33 @@ Please note:
|
|
|
69
69
|
|
|
70
70
|
Keep `config.ts` focused on runtime options. Use sibling files for concerns that benefit from their own location.
|
|
71
71
|
|
|
72
|
-
| Setting | File or folder
|
|
73
|
-
| ------------ |
|
|
74
|
-
| Instructions | [`instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | Keeps the always-on prompt readable as markdown
|
|
75
|
-
| Tools | [`tools/`](https://mastra.ai/reference/file-based-agents/tools)
|
|
76
|
-
| Skills | [`skills/`](https://mastra.ai/reference/file-based-agents/skills)
|
|
77
|
-
| Memory | [`memory.ts`](https://mastra.ai/reference/file-based-agents/memory)
|
|
78
|
-
| Workspace | [`workspace.ts`](https://mastra.ai/reference/file-based-agents/workspace)
|
|
79
|
-
| Processors | [`processors/`](https://mastra.ai/reference/file-based-agents/processors)
|
|
80
|
-
| Subagents | [`subagents/`](https://mastra.ai/reference/file-based-agents/subagents)
|
|
72
|
+
| Setting | File or folder | Why it lives there |
|
|
73
|
+
| ------------ | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
74
|
+
| Instructions | [`instructions.md` or `instructions.ts`](https://mastra.ai/reference/file-based-agents/instructions) | Keeps the always-on prompt readable as markdown, or computed in TypeScript |
|
|
75
|
+
| Tools | [`tools/`](https://mastra.ai/reference/file-based-agents/tools) | Gives each callable action its own typed module |
|
|
76
|
+
| Skills | [`skills/`](https://mastra.ai/reference/file-based-agents/skills) | Keeps load-on-demand procedures separate from always-on instructions |
|
|
77
|
+
| Memory | [`memory.ts`](https://mastra.ai/reference/file-based-agents/memory) | Configures persistent memory without crowding runtime options |
|
|
78
|
+
| Workspace | [`workspace.ts`](https://mastra.ai/reference/file-based-agents/workspace) | Configures files and sandbox behavior separately from model settings |
|
|
79
|
+
| Processors | [`processors/`](https://mastra.ai/reference/file-based-agents/processors) | Separates input and output processing pipelines |
|
|
80
|
+
| Subagents | [`subagents/`](https://mastra.ai/reference/file-based-agents/subagents) | Gives each specialist child agent its own directory |
|
|
81
81
|
|
|
82
82
|
## Precedence
|
|
83
83
|
|
|
84
84
|
`config.ts` merges with the agent's other files according to these rules:
|
|
85
85
|
|
|
86
|
-
| Domain | Source A
|
|
87
|
-
| ------------ |
|
|
88
|
-
| Instructions | Dynamic `config.instructions`
|
|
89
|
-
| Instructions | Static `config.instructions`
|
|
90
|
-
|
|
|
91
|
-
| Tools |
|
|
92
|
-
|
|
|
93
|
-
| Skills |
|
|
94
|
-
|
|
|
95
|
-
|
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
| Domain | Source A | Source B | Winner |
|
|
87
|
+
| ------------ | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
88
|
+
| Instructions | Dynamic `config.instructions` | [`instructions.ts` or `instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | Dynamic `config.instructions` |
|
|
89
|
+
| Instructions | Static `config.instructions` | [`instructions.ts` or `instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | The instructions file |
|
|
90
|
+
| Instructions | [`instructions.ts`](https://mastra.ai/reference/file-based-agents/instructions) | [`instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | `instructions.ts` |
|
|
91
|
+
| Tools | `config.tools` | [`tools/`](https://mastra.ai/reference/file-based-agents/tools) | Both merge; `config.tools` wins on key collisions |
|
|
92
|
+
| Tools | Function `config.tools` | [`tools/`](https://mastra.ai/reference/file-based-agents/tools) | Function `config.tools`; discovered tools are ignored |
|
|
93
|
+
| Skills | `config.skills` | [`skills/`](https://mastra.ai/reference/file-based-agents/skills) | Both merge; `config.skills` wins on name collisions |
|
|
94
|
+
| Skills | Function `config.skills` | [`skills/`](https://mastra.ai/reference/file-based-agents/skills) | Function `config.skills`; discovered skills are ignored |
|
|
95
|
+
| Memory | `config.memory` | [`memory.ts`](https://mastra.ai/reference/file-based-agents/memory) | `config.memory` |
|
|
96
|
+
| Workspace | `config.workspace` | [`workspace.ts`](https://mastra.ai/reference/file-based-agents/workspace) | `config.workspace` |
|
|
97
|
+
|
|
98
|
+
Missing `instructions.md`, `instructions.ts`, and `config.instructions` fails the build. Missing both `config.memory` and `memory.ts` leaves the agent without memory.
|
|
98
99
|
|
|
99
100
|
## Discovery lifecycle
|
|
100
101
|
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
# Instructions
|
|
4
4
|
|
|
5
|
-
An agent's
|
|
5
|
+
An agent's instructions hold its always-on system prompt: the model reads it on every turn. Use them to define the agent's identity, tone, role, and standing rules.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Write them in one of two files at the agent root. Use `instructions.md` when the prompt is fixed text. Use `instructions.ts` when the prompt needs code, for example when it's built from shared constants or resolved per request.
|
|
8
|
+
|
|
9
|
+
Instructions are always in context, so keep them for stable behavior that applies to every request. Move anything conditional, large, or action-oriented into [`tools/`](https://mastra.ai/reference/file-based-agents/tools) or [`skills/`](https://mastra.ai/reference/file-based-agents/skills), which the model uses only when relevant.
|
|
8
10
|
|
|
9
11
|
## Quickstart
|
|
10
12
|
|
|
@@ -25,30 +27,53 @@ Effective instructions cover the parts of an agent's behavior that don't change
|
|
|
25
27
|
|
|
26
28
|
Move conditional, large, or action-oriented guidance into [`tools/`](https://mastra.ai/reference/file-based-agents/tools) or [`skills/`](https://mastra.ai/reference/file-based-agents/skills), which the model uses only when relevant.
|
|
27
29
|
|
|
28
|
-
##
|
|
30
|
+
## Instructions in TypeScript
|
|
31
|
+
|
|
32
|
+
Use `instructions.ts` when markdown can't express the prompt. The file default-exports a string, a system message, or a function returning one, and `agentInstructions()` types the export without changing it.
|
|
33
|
+
|
|
34
|
+
Export a string when the prompt is assembled in code, for example from constants shared with the rest of your app:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { agentInstructions } from '@mastra/core/agent'
|
|
38
|
+
import { SUPPORTED_UNITS } from '../../constants'
|
|
39
|
+
|
|
40
|
+
export default agentInstructions(`
|
|
41
|
+
You are a helpful weather assistant.
|
|
42
|
+
Report conditions using one of these units: ${SUPPORTED_UNITS.join(', ')}.
|
|
43
|
+
`)
|
|
44
|
+
```
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
Export a function when the prompt depends on the request. Mastra calls it on every turn and passes the request context:
|
|
31
47
|
|
|
32
48
|
```typescript
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
export default
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const tier = runtimeContext.get('tier') ?? 'standard'
|
|
39
|
-
return `You are a support agent. Treat this as a ${tier}-tier customer.`
|
|
40
|
-
},
|
|
49
|
+
import { agentInstructions } from '@mastra/core/agent'
|
|
50
|
+
|
|
51
|
+
export default agentInstructions(({ requestContext }) => {
|
|
52
|
+
const tier = requestContext.get('tier') ?? 'standard'
|
|
53
|
+
return `You are a support agent. Treat this as a ${tier}-tier customer.`
|
|
41
54
|
})
|
|
42
55
|
```
|
|
43
56
|
|
|
57
|
+
The function can be `async` and receives `mastra` alongside `requestContext`, so it can read from storage or another registered primitive before returning the prompt.
|
|
58
|
+
|
|
59
|
+
Both files can also live in a [subagent](https://mastra.ai/reference/file-based-agents/subagents) directory, which follows the same rules.
|
|
60
|
+
|
|
44
61
|
## Build-time behavior
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
`instructions.md` and `instructions.ts` reach the deployed agent differently:
|
|
64
|
+
|
|
65
|
+
- `instructions.md`: Mastra reads the file and inlines its contents into the generated code at build time.
|
|
66
|
+
- `instructions.ts`: The generated code imports the module, so it's bundled like any other TypeScript file and can import from the rest of your project.
|
|
67
|
+
|
|
68
|
+
Under `mastra dev`, editing either file triggers a rebuild. In a deployed app neither file is read from disk at runtime, so changes take effect after the next build.
|
|
47
69
|
|
|
48
70
|
## Precedence with config
|
|
49
71
|
|
|
50
|
-
Instructions can come from `instructions.md
|
|
72
|
+
Instructions can come from `instructions.ts`, `instructions.md`, or the `instructions` field in [`config.ts`](https://mastra.ai/reference/file-based-agents/config):
|
|
73
|
+
|
|
74
|
+
- A runtime-defined (function) `instructions` in `config.ts` wins over both files.
|
|
75
|
+
- Otherwise `instructions.ts` wins over `instructions.md`.
|
|
76
|
+
- `instructions.md` wins over a static `instructions` string in `config.ts`.
|
|
77
|
+
- If none is present, the build fails and names the agent directory.
|
|
51
78
|
|
|
52
|
-
|
|
53
|
-
- Otherwise `instructions.md` wins over a static `instructions` string.
|
|
54
|
-
- If neither is present, the build fails and names the agent directory.
|
|
79
|
+
Defining instructions in more than one place logs a warning that names both sources and which one wins. Keep one source per agent.
|