@mastra/mcp-docs-server 1.0.0-beta.13 → 1.0.0-beta.14
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/organized/changelogs/%40mastra%2Fagent-builder.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +98 -98
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +30 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +171 -171
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -2
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +94 -94
- package/.docs/organized/changelogs/create-mastra.md +3 -3
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/agent-v6.md +151 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +2 -3
- package/.docs/raw/agents/agent-approval.mdx +5 -6
- package/.docs/raw/agents/agent-memory.mdx +22 -30
- package/.docs/raw/agents/guardrails.mdx +60 -50
- package/.docs/raw/agents/networks.mdx +8 -12
- package/.docs/raw/agents/overview.mdx +39 -23
- package/.docs/raw/agents/processors.mdx +20 -19
- package/.docs/raw/agents/structured-output.mdx +11 -7
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/deployment/mastra-server.mdx +3 -3
- package/.docs/raw/deployment/overview.mdx +7 -0
- package/.docs/raw/deployment/web-framework.mdx +4 -6
- package/.docs/raw/evals/custom-scorers.mdx +9 -6
- package/.docs/raw/evals/overview.mdx +3 -6
- package/.docs/raw/evals/running-in-ci.mdx +2 -2
- package/.docs/raw/getting-started/manual-install.mdx +20 -20
- package/.docs/raw/getting-started/mcp-docs-server.mdx +2 -2
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +4 -4
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +30 -30
- package/.docs/raw/guides/build-your-ui/assistant-ui.mdx +8 -8
- package/.docs/raw/guides/build-your-ui/copilotkit.mdx +11 -11
- package/.docs/raw/guides/deployment/amazon-ec2.mdx +9 -9
- package/.docs/raw/guides/deployment/aws-lambda.mdx +11 -11
- package/.docs/raw/guides/deployment/azure-app-services.mdx +2 -2
- package/.docs/raw/guides/deployment/cloudflare-deployer.mdx +5 -6
- package/.docs/raw/guides/deployment/digital-ocean.mdx +10 -10
- package/.docs/raw/guides/deployment/index.mdx +1 -1
- package/.docs/raw/guides/deployment/inngest.mdx +386 -0
- package/.docs/raw/guides/deployment/netlify-deployer.mdx +4 -4
- package/.docs/raw/guides/deployment/vercel-deployer.mdx +5 -6
- package/.docs/raw/guides/getting-started/astro.mdx +292 -451
- package/.docs/raw/guides/getting-started/express.mdx +7 -7
- package/.docs/raw/guides/getting-started/hono.mdx +18 -18
- package/.docs/raw/guides/getting-started/next-js.mdx +19 -20
- package/.docs/raw/guides/getting-started/quickstart.mdx +4 -4
- package/.docs/raw/guides/getting-started/sveltekit.mdx +238 -409
- package/.docs/raw/guides/getting-started/vite-react.mdx +21 -21
- package/.docs/raw/guides/guide/ai-recruiter.mdx +10 -10
- package/.docs/raw/guides/guide/chef-michel.mdx +9 -11
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +15 -15
- package/.docs/raw/guides/guide/research-assistant.mdx +13 -13
- package/.docs/raw/guides/guide/stock-agent.mdx +5 -5
- package/.docs/raw/guides/guide/web-search.mdx +8 -8
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +7 -7
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +2 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +0 -2
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +21 -23
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mastra-cloud/setting-up.mdx +6 -2
- package/.docs/raw/mcp/overview.mdx +31 -13
- package/.docs/raw/mcp/publishing-mcp-server.mdx +2 -2
- package/.docs/raw/memory/memory-processors.mdx +9 -9
- package/.docs/raw/memory/message-history.mdx +69 -0
- package/.docs/raw/memory/overview.mdx +34 -76
- package/.docs/raw/memory/semantic-recall.mdx +58 -49
- package/.docs/raw/memory/storage.mdx +188 -0
- package/.docs/raw/memory/working-memory.mdx +7 -7
- package/.docs/raw/observability/logging.mdx +9 -10
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/default.mdx +3 -3
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +1 -2
- package/.docs/raw/observability/tracing/overview.mdx +23 -25
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/rag/chunking-and-embedding.mdx +6 -6
- package/.docs/raw/rag/graph-rag.mdx +7 -7
- package/.docs/raw/rag/overview.mdx +1 -1
- package/.docs/raw/rag/retrieval.mdx +21 -22
- package/.docs/raw/rag/vector-databases.mdx +22 -22
- package/.docs/raw/reference/agents/agent.mdx +3 -3
- package/.docs/raw/reference/agents/generate.mdx +1 -1
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +2 -2
- package/.docs/raw/reference/agents/getMemory.mdx +2 -2
- package/.docs/raw/reference/agents/getModel.mdx +2 -2
- package/.docs/raw/reference/agents/getTools.mdx +2 -2
- package/.docs/raw/reference/agents/getVoice.mdx +2 -2
- package/.docs/raw/reference/agents/listAgents.mdx +2 -2
- package/.docs/raw/reference/agents/listScorers.mdx +2 -2
- package/.docs/raw/reference/agents/listTools.mdx +2 -2
- package/.docs/raw/reference/agents/listWorkflows.mdx +2 -2
- package/.docs/raw/reference/agents/network.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +6 -6
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +2 -2
- package/.docs/raw/reference/auth/auth0.mdx +1 -2
- package/.docs/raw/reference/auth/clerk.mdx +1 -2
- package/.docs/raw/reference/auth/firebase.mdx +2 -4
- package/.docs/raw/reference/auth/jwt.mdx +1 -2
- package/.docs/raw/reference/auth/supabase.mdx +1 -2
- package/.docs/raw/reference/auth/workos.mdx +1 -2
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +9 -9
- package/.docs/raw/reference/client-js/agents.mdx +1 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/core/getAgent.mdx +1 -1
- package/.docs/raw/reference/core/getAgentById.mdx +1 -1
- package/.docs/raw/reference/core/getDeployer.mdx +1 -1
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServer.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServerById.mdx +1 -1
- package/.docs/raw/reference/core/getMemory.mdx +2 -2
- package/.docs/raw/reference/core/getServer.mdx +1 -1
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getStoredAgentById.mdx +3 -3
- package/.docs/raw/reference/core/getTelemetry.mdx +1 -1
- package/.docs/raw/reference/core/getVector.mdx +1 -1
- package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
- package/.docs/raw/reference/core/listAgents.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/listMCPServers.mdx +1 -1
- package/.docs/raw/reference/core/listMemory.mdx +2 -2
- package/.docs/raw/reference/core/listStoredAgents.mdx +4 -4
- package/.docs/raw/reference/core/listVectors.mdx +1 -1
- package/.docs/raw/reference/core/listWorkflows.mdx +1 -1
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +2 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/cloudflare.mdx +1 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -1
- package/.docs/raw/reference/deployer/vercel.mdx +2 -4
- package/.docs/raw/reference/evals/answer-relevancy.mdx +1 -1
- package/.docs/raw/reference/evals/answer-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/bias.mdx +1 -1
- package/.docs/raw/reference/evals/completeness.mdx +1 -1
- package/.docs/raw/reference/evals/content-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/context-precision.mdx +1 -1
- package/.docs/raw/reference/evals/faithfulness.mdx +1 -1
- package/.docs/raw/reference/evals/hallucination.mdx +1 -1
- package/.docs/raw/reference/evals/keyword-coverage.mdx +1 -1
- package/.docs/raw/reference/evals/prompt-alignment.mdx +7 -7
- package/.docs/raw/reference/evals/textual-difference.mdx +1 -1
- package/.docs/raw/reference/evals/tone-consistency.mdx +1 -1
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +10 -10
- package/.docs/raw/reference/evals/toxicity.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +6 -7
- package/.docs/raw/reference/memory/createThread.mdx +2 -2
- package/.docs/raw/reference/memory/deleteMessages.mdx +2 -2
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +2 -2
- package/.docs/raw/reference/memory/memory-class.mdx +3 -3
- package/.docs/raw/reference/memory/query.mdx +2 -2
- package/.docs/raw/reference/memory/recall.mdx +2 -2
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +1 -1
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +2 -2
- package/.docs/raw/reference/processors/language-detector.mdx +2 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +2 -2
- package/.docs/raw/reference/processors/moderation-processor.mdx +3 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +3 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +13 -13
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +2 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +2 -2
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +3 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +2 -2
- package/.docs/raw/reference/processors/working-memory-processor.mdx +3 -3
- package/.docs/raw/reference/rag/chunk.mdx +1 -1
- package/.docs/raw/reference/rag/extract-params.mdx +2 -2
- package/.docs/raw/reference/rag/metadata-filters.mdx +7 -7
- package/.docs/raw/reference/server/create-route.mdx +13 -13
- package/.docs/raw/reference/server/express-adapter.mdx +6 -7
- package/.docs/raw/reference/server/hono-adapter.mdx +6 -7
- package/.docs/raw/reference/server/mastra-server.mdx +20 -20
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +3 -3
- package/.docs/raw/reference/storage/cloudflare.mdx +2 -2
- package/.docs/raw/reference/storage/convex.mdx +6 -6
- package/.docs/raw/reference/storage/dynamodb.mdx +4 -4
- package/.docs/raw/reference/storage/lance.mdx +3 -3
- package/.docs/raw/reference/storage/libsql.mdx +69 -54
- package/.docs/raw/reference/storage/mongodb.mdx +80 -7
- package/.docs/raw/reference/storage/mssql.mdx +4 -4
- package/.docs/raw/{memory → reference}/storage/overview.mdx +12 -110
- package/.docs/raw/reference/storage/postgresql.mdx +78 -7
- package/.docs/raw/reference/storage/upstash.mdx +74 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +5 -5
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/resumeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +4 -4
- package/.docs/raw/reference/templates/overview.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +1 -4
- package/.docs/raw/reference/tools/vector-query-tool.mdx +1 -1
- package/.docs/raw/reference/vectors/astra.mdx +3 -3
- package/.docs/raw/reference/vectors/chroma.mdx +3 -3
- package/.docs/raw/reference/vectors/convex.mdx +12 -12
- package/.docs/raw/reference/vectors/couchbase.mdx +5 -5
- package/.docs/raw/reference/vectors/duckdb.mdx +10 -10
- package/.docs/raw/reference/vectors/elasticsearch.mdx +4 -4
- package/.docs/raw/reference/vectors/lance.mdx +4 -4
- package/.docs/raw/reference/vectors/libsql.mdx +61 -11
- package/.docs/raw/reference/vectors/mongodb.mdx +58 -5
- package/.docs/raw/reference/vectors/pg.mdx +53 -6
- package/.docs/raw/reference/vectors/pinecone.mdx +3 -3
- package/.docs/raw/reference/vectors/qdrant.mdx +3 -3
- package/.docs/raw/reference/vectors/s3vectors.mdx +6 -6
- package/.docs/raw/reference/vectors/turbopuffer.mdx +4 -4
- package/.docs/raw/reference/vectors/upstash.mdx +55 -6
- package/.docs/raw/reference/vectors/vectorize.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +1 -3
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/start.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +5 -5
- package/.docs/raw/reference/workflows/run.mdx +1 -1
- package/.docs/raw/reference/workflows/step.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +6 -6
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +7 -7
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow.mdx +3 -3
- package/.docs/raw/server/auth/auth0.mdx +20 -14
- package/.docs/raw/server/auth/clerk.mdx +16 -9
- package/.docs/raw/server/auth/firebase.mdx +21 -15
- package/.docs/raw/server/auth/jwt.mdx +14 -7
- package/.docs/raw/server/auth/supabase.mdx +16 -9
- package/.docs/raw/server/auth/workos.mdx +19 -13
- package/.docs/raw/server/custom-adapters.mdx +10 -10
- package/.docs/raw/server/custom-api-routes.mdx +2 -4
- package/.docs/raw/server/mastra-client.mdx +24 -13
- package/.docs/raw/server/mastra-server.mdx +3 -3
- package/.docs/raw/server/middleware.mdx +7 -7
- package/.docs/raw/server/request-context.mdx +31 -30
- package/.docs/raw/server/server-adapters.mdx +6 -6
- package/.docs/raw/streaming/events.mdx +14 -7
- package/.docs/raw/streaming/overview.mdx +21 -10
- package/.docs/raw/streaming/tool-streaming.mdx +6 -6
- package/.docs/raw/streaming/workflow-streaming.mdx +6 -8
- package/.docs/raw/tools-mcp/advanced-usage.mdx +2 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +31 -12
- package/.docs/raw/tools-mcp/overview.mdx +9 -10
- package/.docs/raw/voice/overview.mdx +1 -1
- package/.docs/raw/workflows/agents-and-tools.mdx +28 -19
- package/.docs/raw/workflows/control-flow.mdx +27 -40
- package/.docs/raw/workflows/error-handling.mdx +15 -22
- package/.docs/raw/workflows/human-in-the-loop.mdx +6 -7
- package/.docs/raw/workflows/inngest-workflow.mdx +8 -9
- package/.docs/raw/workflows/input-data-mapping.mdx +7 -7
- package/.docs/raw/workflows/overview.mdx +33 -22
- package/.docs/raw/workflows/snapshots.mdx +14 -44
- package/.docs/raw/workflows/suspend-and-resume.mdx +7 -7
- package/.docs/raw/workflows/time-travel.mdx +16 -16
- package/.docs/raw/workflows/workflow-state.mdx +5 -8
- package/CHANGELOG.md +9 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/stdio.js +53 -0
- package/package.json +4 -4
- package/.docs/raw/memory/conversation-history.mdx +0 -24
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +0 -140
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +0 -150
- package/.docs/raw/memory/storage/memory-with-pg.mdx +0 -138
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +0 -146
- package/.docs/raw/memory/threads-and-resources.mdx +0 -95
|
@@ -44,7 +44,7 @@ When using `agent.network()` for multi-agent collaboration, additional event typ
|
|
|
44
44
|
|
|
45
45
|
Iterate over the `stream` with a `for await` loop to inspect all emitted event chunks.
|
|
46
46
|
|
|
47
|
-
```typescript
|
|
47
|
+
```typescript
|
|
48
48
|
const testAgent = mastra.getAgent("testAgent");
|
|
49
49
|
|
|
50
50
|
const stream = await testAgent.stream([
|
|
@@ -56,7 +56,11 @@ for await (const chunk of stream) {
|
|
|
56
56
|
}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
:::info
|
|
60
|
+
|
|
61
|
+
Visit [Agent.stream()](/reference/v1/streaming/agents/stream) for more information.
|
|
62
|
+
|
|
63
|
+
:::
|
|
60
64
|
|
|
61
65
|
### Example agent output
|
|
62
66
|
|
|
@@ -91,7 +95,7 @@ Below is an example of events that may be emitted. Each event always includes a
|
|
|
91
95
|
|
|
92
96
|
Iterate over the `stream` with a `for await` loop to inspect all emitted event chunks.
|
|
93
97
|
|
|
94
|
-
```typescript {5,11}
|
|
98
|
+
```typescript {5,11}
|
|
95
99
|
const testWorkflow = mastra.getWorkflow("testWorkflow");
|
|
96
100
|
|
|
97
101
|
const run = await testWorkflow.createRun();
|
|
@@ -136,7 +140,7 @@ Below is an example of events that may be emitted. Each event always includes a
|
|
|
136
140
|
|
|
137
141
|
When using multi-agent collaboration with `agent.network()`, iterate over the stream to track how tasks are delegated and executed across agents, workflows, and tools.
|
|
138
142
|
|
|
139
|
-
```typescript {3,5}
|
|
143
|
+
```typescript {3,5}
|
|
140
144
|
const networkAgent = mastra.getAgent("networkAgent");
|
|
141
145
|
|
|
142
146
|
const networkStream = await networkAgent.network(
|
|
@@ -148,7 +152,11 @@ for await (const chunk of networkStream) {
|
|
|
148
152
|
}
|
|
149
153
|
```
|
|
150
154
|
|
|
151
|
-
|
|
155
|
+
:::info
|
|
156
|
+
|
|
157
|
+
Visit [Agent.network()](/reference/v1/agents/network) for more information.
|
|
158
|
+
|
|
159
|
+
:::
|
|
152
160
|
|
|
153
161
|
### Example network output
|
|
154
162
|
|
|
@@ -195,14 +203,13 @@ Network streams emit events that track the orchestration flow. Each iteration be
|
|
|
195
203
|
}
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
|
-
// ...more events
|
|
199
206
|
```
|
|
200
207
|
|
|
201
208
|
### Filtering network events
|
|
202
209
|
|
|
203
210
|
You can filter events by type to track specific aspects of the network execution:
|
|
204
211
|
|
|
205
|
-
```typescript {5-8,11-13,16-18}
|
|
212
|
+
```typescript {5-8,11-13,16-18}
|
|
206
213
|
const networkStream = await networkAgent.network(
|
|
207
214
|
"Analyze data and create visualization",
|
|
208
215
|
);
|
|
@@ -22,7 +22,7 @@ You can pass a single string for simple prompts, an array of strings when provid
|
|
|
22
22
|
|
|
23
23
|
A `textStream` breaks the response into chunks as it's generated, allowing output to stream progressively instead of arriving all at once. Iterate over the `textStream` using a `for await` loop to inspect each stream chunk.
|
|
24
24
|
|
|
25
|
-
```typescript {3,7}
|
|
25
|
+
```typescript {3,7}
|
|
26
26
|
const testAgent = mastra.getAgent("testAgent");
|
|
27
27
|
|
|
28
28
|
const stream = await testAgent.stream([
|
|
@@ -34,7 +34,11 @@ for await (const chunk of stream.textStream) {
|
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
:::info
|
|
38
|
+
|
|
39
|
+
Visit [Agent.stream()](/reference/v1/streaming/agents/stream) for more information.
|
|
40
|
+
|
|
41
|
+
:::
|
|
38
42
|
|
|
39
43
|
### Output from `Agent.stream()`
|
|
40
44
|
|
|
@@ -62,7 +66,7 @@ AI SDK v5 uses `LanguageModelV2` for the model providers. If you are getting an
|
|
|
62
66
|
|
|
63
67
|
For integration with AI SDK v5, use the `toAISdkV5Stream()` utility from `@mastra/ai-sdk` to convert Mastra streams to AI SDK-compatible format:
|
|
64
68
|
|
|
65
|
-
```typescript {2,9-12}
|
|
69
|
+
```typescript {2,9-12}
|
|
66
70
|
import { toAISdkV5Stream } from "@mastra/ai-sdk";
|
|
67
71
|
|
|
68
72
|
const testAgent = mastra.getAgent("testAgent");
|
|
@@ -79,7 +83,7 @@ const aiSDKStream = toAISdkV5Stream(stream, { from: "agent" });
|
|
|
79
83
|
|
|
80
84
|
For converting messages to AI SDK v5 format, use the `toAISdkV5Messages()` utility from `@mastra/ai-sdk/ui`:
|
|
81
85
|
|
|
82
|
-
```typescript {1,4}
|
|
86
|
+
```typescript {1,4}
|
|
83
87
|
import { toAISdkV5Messages } from "@mastra/ai-sdk/ui";
|
|
84
88
|
|
|
85
89
|
const messages = [{ role: "user", content: "Hello" }];
|
|
@@ -92,7 +96,7 @@ The `network()` method enables multi-agent collaboration by executing a network
|
|
|
92
96
|
|
|
93
97
|
> **Note**: This method is experimental and requires memory to be configured on the agent.
|
|
94
98
|
|
|
95
|
-
```typescript {3,5-7}
|
|
99
|
+
```typescript {3,5-7}
|
|
96
100
|
const testAgent = mastra.getAgent("testAgent");
|
|
97
101
|
|
|
98
102
|
const networkStream = await testAgent.network("Help me organize my day");
|
|
@@ -102,7 +106,11 @@ for await (const chunk of networkStream) {
|
|
|
102
106
|
}
|
|
103
107
|
```
|
|
104
108
|
|
|
105
|
-
|
|
109
|
+
:::info
|
|
110
|
+
|
|
111
|
+
Visit [Agent.network()](/reference/v1/agents/network) for more information.
|
|
112
|
+
|
|
113
|
+
:::
|
|
106
114
|
|
|
107
115
|
#### Network stream properties
|
|
108
116
|
|
|
@@ -112,7 +120,7 @@ The network stream provides access to execution information:
|
|
|
112
120
|
- **`networkStream.result`**: Promise resolving to the complete execution results
|
|
113
121
|
- **`networkStream.usage`**: Promise resolving to token usage information
|
|
114
122
|
|
|
115
|
-
```typescript {9-11}
|
|
123
|
+
```typescript {9-11}
|
|
116
124
|
const testAgent = mastra.getAgent("testAgent");
|
|
117
125
|
|
|
118
126
|
const networkStream = await testAgent.network(
|
|
@@ -136,7 +144,7 @@ Streaming from a workflow returns a sequence of structured events describing the
|
|
|
136
144
|
|
|
137
145
|
The `stream()` method returns a `ReadableStream` of events directly.
|
|
138
146
|
|
|
139
|
-
```typescript {3,9}
|
|
147
|
+
```typescript {3,9}
|
|
140
148
|
const run = await testWorkflow.createRun();
|
|
141
149
|
|
|
142
150
|
const stream = await run.stream({
|
|
@@ -150,14 +158,17 @@ for await (const chunk of stream) {
|
|
|
150
158
|
}
|
|
151
159
|
```
|
|
152
160
|
|
|
153
|
-
|
|
161
|
+
:::info
|
|
162
|
+
|
|
163
|
+
Visit [Run.stream()](/reference/v1/streaming/workflows/stream) for more information.
|
|
164
|
+
|
|
165
|
+
:::
|
|
154
166
|
|
|
155
167
|
### Output from `Run.stream()`
|
|
156
168
|
|
|
157
169
|
The event structure includes `runId` and `from` at the top level, making it easier to identify and track workflow runs without digging into the payload.
|
|
158
170
|
|
|
159
171
|
```typescript
|
|
160
|
-
// ...
|
|
161
172
|
{
|
|
162
173
|
type: 'workflow-start',
|
|
163
174
|
runId: '1eeaf01a-d2bf-4e3f-8d1b-027795ccd3df',
|
|
@@ -18,7 +18,7 @@ By combining writable tool streams with agent streaming, you gain fine grained c
|
|
|
18
18
|
|
|
19
19
|
Agent streaming can be combined with tool calls, allowing tool outputs to be written directly into the agent’s streaming response. This makes it possible to surface tool activity as part of the overall interaction.
|
|
20
20
|
|
|
21
|
-
```typescript {2,9}
|
|
21
|
+
```typescript {2,9}
|
|
22
22
|
import { Agent } from "@mastra/core/agent";
|
|
23
23
|
import { testTool } from "../tools/test-tool";
|
|
24
24
|
|
|
@@ -41,7 +41,7 @@ You must `await` the call to `writer.write()` or else you will lock the stream a
|
|
|
41
41
|
|
|
42
42
|
:::
|
|
43
43
|
|
|
44
|
-
```typescript {4,7,14}
|
|
44
|
+
```typescript {4,7,14}
|
|
45
45
|
import { createTool } from "@mastra/core/tools";
|
|
46
46
|
|
|
47
47
|
export const testTool = createTool({
|
|
@@ -70,7 +70,7 @@ export const testTool = createTool({
|
|
|
70
70
|
You can also use `writer.custom()` if you want to emit top level stream chunks, This useful and relevant when
|
|
71
71
|
integrating with UI Frameworks
|
|
72
72
|
|
|
73
|
-
```typescript {4,7,14}
|
|
73
|
+
```typescript {4,7,14}
|
|
74
74
|
import { createTool } from "@mastra/core/tools";
|
|
75
75
|
|
|
76
76
|
export const testTool = createTool({
|
|
@@ -100,7 +100,7 @@ export const testTool = createTool({
|
|
|
100
100
|
|
|
101
101
|
Events written to the stream are included in the emitted chunks. These chunks can be inspected to access any custom fields, such as event types, intermediate values, or tool-specific data.
|
|
102
102
|
|
|
103
|
-
```typescript
|
|
103
|
+
```typescript
|
|
104
104
|
const stream = await testAgent.stream([
|
|
105
105
|
"What is the weather in London?",
|
|
106
106
|
"Use the testTool",
|
|
@@ -119,7 +119,7 @@ Tools support lifecycle hooks that allow you to monitor different stages of tool
|
|
|
119
119
|
|
|
120
120
|
### Example: Using onInputAvailable and onOutput
|
|
121
121
|
|
|
122
|
-
```typescript
|
|
122
|
+
```typescript
|
|
123
123
|
import { createTool } from "@mastra/core/tools";
|
|
124
124
|
import { z } from "zod";
|
|
125
125
|
|
|
@@ -161,7 +161,7 @@ For detailed documentation on all lifecycle hooks, see the [createTool() referen
|
|
|
161
161
|
|
|
162
162
|
Pipe an agent's `fullStream` to the tool's `writer`. This streams partial output, and Mastra automatically aggregates the agent's usage into the tool run.
|
|
163
163
|
|
|
164
|
-
```typescript
|
|
164
|
+
```typescript
|
|
165
165
|
import { createTool } from "@mastra/core/tools";
|
|
166
166
|
import { z } from "zod";
|
|
167
167
|
|
|
@@ -24,13 +24,12 @@ You must `await` the call to `writer.write(...)` or else you will lock the strea
|
|
|
24
24
|
|
|
25
25
|
:::
|
|
26
26
|
|
|
27
|
-
```typescript {5,
|
|
27
|
+
```typescript {5,7,14}
|
|
28
28
|
import { createStep } from "@mastra/core/workflows";
|
|
29
29
|
|
|
30
30
|
export const testStep = createStep({
|
|
31
|
-
// ...
|
|
32
31
|
execute: async ({ inputData, writer }) => {
|
|
33
|
-
|
|
32
|
+
const { value } = inputData;
|
|
34
33
|
|
|
35
34
|
await writer?.write({
|
|
36
35
|
type: "custom-event",
|
|
@@ -39,7 +38,7 @@ export const testStep = createStep({
|
|
|
39
38
|
|
|
40
39
|
const response = await fetch(...);
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
await writer?.write({
|
|
43
42
|
type: "custom-event",
|
|
44
43
|
status: "success"
|
|
45
44
|
});
|
|
@@ -55,7 +54,7 @@ export const testStep = createStep({
|
|
|
55
54
|
|
|
56
55
|
Events written to the stream are included in the emitted chunks. These chunks can be inspected to access any custom fields, such as event types, intermediate values, or step-specific data.
|
|
57
56
|
|
|
58
|
-
```typescript
|
|
57
|
+
```typescript
|
|
59
58
|
const testWorkflow = mastra.getWorkflow("testWorkflow");
|
|
60
59
|
|
|
61
60
|
const run = await testWorkflow.createRun();
|
|
@@ -86,7 +85,7 @@ if (result!.status === "suspended") {
|
|
|
86
85
|
|
|
87
86
|
If a workflow stream is closed or interrupted for any reason, you can resume it with the `resumeStream` method. This will return a new `ReadableStream` that you can use to observe the workflow events.
|
|
88
87
|
|
|
89
|
-
```typescript
|
|
88
|
+
```typescript
|
|
90
89
|
const newStream = await run.resumeStream();
|
|
91
90
|
|
|
92
91
|
for await (const chunk of newStream) {
|
|
@@ -98,12 +97,11 @@ for await (const chunk of newStream) {
|
|
|
98
97
|
|
|
99
98
|
Pipe an agent's `textStream` to the workflow step's `writer`. This streams partial output, and Mastra automatically aggregates the agent's usage into the workflow run.
|
|
100
99
|
|
|
101
|
-
```typescript
|
|
100
|
+
```typescript
|
|
102
101
|
import { createStep } from "@mastra/core/workflows";
|
|
103
102
|
import { z } from "zod";
|
|
104
103
|
|
|
105
104
|
export const testStep = createStep({
|
|
106
|
-
// ...
|
|
107
105
|
execute: async ({ inputData, mastra, writer }) => {
|
|
108
106
|
const { city } = inputData;
|
|
109
107
|
|
|
@@ -82,13 +82,13 @@ Mastra maintains compatibility with the tool format used by the Vercel AI SDK (`
|
|
|
82
82
|
|
|
83
83
|
First, ensure you have the `ai` package installed:
|
|
84
84
|
|
|
85
|
-
```bash npm2yarn
|
|
85
|
+
```bash npm2yarn
|
|
86
86
|
npm install ai
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Here's an example of a tool defined using the Vercel AI SDK format:
|
|
90
90
|
|
|
91
|
-
```typescript title="src/mastra/tools/vercelWeatherTool.ts"
|
|
91
|
+
```typescript title="src/mastra/tools/vercelWeatherTool.ts"
|
|
92
92
|
import { tool } from "ai";
|
|
93
93
|
import { z } from "zod";
|
|
94
94
|
|
|
@@ -29,7 +29,7 @@ npm install @mastra/mcp@beta
|
|
|
29
29
|
|
|
30
30
|
The `MCPClient` connects Mastra primitives to external MCP servers, which can be local packages (invoked using `npx`) or remote HTTP(S) endpoints. Each server must be configured with either a `command` or a `url`, depending on how it's hosted.
|
|
31
31
|
|
|
32
|
-
```typescript title="src/mastra/mcp/test-mcp-client.ts"
|
|
32
|
+
```typescript title="src/mastra/mcp/test-mcp-client.ts"
|
|
33
33
|
import { MCPClient } from "@mastra/mcp";
|
|
34
34
|
|
|
35
35
|
export const testMcpClient = new MCPClient({
|
|
@@ -48,13 +48,17 @@ export const testMcpClient = new MCPClient({
|
|
|
48
48
|
});
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
:::info
|
|
52
|
+
|
|
53
|
+
Visit [MCPClient](/reference/v1/tools/mcp-client) for a full list of configuration options.
|
|
54
|
+
|
|
55
|
+
:::
|
|
52
56
|
|
|
53
57
|
## Using `MCPClient` with an agent
|
|
54
58
|
|
|
55
59
|
To use tools from an MCP server in an agent, import your `MCPClient` and call `.listTools()` in the `tools` parameter. This loads from the defined MCP servers, making them available to the agent.
|
|
56
60
|
|
|
57
|
-
```typescript {3,15} title="src/mastra/agents/test-agent.ts"
|
|
61
|
+
```typescript {3,15} title="src/mastra/agents/test-agent.ts"
|
|
58
62
|
import { Agent } from "@mastra/core/agent";
|
|
59
63
|
|
|
60
64
|
import { testMcpClient } from "../mcp/test-mcp-client";
|
|
@@ -74,13 +78,17 @@ export const testAgent = new Agent({
|
|
|
74
78
|
});
|
|
75
79
|
```
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
:::info
|
|
82
|
+
|
|
83
|
+
Visit [Agent Class](/reference/v1/agents/agent) for a full list of configuration options.
|
|
84
|
+
|
|
85
|
+
:::
|
|
78
86
|
|
|
79
87
|
## Configuring `MCPServer`
|
|
80
88
|
|
|
81
89
|
To expose agents, tools, and workflows from your Mastra application to external systems over HTTP(S) use the `MCPServer` class. This makes them accessible to any system or agent that supports the protocol.
|
|
82
90
|
|
|
83
|
-
```typescript title="src/mastra/mcp/test-mcp-server.ts"
|
|
91
|
+
```typescript title="src/mastra/mcp/test-mcp-server.ts"
|
|
84
92
|
import { MCPServer } from "@mastra/mcp";
|
|
85
93
|
|
|
86
94
|
import { testAgent } from "../agents/test-agent";
|
|
@@ -97,7 +105,11 @@ export const testMcpServer = new MCPServer({
|
|
|
97
105
|
});
|
|
98
106
|
```
|
|
99
107
|
|
|
100
|
-
|
|
108
|
+
:::info
|
|
109
|
+
|
|
110
|
+
Visit [MCPServer](/reference/v1/tools/mcp-server) for a full list of configuration options.
|
|
111
|
+
|
|
112
|
+
:::
|
|
101
113
|
|
|
102
114
|
### Serverless deployments
|
|
103
115
|
|
|
@@ -109,13 +121,12 @@ export const testMcpServer = new MCPServer({
|
|
|
109
121
|
|
|
110
122
|
To make an MCP server available to other systems or agents that support the protocol, register it in the main `Mastra` instance using `mcpServers`.
|
|
111
123
|
|
|
112
|
-
```typescript title="src/mastra/index.ts"
|
|
124
|
+
```typescript title="src/mastra/index.ts"
|
|
113
125
|
import { Mastra } from "@mastra/core";
|
|
114
126
|
|
|
115
127
|
import { testMcpServer } from "./mcp/test-mcp-server";
|
|
116
128
|
|
|
117
129
|
export const mastra = new Mastra({
|
|
118
|
-
// ...
|
|
119
130
|
mcpServers: {
|
|
120
131
|
testMcpServer, // Registry key: 'testMcpServer'
|
|
121
132
|
},
|
|
@@ -141,9 +152,13 @@ mastra.getMCPServerById('test-mcp-server'); // By intrinsic ID
|
|
|
141
152
|
|
|
142
153
|
Use the `.listTools()` method to fetch tools from all configured MCP servers. This is suitable when configuration (such as API keys) is static and consistent across users or requests. Call it once and pass the result to the `tools` property when defining your agent.
|
|
143
154
|
|
|
144
|
-
|
|
155
|
+
:::info
|
|
156
|
+
|
|
157
|
+
Visit [listTools()](/reference/v1/tools/mcp-client#listtools) for more information.
|
|
158
|
+
|
|
159
|
+
:::
|
|
145
160
|
|
|
146
|
-
```typescript {7} title="src/mastra/agents/test-agent.ts"
|
|
161
|
+
```typescript {7} title="src/mastra/agents/test-agent.ts"
|
|
147
162
|
import { Agent } from "@mastra/core/agent";
|
|
148
163
|
|
|
149
164
|
import { testMcpClient } from "../mcp/test-mcp-client";
|
|
@@ -158,7 +173,7 @@ export const testAgent = new Agent({
|
|
|
158
173
|
|
|
159
174
|
Use the `.listToolsets()` method when tool configuration may vary by request or user, such as in a multi-tenant system where each user provides their own API key. This method returns toolsets that can be passed to the `toolsets` option in the agent's `.generate()` or `.stream()` calls.
|
|
160
175
|
|
|
161
|
-
```typescript {5-16,21}
|
|
176
|
+
```typescript {5-16,21}
|
|
162
177
|
import { MCPClient } from "@mastra/mcp";
|
|
163
178
|
import { mastra } from "./mastra";
|
|
164
179
|
|
|
@@ -190,7 +205,11 @@ async function handleRequest(userPrompt: string, userApiKey: string) {
|
|
|
190
205
|
}
|
|
191
206
|
```
|
|
192
207
|
|
|
193
|
-
|
|
208
|
+
:::info
|
|
209
|
+
|
|
210
|
+
Visit [listToolsets()](/reference/v1/tools/mcp-client#listtoolsets) for more information.
|
|
211
|
+
|
|
212
|
+
:::
|
|
194
213
|
|
|
195
214
|
## Connecting to an MCP registry
|
|
196
215
|
|
|
@@ -18,7 +18,7 @@ Each tool typically defines:
|
|
|
18
18
|
|
|
19
19
|
In Mastra, you create tools using the [`createTool`](/reference/v1/tools/create-tool) function from the `@mastra/core/tools` package.
|
|
20
20
|
|
|
21
|
-
```typescript title="src/mastra/tools/weatherInfo.ts"
|
|
21
|
+
```typescript title="src/mastra/tools/weatherInfo.ts"
|
|
22
22
|
import { createTool } from "@mastra/core/tools";
|
|
23
23
|
import { z } from "zod";
|
|
24
24
|
|
|
@@ -58,21 +58,16 @@ To make tools available to an agent, you configure them in the agent's definitio
|
|
|
58
58
|
|
|
59
59
|
Use [RequestContext](/docs/v1/server/request-context) to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
|
|
60
60
|
|
|
61
|
-
```typescript title="src/mastra/tools/test-tool.ts"
|
|
61
|
+
```typescript title="src/mastra/tools/test-tool.ts"
|
|
62
62
|
export type UserTier = {
|
|
63
63
|
"user-tier": "enterprise" | "pro";
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
const advancedTools = () => {
|
|
67
|
-
// ...
|
|
68
|
-
};
|
|
66
|
+
const advancedTools = () => {};
|
|
69
67
|
|
|
70
|
-
const baseTools = () => {
|
|
71
|
-
// ...
|
|
72
|
-
};
|
|
68
|
+
const baseTools = () => {};
|
|
73
69
|
|
|
74
70
|
export const testTool = createTool({
|
|
75
|
-
// ...
|
|
76
71
|
execute: async ({ requestContext }) => {
|
|
77
72
|
const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
|
|
78
73
|
|
|
@@ -81,7 +76,11 @@ export const testTool = createTool({
|
|
|
81
76
|
});
|
|
82
77
|
```
|
|
83
78
|
|
|
84
|
-
|
|
79
|
+
:::info
|
|
80
|
+
|
|
81
|
+
Visit [Request Context](/docs/v1/server/request-context) for more information.
|
|
82
|
+
|
|
83
|
+
:::
|
|
85
84
|
|
|
86
85
|
## Testing with Studio
|
|
87
86
|
|
|
@@ -9,15 +9,14 @@ Workflow steps can call agents to leverage LLM reasoning or call tools for type-
|
|
|
9
9
|
|
|
10
10
|
## Using agents in workflows
|
|
11
11
|
|
|
12
|
-
Use agents in workflow steps when you need reasoning, language generation, or other LLM-based tasks. Call from a step's `execute` function for more control over the agent call (e.g., track
|
|
12
|
+
Use agents in workflow steps when you need reasoning, language generation, or other LLM-based tasks. Call from a step's `execute` function for more control over the agent call (e.g., track message history or return structured output). Compose agents as steps when you don't need to modify how the agent is invoked.
|
|
13
13
|
|
|
14
14
|
### Calling agents
|
|
15
15
|
|
|
16
16
|
Call agents inside a step's `execute` function using `.generate()` or `.stream()`. This lets you modify the agent call and handle the response before passing it to the next step.
|
|
17
17
|
|
|
18
|
-
```typescript {
|
|
18
|
+
```typescript {6-14} title="src/mastra/workflows/test-workflow.ts"
|
|
19
19
|
const step1 = createStep({
|
|
20
|
-
// ...
|
|
21
20
|
execute: async ({ inputData, mastra }) => {
|
|
22
21
|
const { message } = inputData;
|
|
23
22
|
|
|
@@ -45,13 +44,12 @@ Compose an agent as a step using `createStep()` when you don't need to modify th
|
|
|
45
44
|
|
|
46
45
|

|
|
47
46
|
|
|
48
|
-
```typescript {1,3,
|
|
47
|
+
```typescript {1,3,7-12} title="src/mastra/workflows/test-workflow.ts"
|
|
49
48
|
import { testAgent } from "../agents/test-agent";
|
|
50
49
|
|
|
51
50
|
const step1 = createStep(testAgent);
|
|
52
51
|
|
|
53
52
|
export const testWorkflow = createWorkflow({
|
|
54
|
-
// ...
|
|
55
53
|
})
|
|
56
54
|
.map(async ({ inputData }) => {
|
|
57
55
|
const { message } = inputData;
|
|
@@ -64,7 +62,11 @@ export const testWorkflow = createWorkflow({
|
|
|
64
62
|
.commit();
|
|
65
63
|
```
|
|
66
64
|
|
|
67
|
-
|
|
65
|
+
:::info
|
|
66
|
+
|
|
67
|
+
Visit [Input Data Mapping](./input-data-mapping) for more information.
|
|
68
|
+
|
|
69
|
+
:::
|
|
68
70
|
|
|
69
71
|
When no `structuredOutput` option is provided, Mastra agents use a default schema that expects a `prompt` string as input and returns a `text` string as output:
|
|
70
72
|
|
|
@@ -83,7 +85,7 @@ When no `structuredOutput` option is provided, Mastra agents use a default schem
|
|
|
83
85
|
|
|
84
86
|
When you need the agent to return structured data instead of plain text, pass the `structuredOutput` option to `createStep()`. The step's output schema will match your provided schema, enabling type-safe chaining to subsequent steps.
|
|
85
87
|
|
|
86
|
-
```typescript {1-6,8-10} title="src/mastra/workflows/test-workflow.ts"
|
|
88
|
+
```typescript {1-6,8-10} title="src/mastra/workflows/test-workflow.ts"
|
|
87
89
|
const articleSchema = z.object({
|
|
88
90
|
title: z.string(),
|
|
89
91
|
summary: z.string(),
|
|
@@ -104,9 +106,7 @@ const processStep = createStep({
|
|
|
104
106
|
}),
|
|
105
107
|
});
|
|
106
108
|
|
|
107
|
-
export const testWorkflow = createWorkflow({
|
|
108
|
-
// ...
|
|
109
|
-
})
|
|
109
|
+
export const testWorkflow = createWorkflow({})
|
|
110
110
|
.map(async ({ inputData }) => ({
|
|
111
111
|
prompt: `Generate an article about: ${inputData.topic}`,
|
|
112
112
|
}))
|
|
@@ -117,7 +117,11 @@ export const testWorkflow = createWorkflow({
|
|
|
117
117
|
|
|
118
118
|
The `structuredOutput.schema` option accepts any Zod schema. The agent will generate output conforming to this schema, and the step's `outputSchema` will be automatically set to match.
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
:::info
|
|
121
|
+
|
|
122
|
+
Visit [Structured Output](/docs/v1/agents/structured-output) for more options like error handling strategies and streaming with structured output.
|
|
123
|
+
|
|
124
|
+
:::
|
|
121
125
|
|
|
122
126
|
## Using tools in workflows
|
|
123
127
|
|
|
@@ -127,11 +131,10 @@ Use tools in workflow steps to leverage existing tool logic. Call from a step's
|
|
|
127
131
|
|
|
128
132
|
Call tools inside a step's `execute` function using `.execute()`. This gives you more control over the tool's input context, or process its response before passing it to the next step.
|
|
129
133
|
|
|
130
|
-
```typescript {
|
|
134
|
+
```typescript {7-12} title="src/mastra/workflows/test-workflow.ts"
|
|
131
135
|
import { testTool } from "../tools/test-tool";
|
|
132
136
|
|
|
133
137
|
const step2 = createStep({
|
|
134
|
-
// ...
|
|
135
138
|
execute: async ({ inputData, requestContext }) => {
|
|
136
139
|
const { formatted } = inputData;
|
|
137
140
|
|
|
@@ -149,7 +152,11 @@ const step2 = createStep({
|
|
|
149
152
|
});
|
|
150
153
|
```
|
|
151
154
|
|
|
152
|
-
|
|
155
|
+
:::info
|
|
156
|
+
|
|
157
|
+
Visit [Calling Tools](/docs/v1/workflows/agents-and-tools#calling-tools) for more examples.
|
|
158
|
+
|
|
159
|
+
:::
|
|
153
160
|
|
|
154
161
|
### Tools as steps
|
|
155
162
|
|
|
@@ -157,14 +164,12 @@ Compose a tool as a step using `createStep()` when the previous step's output ma
|
|
|
157
164
|
|
|
158
165
|

|
|
159
166
|
|
|
160
|
-
```typescript {1,3,
|
|
167
|
+
```typescript {1,3,7-12} title="src/mastra/workflows/test-workflow.ts"
|
|
161
168
|
import { testTool } from "../tools/test-tool";
|
|
162
169
|
|
|
163
170
|
const step2 = createStep(testTool);
|
|
164
171
|
|
|
165
|
-
export const testWorkflow = createWorkflow({
|
|
166
|
-
// ...
|
|
167
|
-
})
|
|
172
|
+
export const testWorkflow = createWorkflow({})
|
|
168
173
|
.then(step1)
|
|
169
174
|
.map(async ({ inputData }) => {
|
|
170
175
|
const { formatted } = inputData;
|
|
@@ -176,7 +181,11 @@ export const testWorkflow = createWorkflow({
|
|
|
176
181
|
.commit();
|
|
177
182
|
```
|
|
178
183
|
|
|
179
|
-
|
|
184
|
+
:::info
|
|
185
|
+
|
|
186
|
+
Visit [Input Data Mapping](./input-data-mapping) for more information.
|
|
187
|
+
|
|
188
|
+
:::
|
|
180
189
|
|
|
181
190
|
## Related
|
|
182
191
|
|