@mastra/mcp-docs-server 1.1.7-alpha.0 → 1.1.8-alpha.0
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/agent-approval.md +61 -31
- package/.docs/docs/agents/supervisor-agents.md +1 -1
- package/.docs/docs/getting-started/manual-install.md +1 -1
- package/.docs/docs/index.md +68 -24
- package/.docs/docs/mastra-cloud/setup.md +1 -1
- package/.docs/docs/memory/observational-memory.md +9 -0
- package/.docs/docs/memory/semantic-recall.md +17 -1
- package/.docs/docs/workspace/skills.md +7 -5
- package/.docs/guides/deployment/aws-lambda.md +76 -165
- package/.docs/guides/deployment/azure-app-services.md +38 -61
- package/.docs/guides/deployment/cloudflare.md +1 -1
- package/.docs/guides/deployment/netlify.md +1 -1
- package/.docs/guides/deployment/vercel.md +1 -1
- package/.docs/models/gateways/netlify.md +5 -1
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/anthropic.md +9 -9
- package/.docs/models/providers/deepseek.md +1 -1
- package/.docs/models/providers/google.md +11 -11
- package/.docs/models/providers/openai.md +19 -19
- package/.docs/models/providers/opencode.md +33 -33
- package/.docs/models/providers/xai.md +3 -3
- package/.docs/reference/agents/agent.md +20 -20
- package/.docs/reference/agents/generate.md +200 -66
- package/.docs/reference/agents/generateLegacy.md +77 -35
- package/.docs/reference/agents/getDefaultGenerateOptions.md +4 -6
- package/.docs/reference/agents/getDefaultOptions.md +4 -6
- package/.docs/reference/agents/getDefaultStreamOptions.md +4 -6
- package/.docs/reference/agents/getDescription.md +1 -1
- package/.docs/reference/agents/getInstructions.md +4 -6
- package/.docs/reference/agents/getLLM.md +6 -8
- package/.docs/reference/agents/getMemory.md +4 -6
- package/.docs/reference/agents/getModel.md +4 -6
- package/.docs/reference/agents/getTools.md +5 -7
- package/.docs/reference/agents/getVoice.md +4 -6
- package/.docs/reference/agents/listAgents.md +4 -6
- package/.docs/reference/agents/listScorers.md +4 -6
- package/.docs/reference/agents/listTools.md +4 -6
- package/.docs/reference/agents/listWorkflows.md +4 -6
- package/.docs/reference/agents/network.md +69 -23
- package/.docs/reference/ai-sdk/chat-route.md +7 -7
- package/.docs/reference/ai-sdk/handle-chat-stream.md +12 -12
- package/.docs/reference/ai-sdk/handle-network-stream.md +4 -4
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +11 -11
- package/.docs/reference/ai-sdk/network-route.md +3 -3
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +9 -9
- package/.docs/reference/ai-sdk/to-ai-sdk-v4-messages.md +9 -9
- package/.docs/reference/ai-sdk/to-ai-sdk-v5-messages.md +5 -5
- package/.docs/reference/ai-sdk/with-mastra.md +12 -12
- package/.docs/reference/ai-sdk/workflow-route.md +3 -3
- package/.docs/reference/auth/auth0.md +6 -6
- package/.docs/reference/auth/better-auth.md +5 -5
- package/.docs/reference/auth/clerk.md +5 -5
- package/.docs/reference/auth/firebase.md +7 -7
- package/.docs/reference/auth/jwt.md +1 -1
- package/.docs/reference/auth/supabase.md +4 -4
- package/.docs/reference/auth/workos.md +6 -6
- package/.docs/reference/cli/create-mastra.md +14 -14
- package/.docs/reference/client-js/mastra-client.md +23 -23
- package/.docs/reference/client-js/workflows.md +3 -3
- package/.docs/reference/core/addGateway.md +2 -2
- package/.docs/reference/core/getAgent.md +2 -2
- package/.docs/reference/core/getAgentById.md +2 -2
- package/.docs/reference/core/getDeployer.md +1 -1
- package/.docs/reference/core/getGateway.md +2 -2
- package/.docs/reference/core/getGatewayById.md +2 -2
- package/.docs/reference/core/getLogger.md +1 -1
- package/.docs/reference/core/getMCPServer.md +2 -2
- package/.docs/reference/core/getMCPServerById.md +3 -3
- package/.docs/reference/core/getMemory.md +2 -2
- package/.docs/reference/core/getScorer.md +2 -2
- package/.docs/reference/core/getScorerById.md +2 -2
- package/.docs/reference/core/getServer.md +1 -1
- package/.docs/reference/core/getStorage.md +1 -1
- package/.docs/reference/core/getStoredAgentById.md +18 -20
- package/.docs/reference/core/getTelemetry.md +1 -1
- package/.docs/reference/core/getVector.md +2 -2
- package/.docs/reference/core/getWorkflow.md +3 -3
- package/.docs/reference/core/listAgents.md +1 -1
- package/.docs/reference/core/listGateways.md +1 -1
- package/.docs/reference/core/listLogs.md +9 -11
- package/.docs/reference/core/listLogsByRunId.md +9 -9
- package/.docs/reference/core/listMCPServers.md +1 -1
- package/.docs/reference/core/listMemory.md +1 -1
- package/.docs/reference/core/listScorers.md +1 -1
- package/.docs/reference/core/listStoredAgents.md +9 -11
- package/.docs/reference/core/listVectors.md +1 -1
- package/.docs/reference/core/listWorkflows.md +2 -2
- package/.docs/reference/core/mastra-class.md +17 -17
- package/.docs/reference/core/mastra-model-gateway.md +15 -15
- package/.docs/reference/core/setLogger.md +2 -4
- package/.docs/reference/core/setStorage.md +1 -1
- package/.docs/reference/datasets/addItem.md +20 -4
- package/.docs/reference/datasets/addItems.md +8 -2
- package/.docs/reference/datasets/compareExperiments.md +15 -3
- package/.docs/reference/datasets/create.md +6 -6
- package/.docs/reference/datasets/dataset.md +1 -1
- package/.docs/reference/datasets/delete.md +2 -2
- package/.docs/reference/datasets/deleteExperiment.md +2 -2
- package/.docs/reference/datasets/deleteItem.md +2 -2
- package/.docs/reference/datasets/deleteItems.md +2 -2
- package/.docs/reference/datasets/get.md +2 -2
- package/.docs/reference/datasets/getDetails.md +9 -9
- package/.docs/reference/datasets/getExperiment.md +2 -2
- package/.docs/reference/datasets/getItem.md +3 -3
- package/.docs/reference/datasets/getItemHistory.md +22 -2
- package/.docs/reference/datasets/list.md +7 -3
- package/.docs/reference/datasets/listExperimentResults.md +34 -4
- package/.docs/reference/datasets/listExperiments.md +41 -3
- package/.docs/reference/datasets/listItems.md +18 -6
- package/.docs/reference/datasets/listVersions.md +23 -3
- package/.docs/reference/datasets/startExperiment.md +62 -12
- package/.docs/reference/datasets/startExperimentAsync.md +5 -1
- package/.docs/reference/datasets/update.md +6 -6
- package/.docs/reference/datasets/updateItem.md +5 -5
- package/.docs/reference/deployer.md +8 -8
- package/.docs/reference/evals/answer-relevancy.md +11 -11
- package/.docs/reference/evals/answer-similarity.md +17 -19
- package/.docs/reference/evals/bias.md +10 -10
- package/.docs/reference/evals/completeness.md +3 -3
- package/.docs/reference/evals/content-similarity.md +6 -6
- package/.docs/reference/evals/context-precision.md +4 -4
- package/.docs/reference/evals/context-relevance.md +4 -4
- package/.docs/reference/evals/create-scorer.md +47 -49
- package/.docs/reference/evals/faithfulness.md +11 -11
- package/.docs/reference/evals/hallucination.md +17 -21
- package/.docs/reference/evals/keyword-coverage.md +4 -4
- package/.docs/reference/evals/mastra-scorer.md +14 -14
- package/.docs/reference/evals/noise-sensitivity.md +4 -4
- package/.docs/reference/evals/prompt-alignment.md +4 -4
- package/.docs/reference/evals/run-evals.md +16 -16
- package/.docs/reference/evals/scorer-utils.md +3 -3
- package/.docs/reference/evals/textual-difference.md +3 -3
- package/.docs/reference/evals/tone-consistency.md +3 -3
- package/.docs/reference/evals/tool-call-accuracy.md +5 -5
- package/.docs/reference/evals/toxicity.md +8 -8
- package/.docs/reference/harness/harness-class.md +34 -42
- package/.docs/reference/logging/pino-logger.md +5 -5
- package/.docs/reference/memory/clone-utilities.md +5 -5
- package/.docs/reference/memory/cloneThread.md +17 -21
- package/.docs/reference/memory/createThread.md +10 -10
- package/.docs/reference/memory/deleteMessages.md +2 -2
- package/.docs/reference/memory/getThreadById.md +2 -2
- package/.docs/reference/memory/listThreads.md +5 -5
- package/.docs/reference/memory/memory-class.md +12 -14
- package/.docs/reference/memory/observational-memory.md +102 -94
- package/.docs/reference/memory/recall.md +14 -16
- package/.docs/reference/observability/tracing/configuration.md +27 -10
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +4 -7
- package/.docs/reference/processors/batch-parts-processor.md +8 -10
- package/.docs/reference/processors/language-detector.md +14 -16
- package/.docs/reference/processors/message-history-processor.md +7 -9
- package/.docs/reference/processors/moderation-processor.md +13 -15
- package/.docs/reference/processors/pii-detector.md +14 -16
- package/.docs/reference/processors/processor-interface.md +62 -62
- package/.docs/reference/processors/prompt-injection-detector.md +11 -13
- package/.docs/reference/processors/semantic-recall-processor.md +14 -16
- package/.docs/reference/processors/system-prompt-scrubber.md +12 -14
- package/.docs/reference/processors/token-limiter-processor.md +11 -13
- package/.docs/reference/processors/tool-call-filter.md +5 -7
- package/.docs/reference/processors/tool-search-processor.md +9 -11
- package/.docs/reference/processors/unicode-normalizer.md +8 -10
- package/.docs/reference/processors/working-memory-processor.md +14 -18
- package/.docs/reference/rag/chunk.md +38 -38
- package/.docs/reference/rag/database-config.md +11 -7
- package/.docs/reference/rag/document.md +2 -2
- package/.docs/reference/rag/embeddings.md +12 -12
- package/.docs/reference/rag/extract-params.md +23 -23
- package/.docs/reference/rag/graph-rag.md +12 -12
- package/.docs/reference/rag/rerank.md +25 -17
- package/.docs/reference/rag/rerankWithScorer.md +25 -17
- package/.docs/reference/server/create-route.md +14 -14
- package/.docs/reference/server/express-adapter.md +10 -10
- package/.docs/reference/server/fastify-adapter.md +10 -10
- package/.docs/reference/server/hono-adapter.md +10 -10
- package/.docs/reference/server/koa-adapter.md +10 -10
- package/.docs/reference/server/mastra-server.md +10 -10
- package/.docs/reference/server/register-api-route.md +13 -13
- package/.docs/reference/storage/cloudflare-d1.md +5 -5
- package/.docs/reference/storage/cloudflare.md +6 -6
- package/.docs/reference/storage/composite.md +9 -9
- package/.docs/reference/storage/convex.md +3 -3
- package/.docs/reference/storage/dynamodb.md +9 -9
- package/.docs/reference/storage/lance.md +3 -3
- package/.docs/reference/storage/libsql.md +2 -2
- package/.docs/reference/storage/mongodb.md +5 -5
- package/.docs/reference/storage/mssql.md +2 -2
- package/.docs/reference/storage/postgresql.md +25 -25
- package/.docs/reference/storage/upstash.md +3 -3
- package/.docs/reference/streaming/ChunkType.md +251 -59
- package/.docs/reference/streaming/agents/MastraModelOutput.md +86 -16
- package/.docs/reference/streaming/agents/stream.md +155 -43
- package/.docs/reference/streaming/agents/streamLegacy.md +79 -39
- package/.docs/reference/streaming/workflows/resumeStream.md +18 -8
- package/.docs/reference/streaming/workflows/stream.md +21 -9
- package/.docs/reference/streaming/workflows/timeTravelStream.md +4 -4
- package/.docs/reference/tools/create-tool.md +25 -21
- package/.docs/reference/tools/document-chunker-tool.md +7 -7
- package/.docs/reference/tools/graph-rag-tool.md +16 -18
- package/.docs/reference/tools/mcp-client.md +38 -27
- package/.docs/reference/tools/mcp-server.md +45 -45
- package/.docs/reference/tools/vector-query-tool.md +34 -22
- package/.docs/reference/vectors/astra.md +22 -22
- package/.docs/reference/vectors/chroma.md +44 -44
- package/.docs/reference/vectors/convex.md +26 -26
- package/.docs/reference/vectors/couchbase.md +30 -30
- package/.docs/reference/vectors/duckdb.md +29 -29
- package/.docs/reference/vectors/elasticsearch.md +27 -27
- package/.docs/reference/vectors/lance.md +46 -38
- package/.docs/reference/vectors/libsql.md +31 -31
- package/.docs/reference/vectors/mongodb.md +32 -32
- package/.docs/reference/vectors/opensearch.md +27 -27
- package/.docs/reference/vectors/pg.md +60 -44
- package/.docs/reference/vectors/pinecone.md +38 -38
- package/.docs/reference/vectors/qdrant.md +36 -36
- package/.docs/reference/vectors/s3vectors.md +24 -24
- package/.docs/reference/vectors/turbopuffer.md +29 -29
- package/.docs/reference/vectors/upstash.md +25 -25
- package/.docs/reference/vectors/vectorize.md +27 -27
- package/.docs/reference/voice/azure.md +19 -15
- package/.docs/reference/voice/cloudflare.md +10 -12
- package/.docs/reference/voice/composite-voice.md +10 -10
- package/.docs/reference/voice/deepgram.md +20 -14
- package/.docs/reference/voice/elevenlabs.md +20 -22
- package/.docs/reference/voice/google-gemini-live.md +42 -44
- package/.docs/reference/voice/google.md +25 -21
- package/.docs/reference/voice/mastra-voice.md +20 -20
- package/.docs/reference/voice/murf.md +24 -28
- package/.docs/reference/voice/openai-realtime.md +26 -26
- package/.docs/reference/voice/openai.md +14 -12
- package/.docs/reference/voice/playai.md +13 -15
- package/.docs/reference/voice/sarvam.md +21 -25
- package/.docs/reference/voice/speechify.md +11 -13
- package/.docs/reference/voice/voice.addInstructions.md +1 -1
- package/.docs/reference/voice/voice.addTools.md +1 -1
- package/.docs/reference/voice/voice.answer.md +1 -1
- package/.docs/reference/voice/voice.connect.md +3 -3
- package/.docs/reference/voice/voice.events.md +11 -11
- package/.docs/reference/voice/voice.getSpeakers.md +30 -30
- package/.docs/reference/voice/voice.listen.md +9 -9
- package/.docs/reference/voice/voice.off.md +2 -2
- package/.docs/reference/voice/voice.on.md +2 -2
- package/.docs/reference/voice/voice.send.md +1 -1
- package/.docs/reference/voice/voice.speak.md +11 -11
- package/.docs/reference/voice/voice.updateConfig.md +3 -3
- package/.docs/reference/workflows/run-methods/cancel.md +2 -2
- package/.docs/reference/workflows/run-methods/restart.md +17 -5
- package/.docs/reference/workflows/run-methods/resume.md +23 -9
- package/.docs/reference/workflows/run-methods/start.md +22 -8
- package/.docs/reference/workflows/run-methods/startAsync.md +12 -6
- package/.docs/reference/workflows/run-methods/timeTravel.md +29 -13
- package/.docs/reference/workflows/run.md +12 -12
- package/.docs/reference/workflows/step.md +24 -26
- package/.docs/reference/workflows/workflow-methods/branch.md +2 -2
- package/.docs/reference/workflows/workflow-methods/commit.md +1 -1
- package/.docs/reference/workflows/workflow-methods/create-run.md +4 -4
- package/.docs/reference/workflows/workflow-methods/dountil.md +3 -3
- package/.docs/reference/workflows/workflow-methods/dowhile.md +3 -3
- package/.docs/reference/workflows/workflow-methods/foreach.md +9 -9
- package/.docs/reference/workflows/workflow-methods/map.md +2 -2
- package/.docs/reference/workflows/workflow-methods/parallel.md +2 -2
- package/.docs/reference/workflows/workflow-methods/sleep.md +2 -2
- package/.docs/reference/workflows/workflow-methods/sleepUntil.md +2 -2
- package/.docs/reference/workflows/workflow-methods/then.md +2 -2
- package/.docs/reference/workflows/workflow.md +40 -50
- package/.docs/reference/workspace/daytona-sandbox.md +33 -33
- package/.docs/reference/workspace/e2b-sandbox.md +20 -20
- package/.docs/reference/workspace/filesystem.md +22 -22
- package/.docs/reference/workspace/gcs-filesystem.md +15 -15
- package/.docs/reference/workspace/local-filesystem.md +35 -35
- package/.docs/reference/workspace/local-sandbox.md +26 -26
- package/.docs/reference/workspace/s3-filesystem.md +18 -18
- package/.docs/reference/workspace/sandbox.md +8 -8
- package/.docs/reference/workspace/workspace-class.md +30 -34
- package/CHANGELOG.md +16 -0
- package/package.json +6 -6
- package/.docs/docs/getting-started/start.md +0 -28
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
# Agent
|
|
1
|
+
# Agent approval
|
|
2
2
|
|
|
3
|
-
Agents sometimes require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in workflows when calling tools that handle sensitive operations, like deleting resources or
|
|
3
|
+
Agents sometimes require the same [human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop) oversight used in workflows when calling tools that handle sensitive operations, like deleting resources or running long processes. With agent approval you can suspend a tool call before it executes so a human can approve or decline it, or let tools suspend themselves to request additional context from the user.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## How approval works
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Mastra offers two distinct mechanisms for pausing tool calls: **pre-execution approval** and **runtime suspension**.
|
|
8
|
+
|
|
9
|
+
### Pre-execution approval
|
|
10
|
+
|
|
11
|
+
Pre-execution approval pauses a tool call _before_ its `execute` function runs. The LLM still decides which tool to call and provides arguments, but `execute` doesn't run until you explicitly approve.
|
|
12
|
+
|
|
13
|
+
Two flags control this, combined with OR logic. If _either_ is `true`, the call pauses:
|
|
14
|
+
|
|
15
|
+
| Flag | Where to set it | Scope |
|
|
16
|
+
| --------------------------- | --------------------------------- | ------------------------------------------- |
|
|
17
|
+
| `requireToolApproval: true` | `stream()` / `generate()` options | Pauses **every** tool call for that request |
|
|
18
|
+
| `requireApproval: true` | `createTool()` definition | Pauses calls to **that specific tool** |
|
|
19
|
+
|
|
20
|
+
The stream emits a `tool-call-approval` chunk when a call is paused this way. You then call `approveToolCall()` or `declineToolCall()` to continue.
|
|
21
|
+
|
|
22
|
+
### Runtime suspension with `suspend()`
|
|
23
|
+
|
|
24
|
+
A tool can also pause _during_ its `execute` function by calling `suspend()`. This is useful when the tool starts running and then discovers it needs additional user input or confirmation before it can finish.
|
|
25
|
+
|
|
26
|
+
The stream emits a `tool-call-suspended` chunk with a custom payload defined by the tool's `suspendSchema`. You resume by calling `resumeStream()` with data matching the tool's `resumeSchema`.
|
|
8
27
|
|
|
9
28
|
### Storage
|
|
10
29
|
|
|
@@ -24,7 +43,7 @@ export const mastra = new Mastra({
|
|
|
24
43
|
|
|
25
44
|
## Agent-level approval
|
|
26
45
|
|
|
27
|
-
|
|
46
|
+
Pass `requireToolApproval: true` to `stream()` or `generate()` to pause every tool call before execution. The LLM still decides which tools to call and with what arguments but no tool runs until you approve or decline.
|
|
28
47
|
|
|
29
48
|
```typescript
|
|
30
49
|
const stream = await agent.stream("What's the weather in London?", {
|
|
@@ -32,9 +51,20 @@ const stream = await agent.stream("What's the weather in London?", {
|
|
|
32
51
|
})
|
|
33
52
|
```
|
|
34
53
|
|
|
54
|
+
When a tool call is paused, the stream emits a `tool-call-approval` chunk containing the `toolCallId`, `toolName`, and `args`. Use this to inspect the pending call and decide whether to approve or decline:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
for await (const chunk of stream.fullStream) {
|
|
58
|
+
if (chunk.type === 'tool-call-approval') {
|
|
59
|
+
console.log('Tool:', chunk.payload.toolName)
|
|
60
|
+
console.log('Args:', chunk.payload.args)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
35
65
|
### Approving tool calls
|
|
36
66
|
|
|
37
|
-
|
|
67
|
+
Call `approveToolCall()` on the agent with the `runId` of the stream to resume the suspended tool call and let it execute:
|
|
38
68
|
|
|
39
69
|
```typescript
|
|
40
70
|
const handleApproval = async () => {
|
|
@@ -49,7 +79,7 @@ const handleApproval = async () => {
|
|
|
49
79
|
|
|
50
80
|
### Declining tool calls
|
|
51
81
|
|
|
52
|
-
|
|
82
|
+
Call `declineToolCall()` on the agent to skip the tool call. The agent continues without executing the tool and responds accordingly:
|
|
53
83
|
|
|
54
84
|
```typescript
|
|
55
85
|
const handleDecline = async () => {
|
|
@@ -64,19 +94,19 @@ const handleDecline = async () => {
|
|
|
64
94
|
|
|
65
95
|
## Tool approval with generate()
|
|
66
96
|
|
|
67
|
-
Tool approval also works with the `generate()` method for non-streaming use cases. When
|
|
97
|
+
Tool approval also works with the `generate()` method for non-streaming use cases. When a tool requires approval during a `generate()` call, the method returns immediately instead of executing the tool.
|
|
68
98
|
|
|
69
99
|
### How it works
|
|
70
100
|
|
|
71
101
|
When a tool requires approval during a `generate()` call, the response includes:
|
|
72
102
|
|
|
73
|
-
- `finishReason: 'suspended'
|
|
74
|
-
- `suspendPayload
|
|
75
|
-
- `runId
|
|
103
|
+
- `finishReason: 'suspended'`: Indicates the agent is waiting for approval
|
|
104
|
+
- `suspendPayload`: Contains tool call details (`toolCallId`, `toolName`, `args`)
|
|
105
|
+
- `runId`: Needed to approve or decline the tool call
|
|
76
106
|
|
|
77
107
|
### Approving tool calls
|
|
78
108
|
|
|
79
|
-
|
|
109
|
+
Use `approveToolCallGenerate()` to approve the tool call and get the final result:
|
|
80
110
|
|
|
81
111
|
```typescript
|
|
82
112
|
const output = await agent.generate('Find user John', {
|
|
@@ -99,7 +129,7 @@ if (output.finishReason === 'suspended') {
|
|
|
99
129
|
|
|
100
130
|
### Declining tool calls
|
|
101
131
|
|
|
102
|
-
|
|
132
|
+
Use `declineToolCallGenerate()` to skip the tool call:
|
|
103
133
|
|
|
104
134
|
```typescript
|
|
105
135
|
if (output.finishReason === 'suspended') {
|
|
@@ -108,12 +138,12 @@ if (output.finishReason === 'suspended') {
|
|
|
108
138
|
toolCallId: output.suspendPayload.toolCallId,
|
|
109
139
|
})
|
|
110
140
|
|
|
111
|
-
// Agent
|
|
141
|
+
// Agent responds acknowledging the declined tool
|
|
112
142
|
console.log(result.text)
|
|
113
143
|
}
|
|
114
144
|
```
|
|
115
145
|
|
|
116
|
-
### Stream vs
|
|
146
|
+
### Stream vs generate comparison
|
|
117
147
|
|
|
118
148
|
| Aspect | `stream()` | `generate()` |
|
|
119
149
|
| ------------------ | ---------------------------- | ------------------------------------------------ |
|
|
@@ -125,11 +155,11 @@ if (output.finishReason === 'suspended') {
|
|
|
125
155
|
|
|
126
156
|
## Tool-level approval
|
|
127
157
|
|
|
128
|
-
|
|
158
|
+
Instead of pausing every tool call at the agent level, you can mark individual tools as requiring approval. This gives you granular control — only specific tools pause, while others execute immediately.
|
|
129
159
|
|
|
130
|
-
###
|
|
160
|
+
### Approval using `requireApproval`
|
|
131
161
|
|
|
132
|
-
|
|
162
|
+
Set `requireApproval: true` on a tool definition. The tool pauses before execution regardless of whether `requireToolApproval` is set on the agent:
|
|
133
163
|
|
|
134
164
|
```typescript
|
|
135
165
|
export const testTool = createTool({
|
|
@@ -154,30 +184,30 @@ export const testTool = createTool({
|
|
|
154
184
|
})
|
|
155
185
|
```
|
|
156
186
|
|
|
157
|
-
When `requireApproval` is true
|
|
187
|
+
When `requireApproval` is `true`, the stream emits `tool-call-approval` chunks the same way agent-level approval does. Use `approveToolCall()` or `declineToolCall()` to continue:
|
|
158
188
|
|
|
159
189
|
```typescript
|
|
160
190
|
const stream = await agent.stream("What's the weather in London?")
|
|
161
191
|
|
|
162
192
|
for await (const chunk of stream.fullStream) {
|
|
163
193
|
if (chunk.type === 'tool-call-approval') {
|
|
164
|
-
console.log('Approval required.
|
|
194
|
+
console.log('Approval required for:', chunk.payload.toolName)
|
|
165
195
|
}
|
|
166
196
|
}
|
|
167
197
|
|
|
168
|
-
const
|
|
169
|
-
const
|
|
198
|
+
const handleApproval = async () => {
|
|
199
|
+
const approvedStream = await agent.approveToolCall({ runId: stream.runId })
|
|
170
200
|
|
|
171
|
-
for await (const chunk of
|
|
201
|
+
for await (const chunk of approvedStream.textStream) {
|
|
172
202
|
process.stdout.write(chunk)
|
|
173
203
|
}
|
|
174
204
|
process.stdout.write('\n')
|
|
175
205
|
}
|
|
176
206
|
```
|
|
177
207
|
|
|
178
|
-
###
|
|
208
|
+
### Approval using `suspend`
|
|
179
209
|
|
|
180
|
-
With this approach, neither the agent nor the tool uses `requireApproval`. Instead, the tool
|
|
210
|
+
With this approach, neither the agent nor the tool uses `requireApproval`. Instead, the tool's `execute` function calls `suspend` to pause at a specific point and return context or confirmation prompts to the user. This is useful when approval depends on runtime conditions rather than being unconditional.
|
|
181
211
|
|
|
182
212
|
```typescript
|
|
183
213
|
export const testToolB = createTool({
|
|
@@ -210,7 +240,7 @@ export const testToolB = createTool({
|
|
|
210
240
|
})
|
|
211
241
|
```
|
|
212
242
|
|
|
213
|
-
With this approach the stream
|
|
243
|
+
With this approach the stream includes a `tool-call-suspended` chunk, and the `suspendPayload` contains the `reason` defined by the tool's `suspendSchema`. Call `resumeStream` with the `resumeSchema` data and `runId` to continue:
|
|
214
244
|
|
|
215
245
|
```typescript
|
|
216
246
|
const stream = await agent.stream("What's the weather in London?")
|
|
@@ -349,7 +379,7 @@ User: "San Francisco"
|
|
|
349
379
|
Agent: "The weather in San Francisco is: San Francisco: ☀️ +72°F"
|
|
350
380
|
```
|
|
351
381
|
|
|
352
|
-
The second message automatically resumes the suspended tool
|
|
382
|
+
The second message automatically resumes the suspended tool, the agent extracts `{ city: "San Francisco" }` from the user's message and passes it as `resumeData`.
|
|
353
383
|
|
|
354
384
|
### Requirements
|
|
355
385
|
|
|
@@ -370,7 +400,7 @@ Both approaches work with the same tool definitions. Automatic resumption trigge
|
|
|
370
400
|
|
|
371
401
|
## Tool approval: Supervisor pattern
|
|
372
402
|
|
|
373
|
-
The [supervisor pattern](https://mastra.ai/docs/agents/networks) lets a supervisor agent coordinate multiple subagents using `.stream()` or `.generate()`. The supervisor delegates tasks to subagents, which may use tools that require approval. When this happens, tool approvals properly propagate through the delegation chain
|
|
403
|
+
The [supervisor pattern](https://mastra.ai/docs/agents/networks) lets a supervisor agent coordinate multiple subagents using `.stream()` or `.generate()`. The supervisor delegates tasks to subagents, which may use tools that require approval. When this happens, tool approvals properly propagate through the delegation chain — the approval request surfaces at the supervisor level where you can handle it, regardless of which subagent triggered it.
|
|
374
404
|
|
|
375
405
|
### How it works
|
|
376
406
|
|
|
@@ -453,7 +483,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
453
483
|
|
|
454
484
|
### Declining tool calls in supervisor pattern
|
|
455
485
|
|
|
456
|
-
|
|
486
|
+
Decline tool calls at the supervisor level by calling `declineToolCall`. The supervisor responds acknowledging the declined tool without executing it:
|
|
457
487
|
|
|
458
488
|
```typescript
|
|
459
489
|
for await (const chunk of stream.fullStream) {
|
|
@@ -466,7 +496,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
466
496
|
toolCallId: chunk.payload.toolCallId,
|
|
467
497
|
})
|
|
468
498
|
|
|
469
|
-
// The supervisor
|
|
499
|
+
// The supervisor responds acknowledging the declined tool
|
|
470
500
|
for await (const declineChunk of declineStream.textStream) {
|
|
471
501
|
process.stdout.write(declineChunk)
|
|
472
502
|
}
|
|
@@ -476,7 +506,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
476
506
|
|
|
477
507
|
### Using suspend() in supervisor pattern
|
|
478
508
|
|
|
479
|
-
Tools can also use [`suspend()`](#
|
|
509
|
+
Tools can also use [`suspend()`](#approval-using-suspend) to pause execution and return context to the user. This approach works through the supervisor delegation chain the same way `requireApproval` does — the suspension surfaces at the supervisor level:
|
|
480
510
|
|
|
481
511
|
```typescript
|
|
482
512
|
const conditionalTool = createTool({
|
|
@@ -192,7 +192,7 @@ const stream = await supervisor.stream('Research AI trends', {
|
|
|
192
192
|
})
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
Return `{ continue: true }` to keep iterating, or `{ continue: false }` to stop. Include optional `feedback` to
|
|
195
|
+
Return `{ continue: true }` to keep iterating, or `{ continue: false }` to stop. Include optional `feedback` to inject guidance into the conversation. When `feedback` is combined with `continue: false`, the model may get one final turn to produce a text response incorporating the feedback, but only if the current iteration is still active (e.g., after tool calls) — otherwise no extra turn is granted.
|
|
196
196
|
|
|
197
197
|
## Memory isolation
|
|
198
198
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Manual Install
|
|
2
2
|
|
|
3
|
-
> **Info:** Use this guide to manually build a standalone Mastra server step by step. In most cases, it's quicker to follow
|
|
3
|
+
> **Info:** Use this guide to manually build a standalone Mastra server step by step. In most cases, it's quicker to follow the [quickstart guide](https://mastra.ai/guides/getting-started/quickstart), which achieves the same result using the [`mastra create`](https://mastra.ai/reference/cli/create-mastra) command. For existing projects, you can also use [`mastra init`](https://mastra.ai/reference/cli/mastra).
|
|
4
4
|
|
|
5
5
|
If you prefer not to use our automatic CLI tool, you can set up your project yourself by following the guide below.
|
|
6
6
|
|
package/.docs/docs/index.md
CHANGED
|
@@ -1,43 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Get Started
|
|
2
2
|
|
|
3
|
-
Mastra is a framework for building AI
|
|
3
|
+
Mastra is a TypeScript framework for building AI agents, workflows, and tools. Create your first project in seconds and start building.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Quickstart
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Run the command below to create a new Mastra project with an example agent:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
**npm**:
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
```bash
|
|
12
|
+
npm create mastra@latest
|
|
13
|
+
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
**pnpm**:
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
```bash
|
|
18
|
+
pnpm create mastra
|
|
19
|
+
```
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
**Yarn**:
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
```bash
|
|
24
|
+
yarn create mastra
|
|
25
|
+
```
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
**Bun**:
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
```bash
|
|
30
|
+
bunx create-mastra
|
|
31
|
+
```
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
This sets up a project you can test immediately in [Studio](https://mastra.ai/docs/getting-started/studio). See the [quickstart guide](https://mastra.ai/guides/getting-started/quickstart) for a full walkthrough.
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
## Integrate with your framework
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
Add Mastra to an existing project or create a new app with your preferred framework.
|
|
30
38
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
39
|
+
- [Next.js](https://mastra.ai/guides/getting-started/next-js)
|
|
40
|
+
- [React](https://mastra.ai/guides/getting-started/vite-react)
|
|
41
|
+
- [Astro](https://mastra.ai/guides/getting-started/astro)
|
|
42
|
+
- [Express](https://mastra.ai/guides/getting-started/express)
|
|
43
|
+
- [SvelteKit](https://mastra.ai/guides/getting-started/sveltekit)
|
|
44
|
+
- [Hono](https://mastra.ai/guides/getting-started/hono)
|
|
36
45
|
|
|
37
|
-
|
|
46
|
+
For other frameworks, see the [framework integration guides](https://mastra.ai/guides/getting-started/next-js).
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
## What you can do
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
<details>
|
|
51
|
+
**Conversational agents**
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
Customer support, onboarding, or internal query bots. Agents maintain context across sessions with thread-based message history and observational memory — background agents that compress conversation history into dense observation logs, keeping the context window small while preserving long-term recall. Stream responses token-by-token for responsive chat UIs. Attach tools so agents can look up orders, create tickets, or call APIs mid-conversation.
|
|
54
|
+
|
|
55
|
+
</details>
|
|
56
|
+
|
|
57
|
+
<details>
|
|
58
|
+
**Domain-specific copilots**
|
|
59
|
+
|
|
60
|
+
Assistants for coding, legal, finance, research, or creative work. Ground agents in your own data with a full RAG pipeline — chunking, embedding, vector storage across 12+ providers, metadata filtering, and re-ranking. Customize behavior with dynamic instructions that adapt per user or request. Connect to external services through typed tools and MCP servers. Add voice interaction with 12+ speech providers, and measure output quality with built-in evaluation scorers.
|
|
61
|
+
|
|
62
|
+
</details>
|
|
63
|
+
|
|
64
|
+
<details>
|
|
65
|
+
**Workflow automations**
|
|
66
|
+
|
|
67
|
+
Multi-step processes that trigger, route, and complete tasks. Define type-safe steps with Zod-validated inputs and outputs, then compose them with sequential chaining, parallel fan-out, conditional branching, loops, and iteration with concurrency control. Suspend workflows mid-execution to wait for human approval or external events, then resume from where they left off. Nest workflows inside other workflows for reusable sub-pipelines.
|
|
68
|
+
|
|
69
|
+
</details>
|
|
70
|
+
|
|
71
|
+
<details>
|
|
72
|
+
**Decision-support tools**
|
|
73
|
+
|
|
74
|
+
Systems that analyze data and provide actionable recommendations. Compose multiple tools so agents can query databases, call APIs, and run analysis functions in a single interaction. Use structured output with Zod schemas to return validated, typed results. Coordinate specialist agents through supervisor patterns, with task-completion scoring to verify recommendation quality before finalizing. Add human-in-the-loop gates for high-stakes decisions.
|
|
75
|
+
|
|
76
|
+
</details>
|
|
77
|
+
|
|
78
|
+
<details>
|
|
79
|
+
**AI-powered applications**
|
|
80
|
+
|
|
81
|
+
Products that combine language understanding, reasoning, and action. Orchestrate multiple agents with supervisor delegation and multi-agent networks. Deploy to any Node.js runtime, cloud provider, or framework — Vercel, Cloudflare, Next.js, Astro, and more. Monitor production behavior with AI-specific tracing that captures token usage, latency, and decision paths. Choose from 10+ storage providers and configure composite backends optimized per workload. Test everything interactively in Studio before shipping.
|
|
82
|
+
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
Browse [templates](https://mastra.ai/templates) from Mastra and the community to see working examples of these use cases.
|
|
86
|
+
|
|
87
|
+
[YouTube video player](https://www.youtube-nocookie.com/embed/1qnmnRICX50)
|
|
@@ -5,7 +5,7 @@ Import your Mastra project to [Mastra Cloud](https://cloud.mastra.ai) to use [St
|
|
|
5
5
|
## Before you begin
|
|
6
6
|
|
|
7
7
|
- [Sign in](https://cloud.mastra.ai) to Cloud
|
|
8
|
-
- Push your [Mastra project](https://mastra.ai/docs
|
|
8
|
+
- Push your [Mastra project](https://mastra.ai/docs) to GitHub
|
|
9
9
|
|
|
10
10
|
## Options
|
|
11
11
|
|
|
@@ -170,6 +170,15 @@ const memory = new Memory({
|
|
|
170
170
|
})
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
+
### Token counting cache
|
|
174
|
+
|
|
175
|
+
OM caches tiktoken part estimates in message metadata to reduce repeat counting work during threshold checks and buffering decisions.
|
|
176
|
+
|
|
177
|
+
- Per-part estimates are stored on `part.providerMetadata.mastra` and reused on subsequent passes when the cache version/tokenizer source matches.
|
|
178
|
+
- For string-only message content (without parts), OM uses a message-level metadata fallback cache.
|
|
179
|
+
- Message and conversation overhead are still recalculated on every pass. The cache only stores payload estimates, so counting semantics stay the same.
|
|
180
|
+
- `data-*` and `reasoning` parts are still skipped and are not cached.
|
|
181
|
+
|
|
173
182
|
## Async Buffering
|
|
174
183
|
|
|
175
184
|
Without async buffering, the Observer runs synchronously when the message threshold is reached — the agent pauses mid-conversation while the Observer LLM call completes. With async buffering (enabled by default), observations are pre-computed in the background as the conversation grows. When the threshold is hit, buffered observations activate instantly with no pause.
|
|
@@ -147,8 +147,24 @@ Supported embedding models:
|
|
|
147
147
|
|
|
148
148
|
- **OpenAI**: `text-embedding-3-small`, `text-embedding-3-large`, `text-embedding-ada-002`
|
|
149
149
|
- **Google**: `gemini-embedding-001`
|
|
150
|
+
- **OpenRouter**: Access embedding models from various providers
|
|
150
151
|
|
|
151
|
-
|
|
152
|
+
```ts
|
|
153
|
+
import { Agent } from '@mastra/core/agent'
|
|
154
|
+
import { Memory } from '@mastra/memory'
|
|
155
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
156
|
+
|
|
157
|
+
const agent = new Agent({
|
|
158
|
+
memory: new Memory({
|
|
159
|
+
embedder: new ModelRouterEmbeddingModel({
|
|
160
|
+
providerId: 'openrouter',
|
|
161
|
+
modelId: 'openai/text-embedding-3-small',
|
|
162
|
+
}),
|
|
163
|
+
}),
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The model router automatically handles API key detection from environment variables (`OPENAI_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`, `OPENROUTER_API_KEY`).
|
|
152
168
|
|
|
153
169
|
### Using AI SDK Packages
|
|
154
170
|
|
|
@@ -117,13 +117,15 @@ const workspace = new Workspace({
|
|
|
117
117
|
|
|
118
118
|
## How agents use skills
|
|
119
119
|
|
|
120
|
-
When
|
|
120
|
+
When a workspace has skills configured, agents automatically get access to skill tools. Available skills are listed in the system message so the agent knows what's available, and the agent can load any skill on demand.
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
The agent has three skill tools:
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
- **`skill`** — Loads a skill's full instructions and returns them in the tool result. The agent calls this whenever it needs a skill's guidance.
|
|
125
|
+
- **`skill_read`** — Reads a file from a skill's `references/`, `scripts/`, or `assets/` directory.
|
|
126
|
+
- **`skill_search`** — Searches across all skill content. Uses BM25 or vector search when configured, otherwise falls back to simple text matching.
|
|
127
|
+
|
|
128
|
+
This design is stateless — there is no activation state to track. If the skill instructions leave the conversation context (due to context window limits or compaction), the agent can call `skill` again to reload them.
|
|
127
129
|
|
|
128
130
|
## Skill search
|
|
129
131
|
|