@mastra/mcp-docs-server 1.0.0-beta.11 → 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 +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +51 -51
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +180 -180
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +68 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +331 -331
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +41 -41
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +96 -96
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +49 -2
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +122 -122
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +39 -39
- package/.docs/organized/changelogs/create-mastra.md +31 -31
- package/.docs/organized/changelogs/mastra.md +51 -51
- package/.docs/organized/code-examples/agent-v6.md +151 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +0 -4
- package/.docs/organized/code-examples/stock-price-tool.md +21 -2
- package/.docs/raw/agents/adding-voice.mdx +2 -3
- package/.docs/raw/agents/agent-approval.mdx +139 -6
- package/.docs/raw/agents/agent-memory.mdx +24 -32
- package/.docs/raw/agents/guardrails.mdx +61 -51
- package/.docs/raw/agents/networks.mdx +9 -13
- package/.docs/raw/agents/overview.mdx +40 -24
- package/.docs/raw/agents/processors.mdx +20 -19
- package/.docs/raw/agents/structured-output.mdx +11 -7
- package/.docs/raw/agents/using-tools.mdx +5 -6
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +1 -2
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +1 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -2
- package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -2
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +3 -4
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -3
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +2 -3
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -2
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +2 -3
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
- package/.docs/raw/deployment/cloud-providers.mdx +20 -0
- package/.docs/raw/deployment/{building-mastra.mdx → mastra-server.mdx} +5 -5
- package/.docs/raw/deployment/monorepo.mdx +23 -44
- package/.docs/raw/deployment/overview.mdx +32 -50
- package/.docs/raw/deployment/web-framework.mdx +15 -19
- 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/getting-started/start.mdx +10 -1
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +4 -4
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1033 -79
- 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/{deployment/cloud-providers → guides/deployment}/amazon-ec2.mdx +9 -9
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/aws-lambda.mdx +13 -16
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/azure-app-services.mdx +5 -7
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/cloudflare-deployer.mdx +8 -5
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/digital-ocean.mdx +12 -15
- package/.docs/raw/guides/deployment/index.mdx +32 -0
- package/.docs/raw/guides/deployment/inngest.mdx +386 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/netlify-deployer.mdx +7 -3
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/vercel-deployer.mdx +8 -5
- package/.docs/raw/guides/getting-started/astro.mdx +292 -451
- package/.docs/raw/guides/getting-started/express.mdx +72 -153
- package/.docs/raw/guides/getting-started/hono.mdx +227 -0
- package/.docs/raw/guides/getting-started/next-js.mdx +170 -61
- 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 +317 -147
- 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 +17 -17
- 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/client.mdx +17 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +6 -0
- 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/{deployment/mastra-cloud → mastra-cloud}/dashboard.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/observability.mdx +1 -5
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/overview.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/setting-up.mdx +8 -7
- 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 +10 -11
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/cloud.mdx +1 -1
- 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 +18 -31
- package/.docs/raw/rag/graph-rag.mdx +220 -0
- package/.docs/raw/rag/overview.mdx +2 -3
- package/.docs/raw/rag/retrieval.mdx +34 -51
- package/.docs/raw/rag/vector-databases.mdx +29 -25
- 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 +3 -3
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +3 -3
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +3 -3
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +3 -3
- package/.docs/raw/reference/agents/getLLM.mdx +3 -3
- package/.docs/raw/reference/agents/getMemory.mdx +3 -3
- package/.docs/raw/reference/agents/getModel.mdx +3 -3
- 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 +3 -3
- 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 +3 -3
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/network-route.mdx +3 -3
- 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 +127 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +107 -0
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +3 -3
- package/.docs/raw/reference/auth/auth0.mdx +2 -3
- package/.docs/raw/reference/auth/clerk.mdx +2 -3
- package/.docs/raw/reference/auth/firebase.mdx +3 -5
- package/.docs/raw/reference/auth/jwt.mdx +2 -3
- package/.docs/raw/reference/auth/supabase.mdx +2 -3
- package/.docs/raw/reference/auth/workos.mdx +2 -3
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +10 -10
- package/.docs/raw/reference/client-js/agents.mdx +1 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +2 -2
- package/.docs/raw/reference/client-js/workflows.mdx +20 -0
- 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 +3 -3
- 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 +7 -8
- 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/database-config.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 +14 -14
- package/.docs/raw/reference/server/express-adapter.mdx +10 -11
- package/.docs/raw/reference/server/hono-adapter.mdx +10 -11
- package/.docs/raw/reference/server/mastra-server.mdx +22 -22
- package/.docs/raw/reference/server/routes.mdx +28 -1
- 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/{server-db/storage.mdx → reference/storage/overview.mdx} +13 -111
- 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 +27 -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 +35 -22
- 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 +24 -5
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +3 -3
- package/.docs/raw/reference/tools/vector-query-tool.mdx +4 -4
- 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 +143 -0
- 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 +37 -2
- 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 +17 -3
- package/.docs/raw/{auth → server/auth}/auth0.mdx +20 -14
- package/.docs/raw/{auth → server/auth}/clerk.mdx +16 -9
- package/.docs/raw/{auth → server/auth}/firebase.mdx +21 -15
- package/.docs/raw/{auth → server/auth}/index.mdx +6 -6
- package/.docs/raw/{auth → server/auth}/jwt.mdx +14 -7
- package/.docs/raw/{auth → server/auth}/supabase.mdx +16 -9
- package/.docs/raw/{auth → server/auth}/workos.mdx +19 -13
- package/.docs/raw/{server-db → server}/custom-adapters.mdx +13 -13
- package/.docs/raw/{server-db → server}/custom-api-routes.mdx +3 -5
- package/.docs/raw/{server-db → server}/mastra-client.mdx +26 -15
- package/.docs/raw/{server-db → server}/mastra-server.mdx +8 -8
- package/.docs/raw/{server-db → server}/middleware.mdx +9 -9
- package/.docs/raw/{server-db → server}/request-context.mdx +33 -32
- package/.docs/raw/{server-db → server}/server-adapters.mdx +12 -12
- 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 +10 -11
- 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 +172 -18
- 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 +34 -23
- 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 +23 -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/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
- 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
|
@@ -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
|
|
|
@@ -22,9 +22,8 @@ Use `.then()` to run steps in order, allowing each step to access the result of
|
|
|
22
22
|
|
|
23
23
|

