@mastra/mcp-docs-server 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/agents/adding-voice.md +349 -0
- package/.docs/docs/agents/agent-approval.md +558 -0
- package/.docs/docs/agents/agent-memory.md +209 -0
- package/.docs/docs/agents/guardrails.md +374 -0
- package/.docs/docs/agents/network-approval.md +275 -0
- package/.docs/docs/agents/networks.md +299 -0
- package/.docs/docs/agents/overview.md +304 -0
- package/.docs/docs/agents/processors.md +622 -0
- package/.docs/docs/agents/structured-output.md +273 -0
- package/.docs/docs/agents/supervisor-agents.md +304 -0
- package/.docs/docs/agents/using-tools.md +214 -0
- package/.docs/docs/build-with-ai/mcp-docs-server.md +238 -0
- package/.docs/docs/build-with-ai/skills.md +35 -0
- package/.docs/docs/community/contributing-templates.md +3 -0
- package/.docs/docs/community/discord.md +9 -0
- package/.docs/docs/community/licensing.md +66 -0
- package/.docs/docs/deployment/cloud-providers.md +15 -0
- package/.docs/docs/deployment/mastra-server.md +122 -0
- package/.docs/docs/deployment/monorepo.md +142 -0
- package/.docs/docs/deployment/overview.md +62 -0
- package/.docs/docs/deployment/studio.md +239 -0
- package/.docs/docs/deployment/web-framework.md +52 -0
- package/.docs/docs/deployment/workflow-runners.md +9 -0
- package/.docs/docs/evals/built-in-scorers.md +47 -0
- package/.docs/docs/evals/custom-scorers.md +519 -0
- package/.docs/docs/evals/overview.md +141 -0
- package/.docs/docs/evals/running-in-ci.md +124 -0
- package/.docs/docs/getting-started/build-with-ai.md +68 -0
- package/.docs/docs/getting-started/manual-install.md +226 -0
- package/.docs/docs/getting-started/project-structure.md +60 -0
- package/.docs/docs/getting-started/start.md +28 -0
- package/.docs/docs/getting-started/studio.md +101 -0
- package/.docs/docs/index.md +43 -0
- package/.docs/docs/mastra-cloud/deployment.md +77 -0
- package/.docs/docs/mastra-cloud/observability.md +38 -0
- package/.docs/docs/mastra-cloud/overview.md +23 -0
- package/.docs/docs/mastra-cloud/setup.md +42 -0
- package/.docs/docs/mastra-cloud/studio.md +24 -0
- package/.docs/docs/mastra-code/configuration.md +299 -0
- package/.docs/docs/mastra-code/customization.md +228 -0
- package/.docs/docs/mastra-code/modes.md +104 -0
- package/.docs/docs/mastra-code/overview.md +135 -0
- package/.docs/docs/mastra-code/tools.md +229 -0
- package/.docs/docs/mcp/overview.md +373 -0
- package/.docs/docs/mcp/publishing-mcp-server.md +95 -0
- package/.docs/docs/memory/memory-processors.md +314 -0
- package/.docs/docs/memory/message-history.md +260 -0
- package/.docs/docs/memory/observational-memory.md +248 -0
- package/.docs/docs/memory/overview.md +45 -0
- package/.docs/docs/memory/semantic-recall.md +272 -0
- package/.docs/docs/memory/storage.md +261 -0
- package/.docs/docs/memory/working-memory.md +400 -0
- package/.docs/docs/observability/datasets/overview.md +198 -0
- package/.docs/docs/observability/datasets/running-experiments.md +274 -0
- package/.docs/docs/observability/logging.md +99 -0
- package/.docs/docs/observability/overview.md +70 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +209 -0
- package/.docs/docs/observability/tracing/exporters/arize.md +272 -0
- package/.docs/docs/observability/tracing/exporters/braintrust.md +111 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +127 -0
- package/.docs/docs/observability/tracing/exporters/datadog.md +187 -0
- package/.docs/docs/observability/tracing/exporters/default.md +209 -0
- package/.docs/docs/observability/tracing/exporters/laminar.md +100 -0
- package/.docs/docs/observability/tracing/exporters/langfuse.md +213 -0
- package/.docs/docs/observability/tracing/exporters/langsmith.md +198 -0
- package/.docs/docs/observability/tracing/exporters/otel.md +476 -0
- package/.docs/docs/observability/tracing/exporters/posthog.md +148 -0
- package/.docs/docs/observability/tracing/exporters/sentry.md +208 -0
- package/.docs/docs/observability/tracing/overview.md +1112 -0
- package/.docs/docs/observability/tracing/processors/sensitive-data-filter.md +300 -0
- package/.docs/docs/rag/chunking-and-embedding.md +183 -0
- package/.docs/docs/rag/graph-rag.md +215 -0
- package/.docs/docs/rag/overview.md +72 -0
- package/.docs/docs/rag/retrieval.md +515 -0
- package/.docs/docs/rag/vector-databases.md +645 -0
- package/.docs/docs/server/auth/auth0.md +220 -0
- package/.docs/docs/server/auth/better-auth.md +203 -0
- package/.docs/docs/server/auth/clerk.md +132 -0
- package/.docs/docs/server/auth/composite-auth.md +234 -0
- package/.docs/docs/server/auth/custom-auth-provider.md +513 -0
- package/.docs/docs/server/auth/firebase.md +272 -0
- package/.docs/docs/server/auth/jwt.md +110 -0
- package/.docs/docs/server/auth/simple-auth.md +180 -0
- package/.docs/docs/server/auth/supabase.md +117 -0
- package/.docs/docs/server/auth/workos.md +186 -0
- package/.docs/docs/server/auth.md +38 -0
- package/.docs/docs/server/custom-adapters.md +378 -0
- package/.docs/docs/server/custom-api-routes.md +267 -0
- package/.docs/docs/server/mastra-client.md +243 -0
- package/.docs/docs/server/mastra-server.md +71 -0
- package/.docs/docs/server/middleware.md +225 -0
- package/.docs/docs/server/request-context.md +471 -0
- package/.docs/docs/server/server-adapters.md +547 -0
- package/.docs/docs/streaming/events.md +237 -0
- package/.docs/docs/streaming/overview.md +175 -0
- package/.docs/docs/streaming/tool-streaming.md +175 -0
- package/.docs/docs/streaming/workflow-streaming.md +109 -0
- package/.docs/docs/voice/overview.md +959 -0
- package/.docs/docs/voice/speech-to-speech.md +102 -0
- package/.docs/docs/voice/speech-to-text.md +79 -0
- package/.docs/docs/voice/text-to-speech.md +83 -0
- package/.docs/docs/workflows/agents-and-tools.md +166 -0
- package/.docs/docs/workflows/control-flow.md +822 -0
- package/.docs/docs/workflows/error-handling.md +360 -0
- package/.docs/docs/workflows/human-in-the-loop.md +215 -0
- package/.docs/docs/workflows/overview.md +370 -0
- package/.docs/docs/workflows/snapshots.md +238 -0
- package/.docs/docs/workflows/suspend-and-resume.md +205 -0
- package/.docs/docs/workflows/time-travel.md +309 -0
- package/.docs/docs/workflows/workflow-state.md +181 -0
- package/.docs/docs/workspace/filesystem.md +164 -0
- package/.docs/docs/workspace/overview.md +239 -0
- package/.docs/docs/workspace/sandbox.md +63 -0
- package/.docs/docs/workspace/search.md +243 -0
- package/.docs/docs/workspace/skills.md +169 -0
- package/.docs/guides/agent-frameworks/ai-sdk.md +140 -0
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +1499 -0
- package/.docs/guides/build-your-ui/assistant-ui.md +156 -0
- package/.docs/guides/build-your-ui/copilotkit.md +289 -0
- package/.docs/guides/deployment/amazon-ec2.md +130 -0
- package/.docs/guides/deployment/aws-lambda.md +248 -0
- package/.docs/guides/deployment/azure-app-services.md +114 -0
- package/.docs/guides/deployment/cloudflare.md +99 -0
- package/.docs/guides/deployment/digital-ocean.md +168 -0
- package/.docs/guides/deployment/inngest.md +682 -0
- package/.docs/guides/deployment/netlify.md +77 -0
- package/.docs/guides/deployment/vercel.md +101 -0
- package/.docs/guides/getting-started/astro.md +398 -0
- package/.docs/guides/getting-started/electron.md +504 -0
- package/.docs/guides/getting-started/express.md +251 -0
- package/.docs/guides/getting-started/hono.md +190 -0
- package/.docs/guides/getting-started/next-js.md +347 -0
- package/.docs/guides/getting-started/nuxt.md +497 -0
- package/.docs/guides/getting-started/quickstart.md +67 -0
- package/.docs/guides/getting-started/sveltekit.md +296 -0
- package/.docs/guides/getting-started/vite-react.md +425 -0
- package/.docs/guides/guide/ai-recruiter.md +226 -0
- package/.docs/guides/guide/chef-michel.md +211 -0
- package/.docs/guides/guide/code-review-bot.md +226 -0
- package/.docs/guides/guide/dev-assistant.md +307 -0
- package/.docs/guides/guide/docs-manager.md +238 -0
- package/.docs/guides/guide/github-actions-pr-description.md +236 -0
- package/.docs/guides/guide/notes-mcp-server.md +416 -0
- package/.docs/guides/guide/research-assistant.md +348 -0
- package/.docs/guides/guide/research-coordinator.md +416 -0
- package/.docs/guides/guide/stock-agent.md +132 -0
- package/.docs/guides/guide/web-search.md +320 -0
- package/.docs/guides/guide/whatsapp-chat-bot.md +405 -0
- package/.docs/guides/index.md +3 -0
- package/.docs/guides/migrations/agentnetwork.md +97 -0
- package/.docs/guides/migrations/ai-sdk-v4-to-v5.md +112 -0
- package/.docs/guides/migrations/network-to-supervisor.md +261 -0
- package/.docs/guides/migrations/upgrade-to-v1/agent.md +404 -0
- package/.docs/guides/migrations/upgrade-to-v1/cli.md +57 -0
- package/.docs/guides/migrations/upgrade-to-v1/client.md +337 -0
- package/.docs/guides/migrations/upgrade-to-v1/deployment.md +37 -0
- package/.docs/guides/migrations/upgrade-to-v1/evals.md +239 -0
- package/.docs/guides/migrations/upgrade-to-v1/mastra.md +143 -0
- package/.docs/guides/migrations/upgrade-to-v1/mcp.md +97 -0
- package/.docs/guides/migrations/upgrade-to-v1/memory.md +285 -0
- package/.docs/guides/migrations/upgrade-to-v1/overview.md +119 -0
- package/.docs/guides/migrations/upgrade-to-v1/processors.md +68 -0
- package/.docs/guides/migrations/upgrade-to-v1/rag.md +42 -0
- package/.docs/guides/migrations/upgrade-to-v1/storage.md +553 -0
- package/.docs/guides/migrations/upgrade-to-v1/tools.md +180 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +412 -0
- package/.docs/guides/migrations/upgrade-to-v1/vectors.md +87 -0
- package/.docs/guides/migrations/upgrade-to-v1/voice.md +30 -0
- package/.docs/guides/migrations/upgrade-to-v1/workflows.md +341 -0
- package/.docs/guides/migrations/vnext-to-standard-apis.md +362 -0
- package/.docs/models/embeddings.md +161 -0
- package/.docs/models/gateways/azure-openai.md +128 -0
- package/.docs/models/gateways/custom-gateways.md +545 -0
- package/.docs/models/gateways/netlify.md +88 -0
- package/.docs/models/gateways/openrouter.md +219 -0
- package/.docs/models/gateways/vercel.md +225 -0
- package/.docs/models/gateways.md +14 -0
- package/.docs/models/index.md +286 -0
- package/.docs/models/providers/302ai.md +134 -0
- package/.docs/models/providers/abacus.md +125 -0
- package/.docs/models/providers/agentrouter.md +90 -0
- package/.docs/models/providers/aihubmix.md +107 -0
- package/.docs/models/providers/alibaba-cn.md +135 -0
- package/.docs/models/providers/alibaba.md +111 -0
- package/.docs/models/providers/amazon-bedrock.md +33 -0
- package/.docs/models/providers/anthropic.md +153 -0
- package/.docs/models/providers/azure.md +33 -0
- package/.docs/models/providers/bailing.md +72 -0
- package/.docs/models/providers/baseten.md +77 -0
- package/.docs/models/providers/berget.md +78 -0
- package/.docs/models/providers/cerebras.md +101 -0
- package/.docs/models/providers/chutes.md +136 -0
- package/.docs/models/providers/cloudflare-ai-gateway.md +33 -0
- package/.docs/models/providers/cloudflare-workers-ai.md +109 -0
- package/.docs/models/providers/cohere.md +33 -0
- package/.docs/models/providers/cortecs.md +91 -0
- package/.docs/models/providers/deepinfra.md +112 -0
- package/.docs/models/providers/deepseek.md +88 -0
- package/.docs/models/providers/fastrouter.md +84 -0
- package/.docs/models/providers/fireworks-ai.md +89 -0
- package/.docs/models/providers/firmware.md +85 -0
- package/.docs/models/providers/friendli.md +78 -0
- package/.docs/models/providers/github-models.md +125 -0
- package/.docs/models/providers/google-vertex.md +33 -0
- package/.docs/models/providers/google.md +159 -0
- package/.docs/models/providers/groq.md +107 -0
- package/.docs/models/providers/helicone.md +161 -0
- package/.docs/models/providers/huggingface.md +90 -0
- package/.docs/models/providers/iflowcn.md +84 -0
- package/.docs/models/providers/inception.md +72 -0
- package/.docs/models/providers/inference.md +79 -0
- package/.docs/models/providers/io-intelligence.md +87 -0
- package/.docs/models/providers/io-net.md +87 -0
- package/.docs/models/providers/jiekou.md +131 -0
- package/.docs/models/providers/kilo.md +333 -0
- package/.docs/models/providers/kimi-for-coding.md +100 -0
- package/.docs/models/providers/kuae-cloud-coding-plan.md +71 -0
- package/.docs/models/providers/llama.md +77 -0
- package/.docs/models/providers/lmstudio.md +73 -0
- package/.docs/models/providers/lucidquery.md +72 -0
- package/.docs/models/providers/minimax-cn-coding-plan.md +102 -0
- package/.docs/models/providers/minimax-cn.md +102 -0
- package/.docs/models/providers/minimax-coding-plan.md +102 -0
- package/.docs/models/providers/minimax.md +104 -0
- package/.docs/models/providers/mistral.md +124 -0
- package/.docs/models/providers/moark.md +72 -0
- package/.docs/models/providers/modelscope.md +77 -0
- package/.docs/models/providers/moonshotai-cn.md +76 -0
- package/.docs/models/providers/moonshotai.md +76 -0
- package/.docs/models/providers/morph.md +73 -0
- package/.docs/models/providers/nano-gpt.md +103 -0
- package/.docs/models/providers/nebius.md +116 -0
- package/.docs/models/providers/nova.md +72 -0
- package/.docs/models/providers/novita-ai.md +154 -0
- package/.docs/models/providers/nvidia.md +141 -0
- package/.docs/models/providers/ollama-cloud.md +103 -0
- package/.docs/models/providers/ollama.md +33 -0
- package/.docs/models/providers/openai.md +193 -0
- package/.docs/models/providers/opencode.md +100 -0
- package/.docs/models/providers/ovhcloud.md +83 -0
- package/.docs/models/providers/perplexity.md +100 -0
- package/.docs/models/providers/poe.md +183 -0
- package/.docs/models/providers/privatemode-ai.md +75 -0
- package/.docs/models/providers/requesty.md +90 -0
- package/.docs/models/providers/scaleway.md +84 -0
- package/.docs/models/providers/siliconflow-cn.md +138 -0
- package/.docs/models/providers/siliconflow.md +140 -0
- package/.docs/models/providers/stackit.md +78 -0
- package/.docs/models/providers/stepfun.md +73 -0
- package/.docs/models/providers/submodel.md +79 -0
- package/.docs/models/providers/synthetic.md +96 -0
- package/.docs/models/providers/togetherai.md +115 -0
- package/.docs/models/providers/upstage.md +73 -0
- package/.docs/models/providers/venice.md +95 -0
- package/.docs/models/providers/vivgrid.md +106 -0
- package/.docs/models/providers/vultr.md +75 -0
- package/.docs/models/providers/wandb.md +80 -0
- package/.docs/models/providers/xai.md +141 -0
- package/.docs/models/providers/xiaomi.md +71 -0
- package/.docs/models/providers/zai-coding-plan.md +80 -0
- package/.docs/models/providers/zai.md +79 -0
- package/.docs/models/providers/zenmux.md +161 -0
- package/.docs/models/providers/zhipuai-coding-plan.md +79 -0
- package/.docs/models/providers/zhipuai.md +79 -0
- package/.docs/models/providers.md +81 -0
- package/.docs/reference/agents/agent.md +141 -0
- package/.docs/reference/agents/generate.md +186 -0
- package/.docs/reference/agents/generateLegacy.md +173 -0
- package/.docs/reference/agents/getDefaultGenerateOptions.md +36 -0
- package/.docs/reference/agents/getDefaultOptions.md +34 -0
- package/.docs/reference/agents/getDefaultStreamOptions.md +36 -0
- package/.docs/reference/agents/getDescription.md +21 -0
- package/.docs/reference/agents/getInstructions.md +34 -0
- package/.docs/reference/agents/getLLM.md +37 -0
- package/.docs/reference/agents/getMemory.md +34 -0
- package/.docs/reference/agents/getModel.md +34 -0
- package/.docs/reference/agents/getTools.md +29 -0
- package/.docs/reference/agents/getVoice.md +34 -0
- package/.docs/reference/agents/listAgents.md +35 -0
- package/.docs/reference/agents/listScorers.md +34 -0
- package/.docs/reference/agents/listTools.md +34 -0
- package/.docs/reference/agents/listWorkflows.md +34 -0
- package/.docs/reference/agents/network.md +133 -0
- package/.docs/reference/ai-sdk/chat-route.md +82 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +53 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +37 -0
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +55 -0
- package/.docs/reference/ai-sdk/network-route.md +74 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +231 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v4-messages.md +79 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v5-messages.md +76 -0
- package/.docs/reference/ai-sdk/with-mastra.md +59 -0
- package/.docs/reference/ai-sdk/workflow-route.md +79 -0
- package/.docs/reference/auth/auth0.md +73 -0
- package/.docs/reference/auth/better-auth.md +71 -0
- package/.docs/reference/auth/clerk.md +36 -0
- package/.docs/reference/auth/firebase.md +80 -0
- package/.docs/reference/auth/jwt.md +26 -0
- package/.docs/reference/auth/supabase.md +33 -0
- package/.docs/reference/auth/workos.md +84 -0
- package/.docs/reference/cli/create-mastra.md +137 -0
- package/.docs/reference/cli/mastra.md +336 -0
- package/.docs/reference/client-js/agents.md +437 -0
- package/.docs/reference/client-js/error-handling.md +16 -0
- package/.docs/reference/client-js/logs.md +24 -0
- package/.docs/reference/client-js/mastra-client.md +63 -0
- package/.docs/reference/client-js/memory.md +221 -0
- package/.docs/reference/client-js/observability.md +72 -0
- package/.docs/reference/client-js/telemetry.md +20 -0
- package/.docs/reference/client-js/tools.md +44 -0
- package/.docs/reference/client-js/vectors.md +79 -0
- package/.docs/reference/client-js/workflows.md +199 -0
- package/.docs/reference/configuration.md +752 -0
- package/.docs/reference/core/addGateway.md +42 -0
- package/.docs/reference/core/getAgent.md +21 -0
- package/.docs/reference/core/getAgentById.md +21 -0
- package/.docs/reference/core/getDeployer.md +22 -0
- package/.docs/reference/core/getGateway.md +38 -0
- package/.docs/reference/core/getGatewayById.md +41 -0
- package/.docs/reference/core/getLogger.md +22 -0
- package/.docs/reference/core/getMCPServer.md +47 -0
- package/.docs/reference/core/getMCPServerById.md +55 -0
- package/.docs/reference/core/getMemory.md +50 -0
- package/.docs/reference/core/getScorer.md +54 -0
- package/.docs/reference/core/getScorerById.md +54 -0
- package/.docs/reference/core/getServer.md +22 -0
- package/.docs/reference/core/getStorage.md +22 -0
- package/.docs/reference/core/getStoredAgentById.md +89 -0
- package/.docs/reference/core/getTelemetry.md +22 -0
- package/.docs/reference/core/getVector.md +22 -0
- package/.docs/reference/core/getWorkflow.md +42 -0
- package/.docs/reference/core/listAgents.md +21 -0
- package/.docs/reference/core/listGateways.md +40 -0
- package/.docs/reference/core/listLogs.md +38 -0
- package/.docs/reference/core/listLogsByRunId.md +36 -0
- package/.docs/reference/core/listMCPServers.md +55 -0
- package/.docs/reference/core/listMemory.md +56 -0
- package/.docs/reference/core/listScorers.md +29 -0
- package/.docs/reference/core/listStoredAgents.md +93 -0
- package/.docs/reference/core/listVectors.md +22 -0
- package/.docs/reference/core/listWorkflows.md +21 -0
- package/.docs/reference/core/mastra-class.md +66 -0
- package/.docs/reference/core/mastra-model-gateway.md +153 -0
- package/.docs/reference/core/setLogger.md +26 -0
- package/.docs/reference/core/setStorage.md +27 -0
- package/.docs/reference/datasets/addItem.md +37 -0
- package/.docs/reference/datasets/addItems.md +35 -0
- package/.docs/reference/datasets/compareExperiments.md +52 -0
- package/.docs/reference/datasets/create.md +51 -0
- package/.docs/reference/datasets/dataset.md +82 -0
- package/.docs/reference/datasets/datasets-manager.md +94 -0
- package/.docs/reference/datasets/delete.md +25 -0
- package/.docs/reference/datasets/deleteExperiment.md +27 -0
- package/.docs/reference/datasets/deleteItem.md +27 -0
- package/.docs/reference/datasets/deleteItems.md +29 -0
- package/.docs/reference/datasets/get.md +31 -0
- package/.docs/reference/datasets/getDetails.md +47 -0
- package/.docs/reference/datasets/getExperiment.md +30 -0
- package/.docs/reference/datasets/getItem.md +33 -0
- package/.docs/reference/datasets/getItemHistory.md +31 -0
- package/.docs/reference/datasets/list.md +31 -0
- package/.docs/reference/datasets/listExperimentResults.md +39 -0
- package/.docs/reference/datasets/listExperiments.md +33 -0
- package/.docs/reference/datasets/listItems.md +46 -0
- package/.docs/reference/datasets/listVersions.md +33 -0
- package/.docs/reference/datasets/startExperiment.md +62 -0
- package/.docs/reference/datasets/startExperimentAsync.md +43 -0
- package/.docs/reference/datasets/update.md +48 -0
- package/.docs/reference/datasets/updateItem.md +38 -0
- package/.docs/reference/deployer/cloudflare.md +79 -0
- package/.docs/reference/deployer/netlify.md +80 -0
- package/.docs/reference/deployer/vercel.md +91 -0
- package/.docs/reference/deployer.md +100 -0
- package/.docs/reference/evals/answer-relevancy.md +105 -0
- package/.docs/reference/evals/answer-similarity.md +99 -0
- package/.docs/reference/evals/bias.md +120 -0
- package/.docs/reference/evals/completeness.md +136 -0
- package/.docs/reference/evals/content-similarity.md +101 -0
- package/.docs/reference/evals/context-precision.md +196 -0
- package/.docs/reference/evals/context-relevance.md +531 -0
- package/.docs/reference/evals/create-scorer.md +270 -0
- package/.docs/reference/evals/faithfulness.md +114 -0
- package/.docs/reference/evals/hallucination.md +213 -0
- package/.docs/reference/evals/keyword-coverage.md +128 -0
- package/.docs/reference/evals/mastra-scorer.md +123 -0
- package/.docs/reference/evals/noise-sensitivity.md +675 -0
- package/.docs/reference/evals/prompt-alignment.md +614 -0
- package/.docs/reference/evals/run-evals.md +179 -0
- package/.docs/reference/evals/scorer-utils.md +326 -0
- package/.docs/reference/evals/textual-difference.md +113 -0
- package/.docs/reference/evals/tone-consistency.md +119 -0
- package/.docs/reference/evals/tool-call-accuracy.md +533 -0
- package/.docs/reference/evals/toxicity.md +123 -0
- package/.docs/reference/harness/harness-class.md +708 -0
- package/.docs/reference/index.md +277 -0
- package/.docs/reference/logging/pino-logger.md +117 -0
- package/.docs/reference/mastra-code/createMastraCode.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +199 -0
- package/.docs/reference/memory/cloneThread.md +130 -0
- package/.docs/reference/memory/createThread.md +68 -0
- package/.docs/reference/memory/deleteMessages.md +38 -0
- package/.docs/reference/memory/getThreadById.md +24 -0
- package/.docs/reference/memory/listThreads.md +145 -0
- package/.docs/reference/memory/memory-class.md +147 -0
- package/.docs/reference/memory/observational-memory.md +565 -0
- package/.docs/reference/memory/recall.md +91 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +131 -0
- package/.docs/reference/observability/tracing/configuration.md +178 -0
- package/.docs/reference/observability/tracing/exporters/arize.md +141 -0
- package/.docs/reference/observability/tracing/exporters/braintrust.md +93 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +163 -0
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +138 -0
- package/.docs/reference/observability/tracing/exporters/datadog.md +116 -0
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +174 -0
- package/.docs/reference/observability/tracing/exporters/laminar.md +78 -0
- package/.docs/reference/observability/tracing/exporters/langfuse.md +134 -0
- package/.docs/reference/observability/tracing/exporters/langsmith.md +108 -0
- package/.docs/reference/observability/tracing/exporters/otel.md +199 -0
- package/.docs/reference/observability/tracing/exporters/posthog.md +92 -0
- package/.docs/reference/observability/tracing/exporters/sentry.md +184 -0
- package/.docs/reference/observability/tracing/instances.md +107 -0
- package/.docs/reference/observability/tracing/interfaces.md +743 -0
- package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +144 -0
- package/.docs/reference/observability/tracing/spans.md +224 -0
- package/.docs/reference/processors/batch-parts-processor.md +61 -0
- package/.docs/reference/processors/language-detector.md +82 -0
- package/.docs/reference/processors/message-history-processor.md +85 -0
- package/.docs/reference/processors/moderation-processor.md +104 -0
- package/.docs/reference/processors/pii-detector.md +108 -0
- package/.docs/reference/processors/processor-interface.md +521 -0
- package/.docs/reference/processors/prompt-injection-detector.md +72 -0
- package/.docs/reference/processors/semantic-recall-processor.md +117 -0
- package/.docs/reference/processors/system-prompt-scrubber.md +80 -0
- package/.docs/reference/processors/token-limiter-processor.md +115 -0
- package/.docs/reference/processors/tool-call-filter.md +85 -0
- package/.docs/reference/processors/tool-search-processor.md +111 -0
- package/.docs/reference/processors/unicode-normalizer.md +62 -0
- package/.docs/reference/processors/working-memory-processor.md +152 -0
- package/.docs/reference/rag/chunk.md +221 -0
- package/.docs/reference/rag/database-config.md +261 -0
- package/.docs/reference/rag/document.md +114 -0
- package/.docs/reference/rag/embeddings.md +92 -0
- package/.docs/reference/rag/extract-params.md +168 -0
- package/.docs/reference/rag/graph-rag.md +111 -0
- package/.docs/reference/rag/metadata-filters.md +216 -0
- package/.docs/reference/rag/rerank.md +75 -0
- package/.docs/reference/rag/rerankWithScorer.md +80 -0
- package/.docs/reference/server/create-route.md +262 -0
- package/.docs/reference/server/express-adapter.md +176 -0
- package/.docs/reference/server/fastify-adapter.md +90 -0
- package/.docs/reference/server/hono-adapter.md +162 -0
- package/.docs/reference/server/koa-adapter.md +127 -0
- package/.docs/reference/server/mastra-server.md +298 -0
- package/.docs/reference/server/register-api-route.md +249 -0
- package/.docs/reference/server/routes.md +306 -0
- package/.docs/reference/storage/cloudflare-d1.md +218 -0
- package/.docs/reference/storage/cloudflare.md +88 -0
- package/.docs/reference/storage/composite.md +235 -0
- package/.docs/reference/storage/convex.md +161 -0
- package/.docs/reference/storage/dynamodb.md +282 -0
- package/.docs/reference/storage/lance.md +131 -0
- package/.docs/reference/storage/libsql.md +135 -0
- package/.docs/reference/storage/mongodb.md +262 -0
- package/.docs/reference/storage/mssql.md +157 -0
- package/.docs/reference/storage/overview.md +121 -0
- package/.docs/reference/storage/postgresql.md +526 -0
- package/.docs/reference/storage/upstash.md +160 -0
- package/.docs/reference/streaming/ChunkType.md +292 -0
- package/.docs/reference/streaming/agents/MastraModelOutput.md +182 -0
- package/.docs/reference/streaming/agents/stream.md +221 -0
- package/.docs/reference/streaming/agents/streamLegacy.md +142 -0
- package/.docs/reference/streaming/workflows/observeStream.md +42 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +61 -0
- package/.docs/reference/streaming/workflows/stream.md +88 -0
- package/.docs/reference/streaming/workflows/timeTravelStream.md +142 -0
- package/.docs/reference/templates/overview.md +194 -0
- package/.docs/reference/tools/create-tool.md +237 -0
- package/.docs/reference/tools/document-chunker-tool.md +89 -0
- package/.docs/reference/tools/graph-rag-tool.md +182 -0
- package/.docs/reference/tools/mcp-client.md +954 -0
- package/.docs/reference/tools/mcp-server.md +1271 -0
- package/.docs/reference/tools/vector-query-tool.md +459 -0
- package/.docs/reference/vectors/astra.md +121 -0
- package/.docs/reference/vectors/chroma.md +264 -0
- package/.docs/reference/vectors/convex.md +300 -0
- package/.docs/reference/vectors/couchbase.md +226 -0
- package/.docs/reference/vectors/duckdb.md +318 -0
- package/.docs/reference/vectors/elasticsearch.md +189 -0
- package/.docs/reference/vectors/lance.md +220 -0
- package/.docs/reference/vectors/libsql.md +305 -0
- package/.docs/reference/vectors/mongodb.md +295 -0
- package/.docs/reference/vectors/opensearch.md +99 -0
- package/.docs/reference/vectors/pg.md +408 -0
- package/.docs/reference/vectors/pinecone.md +168 -0
- package/.docs/reference/vectors/qdrant.md +222 -0
- package/.docs/reference/vectors/s3vectors.md +277 -0
- package/.docs/reference/vectors/turbopuffer.md +157 -0
- package/.docs/reference/vectors/upstash.md +294 -0
- package/.docs/reference/vectors/vectorize.md +147 -0
- package/.docs/reference/voice/azure.md +148 -0
- package/.docs/reference/voice/cloudflare.md +83 -0
- package/.docs/reference/voice/composite-voice.md +121 -0
- package/.docs/reference/voice/deepgram.md +79 -0
- package/.docs/reference/voice/elevenlabs.md +98 -0
- package/.docs/reference/voice/google-gemini-live.md +378 -0
- package/.docs/reference/voice/google.md +228 -0
- package/.docs/reference/voice/mastra-voice.md +311 -0
- package/.docs/reference/voice/murf.md +122 -0
- package/.docs/reference/voice/openai-realtime.md +203 -0
- package/.docs/reference/voice/openai.md +88 -0
- package/.docs/reference/voice/playai.md +80 -0
- package/.docs/reference/voice/sarvam.md +126 -0
- package/.docs/reference/voice/speechify.md +75 -0
- package/.docs/reference/voice/voice.addInstructions.md +55 -0
- package/.docs/reference/voice/voice.addTools.md +67 -0
- package/.docs/reference/voice/voice.answer.md +54 -0
- package/.docs/reference/voice/voice.close.md +51 -0
- package/.docs/reference/voice/voice.connect.md +94 -0
- package/.docs/reference/voice/voice.events.md +37 -0
- package/.docs/reference/voice/voice.getSpeakers.md +129 -0
- package/.docs/reference/voice/voice.listen.md +164 -0
- package/.docs/reference/voice/voice.off.md +54 -0
- package/.docs/reference/voice/voice.on.md +111 -0
- package/.docs/reference/voice/voice.send.md +65 -0
- package/.docs/reference/voice/voice.speak.md +157 -0
- package/.docs/reference/voice/voice.updateConfig.md +60 -0
- package/.docs/reference/workflows/run-methods/cancel.md +86 -0
- package/.docs/reference/workflows/run-methods/restart.md +33 -0
- package/.docs/reference/workflows/run-methods/resume.md +59 -0
- package/.docs/reference/workflows/run-methods/start.md +58 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +67 -0
- package/.docs/reference/workflows/run-methods/timeTravel.md +142 -0
- package/.docs/reference/workflows/run.md +59 -0
- package/.docs/reference/workflows/step.md +119 -0
- package/.docs/reference/workflows/workflow-methods/branch.md +25 -0
- package/.docs/reference/workflows/workflow-methods/commit.md +17 -0
- package/.docs/reference/workflows/workflow-methods/create-run.md +63 -0
- package/.docs/reference/workflows/workflow-methods/dountil.md +25 -0
- package/.docs/reference/workflows/workflow-methods/dowhile.md +25 -0
- package/.docs/reference/workflows/workflow-methods/foreach.md +118 -0
- package/.docs/reference/workflows/workflow-methods/map.md +93 -0
- package/.docs/reference/workflows/workflow-methods/parallel.md +21 -0
- package/.docs/reference/workflows/workflow-methods/sleep.md +35 -0
- package/.docs/reference/workflows/workflow-methods/sleepUntil.md +35 -0
- package/.docs/reference/workflows/workflow-methods/then.md +21 -0
- package/.docs/reference/workflows/workflow.md +157 -0
- package/.docs/reference/workspace/e2b-sandbox.md +289 -0
- package/.docs/reference/workspace/filesystem.md +255 -0
- package/.docs/reference/workspace/gcs-filesystem.md +174 -0
- package/.docs/reference/workspace/local-filesystem.md +343 -0
- package/.docs/reference/workspace/local-sandbox.md +301 -0
- package/.docs/reference/workspace/s3-filesystem.md +175 -0
- package/.docs/reference/workspace/sandbox.md +87 -0
- package/.docs/reference/workspace/workspace-class.md +244 -0
- package/CHANGELOG.md +16 -0
- package/package.json +6 -6
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# Structured Output
|
|
2
|
+
|
|
3
|
+
Structured output lets an agent return an object that matches the shape defined by a schema instead of returning text. The schema tells the model what fields to produce, and the model ensures the final result fits that shape.
|
|
4
|
+
|
|
5
|
+
## When to use structured output
|
|
6
|
+
|
|
7
|
+
Use structured output when you need an agent to return a data object rather than text. Having well defined fields can make it simpler to pull out the values you need for API calls, UI rendering, or application logic.
|
|
8
|
+
|
|
9
|
+
## Defining schemas
|
|
10
|
+
|
|
11
|
+
Agents can return structured data by defining the expected output with either [Zod](https://zod.dev/) or [JSON Schema](https://json-schema.org/). Zod is recommended because it provides TypeScript type inference and runtime validation, while JSON Schema is useful when you need a language agnostic format.
|
|
12
|
+
|
|
13
|
+
**Zod**:
|
|
14
|
+
|
|
15
|
+
Define the `output` shape using [Zod](https://zod.dev/):
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { z } from 'zod'
|
|
19
|
+
|
|
20
|
+
const response = await testAgent.generate('Help me plan my day.', {
|
|
21
|
+
structuredOutput: {
|
|
22
|
+
schema: z.array(
|
|
23
|
+
z.object({
|
|
24
|
+
name: z.string(),
|
|
25
|
+
activities: z.array(z.string()),
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
console.log(response.object)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**JSON Schema**:
|
|
35
|
+
|
|
36
|
+
You can also use JSON Schema to define your output structure:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
const response = await testAgent.generate('Help me plan my day.', {
|
|
40
|
+
structuredOutput: {
|
|
41
|
+
schema: {
|
|
42
|
+
type: 'array',
|
|
43
|
+
items: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
name: { type: 'string' },
|
|
47
|
+
activities: {
|
|
48
|
+
type: 'array',
|
|
49
|
+
items: { type: 'string' },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
required: ['name', 'activities'],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
console.log(response.object)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> **Info:** Visit [.generate()](https://mastra.ai/reference/agents/generate) for a full list of configuration options.
|
|
62
|
+
|
|
63
|
+
### Example output
|
|
64
|
+
|
|
65
|
+
The `response.object` will contain the structured data as defined by the schema.
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
[
|
|
69
|
+
{
|
|
70
|
+
"name": "Morning Routine",
|
|
71
|
+
"activities": ["Wake up at 7am", "Exercise", "Shower", "Breakfast"]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "Work",
|
|
75
|
+
"activities": ["Check emails", "Team meeting", "Lunch break"]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "Evening",
|
|
79
|
+
"activities": ["Dinner", "Relax", "Read a book", "Sleep by 10pm"]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Streaming
|
|
85
|
+
|
|
86
|
+
Streaming also supports structured output. The final structured object is available on `stream.fullStream` and after the stream completes on `stream.object`. Text stream chunks are still emitted, but they contain natural language text rather than structured data.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { z } from 'zod'
|
|
90
|
+
|
|
91
|
+
const stream = await testAgent.stream('Help me plan my day.', {
|
|
92
|
+
structuredOutput: {
|
|
93
|
+
schema: z.array(
|
|
94
|
+
z.object({
|
|
95
|
+
name: z.string(),
|
|
96
|
+
activities: z.array(z.string()),
|
|
97
|
+
}),
|
|
98
|
+
),
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
for await (const chunk of stream.fullStream) {
|
|
103
|
+
if (chunk.type === 'object-result') {
|
|
104
|
+
console.log('\n', JSON.stringify(chunk, null, 2))
|
|
105
|
+
}
|
|
106
|
+
process.stdout.write(JSON.stringify(chunk))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.log(await stream.object)
|
|
110
|
+
|
|
111
|
+
for await (const chunk of stream.textStream) {
|
|
112
|
+
process.stdout.write(chunk)
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Structuring agent
|
|
117
|
+
|
|
118
|
+
When your main agent isn't proficient at creating structured output you can provide a `model` to `structuredOutput`. In this case, Mastra uses a second agent under the hood to extract structured data from the main agent's natural language response. This makes two LLM calls, one to generate the response and another to turn that response into the structured object, which adds some latency and cost but can improve accuracy for complex structuring tasks.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { z } from 'zod'
|
|
122
|
+
|
|
123
|
+
const response = await testAgent.generate('Analyze the TypeScript programming language.', {
|
|
124
|
+
structuredOutput: {
|
|
125
|
+
schema: z.object({
|
|
126
|
+
overview: z.string(),
|
|
127
|
+
strengths: z.array(z.string()),
|
|
128
|
+
weaknesses: z.array(z.string()),
|
|
129
|
+
useCases: z.array(
|
|
130
|
+
z.object({
|
|
131
|
+
scenario: z.string(),
|
|
132
|
+
reasoning: z.string(),
|
|
133
|
+
}),
|
|
134
|
+
),
|
|
135
|
+
comparison: z.object({
|
|
136
|
+
similarTo: z.array(z.string()),
|
|
137
|
+
differentiators: z.array(z.string()),
|
|
138
|
+
}),
|
|
139
|
+
}),
|
|
140
|
+
model: 'openai/gpt-4o',
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
console.log(response.object)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Combining tools and structured output
|
|
148
|
+
|
|
149
|
+
When an agent has both tools and structured output configured, some models may not support using both features together. This is a limitation of the underlying model APIs, not Mastra itself.
|
|
150
|
+
|
|
151
|
+
If your tools aren't being called when structured output is enabled, or you receive an error when combining both features, try one of the workarounds below.
|
|
152
|
+
|
|
153
|
+
### Workaround options
|
|
154
|
+
|
|
155
|
+
When your model doesn't support tools and structured output together, you have three options:
|
|
156
|
+
|
|
157
|
+
1. **Use `jsonPromptInjection: true`** - Injects the schema into the prompt instead of using the API's `response_format` parameter
|
|
158
|
+
2. **Use a separate structuring model** - Pass a `model` to `structuredOutput` to use a second LLM for structuring
|
|
159
|
+
3. **Use `prepareStep`** - Handle tools and structured output in separate steps
|
|
160
|
+
|
|
161
|
+
Each approach is detailed in the sections below.
|
|
162
|
+
|
|
163
|
+
## LLM structured output support
|
|
164
|
+
|
|
165
|
+
Structured output support varies across LLMs due to differences in their APIs. The sections below cover workarounds for models that don't fully support structured output or combining it with tools.
|
|
166
|
+
|
|
167
|
+
### `jsonPromptInjection`
|
|
168
|
+
|
|
169
|
+
By default, Mastra passes the schema to the model provider using the `response_format` API parameter. Most model providers have built-in support for this, which reliably enforces the schema.
|
|
170
|
+
|
|
171
|
+
If your model provider doesn't support `response_format`, you'll get an error from the API. When this happens, set `jsonPromptInjection: true`. This adds the schema to the system prompt instead, instructing the model to output JSON. This is less reliable than the API parameter approach.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { z } from 'zod'
|
|
175
|
+
|
|
176
|
+
const response = await testAgent.generate('Help me plan my day.', {
|
|
177
|
+
structuredOutput: {
|
|
178
|
+
schema: z.array(
|
|
179
|
+
z.object({
|
|
180
|
+
name: z.string(),
|
|
181
|
+
activities: z.array(z.string()),
|
|
182
|
+
}),
|
|
183
|
+
),
|
|
184
|
+
jsonPromptInjection: true,
|
|
185
|
+
},
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
console.log(response.object)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
> **Gemini 2.5 with tools:** Gemini 2.5 models do not support combining `response_format` (structured output) with function calling (tools) in the same API call. If your agent has tools and you're using `structuredOutput` with a Gemini 2.5 model, you must set `jsonPromptInjection: true` to avoid the error `Function calling with a response mime type: 'application/json' is unsupported`.
|
|
192
|
+
>
|
|
193
|
+
> ```typescript
|
|
194
|
+
> const response = await agentWithTools.generate('Your prompt', {
|
|
195
|
+
> structuredOutput: {
|
|
196
|
+
> schema: yourSchema,
|
|
197
|
+
> jsonPromptInjection: true, // Required for Gemini 2.5 when tools are present
|
|
198
|
+
> },
|
|
199
|
+
> })
|
|
200
|
+
> ```
|
|
201
|
+
|
|
202
|
+
### Using a separate structuring model
|
|
203
|
+
|
|
204
|
+
When `model` is provided to the `structuredOutput` property, Mastra uses a separate internal agent to handle the structured output. The main agent will handle all of the steps (including tool calling) and the structured output model will handle only the generation of structured output.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const response = await testAgent.generate("Tell me about TypeScript.", {
|
|
208
|
+
structuredOutput: {
|
|
209
|
+
schema: yourSchema
|
|
210
|
+
model: 'openai/gpt-4o'
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Multi-step approach with `prepareStep`
|
|
216
|
+
|
|
217
|
+
For models that don't support tools and structured outputs together, you can use `prepareStep` to handle them in separate steps.
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
const result = await agent.stream('weather in vancouver?', {
|
|
221
|
+
prepareStep: async ({ stepNumber }) => {
|
|
222
|
+
if (stepNumber === 0) {
|
|
223
|
+
return {
|
|
224
|
+
model: 'anthropic/claude-sonnet-4-20250514',
|
|
225
|
+
tools: {
|
|
226
|
+
weatherTool,
|
|
227
|
+
},
|
|
228
|
+
toolChoice: 'required',
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
model: 'anthropic/claude-sonnet-4-20250514',
|
|
233
|
+
tools: undefined,
|
|
234
|
+
structuredOutput: {
|
|
235
|
+
schema: z.object({
|
|
236
|
+
temperature: z.number(),
|
|
237
|
+
humidity: z.number(),
|
|
238
|
+
windSpeed: z.number(),
|
|
239
|
+
}),
|
|
240
|
+
},
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
})
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Error handling
|
|
247
|
+
|
|
248
|
+
When schema validation fails, you can control how errors are handled using `errorStrategy`. The default `strict` strategy throws an error, while `warn` logs a warning and continues. The `fallback` strategy returns the values provided using `fallbackValue`.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { z } from 'zod'
|
|
252
|
+
|
|
253
|
+
const response = await testAgent.generate('Tell me about TypeScript.', {
|
|
254
|
+
structuredOutput: {
|
|
255
|
+
schema: z.object({
|
|
256
|
+
summary: z.string(),
|
|
257
|
+
keyFeatures: z.array(z.string()),
|
|
258
|
+
}),
|
|
259
|
+
errorStrategy: 'fallback',
|
|
260
|
+
fallbackValue: {
|
|
261
|
+
summary: 'TypeScript is a typed superset of JavaScript',
|
|
262
|
+
keyFeatures: ['Static typing', 'Compiles to JavaScript', 'Better tooling'],
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
console.log(response.object)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Related
|
|
271
|
+
|
|
272
|
+
- [Using Tools](https://mastra.ai/docs/agents/using-tools)
|
|
273
|
+
- [Agent Memory](https://mastra.ai/docs/agents/agent-memory)
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# Supervisor Agents
|
|
2
|
+
|
|
3
|
+
A supervisor agent coordinates multiple subagents using `agent.stream()` or `agent.generate()`. You configure subagents on the supervisor's `agents` property, and the supervisor uses its instructions and each subagent's `description` to decide when and how to delegate tasks.
|
|
4
|
+
|
|
5
|
+
## When to use supervisor agents
|
|
6
|
+
|
|
7
|
+
Use supervisor agents when a task requires multiple agents with different specializations to work together. The supervisor handles delegation decisions, context passing, and result synthesis.
|
|
8
|
+
|
|
9
|
+
Common use cases:
|
|
10
|
+
|
|
11
|
+
- Research and writing workflows where one agent gathers data and another produces content
|
|
12
|
+
- Multi-step tasks that need different expertise at each stage
|
|
13
|
+
- Tasks where you need fine-grained control over delegation behavior
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
Define subagents with clear descriptions, then create a supervisor agent that references them:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { Agent } from '@mastra/core/agent'
|
|
21
|
+
import { Memory } from '@mastra/memory'
|
|
22
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
23
|
+
|
|
24
|
+
const researchAgent = new Agent({
|
|
25
|
+
id: 'research-agent',
|
|
26
|
+
description: 'Gathers factual information and returns bullet-point summaries.',
|
|
27
|
+
model: 'openai/gpt-4o-mini',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const writingAgent = new Agent({
|
|
31
|
+
id: 'writing-agent',
|
|
32
|
+
description: 'Transforms research into well-structured articles.',
|
|
33
|
+
model: 'openai/gpt-4o-mini',
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const supervisor = new Agent({
|
|
37
|
+
id: 'supervisor',
|
|
38
|
+
instructions: `You coordinate research and writing using specialized agents.
|
|
39
|
+
Delegate to research-agent for facts, then writing-agent for content.`,
|
|
40
|
+
model: 'openai/gpt-5.1',
|
|
41
|
+
agents: { researchAgent, writingAgent },
|
|
42
|
+
memory: new Memory({
|
|
43
|
+
storage: new LibSQLStore({ id: 'storage', url: 'file:mastra.db' }),
|
|
44
|
+
}),
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const stream = await supervisor.stream('Research AI in education and write an article', {
|
|
48
|
+
maxSteps: 10,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
for await (const chunk of stream.textStream) {
|
|
52
|
+
process.stdout.write(chunk)
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Delegation hooks
|
|
57
|
+
|
|
58
|
+
Delegation hooks let you intercept, modify, or reject delegations as they happen. Configure them under the `delegation` option, either in the agent's `defaultOptions` or per-call.
|
|
59
|
+
|
|
60
|
+
### onDelegationStart
|
|
61
|
+
|
|
62
|
+
Called before the supervisor delegates to a subagent. Return an object to control the delegation:
|
|
63
|
+
|
|
64
|
+
- `proceed: true` — allow the delegation (default behavior)
|
|
65
|
+
- `proceed: false` — reject the delegation with a `rejectionReason`
|
|
66
|
+
- `modifiedPrompt` — rewrite the prompt sent to the subagent
|
|
67
|
+
- `modifiedMaxSteps` — limit the subagent's iteration count
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const stream = await supervisor.stream('Research AI trends', {
|
|
71
|
+
maxSteps: 10,
|
|
72
|
+
delegation: {
|
|
73
|
+
onDelegationStart: async context => {
|
|
74
|
+
console.log(`Delegating to: ${context.primitiveId}`)
|
|
75
|
+
|
|
76
|
+
// Modify the prompt for a specific agent
|
|
77
|
+
if (context.primitiveId === 'research-agent') {
|
|
78
|
+
return {
|
|
79
|
+
proceed: true,
|
|
80
|
+
modifiedPrompt: `${context.prompt}\n\nFocus on 2024-2025 data.`,
|
|
81
|
+
modifiedMaxSteps: 5,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Reject delegation after too many iterations
|
|
86
|
+
if (context.iteration > 8) {
|
|
87
|
+
return {
|
|
88
|
+
proceed: false,
|
|
89
|
+
rejectionReason: 'Max iterations reached. Synthesize current findings.',
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { proceed: true }
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The `context` object includes:
|
|
100
|
+
|
|
101
|
+
| Property | Description |
|
|
102
|
+
| ------------- | ----------------------------------------- |
|
|
103
|
+
| `primitiveId` | The ID of the subagent being delegated to |
|
|
104
|
+
| `prompt` | The prompt the supervisor is sending |
|
|
105
|
+
| `iteration` | Current iteration number |
|
|
106
|
+
|
|
107
|
+
### onDelegationComplete
|
|
108
|
+
|
|
109
|
+
Called after a delegation finishes. Use it to inspect results, provide feedback, or stop execution:
|
|
110
|
+
|
|
111
|
+
- `context.bail()` — stop the supervisor loop immediately
|
|
112
|
+
- Return `{ feedback: '...' }` — add feedback that gets saved to the supervisor's memory and is visible to subsequent iterations
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
const stream = await supervisor.stream('Research AI trends', {
|
|
116
|
+
maxSteps: 10,
|
|
117
|
+
delegation: {
|
|
118
|
+
onDelegationComplete: async context => {
|
|
119
|
+
console.log(`Completed: ${context.primitiveId}`)
|
|
120
|
+
|
|
121
|
+
// Bail on errors
|
|
122
|
+
if (context.error) {
|
|
123
|
+
context.bail()
|
|
124
|
+
return {
|
|
125
|
+
feedback: `Delegation to ${context.primitiveId} failed: ${context.error}. Try a different approach.`,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The `context` object includes:
|
|
134
|
+
|
|
135
|
+
| Property | Description |
|
|
136
|
+
| ------------- | ------------------------------------ |
|
|
137
|
+
| `primitiveId` | The ID of the subagent that ran |
|
|
138
|
+
| `result` | The subagent's response |
|
|
139
|
+
| `error` | Error if the delegation failed |
|
|
140
|
+
| `bail()` | Function to stop the supervisor loop |
|
|
141
|
+
|
|
142
|
+
## Message filtering
|
|
143
|
+
|
|
144
|
+
By default, subagents receive the full conversation context from the supervisor. Use `messageFilter` to control what messages are shared — for example, to remove sensitive data or limit context size.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const stream = await supervisor.stream('Research AI trends', {
|
|
148
|
+
maxSteps: 10,
|
|
149
|
+
delegation: {
|
|
150
|
+
messageFilter: ({ messages, primitiveId, prompt }) => {
|
|
151
|
+
// Remove messages containing sensitive data
|
|
152
|
+
return messages
|
|
153
|
+
.filter(msg => {
|
|
154
|
+
const content =
|
|
155
|
+
typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content)
|
|
156
|
+
return !content.includes('confidential')
|
|
157
|
+
})
|
|
158
|
+
.slice(-10) // Only pass the last 10 messages
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The callback receives `messages` (the full conversation history), `primitiveId` (the subagent ID), and `prompt` (the delegation prompt). Return the filtered array of messages.
|
|
165
|
+
|
|
166
|
+
## Iteration monitoring
|
|
167
|
+
|
|
168
|
+
`onIterationComplete` is called after each iteration of the supervisor loop. Use it to log progress, inject feedback, or stop execution early.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const stream = await supervisor.stream('Research AI trends', {
|
|
172
|
+
maxSteps: 10,
|
|
173
|
+
onIterationComplete: async context => {
|
|
174
|
+
console.log(`Iteration ${context.iteration}/${context.maxIterations}`)
|
|
175
|
+
console.log(`Finish reason: ${context.finishReason}`)
|
|
176
|
+
|
|
177
|
+
// Inject feedback to guide the agent
|
|
178
|
+
if (!context.text.includes('recommendations')) {
|
|
179
|
+
return {
|
|
180
|
+
continue: true,
|
|
181
|
+
feedback: 'Please include specific recommendations in your analysis.',
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Stop early when the response is sufficient
|
|
186
|
+
if (context.text.length > 1000 && context.finishReason === 'stop') {
|
|
187
|
+
return { continue: false }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return { continue: true }
|
|
191
|
+
},
|
|
192
|
+
})
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Return `{ continue: true }` to keep iterating, or `{ continue: false }` to stop. Include optional `feedback` to add guidance that's visible to the next iteration.
|
|
196
|
+
|
|
197
|
+
## Memory isolation
|
|
198
|
+
|
|
199
|
+
The supervisor pattern implements memory isolation — subagents receive the full conversation context for better decision-making, but only their specific delegation prompt and response are saved to their memory.
|
|
200
|
+
|
|
201
|
+
How it works:
|
|
202
|
+
|
|
203
|
+
1. **Full context forwarded** — When the supervisor delegates, the subagent receives all messages from the supervisor's conversation
|
|
204
|
+
2. **Scoped memory saves** — Only the delegation prompt and the subagent's response are saved to the subagent's memory
|
|
205
|
+
3. **Fresh thread per invocation** — Each delegation uses a unique thread ID, ensuring clean separation
|
|
206
|
+
|
|
207
|
+
This ensures subagents have the context they need without cluttering their memory with the entire supervisor conversation.
|
|
208
|
+
|
|
209
|
+
## Tool approval propagation
|
|
210
|
+
|
|
211
|
+
Tool approvals propagate through the delegation chain. When a subagent uses a tool with `requireApproval: true` or calls `suspend()`, the approval request surfaces to the supervisor level.
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const sensitiveDataTool = createTool({
|
|
215
|
+
id: 'get-user-data',
|
|
216
|
+
requireApproval: true,
|
|
217
|
+
execute: async input => {
|
|
218
|
+
return await database.getUserData(input.userId)
|
|
219
|
+
},
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
const dataAgent = new Agent({
|
|
223
|
+
id: 'data-agent',
|
|
224
|
+
tools: { sensitiveDataTool },
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
const supervisor = new Agent({
|
|
228
|
+
id: 'supervisor',
|
|
229
|
+
agents: { dataAgent },
|
|
230
|
+
memory: new Memory(),
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
const stream = await supervisor.stream('Get data for user 123')
|
|
234
|
+
|
|
235
|
+
for await (const chunk of stream.fullStream) {
|
|
236
|
+
if (chunk.type === 'tool-call-approval') {
|
|
237
|
+
console.log('Tool requires approval:', chunk.payload.toolName)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Task completion scoring
|
|
243
|
+
|
|
244
|
+
Task completion scorers validate whether the task is complete after each iteration. If validation fails, the supervisor continues iterating. Feedback from failed scorers is included in the conversation context so subagents can see what was missing.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { createScorer } from '@mastra/core/evals'
|
|
248
|
+
|
|
249
|
+
const taskCompleteScorer = createScorer({
|
|
250
|
+
id: 'task-complete',
|
|
251
|
+
name: 'Task Completeness',
|
|
252
|
+
}).generateScore(async context => {
|
|
253
|
+
const text = (context.run.output || '').toString()
|
|
254
|
+
const hasAnalysis = text.includes('analysis')
|
|
255
|
+
const hasRecommendations = text.includes('recommendation')
|
|
256
|
+
return hasAnalysis && hasRecommendations ? 1 : 0
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
const stream = await supervisor.stream('Research AI in education', {
|
|
260
|
+
maxSteps: 10,
|
|
261
|
+
isTaskComplete: {
|
|
262
|
+
scorers: [taskCompleteScorer],
|
|
263
|
+
strategy: 'all',
|
|
264
|
+
onComplete: async result => {
|
|
265
|
+
console.log('Task complete:', result.complete)
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
})
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Writing effective instructions
|
|
272
|
+
|
|
273
|
+
Clear instructions are essential for effective delegation. Your supervisor's `instructions` should specify available resources, when to use each one, how to coordinate them, and success criteria.
|
|
274
|
+
|
|
275
|
+
Each subagent should have a clear `description` that explains what it does, what format it returns, and when to use it. The supervisor uses these descriptions to make delegation decisions.
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const supervisor = new Agent({
|
|
279
|
+
instructions: `You coordinate research and writing tasks.
|
|
280
|
+
|
|
281
|
+
Available resources:
|
|
282
|
+
- researchAgent: Gathers factual data and sources (returns bullet points)
|
|
283
|
+
- writingAgent: Transforms research into narrative content (returns full paragraphs)
|
|
284
|
+
|
|
285
|
+
Delegation strategy:
|
|
286
|
+
1. For research requests: Delegate to researchAgent first
|
|
287
|
+
2. For writing requests: Delegate to writingAgent
|
|
288
|
+
3. For complex requests: Delegate to researchAgent first, then writingAgent
|
|
289
|
+
|
|
290
|
+
Success criteria:
|
|
291
|
+
- All user questions are fully answered
|
|
292
|
+
- Response is well-formatted and complete`,
|
|
293
|
+
agents: { researchAgent, writingAgent },
|
|
294
|
+
})
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Related
|
|
298
|
+
|
|
299
|
+
- [Agent Networks](https://mastra.ai/docs/agents/networks)
|
|
300
|
+
- [Migration: .network() to Supervisor Pattern](https://mastra.ai/guides/migrations/network-to-supervisor)
|
|
301
|
+
- [Guide: Research Coordinator](https://mastra.ai/guides/guide/research-coordinator)
|
|
302
|
+
- [Agent.stream() Reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
303
|
+
- [Agent.generate() Reference](https://mastra.ai/reference/agents/generate)
|
|
304
|
+
- [Agent Approval](https://mastra.ai/docs/agents/agent-approval)
|