@mastra/mcp-docs-server 1.0.0-beta.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +3 -1
- package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +3 -1
- package/.docs/organized/changelogs/%40internal%2Fplayground.md +40 -0
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +8 -8
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +3 -1
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +287 -287
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +299 -299
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +53 -53
- package/.docs/organized/changelogs/%40mastra%2Fauth.md +38 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +66 -66
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +522 -212
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +662 -200
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +439 -234
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +450 -211
- package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +202 -0
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +448 -22
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +3359 -289
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +60 -60
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +289 -289
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +90 -90
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +74 -74
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +70 -70
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +248 -221
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +70 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +403 -225
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +72 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +145 -145
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +54 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +456 -226
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +625 -229
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +71 -71
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +247 -247
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +281 -281
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +354 -156
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +545 -212
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +481 -202
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +194 -194
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +781 -235
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +198 -198
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +655 -248
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +163 -163
- package/.docs/organized/changelogs/%40mastra%2Frag.md +310 -310
- package/.docs/organized/changelogs/%40mastra%2Freact.md +328 -237
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +64 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +160 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +850 -239
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +479 -232
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +53 -53
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +110 -110
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +15 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +98 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +54 -54
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +46 -46
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +93 -93
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +45 -45
- package/.docs/organized/changelogs/create-mastra.md +215 -215
- package/.docs/organized/changelogs/mastra.md +278 -278
- package/.docs/organized/code-examples/a2a.md +2 -2
- package/.docs/organized/code-examples/agent-v6.md +221 -0
- package/.docs/organized/code-examples/agui.md +4 -4
- package/.docs/organized/code-examples/ai-elements.md +3 -3
- package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
- package/.docs/organized/code-examples/ai-sdk-v5.md +3 -3
- package/.docs/organized/code-examples/assistant-ui.md +5 -5
- package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +2 -2
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +3 -3
- package/.docs/organized/code-examples/client-side-tools.md +4 -4
- package/.docs/organized/code-examples/crypto-chatbot.md +5 -5
- package/.docs/organized/code-examples/experimental-auth-weather-agent.md +1 -1
- package/.docs/organized/code-examples/fireworks-r1.md +2 -2
- package/.docs/organized/code-examples/heads-up-game.md +7 -7
- package/.docs/organized/code-examples/inngest.md +1075 -0
- package/.docs/organized/code-examples/mcp-configuration.md +1 -1
- package/.docs/organized/code-examples/mcp-server-adapters.md +2 -2
- package/.docs/organized/code-examples/memory-per-resource-example.md +3 -3
- package/.docs/organized/code-examples/memory-todo-agent.md +1 -1
- package/.docs/organized/code-examples/memory-with-context.md +1 -1
- package/.docs/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/openapi-spec-writer.md +3 -3
- package/.docs/organized/code-examples/quick-start.md +1 -5
- package/.docs/organized/code-examples/server-app-access.md +2 -2
- package/.docs/organized/code-examples/server-express-adapter.md +1 -1
- package/.docs/organized/code-examples/server-fastify-adapter.md +83 -0
- package/.docs/organized/code-examples/server-hono-adapter.md +2 -2
- package/.docs/organized/code-examples/server-koa-adapter.md +94 -0
- package/.docs/organized/code-examples/stock-price-tool.md +21 -2
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +1 -1
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +1 -1
- package/.docs/organized/code-examples/workflow-with-memory.md +1 -1
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +1 -1
- package/.docs/organized/code-examples/workflow-with-suspend-resume.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +24 -6
- package/.docs/raw/agents/agent-approval.mdx +209 -12
- package/.docs/raw/agents/agent-memory.mdx +36 -32
- package/.docs/raw/agents/guardrails.mdx +105 -56
- package/.docs/raw/agents/network-approval.mdx +281 -0
- package/.docs/raw/agents/networks.mdx +69 -13
- package/.docs/raw/agents/overview.mdx +43 -25
- package/.docs/raw/agents/processors.mdx +234 -17
- package/.docs/raw/agents/structured-output.mdx +78 -8
- package/.docs/raw/agents/using-tools.mdx +67 -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 +3 -3
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
- package/.docs/raw/course/03-agent-memory/07-understanding-memory-threads.md +35 -0
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
- package/.docs/raw/course/03-agent-memory/13-vector-store-configuration.md +1 -1
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +4 -5
- package/.docs/raw/course/03-agent-memory/18-advanced-configuration-semantic-recall.md +1 -1
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +3 -4
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +3 -4
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +3 -4
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +3 -4
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
- package/.docs/raw/deployment/cloud-providers.mdx +22 -0
- package/.docs/raw/deployment/mastra-server.mdx +140 -0
- package/.docs/raw/deployment/monorepo.mdx +106 -42
- package/.docs/raw/deployment/overview.mdx +35 -48
- package/.docs/raw/deployment/web-framework.mdx +17 -19
- package/.docs/raw/deployment/workflow-runners.mdx +16 -0
- package/.docs/raw/evals/built-in-scorers.mdx +2 -0
- package/.docs/raw/evals/custom-scorers.mdx +60 -12
- package/.docs/raw/evals/overview.mdx +6 -6
- package/.docs/raw/evals/running-in-ci.mdx +4 -2
- package/.docs/raw/getting-started/manual-install.mdx +20 -20
- package/.docs/raw/getting-started/mcp-docs-server.mdx +59 -2
- package/.docs/raw/getting-started/project-structure.mdx +2 -2
- package/.docs/raw/getting-started/start.mdx +17 -1
- package/.docs/raw/getting-started/studio.mdx +6 -35
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +23 -33
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1034 -80
- package/.docs/raw/guides/build-your-ui/assistant-ui.mdx +8 -8
- package/.docs/raw/guides/build-your-ui/copilotkit.mdx +32 -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 +18 -23
- package/.docs/raw/guides/deployment/index.mdx +32 -0
- package/.docs/raw/guides/deployment/inngest.mdx +673 -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 +173 -61
- package/.docs/raw/guides/getting-started/nuxt.mdx +505 -0
- package/.docs/raw/guides/getting-started/quickstart.mdx +5 -5
- 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 +20 -20
- package/.docs/raw/guides/guide/stock-agent.mdx +5 -5
- package/.docs/raw/guides/guide/web-search.mdx +38 -38
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +7 -7
- package/.docs/raw/guides/index.mdx +0 -1
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +2 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +105 -4
- package/.docs/raw/guides/migrations/upgrade-to-v1/cli.mdx +15 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +170 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/deployment.mdx +42 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/mastra.mdx +0 -35
- package/.docs/raw/guides/migrations/upgrade-to-v1/memory.mdx +40 -3
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +17 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/processors.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/rag.mdx +47 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/storage.mdx +271 -25
- package/.docs/raw/guides/migrations/upgrade-to-v1/tracing.mdx +72 -17
- package/.docs/raw/guides/migrations/upgrade-to-v1/vectors.mdx +46 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +50 -7
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +21 -23
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mastra-cloud/deployment.mdx +86 -0
- package/.docs/raw/mastra-cloud/observability.mdx +43 -0
- package/.docs/raw/mastra-cloud/overview.mdx +31 -0
- package/.docs/raw/mastra-cloud/setup.mdx +64 -0
- package/.docs/raw/mastra-cloud/studio.mdx +35 -0
- package/.docs/raw/mcp/overview.mdx +60 -25
- package/.docs/raw/mcp/publishing-mcp-server.mdx +7 -4
- package/.docs/raw/memory/memory-processors.mdx +17 -12
- package/.docs/raw/memory/message-history.mdx +72 -0
- package/.docs/raw/memory/overview.mdx +38 -76
- package/.docs/raw/memory/semantic-recall.mdx +65 -52
- package/.docs/raw/memory/storage.mdx +248 -0
- package/.docs/raw/memory/working-memory.mdx +24 -13
- package/.docs/raw/observability/logging.mdx +16 -15
- package/.docs/raw/observability/overview.mdx +27 -7
- package/.docs/raw/observability/tracing/bridges/otel.mdx +7 -4
- package/.docs/raw/observability/tracing/exporters/arize.mdx +61 -24
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +32 -22
- package/.docs/raw/observability/tracing/exporters/cloud.mdx +24 -5
- package/.docs/raw/observability/tracing/exporters/datadog.mdx +175 -0
- package/.docs/raw/observability/tracing/exporters/default.mdx +28 -7
- package/.docs/raw/observability/tracing/exporters/laminar.mdx +89 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +31 -22
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +33 -3
- package/.docs/raw/observability/tracing/exporters/otel.mdx +194 -22
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +32 -22
- package/.docs/raw/observability/tracing/exporters/sentry.mdx +198 -0
- package/.docs/raw/observability/tracing/overview.mdx +388 -108
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +27 -7
- package/.docs/raw/rag/chunking-and-embedding.mdx +22 -33
- package/.docs/raw/rag/graph-rag.mdx +223 -0
- package/.docs/raw/rag/overview.mdx +6 -3
- package/.docs/raw/rag/retrieval.mdx +53 -57
- package/.docs/raw/rag/vector-databases.mdx +55 -31
- package/.docs/raw/reference/agents/agent.mdx +17 -14
- package/.docs/raw/reference/agents/generate.mdx +172 -44
- package/.docs/raw/reference/agents/generateLegacy.mdx +5 -3
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +5 -3
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +5 -3
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +5 -3
- package/.docs/raw/reference/agents/getDescription.mdx +3 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +5 -3
- package/.docs/raw/reference/agents/getLLM.mdx +5 -3
- package/.docs/raw/reference/agents/getMemory.mdx +5 -3
- package/.docs/raw/reference/agents/getModel.mdx +5 -3
- package/.docs/raw/reference/agents/getTools.mdx +4 -2
- package/.docs/raw/reference/agents/getVoice.mdx +4 -2
- package/.docs/raw/reference/agents/listAgents.mdx +4 -2
- package/.docs/raw/reference/agents/listScorers.mdx +5 -3
- package/.docs/raw/reference/agents/listTools.mdx +4 -2
- package/.docs/raw/reference/agents/listWorkflows.mdx +4 -2
- package/.docs/raw/reference/agents/network.mdx +113 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +6 -3
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +4 -2
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +4 -2
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +5 -3
- package/.docs/raw/reference/ai-sdk/network-route.mdx +6 -3
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +10 -6
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +130 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +110 -0
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +122 -0
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +7 -4
- package/.docs/raw/reference/auth/auth0.mdx +5 -3
- package/.docs/raw/reference/auth/clerk.mdx +5 -3
- package/.docs/raw/reference/auth/firebase.mdx +6 -5
- package/.docs/raw/reference/auth/jwt.mdx +5 -3
- package/.docs/raw/reference/auth/supabase.mdx +5 -3
- package/.docs/raw/reference/auth/workos.mdx +5 -3
- package/.docs/raw/reference/cli/create-mastra.mdx +12 -10
- package/.docs/raw/reference/cli/mastra.mdx +63 -15
- package/.docs/raw/reference/client-js/agents.mdx +77 -35
- package/.docs/raw/reference/client-js/error-handling.mdx +3 -3
- package/.docs/raw/reference/client-js/logs.mdx +2 -0
- package/.docs/raw/reference/client-js/mastra-client.mdx +4 -2
- package/.docs/raw/reference/client-js/memory.mdx +43 -1
- package/.docs/raw/reference/client-js/observability.mdx +2 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +2 -0
- package/.docs/raw/reference/client-js/tools.mdx +2 -0
- package/.docs/raw/reference/client-js/vectors.mdx +2 -0
- package/.docs/raw/reference/client-js/workflows.mdx +47 -3
- package/.docs/raw/reference/configuration.mdx +761 -0
- package/.docs/raw/reference/core/addGateway.mdx +2 -0
- package/.docs/raw/reference/core/getAgent.mdx +3 -1
- package/.docs/raw/reference/core/getAgentById.mdx +3 -1
- package/.docs/raw/reference/core/getDeployer.mdx +3 -1
- package/.docs/raw/reference/core/getGateway.mdx +2 -0
- package/.docs/raw/reference/core/getGatewayById.mdx +2 -0
- package/.docs/raw/reference/core/getLogger.mdx +3 -1
- package/.docs/raw/reference/core/getMCPServer.mdx +3 -1
- package/.docs/raw/reference/core/getMCPServerById.mdx +3 -1
- package/.docs/raw/reference/core/getMemory.mdx +7 -3
- package/.docs/raw/reference/core/getScorer.mdx +2 -0
- package/.docs/raw/reference/core/getScorerById.mdx +2 -0
- package/.docs/raw/reference/core/getServer.mdx +6 -4
- package/.docs/raw/reference/core/getStorage.mdx +5 -3
- package/.docs/raw/reference/core/getStoredAgentById.mdx +6 -4
- package/.docs/raw/reference/core/getTelemetry.mdx +3 -1
- package/.docs/raw/reference/core/getVector.mdx +3 -1
- package/.docs/raw/reference/core/getWorkflow.mdx +3 -1
- package/.docs/raw/reference/core/listAgents.mdx +3 -1
- package/.docs/raw/reference/core/listGateways.mdx +2 -0
- package/.docs/raw/reference/core/listLogs.mdx +3 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +3 -1
- package/.docs/raw/reference/core/listMCPServers.mdx +3 -1
- package/.docs/raw/reference/core/listMemory.mdx +8 -4
- package/.docs/raw/reference/core/listScorers.mdx +2 -0
- package/.docs/raw/reference/core/listStoredAgents.mdx +7 -5
- package/.docs/raw/reference/core/listVectors.mdx +3 -1
- package/.docs/raw/reference/core/listWorkflows.mdx +3 -1
- package/.docs/raw/reference/core/mastra-class.mdx +27 -20
- package/.docs/raw/reference/core/mastra-model-gateway.mdx +2 -0
- package/.docs/raw/reference/core/setLogger.mdx +3 -1
- package/.docs/raw/reference/core/setStorage.mdx +6 -4
- package/.docs/raw/reference/deployer/cloudflare.mdx +22 -53
- package/.docs/raw/reference/deployer/deployer.mdx +2 -1
- package/.docs/raw/reference/deployer/netlify.mdx +4 -1
- package/.docs/raw/reference/deployer/vercel.mdx +5 -4
- package/.docs/raw/reference/evals/answer-relevancy.mdx +4 -1
- package/.docs/raw/reference/evals/answer-similarity.mdx +4 -1
- package/.docs/raw/reference/evals/bias.mdx +4 -1
- package/.docs/raw/reference/evals/completeness.mdx +4 -1
- package/.docs/raw/reference/evals/content-similarity.mdx +4 -1
- package/.docs/raw/reference/evals/context-precision.mdx +4 -1
- package/.docs/raw/reference/evals/context-relevance.mdx +2 -0
- package/.docs/raw/reference/evals/create-scorer.mdx +11 -3
- package/.docs/raw/reference/evals/faithfulness.mdx +4 -1
- package/.docs/raw/reference/evals/hallucination.mdx +4 -1
- package/.docs/raw/reference/evals/keyword-coverage.mdx +4 -1
- package/.docs/raw/reference/evals/mastra-scorer.mdx +2 -0
- package/.docs/raw/reference/evals/noise-sensitivity.mdx +2 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +9 -7
- package/.docs/raw/reference/evals/run-evals.mdx +3 -1
- package/.docs/raw/reference/evals/scorer-utils.mdx +3 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +4 -1
- package/.docs/raw/reference/evals/tone-consistency.mdx +4 -1
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +25 -23
- package/.docs/raw/reference/evals/toxicity.mdx +4 -1
- package/.docs/raw/reference/index.mdx +2 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +10 -8
- package/.docs/raw/reference/memory/clone-utilities.mdx +345 -0
- package/.docs/raw/reference/memory/cloneThread.mdx +237 -0
- package/.docs/raw/reference/memory/createThread.mdx +6 -4
- package/.docs/raw/reference/memory/deleteMessages.mdx +4 -2
- package/.docs/raw/reference/memory/getThreadById.mdx +3 -1
- package/.docs/raw/reference/memory/listThreads.mdx +187 -0
- package/.docs/raw/reference/memory/memory-class.mdx +27 -20
- package/.docs/raw/reference/memory/recall.mdx +6 -4
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +6 -2
- package/.docs/raw/reference/observability/tracing/configuration.mdx +51 -0
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +25 -6
- package/.docs/raw/reference/observability/tracing/exporters/braintrust.mdx +23 -2
- package/.docs/raw/reference/observability/tracing/exporters/cloud-exporter.mdx +10 -0
- package/.docs/raw/reference/observability/tracing/exporters/console-exporter.mdx +3 -0
- package/.docs/raw/reference/observability/tracing/exporters/datadog.mdx +172 -0
- package/.docs/raw/reference/observability/tracing/exporters/default-exporter.mdx +10 -0
- package/.docs/raw/reference/observability/tracing/exporters/laminar.mdx +139 -0
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +26 -4
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +10 -0
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +51 -34
- package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +25 -4
- package/.docs/raw/reference/observability/tracing/exporters/sentry.mdx +224 -0
- package/.docs/raw/reference/observability/tracing/instances.mdx +2 -0
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +20 -0
- package/.docs/raw/reference/observability/tracing/processors/sensitive-data-filter.mdx +2 -0
- package/.docs/raw/reference/observability/tracing/spans.mdx +2 -0
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +4 -2
- package/.docs/raw/reference/processors/language-detector.mdx +6 -3
- package/.docs/raw/reference/processors/message-history-processor.mdx +5 -2
- package/.docs/raw/reference/processors/moderation-processor.mdx +6 -4
- package/.docs/raw/reference/processors/pii-detector.mdx +6 -4
- package/.docs/raw/reference/processors/processor-interface.mdx +326 -23
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +5 -3
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +7 -2
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +5 -3
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +62 -19
- package/.docs/raw/reference/processors/tool-call-filter.mdx +5 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +6 -3
- package/.docs/raw/reference/processors/working-memory-processor.mdx +6 -3
- package/.docs/raw/reference/rag/chunk.mdx +7 -6
- package/.docs/raw/reference/rag/database-config.mdx +8 -6
- package/.docs/raw/reference/rag/document.mdx +2 -0
- package/.docs/raw/reference/rag/embeddings.mdx +2 -0
- package/.docs/raw/reference/rag/extract-params.mdx +57 -3
- package/.docs/raw/reference/rag/graph-rag.mdx +2 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +27 -7
- package/.docs/raw/reference/rag/rerank.mdx +2 -0
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +2 -0
- package/.docs/raw/reference/server/create-route.mdx +34 -18
- package/.docs/raw/reference/server/express-adapter.mdx +27 -51
- package/.docs/raw/reference/server/fastify-adapter.mdx +130 -0
- package/.docs/raw/reference/server/hono-adapter.mdx +27 -51
- package/.docs/raw/reference/server/koa-adapter.mdx +129 -0
- package/.docs/raw/reference/server/mastra-server.mdx +52 -34
- package/.docs/raw/reference/server/routes.mdx +73 -10
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +10 -5
- package/.docs/raw/reference/storage/cloudflare.mdx +12 -2
- package/.docs/raw/reference/storage/composite.mdx +245 -0
- package/.docs/raw/reference/storage/convex.mdx +8 -6
- package/.docs/raw/reference/storage/dynamodb.mdx +134 -8
- package/.docs/raw/reference/storage/lance.mdx +9 -5
- package/.docs/raw/reference/storage/libsql.mdx +76 -54
- package/.docs/raw/reference/storage/mongodb.mdx +115 -16
- package/.docs/raw/reference/storage/mssql.mdx +11 -6
- package/.docs/raw/{server-db/storage.mdx → reference/storage/overview.mdx} +15 -111
- package/.docs/raw/reference/storage/postgresql.mdx +228 -83
- package/.docs/raw/reference/storage/upstash.mdx +78 -2
- package/.docs/raw/reference/streaming/ChunkType.mdx +31 -3
- package/.docs/raw/reference/streaming/agents/MastraModelOutput.mdx +67 -6
- package/.docs/raw/reference/streaming/agents/stream.mdx +48 -51
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +5 -3
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +3 -1
- package/.docs/raw/reference/streaming/workflows/resumeStream.mdx +3 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +37 -22
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +6 -4
- package/.docs/raw/reference/templates/overview.mdx +3 -2
- package/.docs/raw/reference/tools/client.mdx +3 -0
- package/.docs/raw/reference/tools/create-tool.mdx +127 -5
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +2 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +40 -3
- package/.docs/raw/reference/tools/mcp-client.mdx +110 -1
- package/.docs/raw/reference/tools/mcp-server.mdx +278 -24
- package/.docs/raw/reference/tools/vector-query-tool.mdx +68 -4
- package/.docs/raw/reference/vectors/astra.mdx +5 -3
- package/.docs/raw/reference/vectors/chroma.mdx +5 -3
- package/.docs/raw/reference/vectors/convex.mdx +14 -12
- package/.docs/raw/reference/vectors/couchbase.mdx +7 -5
- package/.docs/raw/reference/vectors/duckdb.mdx +12 -10
- package/.docs/raw/reference/vectors/elasticsearch.mdx +12 -4
- package/.docs/raw/reference/vectors/lance.mdx +6 -4
- package/.docs/raw/reference/vectors/libsql.mdx +66 -13
- package/.docs/raw/reference/vectors/mongodb.mdx +90 -10
- package/.docs/raw/reference/vectors/opensearch.mdx +30 -3
- package/.docs/raw/reference/vectors/pg.mdx +58 -6
- package/.docs/raw/reference/vectors/pinecone.mdx +23 -8
- package/.docs/raw/reference/vectors/qdrant.mdx +148 -4
- package/.docs/raw/reference/vectors/s3vectors.mdx +8 -6
- package/.docs/raw/reference/vectors/turbopuffer.mdx +6 -4
- package/.docs/raw/reference/vectors/upstash.mdx +60 -6
- package/.docs/raw/reference/vectors/vectorize.mdx +5 -3
- package/.docs/raw/reference/voice/azure.mdx +2 -0
- package/.docs/raw/reference/voice/cloudflare.mdx +2 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +4 -0
- package/.docs/raw/reference/voice/deepgram.mdx +2 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +2 -0
- package/.docs/raw/reference/voice/google-gemini-live.mdx +3 -0
- package/.docs/raw/reference/voice/google.mdx +2 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +2 -0
- package/.docs/raw/reference/voice/murf.mdx +2 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +3 -0
- package/.docs/raw/reference/voice/openai.mdx +2 -0
- package/.docs/raw/reference/voice/playai.mdx +2 -0
- package/.docs/raw/reference/voice/sarvam.mdx +2 -0
- package/.docs/raw/reference/voice/speechify.mdx +2 -0
- package/.docs/raw/reference/voice/voice.addInstructions.mdx +3 -0
- package/.docs/raw/reference/voice/voice.addTools.mdx +3 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +4 -0
- package/.docs/raw/reference/voice/voice.close.mdx +3 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +5 -1
- package/.docs/raw/reference/voice/voice.events.mdx +2 -0
- package/.docs/raw/reference/voice/voice.getSpeakers.mdx +3 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +6 -0
- package/.docs/raw/reference/voice/voice.off.mdx +2 -0
- package/.docs/raw/reference/voice/voice.on.mdx +5 -1
- package/.docs/raw/reference/voice/voice.send.mdx +4 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +6 -0
- package/.docs/raw/reference/voice/voice.updateConfig.mdx +2 -0
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +55 -5
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +6 -4
- package/.docs/raw/reference/workflows/run-methods/start.mdx +7 -5
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +145 -0
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +10 -8
- package/.docs/raw/reference/workflows/run.mdx +11 -3
- package/.docs/raw/reference/workflows/step.mdx +56 -3
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +3 -1
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +3 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +39 -2
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +3 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +3 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +71 -4
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +9 -7
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +3 -1
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +4 -6
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +4 -6
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +3 -1
- package/.docs/raw/reference/workflows/workflow.mdx +193 -2
- package/.docs/raw/{auth → server/auth}/auth0.mdx +40 -21
- package/.docs/raw/{auth → server/auth}/clerk.mdx +37 -16
- package/.docs/raw/{auth → server/auth}/firebase.mdx +47 -25
- package/.docs/raw/{auth → server/auth}/index.mdx +8 -6
- package/.docs/raw/{auth → server/auth}/jwt.mdx +22 -10
- package/.docs/raw/{auth → server/auth}/supabase.mdx +45 -25
- package/.docs/raw/{auth → server/auth}/workos.mdx +39 -20
- package/.docs/raw/{server-db → server}/custom-adapters.mdx +40 -24
- package/.docs/raw/{server-db → server}/custom-api-routes.mdx +6 -6
- package/.docs/raw/{server-db → server}/mastra-client.mdx +35 -38
- package/.docs/raw/server/mastra-server.mdx +86 -0
- package/.docs/raw/{server-db → server}/middleware.mdx +11 -9
- package/.docs/raw/{server-db → server}/request-context.mdx +85 -43
- package/.docs/raw/{server-db → server}/server-adapters.mdx +154 -33
- package/.docs/raw/streaming/events.mdx +16 -7
- package/.docs/raw/streaming/overview.mdx +30 -17
- package/.docs/raw/streaming/tool-streaming.mdx +8 -6
- package/.docs/raw/streaming/workflow-streaming.mdx +8 -8
- package/.docs/raw/tools-mcp/advanced-usage.mdx +4 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +46 -12
- package/.docs/raw/tools-mcp/overview.mdx +14 -13
- package/.docs/raw/voice/overview.mdx +17 -2
- package/.docs/raw/voice/speech-to-speech.mdx +5 -0
- package/.docs/raw/voice/speech-to-text.mdx +4 -0
- package/.docs/raw/voice/text-to-speech.mdx +3 -0
- package/.docs/raw/workflows/agents-and-tools.mdx +70 -21
- package/.docs/raw/workflows/control-flow.mdx +369 -34
- package/.docs/raw/workflows/error-handling.mdx +192 -18
- package/.docs/raw/workflows/human-in-the-loop.mdx +8 -7
- package/.docs/raw/workflows/input-data-mapping.mdx +9 -7
- package/.docs/raw/workflows/overview.mdx +80 -34
- package/.docs/raw/workflows/snapshots.mdx +19 -45
- package/.docs/raw/workflows/suspend-and-resume.mdx +14 -14
- package/.docs/raw/workflows/time-travel.mdx +25 -21
- package/.docs/raw/workflows/workflow-state.mdx +7 -8
- package/CHANGELOG.md +246 -0
- package/README.md +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/stdio.js +746 -49
- package/dist/tools/course.d.ts.map +1 -1
- package/dist/tools/embedded-docs.d.ts +276 -0
- package/dist/tools/embedded-docs.d.ts.map +1 -0
- package/package.json +9 -8
- package/.docs/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
- package/.docs/raw/deployment/building-mastra.mdx +0 -73
- package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
- package/.docs/raw/deployment/mastra-cloud/dashboard.mdx +0 -100
- package/.docs/raw/deployment/mastra-cloud/observability.mdx +0 -53
- package/.docs/raw/deployment/mastra-cloud/overview.mdx +0 -65
- package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +0 -105
- 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
- package/.docs/raw/reference/core/setTelemetry.mdx +0 -36
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +0 -110
- package/.docs/raw/reference/memory/query.mdx +0 -189
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +0 -70
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +0 -66
- package/.docs/raw/server-db/mastra-server.mdx +0 -97
- package/.docs/raw/workflows/inngest-workflow.mdx +0 -363
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Processors | Agents
|
|
2
|
+
title: "Processors | Agents"
|
|
3
3
|
description: "Learn how to use input and output processors to transform, validate, and control messages in Mastra agents."
|
|
4
|
+
packages:
|
|
5
|
+
- "@mastra/core"
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# Processors
|
|
@@ -12,6 +14,8 @@ Processors are configured as:
|
|
|
12
14
|
- **`inputProcessors`**: Run before messages reach the language model.
|
|
13
15
|
- **`outputProcessors`**: Run after the language model generates a response, but before it's returned to users.
|
|
14
16
|
|
|
17
|
+
You can use individual `Processor` objects or compose them into workflows using Mastra's workflow primitives. Workflows give you advanced control over processor execution order, parallel processing, and conditional logic.
|
|
18
|
+
|
|
15
19
|
Some processors implement both input and output logic and can be used in either array depending on where the transformation should occur.
|
|
16
20
|
|
|
17
21
|
## When to use processors
|
|
@@ -33,18 +37,17 @@ Mastra includes several processors for common use cases. You can also create cus
|
|
|
33
37
|
|
|
34
38
|
Import and instantiate the processor, then pass it to the agent's `inputProcessors` or `outputProcessors` array:
|
|
35
39
|
|
|
36
|
-
```typescript {
|
|
37
|
-
import { openai } from "@ai-sdk/openai";
|
|
40
|
+
```typescript {2,8-14} title="src/mastra/agents/moderated-agent.ts"
|
|
38
41
|
import { Agent } from "@mastra/core/agent";
|
|
39
42
|
import { ModerationProcessor } from "@mastra/core/processors";
|
|
40
43
|
|
|
41
44
|
export const moderatedAgent = new Agent({
|
|
42
45
|
name: "moderated-agent",
|
|
43
46
|
instructions: "You are a helpful assistant",
|
|
44
|
-
model: openai
|
|
47
|
+
model: "openai/gpt-4o-mini",
|
|
45
48
|
inputProcessors: [
|
|
46
49
|
new ModerationProcessor({
|
|
47
|
-
model: openai
|
|
50
|
+
model: "openai/gpt-4.1-nano",
|
|
48
51
|
categories: ["hate", "harassment", "violence"],
|
|
49
52
|
threshold: 0.7,
|
|
50
53
|
strategy: "block",
|
|
@@ -75,7 +78,7 @@ When memory is enabled on an agent, memory processors are automatically added to
|
|
|
75
78
|
```
|
|
76
79
|
[Memory Processors] → [Your inputProcessors]
|
|
77
80
|
```
|
|
78
|
-
Memory loads
|
|
81
|
+
Memory loads message history first, then your processors run.
|
|
79
82
|
|
|
80
83
|
**Output processors:**
|
|
81
84
|
```
|
|
@@ -91,7 +94,7 @@ Custom processors implement the `Processor` interface:
|
|
|
91
94
|
|
|
92
95
|
### Custom input processor
|
|
93
96
|
|
|
94
|
-
```typescript title="src/mastra/processors/custom-input.ts"
|
|
97
|
+
```typescript title="src/mastra/processors/custom-input.ts"
|
|
95
98
|
import type {
|
|
96
99
|
Processor,
|
|
97
100
|
MastraDBMessage,
|
|
@@ -139,7 +142,7 @@ The framework handles both return formats, so modifying system messages is optio
|
|
|
139
142
|
|
|
140
143
|
To modify system messages (e.g., trim verbose prompts for smaller models), return an object with both `messages` and `systemMessages`:
|
|
141
144
|
|
|
142
|
-
```typescript title="src/mastra/processors/system-trimmer.ts"
|
|
145
|
+
```typescript title="src/mastra/processors/system-trimmer.ts"
|
|
143
146
|
import type { Processor, CoreMessage, MastraDBMessage } from "@mastra/core";
|
|
144
147
|
|
|
145
148
|
export class SystemTrimmer implements Processor {
|
|
@@ -168,9 +171,83 @@ This is useful for:
|
|
|
168
171
|
- Filtering or modifying semantic recall content to prevent "prompt too long" errors
|
|
169
172
|
- Dynamically adjusting system instructions based on the conversation
|
|
170
173
|
|
|
174
|
+
### Per-step processing with processInputStep
|
|
175
|
+
|
|
176
|
+
While `processInput` runs once at the start of agent execution, `processInputStep` runs at **each step** of the agentic loop (including tool call continuations). This enables per-step configuration changes like dynamic model switching or tool choice modifications.
|
|
177
|
+
|
|
178
|
+
```typescript title="src/mastra/processors/step-processor.ts"
|
|
179
|
+
import type { Processor, ProcessInputStepArgs, ProcessInputStepResult } from "@mastra/core";
|
|
180
|
+
|
|
181
|
+
export class DynamicModelProcessor implements Processor {
|
|
182
|
+
id = "dynamic-model";
|
|
183
|
+
|
|
184
|
+
async processInputStep({
|
|
185
|
+
stepNumber,
|
|
186
|
+
model,
|
|
187
|
+
toolChoice,
|
|
188
|
+
messageList,
|
|
189
|
+
}: ProcessInputStepArgs): Promise<ProcessInputStepResult> {
|
|
190
|
+
// Use a fast model for initial response
|
|
191
|
+
if (stepNumber === 0) {
|
|
192
|
+
return { model: "openai/gpt-4o-mini" };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Disable tools after 5 steps to force completion
|
|
196
|
+
if (stepNumber > 5) {
|
|
197
|
+
return { toolChoice: "none" };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// No changes for other steps
|
|
201
|
+
return {};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The `processInputStep` method receives:
|
|
207
|
+
- `stepNumber`: Current step in the agentic loop (0-indexed)
|
|
208
|
+
- `steps`: Results from previous steps
|
|
209
|
+
- `messages`: Current messages snapshot (read-only)
|
|
210
|
+
- `systemMessages`: Current system messages (read-only)
|
|
211
|
+
- `messageList`: The full MessageList instance for mutations
|
|
212
|
+
- `model`: Current model being used
|
|
213
|
+
- `tools`: Current tools available for this step
|
|
214
|
+
- `toolChoice`: Current tool choice setting
|
|
215
|
+
- `activeTools`: Currently active tools
|
|
216
|
+
- `providerOptions`: Provider-specific options
|
|
217
|
+
- `modelSettings`: Model settings like temperature
|
|
218
|
+
- `structuredOutput`: Structured output configuration
|
|
219
|
+
|
|
220
|
+
The method can return any combination of:
|
|
221
|
+
- `model`: Change the model for this step
|
|
222
|
+
- `tools`: Replace or add tools (use spread to merge: `{ tools: { ...tools, newTool } }`)
|
|
223
|
+
- `toolChoice`: Change tool selection behavior
|
|
224
|
+
- `activeTools`: Filter which tools are available
|
|
225
|
+
- `messages`: Replace messages (applied to messageList)
|
|
226
|
+
- `systemMessages`: Replace all system messages
|
|
227
|
+
- `providerOptions`: Modify provider options
|
|
228
|
+
- `modelSettings`: Modify model settings
|
|
229
|
+
- `structuredOutput`: Modify structured output configuration
|
|
230
|
+
|
|
231
|
+
#### Using prepareStep callback
|
|
232
|
+
|
|
233
|
+
For simpler per-step logic, you can use the `prepareStep` callback on `generate()` or `stream()` instead of creating a full processor:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
await agent.generate("Complex task", {
|
|
237
|
+
prepareStep: async ({ stepNumber, model }) => {
|
|
238
|
+
if (stepNumber === 0) {
|
|
239
|
+
return { model: "openai/gpt-4o-mini" };
|
|
240
|
+
}
|
|
241
|
+
if (stepNumber > 5) {
|
|
242
|
+
return { toolChoice: "none" };
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
171
248
|
### Custom output processor
|
|
172
249
|
|
|
173
|
-
```typescript title="src/mastra/processors/custom-output.ts"
|
|
250
|
+
```typescript title="src/mastra/processors/custom-output.ts"
|
|
174
251
|
import type {
|
|
175
252
|
Processor,
|
|
176
253
|
MastraDBMessage,
|
|
@@ -204,6 +281,70 @@ export class CustomOutputProcessor implements Processor {
|
|
|
204
281
|
}
|
|
205
282
|
```
|
|
206
283
|
|
|
284
|
+
#### Adding metadata in output processors
|
|
285
|
+
|
|
286
|
+
You can add custom metadata to messages in `processOutputResult`. This metadata is accessible via the response object:
|
|
287
|
+
|
|
288
|
+
```typescript title="src/mastra/processors/metadata-processor.ts"
|
|
289
|
+
import type { Processor, MastraDBMessage } from "@mastra/core";
|
|
290
|
+
|
|
291
|
+
export class MetadataProcessor implements Processor {
|
|
292
|
+
id = "metadata-processor";
|
|
293
|
+
|
|
294
|
+
async processOutputResult({
|
|
295
|
+
messages,
|
|
296
|
+
}: {
|
|
297
|
+
messages: MastraDBMessage[];
|
|
298
|
+
}): Promise<MastraDBMessage[]> {
|
|
299
|
+
return messages.map((msg) => {
|
|
300
|
+
if (msg.role === "assistant") {
|
|
301
|
+
return {
|
|
302
|
+
...msg,
|
|
303
|
+
content: {
|
|
304
|
+
...msg.content,
|
|
305
|
+
metadata: {
|
|
306
|
+
...msg.content.metadata,
|
|
307
|
+
processedAt: new Date().toISOString(),
|
|
308
|
+
customData: "your data here",
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
return msg;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Access the metadata with `generate()`:
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
const result = await agent.generate("Hello");
|
|
323
|
+
|
|
324
|
+
// The response includes uiMessages with processor-added metadata
|
|
325
|
+
const assistantMessage = result.response?.uiMessages?.find((m) => m.role === "assistant");
|
|
326
|
+
console.log(assistantMessage?.metadata?.customData);
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Access the metadata when streaming:
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
const stream = await agent.stream("Hello");
|
|
333
|
+
|
|
334
|
+
for await (const chunk of stream.fullStream) {
|
|
335
|
+
if (chunk.type === "finish") {
|
|
336
|
+
// Access response with processor-added metadata from the finish chunk
|
|
337
|
+
const uiMessages = chunk.payload.response?.uiMessages;
|
|
338
|
+
const assistantMessage = uiMessages?.find((m) => m.role === "assistant");
|
|
339
|
+
console.log(assistantMessage?.metadata?.customData);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Or via the response promise after consuming the stream
|
|
344
|
+
const response = await stream.response;
|
|
345
|
+
console.log(response.uiMessages);
|
|
346
|
+
```
|
|
347
|
+
|
|
207
348
|
## Built-in Utility Processors
|
|
208
349
|
|
|
209
350
|
Mastra provides utility processors for common tasks:
|
|
@@ -215,14 +356,13 @@ Mastra provides utility processors for common tasks:
|
|
|
215
356
|
|
|
216
357
|
Prevents context window overflow by removing older messages when the total token count exceeds a specified limit.
|
|
217
358
|
|
|
218
|
-
```typescript
|
|
359
|
+
```typescript {7-10}
|
|
219
360
|
import { Agent } from "@mastra/core/agent";
|
|
220
361
|
import { TokenLimiter } from "@mastra/core/processors";
|
|
221
|
-
import { openai } from "@ai-sdk/openai";
|
|
222
362
|
|
|
223
363
|
const agent = new Agent({
|
|
224
364
|
name: "my-agent",
|
|
225
|
-
model: openai
|
|
365
|
+
model: "openai/gpt-4o",
|
|
226
366
|
inputProcessors: [
|
|
227
367
|
// Ensure the total tokens don't exceed ~127k
|
|
228
368
|
new TokenLimiter(127000),
|
|
@@ -232,7 +372,7 @@ const agent = new Agent({
|
|
|
232
372
|
|
|
233
373
|
The `TokenLimiter` uses the `o200k_base` encoding by default (suitable for GPT-4o). You can specify other encodings for different models:
|
|
234
374
|
|
|
235
|
-
```typescript
|
|
375
|
+
```typescript {6-9}
|
|
236
376
|
import cl100k_base from "js-tiktoken/ranks/cl100k_base";
|
|
237
377
|
|
|
238
378
|
const agent = new Agent({
|
|
@@ -250,14 +390,13 @@ const agent = new Agent({
|
|
|
250
390
|
|
|
251
391
|
Removes tool calls from messages sent to the LLM, saving tokens by excluding potentially verbose tool interactions.
|
|
252
392
|
|
|
253
|
-
```typescript
|
|
393
|
+
```typescript {7-16}
|
|
254
394
|
import { Agent } from "@mastra/core/agent";
|
|
255
395
|
import { ToolCallFilter, TokenLimiter } from "@mastra/core/processors";
|
|
256
|
-
import { openai } from "@ai-sdk/openai";
|
|
257
396
|
|
|
258
397
|
const agent = new Agent({
|
|
259
398
|
name: "my-agent",
|
|
260
|
-
model: openai
|
|
399
|
+
model: "openai/gpt-4o",
|
|
261
400
|
inputProcessors: [
|
|
262
401
|
// Example 1: Remove all tool calls/results
|
|
263
402
|
new ToolCallFilter(),
|
|
@@ -271,9 +410,87 @@ const agent = new Agent({
|
|
|
271
410
|
});
|
|
272
411
|
```
|
|
273
412
|
|
|
274
|
-
|
|
413
|
+
:::note
|
|
414
|
+
|
|
415
|
+
The example above filters tool calls and limits tokens for the LLM, but these filtered messages will still be saved to memory. To also filter messages before they're saved to memory, manually add memory processors before utility processors. See [Memory Processors](/docs/v1/memory/memory-processors#manual-control-and-deduplication) for details.
|
|
416
|
+
|
|
417
|
+
:::
|
|
418
|
+
|
|
419
|
+
## Using workflows as processors
|
|
420
|
+
|
|
421
|
+
You can use Mastra workflows as processors to create complex processing pipelines with parallel execution, conditional branching, and error handling:
|
|
422
|
+
|
|
423
|
+
```typescript title="src/mastra/processors/moderation-workflow.ts"
|
|
424
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
425
|
+
import { ProcessorStepSchema } from "@mastra/core/processors";
|
|
426
|
+
import { Agent } from "@mastra/core/agent";
|
|
427
|
+
|
|
428
|
+
// Create a workflow that runs multiple checks in parallel
|
|
429
|
+
const moderationWorkflow = createWorkflow({
|
|
430
|
+
id: "moderation-pipeline",
|
|
431
|
+
inputSchema: ProcessorStepSchema,
|
|
432
|
+
outputSchema: ProcessorStepSchema,
|
|
433
|
+
})
|
|
434
|
+
.then(createStep(new LengthValidator({ maxLength: 10000 })))
|
|
435
|
+
.parallel([
|
|
436
|
+
createStep(new PIIDetector({ strategy: "redact" })),
|
|
437
|
+
createStep(new ToxicityChecker({ threshold: 0.8 })),
|
|
438
|
+
])
|
|
439
|
+
.commit();
|
|
440
|
+
|
|
441
|
+
// Use the workflow as an input processor
|
|
442
|
+
const agent = new Agent({
|
|
443
|
+
id: "moderated-agent",
|
|
444
|
+
name: "Moderated Agent",
|
|
445
|
+
model: "openai/gpt-4o",
|
|
446
|
+
inputProcessors: [moderationWorkflow],
|
|
447
|
+
});
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
When an agent is registered with Mastra, processor workflows are automatically registered as workflows, allowing you to view and debug them in the [Studio](/docs/v1/getting-started/studio).
|
|
451
|
+
|
|
452
|
+
## Retry mechanism
|
|
453
|
+
|
|
454
|
+
Processors can request that the LLM retry its response with feedback. This is useful for implementing quality checks, output validation, or iterative refinement:
|
|
455
|
+
|
|
456
|
+
```typescript title="src/mastra/processors/quality-checker.ts"
|
|
457
|
+
import type { Processor } from "@mastra/core";
|
|
458
|
+
|
|
459
|
+
export class QualityChecker implements Processor {
|
|
460
|
+
id = "quality-checker";
|
|
461
|
+
|
|
462
|
+
async processOutputStep({ text, abort, retryCount }) {
|
|
463
|
+
const qualityScore = await evaluateQuality(text);
|
|
464
|
+
|
|
465
|
+
if (qualityScore < 0.7 && retryCount < 3) {
|
|
466
|
+
// Request a retry with feedback for the LLM
|
|
467
|
+
abort("Response quality score too low. Please provide a more detailed answer.", {
|
|
468
|
+
retry: true,
|
|
469
|
+
metadata: { score: qualityScore },
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return [];
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const agent = new Agent({
|
|
478
|
+
id: "quality-agent",
|
|
479
|
+
name: "Quality Agent",
|
|
480
|
+
model: "openai/gpt-4o",
|
|
481
|
+
outputProcessors: [new QualityChecker()],
|
|
482
|
+
maxProcessorRetries: 3, // Maximum retry attempts (default: 3)
|
|
483
|
+
});
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
The retry mechanism:
|
|
487
|
+
- Only works in `processOutputStep` and `processInputStep` methods
|
|
488
|
+
- Replays the step with the abort reason added as context for the LLM
|
|
489
|
+
- Tracks retry count via the `retryCount` parameter
|
|
490
|
+
- Respects `maxProcessorRetries` limit on the agent
|
|
275
491
|
|
|
276
492
|
## Related documentation
|
|
277
493
|
|
|
278
494
|
- [Guardrails](/docs/v1/agents/guardrails) - Security and validation processors
|
|
279
495
|
- [Memory Processors](/docs/v1/memory/memory-processors) - Memory-specific processors and automatic integration
|
|
496
|
+
- [Processor Interface](/reference/v1/processors/processor-interface) - Full API reference for processors
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Structured Output | Agents"
|
|
3
3
|
description: "Learn how to generate structured data from agents using schemas and validation."
|
|
4
|
+
packages:
|
|
5
|
+
- "@mastra/core"
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
import Tabs from "@theme/Tabs";
|
|
@@ -23,7 +25,7 @@ Agents can return structured data by defining the expected output with either [Z
|
|
|
23
25
|
|
|
24
26
|
Define the `output` shape using [Zod](https://zod.dev/):
|
|
25
27
|
|
|
26
|
-
```typescript
|
|
28
|
+
```typescript
|
|
27
29
|
import { z } from "zod";
|
|
28
30
|
|
|
29
31
|
const response = await testAgent.generate("Help me plan my day.", {
|
|
@@ -45,7 +47,7 @@ console.log(response.object);
|
|
|
45
47
|
|
|
46
48
|
You can also use JSON Schema to define your output structure:
|
|
47
49
|
|
|
48
|
-
```typescript
|
|
50
|
+
```typescript
|
|
49
51
|
const response = await testAgent.generate("Help me plan my day.", {
|
|
50
52
|
structuredOutput: {
|
|
51
53
|
schema: {
|
|
@@ -72,7 +74,11 @@ console.log(response.object);
|
|
|
72
74
|
</Tabs>
|
|
73
75
|
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
:::info
|
|
78
|
+
|
|
79
|
+
Visit [.generate()](/reference/v1/agents/generate) for a full list of configuration options.
|
|
80
|
+
|
|
81
|
+
:::
|
|
76
82
|
|
|
77
83
|
### Example output
|
|
78
84
|
|
|
@@ -99,7 +105,7 @@ The `response.object` will contain the structured data as defined by the schema.
|
|
|
99
105
|
|
|
100
106
|
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.
|
|
101
107
|
|
|
102
|
-
```typescript
|
|
108
|
+
```typescript
|
|
103
109
|
import { z } from "zod";
|
|
104
110
|
|
|
105
111
|
const stream = await testAgent.stream("Help me plan my day.", {
|
|
@@ -131,7 +137,7 @@ for await (const chunk of stream.textStream) {
|
|
|
131
137
|
|
|
132
138
|
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.
|
|
133
139
|
|
|
134
|
-
```typescript
|
|
140
|
+
```typescript
|
|
135
141
|
import { z } from "zod";
|
|
136
142
|
|
|
137
143
|
const response = await testAgent.generate("Analyze the TypeScript programming language.", {
|
|
@@ -156,13 +162,33 @@ const response = await testAgent.generate("Analyze the TypeScript programming la
|
|
|
156
162
|
console.log(response.object);
|
|
157
163
|
```
|
|
158
164
|
|
|
159
|
-
##
|
|
165
|
+
## Combining tools and structured output
|
|
166
|
+
|
|
167
|
+
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.
|
|
168
|
+
|
|
169
|
+
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.
|
|
170
|
+
|
|
171
|
+
### Workaround options
|
|
172
|
+
|
|
173
|
+
When your model doesn't support tools and structured output together, you have three options:
|
|
174
|
+
|
|
175
|
+
1. **Use `jsonPromptInjection: true`** - Injects the schema into the prompt instead of using the API's `response_format` parameter
|
|
176
|
+
2. **Use a separate structuring model** - Pass a `model` to `structuredOutput` to use a second LLM for structuring
|
|
177
|
+
3. **Use `prepareStep`** - Handle tools and structured output in separate steps
|
|
178
|
+
|
|
179
|
+
Each approach is detailed in the sections below.
|
|
180
|
+
|
|
181
|
+
## LLM structured output support
|
|
182
|
+
|
|
183
|
+
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.
|
|
184
|
+
|
|
185
|
+
### `jsonPromptInjection`
|
|
160
186
|
|
|
161
187
|
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.
|
|
162
188
|
|
|
163
189
|
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.
|
|
164
190
|
|
|
165
|
-
```typescript
|
|
191
|
+
```typescript
|
|
166
192
|
import { z } from "zod";
|
|
167
193
|
|
|
168
194
|
const response = await testAgent.generate("Help me plan my day.", {
|
|
@@ -194,11 +220,55 @@ const response = await agentWithTools.generate("Your prompt", {
|
|
|
194
220
|
```
|
|
195
221
|
:::
|
|
196
222
|
|
|
223
|
+
### Using a separate structuring model
|
|
224
|
+
|
|
225
|
+
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.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
const response = await testAgent.generate("Tell me about TypeScript.", {
|
|
229
|
+
structuredOutput: {
|
|
230
|
+
schema: yourSchema
|
|
231
|
+
model: 'openai/gpt-4o'
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Multi-step approach with `prepareStep`
|
|
237
|
+
|
|
238
|
+
For models that don't support tools and structured outputs together, you can use `prepareStep` to handle them in separate steps.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
const result = await agent.stream("weather in vancouver?", {
|
|
242
|
+
prepareStep: async ({ stepNumber }) => {
|
|
243
|
+
if (stepNumber === 0) {
|
|
244
|
+
return {
|
|
245
|
+
model: "anthropic/claude-sonnet-4-20250514",
|
|
246
|
+
tools: {
|
|
247
|
+
weatherTool,
|
|
248
|
+
},
|
|
249
|
+
toolChoice: "required",
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
model: "anthropic/claude-sonnet-4-20250514",
|
|
254
|
+
tools: undefined,
|
|
255
|
+
structuredOutput: {
|
|
256
|
+
schema: z.object({
|
|
257
|
+
temperature: z.number(),
|
|
258
|
+
humidity: z.number(),
|
|
259
|
+
windSpeed: z.number(),
|
|
260
|
+
}),
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
197
267
|
## Error handling
|
|
198
268
|
|
|
199
269
|
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`.
|
|
200
270
|
|
|
201
|
-
```typescript
|
|
271
|
+
```typescript
|
|
202
272
|
import { z } from "zod";
|
|
203
273
|
|
|
204
274
|
const response = await testAgent.generate("Tell me about TypeScript.", {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Using Tools | Agents"
|
|
3
3
|
description: Learn how to create tools and add them to agents to extend capabilities beyond text generation.
|
|
4
|
+
packages:
|
|
5
|
+
- "@mastra/core"
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# Using Tools
|
|
@@ -17,7 +19,7 @@ When creating tools, keep descriptions simple and focused on what the tool does,
|
|
|
17
19
|
|
|
18
20
|
This example shows how to create a tool that fetches weather data from an API. When the agent calls the tool, it provides the required input as defined by the tool's `inputSchema`. The tool accesses this data through its `inputData` parameter, which in this example includes the `location` used in the weather API query.
|
|
19
21
|
|
|
20
|
-
```typescript
|
|
22
|
+
```typescript title="src/mastra/tools/weather-tool.ts"
|
|
21
23
|
import { createTool } from "@mastra/core/tools";
|
|
22
24
|
import { z } from "zod";
|
|
23
25
|
|
|
@@ -47,7 +49,7 @@ To make a tool available to an agent, add it to `tools`. Mentioning available to
|
|
|
47
49
|
|
|
48
50
|
An agent can use multiple tools to handle more complex tasks by delegating specific parts to individual tools. The agent decides which tools to use based on the user's message, the agent's instructions, and the tool descriptions and schemas.
|
|
49
51
|
|
|
50
|
-
```typescript {
|
|
52
|
+
```typescript {11} title="src/mastra/agents/weather-agent.ts"
|
|
51
53
|
import { Agent } from "@mastra/core/agent";
|
|
52
54
|
import { weatherTool } from "../tools/weather-tool";
|
|
53
55
|
|
|
@@ -66,7 +68,7 @@ export const weatherAgent = new Agent({
|
|
|
66
68
|
|
|
67
69
|
The agent uses the tool's `inputSchema` to infer what data the tool expects. In this case, it extracts `London` as the `location` from the message and passes it to the tool's inputData parameter.
|
|
68
70
|
|
|
69
|
-
```typescript title="src/test-tool.ts"
|
|
71
|
+
```typescript title="src/test-tool.ts"
|
|
70
72
|
import { mastra } from "./mastra";
|
|
71
73
|
|
|
72
74
|
const agent = mastra.getAgent("weatherAgent");
|
|
@@ -78,20 +80,79 @@ const result = await agent.generate("What's the weather in London?");
|
|
|
78
80
|
|
|
79
81
|
When multiple tools are available, the agent may choose to use one, several, or none, depending on what's needed to answer the query.
|
|
80
82
|
|
|
81
|
-
```typescript {
|
|
83
|
+
```typescript {7} title="src/mastra/agents/weather-agent.ts"
|
|
82
84
|
import { weatherTool } from "../tools/weather-tool";
|
|
83
85
|
import { activitiesTool } from "../tools/activities-tool";
|
|
84
86
|
|
|
85
87
|
export const weatherAgent = new Agent({
|
|
86
88
|
id: "weather-agent",
|
|
87
89
|
name: "Weather Agent",
|
|
88
|
-
// ..
|
|
89
90
|
tools: { weatherTool, activitiesTool },
|
|
90
91
|
});
|
|
91
92
|
```
|
|
92
93
|
|
|
94
|
+
## Using workflows as tools
|
|
95
|
+
|
|
96
|
+
Workflows can be added to agents through the `workflows` configuration. When you add a workflow, Mastra automatically converts it to a tool that the agent can call. The generated tool is named `workflow-<workflowName>` and uses the workflow's `inputSchema` and `outputSchema`.
|
|
97
|
+
|
|
98
|
+
```typescript {14-16} title="src/mastra/agents/research-agent.ts"
|
|
99
|
+
import { Agent } from "@mastra/core/agent";
|
|
100
|
+
import { researchWorkflow } from "../workflows/research-workflow";
|
|
101
|
+
|
|
102
|
+
export const researchAgent = new Agent({
|
|
103
|
+
id: "research-agent",
|
|
104
|
+
name: "Research Agent",
|
|
105
|
+
instructions: `
|
|
106
|
+
You are a research assistant.
|
|
107
|
+
Use the research workflow to gather and compile information on topics.`,
|
|
108
|
+
model: "openai/gpt-5.1",
|
|
109
|
+
tools: {
|
|
110
|
+
weatherTool,
|
|
111
|
+
},
|
|
112
|
+
workflows: {
|
|
113
|
+
researchWorkflow,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The workflow should include a `description` to help the agent understand when to use it:
|
|
119
|
+
|
|
120
|
+
```typescript title="src/mastra/workflows/research-workflow.ts"
|
|
121
|
+
import { createWorkflow } from "@mastra/core/workflows";
|
|
122
|
+
import { z } from "zod";
|
|
123
|
+
|
|
124
|
+
export const researchWorkflow = createWorkflow({
|
|
125
|
+
id: "research-workflow",
|
|
126
|
+
description: "Gathers information on a topic and compiles a summary report.",
|
|
127
|
+
inputSchema: z.object({
|
|
128
|
+
topic: z.string(),
|
|
129
|
+
}),
|
|
130
|
+
outputSchema: z.object({
|
|
131
|
+
summary: z.string(),
|
|
132
|
+
sources: z.array(z.string()),
|
|
133
|
+
}),
|
|
134
|
+
})
|
|
135
|
+
.then(gatherSourcesStep)
|
|
136
|
+
.then(compileReportStep)
|
|
137
|
+
.commit();
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
When the agent calls the workflow tool, it receives a response containing the workflow result and a `runId` that can be used to track the execution:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
{
|
|
144
|
+
result: { summary: "...", sources: ["..."] },
|
|
145
|
+
runId: "abc-123"
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Tools with structured output
|
|
150
|
+
|
|
151
|
+
When using tools with [structured output](/docs/v1/agents/structured-output), some models don't support combining both features in the same API call. If your tools aren't being called when structured output is enabled, or you receive errors about incompatible options, see [Combining tools and structured output](/docs/v1/agents/structured-output#combining-tools-and-structured-output) for model compatibility information and workarounds.
|
|
152
|
+
|
|
93
153
|
## Related
|
|
94
154
|
|
|
95
155
|
- [MCP Overview](/docs/v1/mcp/overview)
|
|
156
|
+
- [Structured Output](/docs/v1/agents/structured-output)
|
|
96
157
|
- [Agent Memory](/docs/v1/agents/agent-memory)
|
|
97
|
-
- [Request Context](/docs/v1/server
|
|
158
|
+
- [Request Context](/docs/v1/server/request-context)
|
|
@@ -8,7 +8,6 @@ Now add the necessary imports at the top of your file:
|
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
import { Agent } from "@mastra/core/agent";
|
|
11
|
-
import { openai } from "@ai-sdk/openai";
|
|
12
11
|
// We'll import our tool in a later step
|
|
13
12
|
```
|
|
14
13
|
|
|
@@ -43,7 +42,7 @@ SUCCESS CRITERIA
|
|
|
43
42
|
- Deliver accurate and helpful analysis of transaction data.
|
|
44
43
|
- Achieve high user satisfaction through clear and helpful responses.
|
|
45
44
|
- Maintain user trust by ensuring data privacy and security.`,
|
|
46
|
-
model: openai
|
|
45
|
+
model: "openai/gpt-4.1-mini",
|
|
47
46
|
tools: {}, // We'll add tools in a later step
|
|
48
47
|
});
|
|
49
48
|
```
|
|
@@ -19,7 +19,7 @@ export const financialAgent = new Agent({
|
|
|
19
19
|
TOOLS
|
|
20
20
|
- Use the getTransactions tool to fetch financial transaction data.
|
|
21
21
|
- Analyze the transaction data to answer user questions about their spending.`,
|
|
22
|
-
model: openai
|
|
22
|
+
model: "openai/gpt-4.1-mini",
|
|
23
23
|
tools: { getTransactionsTool }, // Add our tool here
|
|
24
24
|
});
|
|
25
25
|
```
|
|
@@ -6,7 +6,6 @@ Now, let's update our agent to include memory. Open your `agents/index.ts` file
|
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
8
|
import { Agent } from "@mastra/core/agent";
|
|
9
|
-
import { openai } from "@ai-sdk/openai";
|
|
10
9
|
import { Memory } from "@mastra/memory";
|
|
11
10
|
import { LibSQLStore } from "@mastra/libsql";
|
|
12
11
|
import { getTransactionsTool } from "../tools";
|
|
@@ -20,7 +19,7 @@ export const financialAgent = new Agent({
|
|
|
20
19
|
instructions: `ROLE DEFINITION
|
|
21
20
|
// ... existing instructions ...
|
|
22
21
|
`,
|
|
23
|
-
model: openai
|
|
22
|
+
model: "openai/gpt-4.1-mini",
|
|
24
23
|
tools: { getTransactionsTool },
|
|
25
24
|
memory: new Memory({
|
|
26
25
|
storage: new LibSQLStore({
|