|
|
24
24
|
|
|
25
|
-
```typescript {
|
|
25
|
+
```typescript {27-28} title="src/mastra/workflows/test-workflow.ts"
|
|
26
26
|
const step1 = createStep({
|
|
27
|
-
//...
|
|
28
27
|
inputSchema: z.object({
|
|
29
28
|
message: z.string()
|
|
30
29
|
}),
|
|
@@ -34,7 +33,6 @@ const step1 = createStep({
|
|
|
34
33
|
});
|
|
35
34
|
|
|
36
35
|
const step2 = createStep({
|
|
37
|
-
// ...
|
|
38
36
|
inputSchema: z.object({
|
|
39
37
|
formatted: z.string()
|
|
40
38
|
}),
|
|
@@ -44,7 +42,6 @@ const step2 = createStep({
|
|
|
44
42
|
});
|
|
45
43
|
|
|
46
44
|
export const testWorkflow = createWorkflow({
|
|
47
|
-
// ...
|
|
48
45
|
inputSchema: z.object({
|
|
49
46
|
message: z.string()
|
|
50
47
|
}),
|
|
@@ -63,15 +60,13 @@ Use `.parallel()` to run steps at the same time. All parallel steps must complet
|
|
|
63
60
|
|
|
64
61
|

|
|
65
62
|
|
|
66
|
-
```typescript {
|
|
63
|
+
```typescript {39} title="src/mastra/workflows/test-workflow.ts"
|
|
67
64
|
const step1 = createStep({
|
|
68
65
|
id: "step-1",
|
|
69
|
-
// ...
|
|
70
66
|
});
|
|
71
67
|
|
|
72
68
|
const step2 = createStep({
|
|
73
69
|
id: "step-2",
|
|
74
|
-
// ...
|
|
75
70
|
});
|
|
76
71
|
|
|
77
72
|
const step3 = createStep({
|
|
@@ -97,7 +92,6 @@ const step3 = createStep({
|
|
|
97
92
|
});
|
|
98
93
|
|
|
99
94
|
export const testWorkflow = createWorkflow({
|
|
100
|
-
// ...
|
|
101
95
|
inputSchema: z.object({
|
|
102
96
|
message: z.string()
|
|
103
97
|
}),
|
|
@@ -116,7 +110,7 @@ export const testWorkflow = createWorkflow({
|
|
|
116
110
|
|
|
117
111
|
When steps run in parallel, the output is an object where each key is the step's `id` and the value is that step's output. This allows you to access each parallel step's result independently.
|
|
118
112
|
|
|
119
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
113
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
120
114
|
const step1 = createStep({
|
|
121
115
|
id: "format-step",
|
|
122
116
|
inputSchema: z.object({ message: z.string() }),
|
|
@@ -176,7 +170,11 @@ export const testWorkflow = createWorkflow({
|
|
|
176
170
|
- The next step receives an object containing all parallel step outputs
|
|
177
171
|
- You must define the `inputSchema` of the following step to match this structure
|
|
178
172
|
|
|
179
|
-
|
|
173
|
+
:::info
|
|
174
|
+
|
|
175
|
+
Visit [Choosing the right pattern](#choosing-the-right-pattern) to understand when to use `.parallel()` vs `.foreach()`.
|
|
176
|
+
|
|
177
|
+
:::
|
|
180
178
|
|
|
181
179
|
## Conditional logic with `.branch()`
|
|
182
180
|
|
|
@@ -184,11 +182,10 @@ Use `.branch()` to choose which step to run based on a condition. All steps in a
|
|
|
184
182
|
|
|
185
183
|

|
|
186
184
|
|
|
187
|
-
```typescript {33
|
|
185
|
+
```typescript {30-33} title="src/mastra/workflows/test-workflow.ts"
|
|
188
186
|
const step1 = createStep({...})
|
|
189
187
|
|
|
190
188
|
const stepA = createStep({
|
|
191
|
-
// ...
|
|
192
189
|
inputSchema: z.object({
|
|
193
190
|
value: z.number()
|
|
194
191
|
}),
|
|
@@ -198,7 +195,6 @@ const stepA = createStep({
|
|
|
198
195
|
});
|
|
199
196
|
|
|
200
197
|
const stepB = createStep({
|
|
201
|
-
// ...
|
|
202
198
|
inputSchema: z.object({
|
|
203
199
|
value: z.number()
|
|
204
200
|
}),
|
|
@@ -208,7 +204,6 @@ const stepB = createStep({
|
|
|
208
204
|
});
|
|
209
205
|
|
|
210
206
|
export const testWorkflow = createWorkflow({
|
|
211
|
-
// ...
|
|
212
207
|
inputSchema: z.object({
|
|
213
208
|
value: z.number()
|
|
214
209
|
}),
|
|
@@ -228,7 +223,7 @@ export const testWorkflow = createWorkflow({
|
|
|
228
223
|
|
|
229
224
|
When using conditional branching, only one branch executes based on which condition evaluates to `true` first. The output structure is similar to `.parallel()`, where the result is keyed by the executed step's `id`.
|
|
230
225
|
|
|
231
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
226
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
232
227
|
const step1 = createStep({
|
|
233
228
|
id: "initial-step",
|
|
234
229
|
inputSchema: z.object({ value: z.number() }),
|
|
@@ -309,7 +304,7 @@ When using `.then()`, `.parallel()`, or `.branch()`, it is sometimes necessary t
|
|
|
309
304
|
|
|
310
305
|

|
|
311
306
|
|
|
312
|
-
```typescript {9} title="src/mastra/workflows/test-workflow.ts"
|
|
307
|
+
```typescript {9} title="src/mastra/workflows/test-workflow.ts"
|
|
313
308
|
const step1 = createStep({...});
|
|
314
309
|
const step2 = createStep({...});
|
|
315
310
|
|
|
@@ -337,7 +332,7 @@ The `.map()` method provides additional helper functions for more complex mappin
|
|
|
337
332
|
|
|
338
333
|
When working with `.parallel()` or `.branch()` outputs, you can use `.map()` to transform the data structure before passing it to the next step. This is especially useful when you need to flatten or restructure the output.
|
|
339
334
|
|
|
340
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
335
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
341
336
|
export const testWorkflow = createWorkflow({...})
|
|
342
337
|
.parallel([step1, step2])
|
|
343
338
|
.map(async ({ inputData }) => {
|
|
@@ -352,7 +347,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
352
347
|
|
|
353
348
|
You can also use the helper functions provided by `.map()`:
|
|
354
349
|
|
|
355
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
350
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
356
351
|
export const testWorkflow = createWorkflow({...})
|
|
357
352
|
.branch([
|
|
358
353
|
[condition1, stepA],
|
|
@@ -380,11 +375,10 @@ Use `.dountil()` to run a step repeatedly until a condition becomes true.
|
|
|
380
375
|
|
|
381
376
|

|
|
382
377
|
|
|
383
|
-
```typescript {
|
|
378
|
+
```typescript {14} title="src/mastra/workflows/test-workflow.ts"
|
|
384
379
|
const step1 = createStep({...});
|
|
385
380
|
|
|
386
381
|
const step2 = createStep({
|
|
387
|
-
// ...
|
|
388
382
|
execute: async ({ inputData }) => {
|
|
389
383
|
const { number } = inputData;
|
|
390
384
|
return {
|
|
@@ -393,9 +387,7 @@ const step2 = createStep({
|
|
|
393
387
|
}
|
|
394
388
|
});
|
|
395
389
|
|
|
396
|
-
export const testWorkflow = createWorkflow({
|
|
397
|
-
// ...
|
|
398
|
-
})
|
|
390
|
+
export const testWorkflow = createWorkflow({})
|
|
399
391
|
.then(step1)
|
|
400
392
|
.dountil(step2, async ({ inputData: { number } }) => number > 10)
|
|
401
393
|
.commit();
|
|
@@ -407,11 +399,10 @@ Use `.dowhile()` to run a step repeatedly while a condition remains true.
|
|
|
407
399
|
|
|
408
400
|

|
|
409
401
|
|
|
410
|
-
```typescript {
|
|
402
|
+
```typescript {14} title="src/mastra/workflows/test-workflow.ts"
|
|
411
403
|
const step1 = createStep({...});
|
|
412
404
|
|
|
413
405
|
const step2 = createStep({
|
|
414
|
-
// ...
|
|
415
406
|
execute: async ({ inputData }) => {
|
|
416
407
|
const { number } = inputData;
|
|
417
408
|
return {
|
|
@@ -420,9 +411,7 @@ const step2 = createStep({
|
|
|
420
411
|
}
|
|
421
412
|
});
|
|
422
413
|
|
|
423
|
-
export const testWorkflow = createWorkflow({
|
|
424
|
-
// ...
|
|
425
|
-
})
|
|
414
|
+
export const testWorkflow = createWorkflow({})
|
|
426
415
|
.then(step1)
|
|
427
416
|
.dowhile(step2, async ({ inputData: { number } }) => number < 10)
|
|
428
417
|
.commit();
|
|
@@ -434,9 +423,8 @@ Use `.foreach()` to run the same step for each item in an array. The input must
|
|
|
434
423
|
|
|
435
424
|

|
|
436
425
|
|
|
437
|
-
```typescript {
|
|
426
|
+
```typescript {15} title="src/mastra/workflows/test-workflow.ts"
|
|
438
427
|
const step1 = createStep({
|
|
439
|
-
// ...
|
|
440
428
|
inputSchema: z.string(),
|
|
441
429
|
outputSchema: z.string(),
|
|
442
430
|
execute: async ({ inputData }) => {
|
|
@@ -447,7 +435,6 @@ const step1 = createStep({
|
|
|
447
435
|
const step2 = createStep({...});
|
|
448
436
|
|
|
449
437
|
export const testWorkflow = createWorkflow({
|
|
450
|
-
// ...
|
|
451
438
|
inputSchema: z.array(z.string()),
|
|
452
439
|
outputSchema: z.array(z.string())
|
|
453
440
|
})
|
|
@@ -460,7 +447,7 @@ export const testWorkflow = createWorkflow({
|
|
|
460
447
|
|
|
461
448
|
The `.foreach()` method always returns an array containing the output of each iteration. The order of outputs matches the order of inputs.
|
|
462
449
|
|
|
463
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
450
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
464
451
|
const addTenStep = createStep({
|
|
465
452
|
id: "add-ten",
|
|
466
453
|
inputSchema: z.object({ value: z.number() }),
|
|
@@ -486,7 +473,7 @@ export const testWorkflow = createWorkflow({
|
|
|
486
473
|
|
|
487
474
|
Use `concurrency` to control the number of array items processed at the same time. The default is `1`, which runs steps sequentially. Increasing the value allows `.foreach()` to process multiple items simultaneously.
|
|
488
475
|
|
|
489
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
476
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
490
477
|
const step1 = createStep({...})
|
|
491
478
|
|
|
492
479
|
export const testWorkflow = createWorkflow({...})
|
|
@@ -498,7 +485,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
498
485
|
|
|
499
486
|
Since `.foreach()` outputs an array, you can use `.then()` or `.map()` to aggregate or transform the results. The step following `.foreach()` receives the entire array as its input.
|
|
500
487
|
|
|
501
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
488
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
502
489
|
const processItemStep = createStep({
|
|
503
490
|
id: "process-item",
|
|
504
491
|
inputSchema: z.object({ value: z.number() }),
|
|
@@ -535,7 +522,7 @@ export const testWorkflow = createWorkflow({
|
|
|
535
522
|
|
|
536
523
|
You can also use `.map()` to transform the array output:
|
|
537
524
|
|
|
538
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
525
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
539
526
|
export const testWorkflow = createWorkflow({...})
|
|
540
527
|
.foreach(processItemStep)
|
|
541
528
|
.map(async ({ inputData }) => ({
|
|
@@ -551,7 +538,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
551
538
|
|
|
552
539
|
When you chain `.foreach()` calls, each operates on the array output of the previous step. This is useful when each item in your array needs to be transformed by multiple steps in sequence.
|
|
553
540
|
|
|
554
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
541
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
555
542
|
const chunkStep = createStep({
|
|
556
543
|
id: "chunk",
|
|
557
544
|
// Takes a document, returns an array of chunks
|
|
@@ -589,7 +576,7 @@ For processing multiple documents where each produces multiple chunks, you have
|
|
|
589
576
|
|
|
590
577
|
**Option 1: Process all documents in a single step with batching control**
|
|
591
578
|
|
|
592
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
579
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
593
580
|
const downloadAndChunkStep = createStep({
|
|
594
581
|
id: "download-and-chunk",
|
|
595
582
|
inputSchema: z.array(z.string()), // Array of URLs
|
|
@@ -614,7 +601,7 @@ export const multiDocWorkflow = createWorkflow({...})
|
|
|
614
601
|
|
|
615
602
|
**Option 2: Use foreach for documents, aggregate chunks, then foreach for embeddings**
|
|
616
603
|
|
|
617
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
604
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
618
605
|
const downloadStep = createStep({
|
|
619
606
|
id: "download",
|
|
620
607
|
inputSchema: z.string(), // Single URL
|
|
@@ -660,7 +647,7 @@ export const multiDocWorkflow = createWorkflow({
|
|
|
660
647
|
|
|
661
648
|
The step after `.foreach()` only executes after all iterations complete. If you need to run multiple sequential operations per item, use a nested workflow instead of chaining multiple `.foreach()` calls. This keeps all operations for each item together and makes the data flow clearer.
|
|
662
649
|
|
|
663
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
650
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
664
651
|
// Define a workflow that processes a single document
|
|
665
652
|
const processDocumentWorkflow = createWorkflow({
|
|
666
653
|
id: "process-document",
|
|
@@ -820,7 +807,7 @@ Loop conditions can be implemented in different ways depending on how you want t
|
|
|
820
807
|
|
|
821
808
|
Use `iterationCount` to limit how many times a loop runs. If the count exceeds your threshold, throw an error to fail the step and stop the workflow.
|
|
822
809
|
|
|
823
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
810
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
824
811
|
const step1 = createStep({...});
|
|
825
812
|
|
|
826
813
|
export const testWorkflow = createWorkflow({...})
|
|
@@ -5,20 +5,180 @@ description: "Learn how to handle errors in Mastra workflows using step retries,
|
|
|
5
5
|
|
|
6
6
|
# Error Handling
|
|
7
7
|
|
|
8
|
-
Mastra
|
|
8
|
+
Mastra workflows support error handling through result status checks after execution, retry policies for transient failures, and lifecycle callbacks for centralized error logging or alerting.
|
|
9
|
+
|
|
10
|
+
## Handling workflow results
|
|
11
|
+
|
|
12
|
+
When you run a workflow, the result object contains the status and any errors that occurred.
|
|
13
|
+
|
|
14
|
+
### Checking the result status
|
|
15
|
+
|
|
16
|
+
```typescript title="src/run-workflow.ts"
|
|
17
|
+
import { mastra } from "./mastra";
|
|
18
|
+
|
|
19
|
+
const workflow = mastra.getWorkflow("myWorkflow");
|
|
20
|
+
const run = await workflow.createRun();
|
|
21
|
+
const result = await run.start({ inputData: { value: "test" } });
|
|
22
|
+
|
|
23
|
+
switch (result.status) {
|
|
24
|
+
case 'success':
|
|
25
|
+
console.log('Workflow completed:', result.result);
|
|
26
|
+
break;
|
|
27
|
+
case 'failed':
|
|
28
|
+
console.error('Workflow failed:', result.error);
|
|
29
|
+
break;
|
|
30
|
+
case 'suspended':
|
|
31
|
+
console.log('Workflow suspended, waiting for resume');
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Result object structure
|
|
37
|
+
|
|
38
|
+
The result object contains:
|
|
39
|
+
|
|
40
|
+
- `status` - The workflow status: `'success'`, `'failed'`, `'suspended'`, or `'tripwire'`
|
|
41
|
+
- `result` - The workflow output (when status is `'success'`)
|
|
42
|
+
- `error` - Error details (when status is `'failed'`)
|
|
43
|
+
- `steps` - Individual step results with their status and output
|
|
44
|
+
|
|
45
|
+
### Accessing step results
|
|
46
|
+
|
|
47
|
+
You can inspect individual step results to understand where a failure occurred:
|
|
48
|
+
|
|
49
|
+
```typescript title="src/run-workflow.ts"
|
|
50
|
+
const result = await run.start({ inputData: { value: "test" } });
|
|
51
|
+
|
|
52
|
+
if (result.status === 'failed') {
|
|
53
|
+
// Find which step failed
|
|
54
|
+
for (const [stepId, stepResult] of Object.entries(result.steps)) {
|
|
55
|
+
if (stepResult.status === 'failed') {
|
|
56
|
+
console.error(`Step ${stepId} failed:`, stepResult.error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Lifecycle callbacks
|
|
63
|
+
|
|
64
|
+
For scenarios where you need to handle workflow completion without awaiting the result—such as background jobs, fire-and-forget workflows, or centralized logging—you can use lifecycle callbacks.
|
|
65
|
+
|
|
66
|
+
### onFinish
|
|
67
|
+
|
|
68
|
+
Called when a workflow completes with any status (success, failed, suspended, or tripwire):
|
|
69
|
+
|
|
70
|
+
```typescript {8-15} title="src/mastra/workflows/order-workflow.ts"
|
|
71
|
+
import { createWorkflow } from "@mastra/core/workflows";
|
|
72
|
+
import { z } from "zod";
|
|
73
|
+
|
|
74
|
+
const orderWorkflow = createWorkflow({
|
|
75
|
+
id: 'order-processing',
|
|
76
|
+
inputSchema: z.object({ orderId: z.string() }),
|
|
77
|
+
outputSchema: z.object({ orderId: z.string(), status: z.string() }),
|
|
78
|
+
options: {
|
|
79
|
+
onFinish: async (result) => {
|
|
80
|
+
await db.updateOrderStatus(result.result?.orderId, result.status);
|
|
81
|
+
await analytics.track('workflow_completed', {
|
|
82
|
+
workflowId: 'order-processing',
|
|
83
|
+
status: result.status,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The `onFinish` callback receives:
|
|
91
|
+
|
|
92
|
+
- `status` - The workflow status
|
|
93
|
+
- `result` - The workflow output (on success)
|
|
94
|
+
- `error` - Error details (on failure)
|
|
95
|
+
- `steps` - Individual step results
|
|
96
|
+
- `tripwire` - Tripwire info (if status is `'tripwire'`)
|
|
97
|
+
|
|
98
|
+
### onError
|
|
99
|
+
|
|
100
|
+
Called only when a workflow fails (status is `'failed'` or `'tripwire'`):
|
|
101
|
+
|
|
102
|
+
```typescript {8-14} title="src/mastra/workflows/payment-workflow.ts"
|
|
103
|
+
import { createWorkflow } from "@mastra/core/workflows";
|
|
104
|
+
import { z } from "zod";
|
|
105
|
+
|
|
106
|
+
const paymentWorkflow = createWorkflow({
|
|
107
|
+
id: 'payment-processing',
|
|
108
|
+
inputSchema: z.object({ amount: z.number() }),
|
|
109
|
+
outputSchema: z.object({ transactionId: z.string() }),
|
|
110
|
+
options: {
|
|
111
|
+
onError: async (errorInfo) => {
|
|
112
|
+
await alertService.notify({
|
|
113
|
+
channel: 'payments-alerts',
|
|
114
|
+
message: `Payment workflow failed: ${errorInfo.error?.message}`,
|
|
115
|
+
});
|
|
116
|
+
await errorTracker.capture(errorInfo.error);
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The `onError` callback receives:
|
|
123
|
+
|
|
124
|
+
- `status` - Either `'failed'` or `'tripwire'`
|
|
125
|
+
- `error` - Error details
|
|
126
|
+
- `steps` - Individual step results
|
|
127
|
+
- `tripwire` - Tripwire info (if status is `'tripwire'`)
|
|
128
|
+
|
|
129
|
+
### Using both callbacks
|
|
130
|
+
|
|
131
|
+
You can use both callbacks together:
|
|
132
|
+
|
|
133
|
+
```typescript {8-16} title="src/mastra/workflows/pipeline-workflow.ts"
|
|
134
|
+
import { createWorkflow } from "@mastra/core/workflows";
|
|
135
|
+
import { z } from "zod";
|
|
136
|
+
|
|
137
|
+
const pipelineWorkflow = createWorkflow({
|
|
138
|
+
id: 'data-pipeline',
|
|
139
|
+
inputSchema: z.object({ source: z.string() }),
|
|
140
|
+
outputSchema: z.object({ recordsProcessed: z.number() }),
|
|
141
|
+
options: {
|
|
142
|
+
onFinish: async (result) => {
|
|
143
|
+
// Always log completion
|
|
144
|
+
await logger.info('Pipeline completed', { status: result.status });
|
|
145
|
+
},
|
|
146
|
+
onError: async (errorInfo) => {
|
|
147
|
+
// Alert on failures
|
|
148
|
+
await pagerDuty.alert('Data pipeline failed', errorInfo.error);
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Error handling in callbacks
|
|
155
|
+
|
|
156
|
+
Errors thrown inside callbacks are caught and logged—they will not affect the workflow result or cause it to fail. This ensures that callback issues don't break your workflows in production.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
options: {
|
|
160
|
+
onFinish: async (result) => {
|
|
161
|
+
// If this throws, it's logged but the workflow result is unchanged
|
|
162
|
+
await externalService.notify(result);
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Retries
|
|
168
|
+
|
|
169
|
+
Mastra has a retry mechanism for workflows or steps that fail due to transient errors, for example when steps interact with external services or resources that may be temporarily unavailable.
|
|
9
170
|
|
|
10
171
|
## Workflow-level using `retryConfig`
|
|
11
172
|
|
|
12
173
|
You can configure retries at the workflow level, which applies to all steps in the workflow:
|
|
13
174
|
|
|
14
|
-
```typescript {
|
|
175
|
+
```typescript {7-10} title="src/mastra/workflows/test-workflow.ts"
|
|
15
176
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
16
177
|
import { z } from "zod";
|
|
17
178
|
|
|
18
179
|
const step1 = createStep({...});
|
|
19
180
|
|
|
20
181
|
export const testWorkflow = createWorkflow({
|
|
21
|
-
// ...
|
|
22
182
|
retryConfig: {
|
|
23
183
|
attempts: 5,
|
|
24
184
|
delay: 2000
|
|
@@ -32,14 +192,13 @@ export const testWorkflow = createWorkflow({
|
|
|
32
192
|
|
|
33
193
|
You can configure retries for individual steps using the `retries` property. This overrides the workflow-level retry configuration for that specific step:
|
|
34
194
|
|
|
35
|
-
```typescript {
|
|
195
|
+
```typescript {16} title="src/mastra/workflows/test-workflow.ts"
|
|
36
196
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
37
197
|
import { z } from "zod";
|
|
38
198
|
|
|
39
199
|
const step1 = createStep({
|
|
40
|
-
// ...
|
|
41
200
|
execute: async () => {
|
|
42
|
-
const response = await
|
|
201
|
+
const response = await fetch('example-url');
|
|
43
202
|
|
|
44
203
|
if (!response.ok) {
|
|
45
204
|
throw new Error('Error');
|
|
@@ -57,15 +216,14 @@ const step1 = createStep({
|
|
|
57
216
|
|
|
58
217
|
You can create alternative workflow paths based on the success or failure of previous steps using conditional logic:
|
|
59
218
|
|
|
60
|
-
```typescript {
|
|
219
|
+
```typescript {14,18,29-32} title="src/mastra/workflows/test-workflow.ts"
|
|
61
220
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
62
221
|
import { z } from "zod";
|
|
63
222
|
|
|
64
223
|
const step1 = createStep({
|
|
65
|
-
// ...
|
|
66
224
|
execute: async () => {
|
|
67
225
|
try {
|
|
68
|
-
const response = await
|
|
226
|
+
const response = await fetch('example-url');
|
|
69
227
|
|
|
70
228
|
if (!response.ok) {
|
|
71
229
|
throw new Error('error');
|
|
@@ -85,9 +243,7 @@ const step1 = createStep({
|
|
|
85
243
|
const step2 = createStep({...});
|
|
86
244
|
const fallback = createStep({...});
|
|
87
245
|
|
|
88
|
-
export const testWorkflow = createWorkflow({
|
|
89
|
-
// ...
|
|
90
|
-
})
|
|
246
|
+
export const testWorkflow = createWorkflow({})
|
|
91
247
|
.then(step1)
|
|
92
248
|
.branch([
|
|
93
249
|
[async ({ inputData: { status } }) => status === "ok", step2],
|
|
@@ -100,16 +256,14 @@ export const testWorkflow = createWorkflow({
|
|
|
100
256
|
|
|
101
257
|
Use `getStepResult()` to inspect a previous step’s results.
|
|
102
258
|
|
|
103
|
-
```typescript {
|
|
259
|
+
```typescript {8} title="src/mastra/workflows/test-workflow.ts"
|
|
104
260
|
import { createStep } from "@mastra/core/workflows";
|
|
105
261
|
import { z } from "zod";
|
|
106
262
|
|
|
107
263
|
const step1 = createStep({...});
|
|
108
264
|
|
|
109
265
|
const step2 = createStep({
|
|
110
|
-
// ...
|
|
111
266
|
execute: async ({ getStepResult }) => {
|
|
112
|
-
|
|
113
267
|
const step1Result = getStepResult(step1);
|
|
114
268
|
|
|
115
269
|
return {
|
|
@@ -123,7 +277,7 @@ const step2 = createStep({
|
|
|
123
277
|
|
|
124
278
|
Use `bail()` in a step to exit early with a successful result. This returns the provided payload as the step output and ends workflow execution.
|
|
125
279
|
|
|
126
|
-
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
280
|
+
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
127
281
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
128
282
|
import { z } from "zod";
|
|
129
283
|
|
|
@@ -145,7 +299,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
145
299
|
|
|
146
300
|
Use `throw new Error()` in a step to exit with an error.
|
|
147
301
|
|
|
148
|
-
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
302
|
+
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
149
303
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
150
304
|
import { z } from "zod";
|
|
151
305
|
|
|
@@ -167,7 +321,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
167
321
|
|
|
168
322
|
You can monitor workflows for errors using `stream`:
|
|
169
323
|
|
|
170
|
-
```typescript {11} title="src/test-workflow.ts"
|
|
324
|
+
```typescript {11} title="src/test-workflow.ts"
|
|
171
325
|
import { mastra } from "../src/mastra";
|
|
172
326
|
|
|
173
327
|
const workflow = mastra.getWorkflow("testWorkflow");
|