@mastra/mcp-docs-server 1.0.0-beta.11 → 1.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +51 -51
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +180 -180
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +68 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +331 -331
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +41 -41
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +96 -96
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +49 -2
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +122 -122
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +39 -39
- package/.docs/organized/changelogs/create-mastra.md +31 -31
- package/.docs/organized/changelogs/mastra.md +51 -51
- package/.docs/organized/code-examples/agent-v6.md +151 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +0 -4
- package/.docs/organized/code-examples/stock-price-tool.md +21 -2
- package/.docs/raw/agents/adding-voice.mdx +2 -3
- package/.docs/raw/agents/agent-approval.mdx +139 -6
- package/.docs/raw/agents/agent-memory.mdx +24 -32
- package/.docs/raw/agents/guardrails.mdx +61 -51
- package/.docs/raw/agents/networks.mdx +9 -13
- package/.docs/raw/agents/overview.mdx +40 -24
- package/.docs/raw/agents/processors.mdx +20 -19
- package/.docs/raw/agents/structured-output.mdx +11 -7
- package/.docs/raw/agents/using-tools.mdx +5 -6
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +1 -2
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +1 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -2
- package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -2
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +3 -4
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -3
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +2 -3
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -2
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +2 -3
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
- package/.docs/raw/deployment/cloud-providers.mdx +20 -0
- package/.docs/raw/deployment/{building-mastra.mdx → mastra-server.mdx} +5 -5
- package/.docs/raw/deployment/monorepo.mdx +23 -44
- package/.docs/raw/deployment/overview.mdx +32 -50
- package/.docs/raw/deployment/web-framework.mdx +15 -19
- package/.docs/raw/evals/custom-scorers.mdx +9 -6
- package/.docs/raw/evals/overview.mdx +3 -6
- package/.docs/raw/evals/running-in-ci.mdx +2 -2
- package/.docs/raw/getting-started/manual-install.mdx +20 -20
- package/.docs/raw/getting-started/mcp-docs-server.mdx +2 -2
- package/.docs/raw/getting-started/start.mdx +10 -1
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +4 -4
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1033 -79
- package/.docs/raw/guides/build-your-ui/assistant-ui.mdx +8 -8
- package/.docs/raw/guides/build-your-ui/copilotkit.mdx +11 -11
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/amazon-ec2.mdx +9 -9
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/aws-lambda.mdx +13 -16
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/azure-app-services.mdx +5 -7
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/cloudflare-deployer.mdx +8 -5
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/digital-ocean.mdx +12 -15
- package/.docs/raw/guides/deployment/index.mdx +32 -0
- package/.docs/raw/guides/deployment/inngest.mdx +386 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/netlify-deployer.mdx +7 -3
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/vercel-deployer.mdx +8 -5
- package/.docs/raw/guides/getting-started/astro.mdx +292 -451
- package/.docs/raw/guides/getting-started/express.mdx +72 -153
- package/.docs/raw/guides/getting-started/hono.mdx +227 -0
- package/.docs/raw/guides/getting-started/next-js.mdx +170 -61
- package/.docs/raw/guides/getting-started/quickstart.mdx +4 -4
- package/.docs/raw/guides/getting-started/sveltekit.mdx +238 -409
- package/.docs/raw/guides/getting-started/vite-react.mdx +317 -147
- package/.docs/raw/guides/guide/ai-recruiter.mdx +10 -10
- package/.docs/raw/guides/guide/chef-michel.mdx +9 -11
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +15 -15
- package/.docs/raw/guides/guide/research-assistant.mdx +17 -17
- package/.docs/raw/guides/guide/stock-agent.mdx +5 -5
- package/.docs/raw/guides/guide/web-search.mdx +8 -8
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +7 -7
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +2 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +17 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +6 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +0 -2
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +21 -23
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/dashboard.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/observability.mdx +1 -5
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/overview.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/setting-up.mdx +8 -7
- package/.docs/raw/mcp/overview.mdx +31 -13
- package/.docs/raw/mcp/publishing-mcp-server.mdx +2 -2
- package/.docs/raw/memory/memory-processors.mdx +9 -9
- package/.docs/raw/memory/message-history.mdx +69 -0
- package/.docs/raw/memory/overview.mdx +34 -76
- package/.docs/raw/memory/semantic-recall.mdx +58 -49
- package/.docs/raw/memory/storage.mdx +188 -0
- package/.docs/raw/memory/working-memory.mdx +7 -7
- package/.docs/raw/observability/logging.mdx +10 -11
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/cloud.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/default.mdx +3 -3
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +1 -2
- package/.docs/raw/observability/tracing/overview.mdx +23 -25
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/rag/chunking-and-embedding.mdx +18 -31
- package/.docs/raw/rag/graph-rag.mdx +220 -0
- package/.docs/raw/rag/overview.mdx +2 -3
- package/.docs/raw/rag/retrieval.mdx +34 -51
- package/.docs/raw/rag/vector-databases.mdx +29 -25
- package/.docs/raw/reference/agents/agent.mdx +3 -3
- package/.docs/raw/reference/agents/generate.mdx +1 -1
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +3 -3
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +3 -3
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +3 -3
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +3 -3
- package/.docs/raw/reference/agents/getLLM.mdx +3 -3
- package/.docs/raw/reference/agents/getMemory.mdx +3 -3
- package/.docs/raw/reference/agents/getModel.mdx +3 -3
- package/.docs/raw/reference/agents/getTools.mdx +2 -2
- package/.docs/raw/reference/agents/getVoice.mdx +2 -2
- package/.docs/raw/reference/agents/listAgents.mdx +2 -2
- package/.docs/raw/reference/agents/listScorers.mdx +3 -3
- package/.docs/raw/reference/agents/listTools.mdx +2 -2
- package/.docs/raw/reference/agents/listWorkflows.mdx +2 -2
- package/.docs/raw/reference/agents/network.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/network-route.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +6 -6
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +127 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +107 -0
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +3 -3
- package/.docs/raw/reference/auth/auth0.mdx +2 -3
- package/.docs/raw/reference/auth/clerk.mdx +2 -3
- package/.docs/raw/reference/auth/firebase.mdx +3 -5
- package/.docs/raw/reference/auth/jwt.mdx +2 -3
- package/.docs/raw/reference/auth/supabase.mdx +2 -3
- package/.docs/raw/reference/auth/workos.mdx +2 -3
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +10 -10
- package/.docs/raw/reference/client-js/agents.mdx +1 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +2 -2
- package/.docs/raw/reference/client-js/workflows.mdx +20 -0
- package/.docs/raw/reference/core/getAgent.mdx +1 -1
- package/.docs/raw/reference/core/getAgentById.mdx +1 -1
- package/.docs/raw/reference/core/getDeployer.mdx +1 -1
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServer.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServerById.mdx +1 -1
- package/.docs/raw/reference/core/getMemory.mdx +2 -2
- package/.docs/raw/reference/core/getServer.mdx +3 -3
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getStoredAgentById.mdx +3 -3
- package/.docs/raw/reference/core/getTelemetry.mdx +1 -1
- package/.docs/raw/reference/core/getVector.mdx +1 -1
- package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
- package/.docs/raw/reference/core/listAgents.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/listMCPServers.mdx +1 -1
- package/.docs/raw/reference/core/listMemory.mdx +2 -2
- package/.docs/raw/reference/core/listStoredAgents.mdx +4 -4
- package/.docs/raw/reference/core/listVectors.mdx +1 -1
- package/.docs/raw/reference/core/listWorkflows.mdx +1 -1
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +2 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/cloudflare.mdx +1 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -1
- package/.docs/raw/reference/deployer/vercel.mdx +2 -4
- package/.docs/raw/reference/evals/answer-relevancy.mdx +1 -1
- package/.docs/raw/reference/evals/answer-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/bias.mdx +1 -1
- package/.docs/raw/reference/evals/completeness.mdx +1 -1
- package/.docs/raw/reference/evals/content-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/context-precision.mdx +1 -1
- package/.docs/raw/reference/evals/faithfulness.mdx +1 -1
- package/.docs/raw/reference/evals/hallucination.mdx +1 -1
- package/.docs/raw/reference/evals/keyword-coverage.mdx +1 -1
- package/.docs/raw/reference/evals/prompt-alignment.mdx +7 -7
- package/.docs/raw/reference/evals/textual-difference.mdx +1 -1
- package/.docs/raw/reference/evals/tone-consistency.mdx +1 -1
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +10 -10
- package/.docs/raw/reference/evals/toxicity.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +7 -8
- package/.docs/raw/reference/memory/createThread.mdx +2 -2
- package/.docs/raw/reference/memory/deleteMessages.mdx +2 -2
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +2 -2
- package/.docs/raw/reference/memory/memory-class.mdx +3 -3
- package/.docs/raw/reference/memory/query.mdx +2 -2
- package/.docs/raw/reference/memory/recall.mdx +2 -2
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +1 -1
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +2 -2
- package/.docs/raw/reference/processors/language-detector.mdx +2 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +2 -2
- package/.docs/raw/reference/processors/moderation-processor.mdx +3 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +3 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +13 -13
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +2 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +2 -2
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +3 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +2 -2
- package/.docs/raw/reference/processors/working-memory-processor.mdx +3 -3
- package/.docs/raw/reference/rag/chunk.mdx +1 -1
- package/.docs/raw/reference/rag/database-config.mdx +1 -1
- package/.docs/raw/reference/rag/extract-params.mdx +2 -2
- package/.docs/raw/reference/rag/metadata-filters.mdx +7 -7
- package/.docs/raw/reference/server/create-route.mdx +14 -14
- package/.docs/raw/reference/server/express-adapter.mdx +10 -11
- package/.docs/raw/reference/server/hono-adapter.mdx +10 -11
- package/.docs/raw/reference/server/mastra-server.mdx +22 -22
- package/.docs/raw/reference/server/routes.mdx +28 -1
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +3 -3
- package/.docs/raw/reference/storage/cloudflare.mdx +2 -2
- package/.docs/raw/reference/storage/convex.mdx +6 -6
- package/.docs/raw/reference/storage/dynamodb.mdx +4 -4
- package/.docs/raw/reference/storage/lance.mdx +3 -3
- package/.docs/raw/reference/storage/libsql.mdx +69 -54
- package/.docs/raw/reference/storage/mongodb.mdx +80 -7
- package/.docs/raw/reference/storage/mssql.mdx +4 -4
- package/.docs/raw/{server-db/storage.mdx → reference/storage/overview.mdx} +13 -111
- package/.docs/raw/reference/storage/postgresql.mdx +78 -7
- package/.docs/raw/reference/storage/upstash.mdx +74 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +27 -5
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/resumeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +35 -22
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +4 -4
- package/.docs/raw/reference/templates/overview.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +24 -5
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +3 -3
- package/.docs/raw/reference/tools/vector-query-tool.mdx +4 -4
- package/.docs/raw/reference/vectors/astra.mdx +3 -3
- package/.docs/raw/reference/vectors/chroma.mdx +3 -3
- package/.docs/raw/reference/vectors/convex.mdx +12 -12
- package/.docs/raw/reference/vectors/couchbase.mdx +5 -5
- package/.docs/raw/reference/vectors/duckdb.mdx +10 -10
- package/.docs/raw/reference/vectors/elasticsearch.mdx +4 -4
- package/.docs/raw/reference/vectors/lance.mdx +4 -4
- package/.docs/raw/reference/vectors/libsql.mdx +61 -11
- package/.docs/raw/reference/vectors/mongodb.mdx +58 -5
- package/.docs/raw/reference/vectors/pg.mdx +53 -6
- package/.docs/raw/reference/vectors/pinecone.mdx +3 -3
- package/.docs/raw/reference/vectors/qdrant.mdx +3 -3
- package/.docs/raw/reference/vectors/s3vectors.mdx +6 -6
- package/.docs/raw/reference/vectors/turbopuffer.mdx +4 -4
- package/.docs/raw/reference/vectors/upstash.mdx +55 -6
- package/.docs/raw/reference/vectors/vectorize.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +1 -3
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/start.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +143 -0
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +5 -5
- package/.docs/raw/reference/workflows/run.mdx +1 -1
- package/.docs/raw/reference/workflows/step.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +37 -2
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +6 -6
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +7 -7
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow.mdx +17 -3
- package/.docs/raw/{auth → server/auth}/auth0.mdx +20 -14
- package/.docs/raw/{auth → server/auth}/clerk.mdx +16 -9
- package/.docs/raw/{auth → server/auth}/firebase.mdx +21 -15
- package/.docs/raw/{auth → server/auth}/index.mdx +6 -6
- package/.docs/raw/{auth → server/auth}/jwt.mdx +14 -7
- package/.docs/raw/{auth → server/auth}/supabase.mdx +16 -9
- package/.docs/raw/{auth → server/auth}/workos.mdx +19 -13
- package/.docs/raw/{server-db → server}/custom-adapters.mdx +13 -13
- package/.docs/raw/{server-db → server}/custom-api-routes.mdx +3 -5
- package/.docs/raw/{server-db → server}/mastra-client.mdx +26 -15
- package/.docs/raw/{server-db → server}/mastra-server.mdx +8 -8
- package/.docs/raw/{server-db → server}/middleware.mdx +9 -9
- package/.docs/raw/{server-db → server}/request-context.mdx +33 -32
- package/.docs/raw/{server-db → server}/server-adapters.mdx +12 -12
- package/.docs/raw/streaming/events.mdx +14 -7
- package/.docs/raw/streaming/overview.mdx +21 -10
- package/.docs/raw/streaming/tool-streaming.mdx +6 -6
- package/.docs/raw/streaming/workflow-streaming.mdx +6 -8
- package/.docs/raw/tools-mcp/advanced-usage.mdx +2 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +31 -12
- package/.docs/raw/tools-mcp/overview.mdx +10 -11
- package/.docs/raw/voice/overview.mdx +1 -1
- package/.docs/raw/workflows/agents-and-tools.mdx +28 -19
- package/.docs/raw/workflows/control-flow.mdx +27 -40
- package/.docs/raw/workflows/error-handling.mdx +172 -18
- package/.docs/raw/workflows/human-in-the-loop.mdx +6 -7
- package/.docs/raw/workflows/inngest-workflow.mdx +8 -9
- package/.docs/raw/workflows/input-data-mapping.mdx +7 -7
- package/.docs/raw/workflows/overview.mdx +34 -23
- package/.docs/raw/workflows/snapshots.mdx +14 -44
- package/.docs/raw/workflows/suspend-and-resume.mdx +7 -7
- package/.docs/raw/workflows/time-travel.mdx +16 -16
- package/.docs/raw/workflows/workflow-state.mdx +5 -8
- package/CHANGELOG.md +23 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/stdio.js +53 -0
- package/package.json +4 -4
- package/.docs/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
- package/.docs/raw/memory/conversation-history.mdx +0 -24
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +0 -140
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +0 -150
- package/.docs/raw/memory/storage/memory-with-pg.mdx +0 -138
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +0 -146
- package/.docs/raw/memory/threads-and-resources.mdx +0 -95
|
@@ -22,7 +22,7 @@ Use processors for content moderation, prompt injection prevention, response san
|
|
|
22
22
|
|
|
23
23
|
Import and instantiate the relevant processor class, and pass it to your agent’s configuration using either the `inputProcessors` or `outputProcessors` option:
|
|
24
24
|
|
|
25
|
-
```typescript {2,
|
|
25
|
+
```typescript {2,9-17} title="src/mastra/agents/moderated-agent.ts"
|
|
26
26
|
import { Agent } from "@mastra/core/agent";
|
|
27
27
|
import { ModerationProcessor } from "@mastra/core/processors";
|
|
28
28
|
|
|
@@ -51,13 +51,12 @@ Input processors are applied before user messages reach the language model. They
|
|
|
51
51
|
|
|
52
52
|
The `UnicodeNormalizer` is an input processor that cleans and normalizes user input by unifying Unicode characters, standardizing whitespace, and removing problematic symbols, allowing the LLM to better understand user messages.
|
|
53
53
|
|
|
54
|
-
```typescript {
|
|
54
|
+
```typescript {7-10} title="src/mastra/agents/normalized-agent.ts"
|
|
55
55
|
import { UnicodeNormalizer } from "@mastra/core/processors";
|
|
56
56
|
|
|
57
57
|
export const normalizedAgent = new Agent({
|
|
58
58
|
id: "normalized-agent",
|
|
59
59
|
name: "Normalized Agent",
|
|
60
|
-
// ...
|
|
61
60
|
inputProcessors: [
|
|
62
61
|
new UnicodeNormalizer({
|
|
63
62
|
stripControlChars: true,
|
|
@@ -67,19 +66,22 @@ export const normalizedAgent = new Agent({
|
|
|
67
66
|
});
|
|
68
67
|
```
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
:::info
|
|
70
|
+
|
|
71
|
+
Visit [UnicodeNormalizer](/reference/v1/processors/unicode-normalizer) for a full list of configuration options.
|
|
72
|
+
|
|
73
|
+
:::
|
|
71
74
|
|
|
72
75
|
### Preventing prompt injection
|
|
73
76
|
|
|
74
77
|
The `PromptInjectionDetector` is an input processor that scans user messages for prompt injection, jailbreak attempts, and system override patterns. It uses an LLM to classify risky input and can block or rewrite it before it reaches the model.
|
|
75
78
|
|
|
76
|
-
```typescript {
|
|
79
|
+
```typescript {7-12} title="src/mastra/agents/secure-agent.ts"
|
|
77
80
|
import { PromptInjectionDetector } from "@mastra/core/processors";
|
|
78
81
|
|
|
79
82
|
export const secureAgent = new Agent({
|
|
80
83
|
id: "secure-agent",
|
|
81
84
|
name: "Secure Agent",
|
|
82
|
-
// ...
|
|
83
85
|
inputProcessors: [
|
|
84
86
|
new PromptInjectionDetector({
|
|
85
87
|
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
@@ -91,19 +93,22 @@ export const secureAgent = new Agent({
|
|
|
91
93
|
});
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
:::info
|
|
97
|
+
|
|
98
|
+
Visit [PromptInjectionDetector](/reference/v1/processors/prompt-injection-detector) for a full list of configuration options.
|
|
99
|
+
|
|
100
|
+
:::
|
|
95
101
|
|
|
96
102
|
### Detecting and translating language
|
|
97
103
|
|
|
98
104
|
The `LanguageDetector` is an input processor that detects and translates user messages into a target language, enabling multilingual support while maintaining consistent interaction. It uses an LLM to identify the language and perform the translation.
|
|
99
105
|
|
|
100
|
-
```typescript {
|
|
106
|
+
```typescript {7-12} title="src/mastra/agents/multilingual-agent.ts"
|
|
101
107
|
import { LanguageDetector } from "@mastra/core/processors";
|
|
102
108
|
|
|
103
109
|
export const multilingualAgent = new Agent({
|
|
104
110
|
id: "multilingual-agent",
|
|
105
111
|
name: "Multilingual Agent",
|
|
106
|
-
// ...
|
|
107
112
|
inputProcessors: [
|
|
108
113
|
new LanguageDetector({
|
|
109
114
|
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
@@ -115,7 +120,11 @@ export const multilingualAgent = new Agent({
|
|
|
115
120
|
});
|
|
116
121
|
```
|
|
117
122
|
|
|
118
|
-
|
|
123
|
+
:::info
|
|
124
|
+
|
|
125
|
+
Visit [LanguageDetector](/reference/v1/processors/language-detector) for a full list of configuration options.
|
|
126
|
+
|
|
127
|
+
:::
|
|
119
128
|
|
|
120
129
|
## Output processors
|
|
121
130
|
|
|
@@ -125,13 +134,12 @@ Output processors are applied after the language model generates a response, but
|
|
|
125
134
|
|
|
126
135
|
The `BatchPartsProcessor` is an output processor that combines multiple stream parts before emitting them to the client. This reduces network overhead and improves the user experience by consolidating small chunks into larger batches.
|
|
127
136
|
|
|
128
|
-
```typescript {
|
|
137
|
+
```typescript {7-11} title="src/mastra/agents/batched-agent.ts"
|
|
129
138
|
import { BatchPartsProcessor } from "@mastra/core/processors";
|
|
130
139
|
|
|
131
140
|
export const batchedAgent = new Agent({
|
|
132
141
|
id: "batched-agent",
|
|
133
142
|
name: "Batched Agent",
|
|
134
|
-
// ...
|
|
135
143
|
outputProcessors: [
|
|
136
144
|
new BatchPartsProcessor({
|
|
137
145
|
batchSize: 5,
|
|
@@ -142,19 +150,22 @@ export const batchedAgent = new Agent({
|
|
|
142
150
|
});
|
|
143
151
|
```
|
|
144
152
|
|
|
145
|
-
|
|
153
|
+
:::info
|
|
154
|
+
|
|
155
|
+
Visit [BatchPartsProcessor](/reference/v1/processors/batch-parts-processor) for a full list of configuration options.
|
|
156
|
+
|
|
157
|
+
:::
|
|
146
158
|
|
|
147
159
|
### Limiting token usage
|
|
148
160
|
|
|
149
161
|
The `TokenLimiterProcessor` is an output processor that limits the number of tokens in model responses. It helps manage cost and performance by truncating or blocking messages when the limit is exceeded.
|
|
150
162
|
|
|
151
|
-
```typescript {
|
|
163
|
+
```typescript {7-11} title="src/mastra/agents/limited-agent.ts"
|
|
152
164
|
import { TokenLimiterProcessor } from "@mastra/core/processors";
|
|
153
165
|
|
|
154
166
|
export const limitedAgent = new Agent({
|
|
155
167
|
id: "limited-agent",
|
|
156
168
|
name: "Limited Agent",
|
|
157
|
-
// ...
|
|
158
169
|
outputProcessors: [
|
|
159
170
|
new TokenLimiterProcessor({
|
|
160
171
|
limit: 1000,
|
|
@@ -165,13 +176,17 @@ export const limitedAgent = new Agent({
|
|
|
165
176
|
});
|
|
166
177
|
```
|
|
167
178
|
|
|
168
|
-
|
|
179
|
+
:::info
|
|
180
|
+
|
|
181
|
+
Visit [TokenLimiterProcessor](/reference/v1/processors/token-limiter-processor) for a full list of configuration options.
|
|
182
|
+
|
|
183
|
+
:::
|
|
169
184
|
|
|
170
185
|
### Scrubbing system prompts
|
|
171
186
|
|
|
172
187
|
The `SystemPromptScrubber` is an output processor that detects and redacts system prompts or other internal instructions from model responses. It helps prevent unintended disclosure of prompt content or configuration details that could introduce security risks. It uses an LLM to identify and redact sensitive content based on configured detection types.
|
|
173
188
|
|
|
174
|
-
```typescript {7-16} title="src/mastra/agents/scrubbed-agent.ts"
|
|
189
|
+
```typescript {7-16} title="src/mastra/agents/scrubbed-agent.ts"
|
|
175
190
|
import { SystemPromptScrubber } from "@mastra/core/processors";
|
|
176
191
|
|
|
177
192
|
const scrubbedAgent = new Agent({
|
|
@@ -192,10 +207,14 @@ const scrubbedAgent = new Agent({
|
|
|
192
207
|
});
|
|
193
208
|
```
|
|
194
209
|
|
|
195
|
-
|
|
210
|
+
:::info
|
|
211
|
+
|
|
212
|
+
Visit [SystemPromptScrubber](/reference/v1/processors/system-prompt-scrubber) for a full list of configuration options.
|
|
213
|
+
|
|
214
|
+
:::
|
|
196
215
|
|
|
197
216
|
:::note
|
|
198
|
-
When streaming responses over HTTP, Mastra redacts sensitive request data (system prompts, tool definitions, API keys) from stream chunks at the server level by default. See [Stream data redaction](/docs/v1/server
|
|
217
|
+
When streaming responses over HTTP, Mastra redacts sensitive request data (system prompts, tool definitions, API keys) from stream chunks at the server level by default. See [Stream data redaction](/docs/v1/server/mastra-server#stream-data-redaction) for details.
|
|
199
218
|
:::
|
|
200
219
|
|
|
201
220
|
## Hybrid processors
|
|
@@ -206,13 +225,12 @@ Hybrid processors can be applied either before messages are sent to the language
|
|
|
206
225
|
|
|
207
226
|
The `ModerationProcessor` is a hybrid processor that detects inappropriate or harmful content across categories like hate, harassment, and violence. It can be used to moderate either user input or model output, depending on where it's applied. It uses an LLM to classify the message and can block or rewrite it based on your configuration.
|
|
208
227
|
|
|
209
|
-
```typescript {
|
|
228
|
+
```typescript {7-12,15} title="src/mastra/agents/moderated-agent.ts"
|
|
210
229
|
import { ModerationProcessor } from "@mastra/core/processors";
|
|
211
230
|
|
|
212
231
|
export const moderatedAgent = new Agent({
|
|
213
232
|
id: "moderated-agent",
|
|
214
233
|
name: "Moderated Agent",
|
|
215
|
-
// ...
|
|
216
234
|
inputProcessors: [
|
|
217
235
|
new ModerationProcessor({
|
|
218
236
|
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
@@ -222,26 +240,27 @@ export const moderatedAgent = new Agent({
|
|
|
222
240
|
}),
|
|
223
241
|
],
|
|
224
242
|
outputProcessors: [
|
|
225
|
-
new ModerationProcessor(
|
|
226
|
-
// ...
|
|
227
|
-
}),
|
|
243
|
+
new ModerationProcessor(),
|
|
228
244
|
],
|
|
229
245
|
});
|
|
230
246
|
```
|
|
231
247
|
|
|
232
|
-
|
|
248
|
+
:::info
|
|
249
|
+
|
|
250
|
+
Visit [ModerationProcessor](/reference/v1/processors/moderation-processor) for a full list of configuration options.
|
|
251
|
+
|
|
252
|
+
:::
|
|
233
253
|
|
|
234
254
|
### Detecting and redacting PII
|
|
235
255
|
|
|
236
256
|
The `PIIDetector` is a hybrid processor that detects and removes personally identifiable information such as emails, phone numbers, and credit cards. It can redact either user input or model output, depending on where it's applied. It uses an LLM to identify sensitive content based on configured detection types.
|
|
237
257
|
|
|
238
|
-
```typescript {
|
|
258
|
+
```typescript {7-14,17} title="src/mastra/agents/private-agent.ts"
|
|
239
259
|
import { PIIDetector } from "@mastra/core/processors";
|
|
240
260
|
|
|
241
261
|
export const privateAgent = new Agent({
|
|
242
262
|
id: "private-agent",
|
|
243
263
|
name: "Private Agent",
|
|
244
|
-
// ...
|
|
245
264
|
inputProcessors: [
|
|
246
265
|
new PIIDetector({
|
|
247
266
|
model: "openrouter/openai/gpt-oss-safeguard-20b",
|
|
@@ -253,14 +272,16 @@ export const privateAgent = new Agent({
|
|
|
253
272
|
}),
|
|
254
273
|
],
|
|
255
274
|
outputProcessors: [
|
|
256
|
-
new PIIDetector(
|
|
257
|
-
// ...
|
|
258
|
-
}),
|
|
275
|
+
new PIIDetector(),
|
|
259
276
|
],
|
|
260
277
|
});
|
|
261
278
|
```
|
|
262
279
|
|
|
263
|
-
|
|
280
|
+
:::info
|
|
281
|
+
|
|
282
|
+
Visit [PIIDetector](/reference/v1/processors/pii-detector) for a full list of configuration options.
|
|
283
|
+
|
|
284
|
+
:::
|
|
264
285
|
|
|
265
286
|
## Applying multiple processors
|
|
266
287
|
|
|
@@ -274,7 +295,7 @@ A typical order might be:
|
|
|
274
295
|
|
|
275
296
|
The order affects behavior, so arrange processors to suit your goals.
|
|
276
297
|
|
|
277
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
298
|
+
```typescript title="src/mastra/agents/test-agent.ts"
|
|
278
299
|
import {
|
|
279
300
|
UnicodeNormalizer,
|
|
280
301
|
ModerationProcessor,
|
|
@@ -285,20 +306,11 @@ import {
|
|
|
285
306
|
export const testAgent = new Agent({
|
|
286
307
|
id: "test-agent",
|
|
287
308
|
name: "Test Agent",
|
|
288
|
-
// ...
|
|
289
309
|
inputProcessors: [
|
|
290
|
-
new UnicodeNormalizer(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
new
|
|
294
|
-
// ...
|
|
295
|
-
}),
|
|
296
|
-
new PIIDetector({
|
|
297
|
-
// ...
|
|
298
|
-
}),
|
|
299
|
-
new ModerationProcessor({
|
|
300
|
-
// ...
|
|
301
|
-
}),
|
|
310
|
+
new UnicodeNormalizer(),
|
|
311
|
+
new PromptInjectionDetector(),
|
|
312
|
+
new PIIDetector(),
|
|
313
|
+
new ModerationProcessor(),
|
|
302
314
|
],
|
|
303
315
|
});
|
|
304
316
|
```
|
|
@@ -309,16 +321,14 @@ Many of the built-in processors support a `strategy` parameter that controls how
|
|
|
309
321
|
|
|
310
322
|
Most strategies allow the request to continue without interruption. When `block` is used, the processor calls its internal `abort()` function, which immediately stops the request and prevents any subsequent processors from running.
|
|
311
323
|
|
|
312
|
-
```typescript {
|
|
324
|
+
```typescript {8} title="src/mastra/agents/private-agent.ts"
|
|
313
325
|
import { PIIDetector } from "@mastra/core/processors";
|
|
314
326
|
|
|
315
327
|
export const privateAgent = new Agent({
|
|
316
328
|
id: "private-agent",
|
|
317
329
|
name: "Private Agent",
|
|
318
|
-
// ...
|
|
319
330
|
inputProcessors: [
|
|
320
331
|
new PIIDetector({
|
|
321
|
-
// ...
|
|
322
332
|
strategy: "block",
|
|
323
333
|
}),
|
|
324
334
|
],
|
|
@@ -333,7 +343,7 @@ For example, if an agent uses the `PIIDetector` with `strategy: "block"` and the
|
|
|
333
343
|
|
|
334
344
|
#### `.generate()` example
|
|
335
345
|
|
|
336
|
-
```typescript
|
|
346
|
+
```typescript
|
|
337
347
|
const result = await agent.generate(
|
|
338
348
|
"Is this credit card number valid?: 4543 1374 5089 4332",
|
|
339
349
|
);
|
|
@@ -350,7 +360,7 @@ if (result.tripwire) {
|
|
|
350
360
|
|
|
351
361
|
#### `.stream()` example
|
|
352
362
|
|
|
353
|
-
```typescript
|
|
363
|
+
```typescript
|
|
354
364
|
const stream = await agent.stream(
|
|
355
365
|
"Is this credit card number valid?: 4543 1374 5089 4332",
|
|
356
366
|
);
|
|
@@ -373,7 +383,7 @@ PII detected. Types: credit-card
|
|
|
373
383
|
|
|
374
384
|
Processors can request that the LLM retry its response with feedback. This is useful for implementing quality checks:
|
|
375
385
|
|
|
376
|
-
```typescript
|
|
386
|
+
```typescript
|
|
377
387
|
export class QualityChecker implements Processor {
|
|
378
388
|
id = "quality-checker";
|
|
379
389
|
|
|
@@ -23,7 +23,7 @@ Mastra agent networks operate using these principles:
|
|
|
23
23
|
|
|
24
24
|
An agent network is built around a top-level routing agent that delegates tasks to agents, workflows, and tools defined in its configuration. Memory is configured on the routing agent using the `memory` option, and `instructions` define the agent's routing behavior.
|
|
25
25
|
|
|
26
|
-
```typescript {22-23,26,29} title="src/mastra/agents/routing-agent.ts"
|
|
26
|
+
```typescript {22-23,26,29} title="src/mastra/agents/routing-agent.ts"
|
|
27
27
|
import { Agent } from "@mastra/core/agent";
|
|
28
28
|
import { Memory } from "@mastra/memory";
|
|
29
29
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -71,25 +71,23 @@ When configuring a Mastra agent network, each primitive (agent, workflow, or too
|
|
|
71
71
|
|
|
72
72
|
Each agent in a network should include a clear `description` that explains what the agent does.
|
|
73
73
|
|
|
74
|
-
```typescript title="src/mastra/agents/research-agent.ts"
|
|
74
|
+
```typescript title="src/mastra/agents/research-agent.ts"
|
|
75
75
|
export const researchAgent = new Agent({
|
|
76
76
|
id: "research-agent",
|
|
77
77
|
name: "Research Agent",
|
|
78
78
|
description: `This agent gathers concise research insights in bullet-point form.
|
|
79
79
|
It's designed to extract key facts without generating full
|
|
80
80
|
responses or narrative content.`,
|
|
81
|
-
// ...
|
|
82
81
|
});
|
|
83
82
|
```
|
|
84
83
|
|
|
85
|
-
```typescript title="src/mastra/agents/writing-agent.ts"
|
|
84
|
+
```typescript title="src/mastra/agents/writing-agent.ts"
|
|
86
85
|
export const writingAgent = new Agent({
|
|
87
86
|
id: "writing-agent",
|
|
88
87
|
name: "Writing Agent",
|
|
89
88
|
description: `This agent turns researched material into well-structured
|
|
90
89
|
written content. It produces full-paragraph reports with no bullet points,
|
|
91
90
|
suitable for use in articles, summaries, or blog posts.`,
|
|
92
|
-
// ...
|
|
93
91
|
});
|
|
94
92
|
```
|
|
95
93
|
|
|
@@ -97,7 +95,7 @@ export const writingAgent = new Agent({
|
|
|
97
95
|
|
|
98
96
|
Workflows in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
|
|
99
97
|
|
|
100
|
-
```typescript title="src/mastra/workflows/city-workflow.ts"
|
|
98
|
+
```typescript title="src/mastra/workflows/city-workflow.ts"
|
|
101
99
|
export const cityWorkflow = createWorkflow({
|
|
102
100
|
id: "city-workflow",
|
|
103
101
|
description: `This workflow handles city-specific research tasks.
|
|
@@ -110,7 +108,6 @@ export const cityWorkflow = createWorkflow({
|
|
|
110
108
|
outputSchema: z.object({
|
|
111
109
|
text: z.string(),
|
|
112
110
|
}),
|
|
113
|
-
//...
|
|
114
111
|
});
|
|
115
112
|
```
|
|
116
113
|
|
|
@@ -118,7 +115,7 @@ export const cityWorkflow = createWorkflow({
|
|
|
118
115
|
|
|
119
116
|
Tools in a network should include a `description` to explain their purpose, along with `inputSchema` and `outputSchema` to describe the expected data.
|
|
120
117
|
|
|
121
|
-
```typescript title="src/mastra/tools/weather-tool.ts"
|
|
118
|
+
```typescript title="src/mastra/tools/weather-tool.ts"
|
|
122
119
|
export const weatherTool = createTool({
|
|
123
120
|
id: "weather-tool",
|
|
124
121
|
description: ` Retrieves current weather information using the wttr.in API.
|
|
@@ -131,7 +128,6 @@ export const weatherTool = createTool({
|
|
|
131
128
|
outputSchema: z.object({
|
|
132
129
|
weather: z.string(),
|
|
133
130
|
}),
|
|
134
|
-
// ...
|
|
135
131
|
});
|
|
136
132
|
```
|
|
137
133
|
|
|
@@ -143,7 +139,7 @@ Call a Mastra agent network using `.network()` with a user message. The method r
|
|
|
143
139
|
|
|
144
140
|
In this example, the network interprets the message and would route the request to both the `researchAgent` and `writingAgent` to generate a complete response.
|
|
145
141
|
|
|
146
|
-
```typescript
|
|
142
|
+
```typescript
|
|
147
143
|
const result = await routingAgent.network(
|
|
148
144
|
"Tell me three cool ways to use Mastra",
|
|
149
145
|
);
|
|
@@ -179,7 +175,7 @@ network-execution-event-step-finish
|
|
|
179
175
|
|
|
180
176
|
In this example, the routing agent recognizes the city name in the message and runs the `cityWorkflow`. The workflow defines steps that call the `researchAgent` to gather facts, then the `writingAgent` to generate the final text.
|
|
181
177
|
|
|
182
|
-
```typescript
|
|
178
|
+
```typescript
|
|
183
179
|
const result = await routingAgent.network(
|
|
184
180
|
"Tell me some historical facts about London",
|
|
185
181
|
);
|
|
@@ -212,7 +208,7 @@ network-execution-event-step-finish
|
|
|
212
208
|
|
|
213
209
|
In this example, the routing agent skips the `researchAgent`, `writingAgent`, and `cityWorkflow`, and calls the `weatherTool` directly to complete the task.
|
|
214
210
|
|
|
215
|
-
```typescript
|
|
211
|
+
```typescript
|
|
216
212
|
const result = await routingAgent.network("What's the weather in London?");
|
|
217
213
|
|
|
218
214
|
for await (const chunk of result) {
|
|
@@ -239,5 +235,5 @@ network-execution-event-step-finish
|
|
|
239
235
|
|
|
240
236
|
- [Agent Memory](./agent-memory)
|
|
241
237
|
- [Workflows Overview](../workflows/overview)
|
|
242
|
-
- [Request Context](/docs/v1/server
|
|
238
|
+
- [Request Context](/docs/v1/server/request-context)
|
|
243
239
|
- [Supervisor example](https://github.com/mastra-ai/mastra/tree/main/examples/supervisor-agent)
|
|
@@ -39,7 +39,7 @@ npm install @mastra/core@beta
|
|
|
39
39
|
|
|
40
40
|
Mastra's model router auto-detects environment variables for your chosen provider. For OpenAI, set `OPENAI_API_KEY`:
|
|
41
41
|
|
|
42
|
-
```bash title=".env"
|
|
42
|
+
```bash title=".env"
|
|
43
43
|
OPENAI_API_KEY=<your-api-key>
|
|
44
44
|
```
|
|
45
45
|
|
|
@@ -55,7 +55,7 @@ Mastra supports more than 600 models. Choose from the [full list](/models/v1).
|
|
|
55
55
|
|
|
56
56
|
Create an agent by instantiating the `Agent` class with system `instructions` and a `model`:
|
|
57
57
|
|
|
58
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
58
|
+
```typescript title="src/mastra/agents/test-agent.ts"
|
|
59
59
|
import { Agent } from "@mastra/core/agent";
|
|
60
60
|
|
|
61
61
|
export const testAgent = new Agent({
|
|
@@ -77,7 +77,7 @@ They are system-level prompts that establish the agent's core identity and exper
|
|
|
77
77
|
|
|
78
78
|
Instructions can be provided in multiple formats for greater flexibility. The examples below illustrate the supported shapes:
|
|
79
79
|
|
|
80
|
-
```typescript
|
|
80
|
+
```typescript
|
|
81
81
|
// String (most common)
|
|
82
82
|
instructions: "You are a helpful assistant.";
|
|
83
83
|
|
|
@@ -99,7 +99,7 @@ instructions: [
|
|
|
99
99
|
|
|
100
100
|
Each model provider also enables a few different options, including prompt caching and configuring reasoning. We provide a `providerOptions` flag to manage these. You can set `providerOptions` on the instruction level to set different caching strategy per system instruction/prompt.
|
|
101
101
|
|
|
102
|
-
```typescript
|
|
102
|
+
```typescript
|
|
103
103
|
// With provider-specific options (e.g., caching, reasoning)
|
|
104
104
|
instructions: {
|
|
105
105
|
role: "system",
|
|
@@ -112,18 +112,21 @@ instructions: {
|
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
:::info
|
|
116
|
+
|
|
117
|
+
Visit [Agent reference](/reference/v1/agents/agent) for more information.
|
|
118
|
+
|
|
119
|
+
:::
|
|
116
120
|
|
|
117
121
|
### Registering an agent
|
|
118
122
|
|
|
119
123
|
Register your agent in the Mastra instance to make it available throughout your application. Once registered, it can be called from workflows, tools, or other agents, and has access to shared resources such as memory, logging, and observability features:
|
|
120
124
|
|
|
121
|
-
```typescript {
|
|
125
|
+
```typescript {5} title="src/mastra/index.ts"
|
|
122
126
|
import { Mastra } from "@mastra/core";
|
|
123
127
|
import { testAgent } from "./agents/test-agent";
|
|
124
128
|
|
|
125
129
|
export const mastra = new Mastra({
|
|
126
|
-
// ...
|
|
127
130
|
agents: { testAgent },
|
|
128
131
|
});
|
|
129
132
|
```
|
|
@@ -132,7 +135,7 @@ export const mastra = new Mastra({
|
|
|
132
135
|
|
|
133
136
|
You can call agents from workflow steps, tools, the Mastra Client, or the command line. Get a reference by calling `.getAgent()` on your `mastra` or `mastraClient` instance, depending on your setup:
|
|
134
137
|
|
|
135
|
-
```typescript
|
|
138
|
+
```typescript
|
|
136
139
|
const testAgent = mastra.getAgent("testAgent");
|
|
137
140
|
```
|
|
138
141
|
|
|
@@ -152,7 +155,7 @@ Pass a single string for simple prompts, an array of strings when providing mult
|
|
|
152
155
|
|
|
153
156
|
(The `role` defines the speaker for each message. Typical roles are `user` for human input, `assistant` for agent responses, and `system` for instructions.)
|
|
154
157
|
|
|
155
|
-
```typescript
|
|
158
|
+
```typescript
|
|
156
159
|
const response = await testAgent.generate([
|
|
157
160
|
{ role: "user", content: "Help me organize my day" },
|
|
158
161
|
{ role: "user", content: "My day starts at 9am and finishes at 5.30pm" },
|
|
@@ -172,7 +175,7 @@ Pass a single string for simple prompts, an array of strings when providing mult
|
|
|
172
175
|
|
|
173
176
|
(The `role` defines the speaker for each message. Typical roles are `user` for human input, `assistant` for agent responses, and `system` for instructions.)
|
|
174
177
|
|
|
175
|
-
```typescript
|
|
178
|
+
```typescript
|
|
176
179
|
const stream = await testAgent.stream([
|
|
177
180
|
{ role: "user", content: "Help me organize my day" },
|
|
178
181
|
{ role: "user", content: "My day starts at 9am and finishes at 5.30pm" },
|
|
@@ -193,7 +196,7 @@ for await (const chunk of stream.textStream) {
|
|
|
193
196
|
When streaming responses, the `onFinish()` callback runs after the LLM finishes generating its response and all tool executions are complete.
|
|
194
197
|
It provides the final `text`, execution `steps`, `finishReason`, token `usage` statistics, and other metadata useful for monitoring or logging.
|
|
195
198
|
|
|
196
|
-
```typescript
|
|
199
|
+
```typescript
|
|
197
200
|
const stream = await testAgent.stream("Help me organize my day", {
|
|
198
201
|
onFinish: ({ steps, text, finishReason, usage }) => {
|
|
199
202
|
console.log({ steps, text, finishReason, usage });
|
|
@@ -208,19 +211,27 @@ for await (const chunk of stream.textStream) {
|
|
|
208
211
|
</TabItem>
|
|
209
212
|
</Tabs>
|
|
210
213
|
|
|
211
|
-
|
|
214
|
+
:::info
|
|
215
|
+
|
|
216
|
+
Visit [.generate()](/reference/v1/agents/generate) or [.stream()](/reference/v1/streaming/agents/stream) for more information.
|
|
217
|
+
|
|
218
|
+
:::
|
|
212
219
|
|
|
213
220
|
## Structured output
|
|
214
221
|
|
|
215
222
|
Agents can return structured, type-safe data using Zod or JSON Schema. The parsed result is available on `response.object`.
|
|
216
223
|
|
|
217
|
-
|
|
224
|
+
:::info
|
|
225
|
+
|
|
226
|
+
Visit [Structured Output](/docs/v1/agents/structured-output) for more information.
|
|
227
|
+
|
|
228
|
+
:::
|
|
218
229
|
|
|
219
230
|
## Analyzing images
|
|
220
231
|
|
|
221
232
|
Agents can analyze and describe images by processing both the visual content and any text within them. To enable image analysis, pass an object with `type: 'image'` and the image URL in the `content` array. You can combine image content with text prompts to guide the agent's analysis.
|
|
222
233
|
|
|
223
|
-
```typescript
|
|
234
|
+
```typescript
|
|
224
235
|
const response = await testAgent.generate([
|
|
225
236
|
{
|
|
226
237
|
role: "user",
|
|
@@ -241,12 +252,11 @@ const response = await testAgent.generate([
|
|
|
241
252
|
console.log(response.text);
|
|
242
253
|
```
|
|
243
254
|
|
|
244
|
-
|
|
245
255
|
## Using `maxSteps`
|
|
246
256
|
|
|
247
257
|
The `maxSteps` parameter controls the maximum number of sequential LLM calls an agent can make. Each step includes generating a response, executing any tool calls, and processing the result. Limiting steps helps prevent infinite loops, reduce latency, and control token usage for agents that use tools. The default is 1, but can be increased:
|
|
248
258
|
|
|
249
|
-
```typescript
|
|
259
|
+
```typescript
|
|
250
260
|
const response = await testAgent.generate("Help me organize my day", {
|
|
251
261
|
maxSteps: 10,
|
|
252
262
|
});
|
|
@@ -260,7 +270,7 @@ You can monitor the progress of multi-step operations using the `onStepFinish` c
|
|
|
260
270
|
|
|
261
271
|
`onStepFinish` is only available when streaming or generating text without structured output.
|
|
262
272
|
|
|
263
|
-
```typescript
|
|
273
|
+
```typescript
|
|
264
274
|
const response = await testAgent.generate("Help me organize my day", {
|
|
265
275
|
onStepFinish: ({ text, toolCalls, toolResults, finishReason, usage }) => {
|
|
266
276
|
console.log({ text, toolCalls, toolResults, finishReason, usage });
|
|
@@ -272,22 +282,25 @@ const response = await testAgent.generate("Help me organize my day", {
|
|
|
272
282
|
|
|
273
283
|
Agents can use tools to go beyond language generation, enabling structured interactions with external APIs and services. Tools allow agents to access data and perform clearly defined operations in a reliable, repeatable way.
|
|
274
284
|
|
|
275
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
285
|
+
```typescript title="src/mastra/agents/test-agent.ts"
|
|
276
286
|
export const testAgent = new Agent({
|
|
277
287
|
id: "test-agent",
|
|
278
288
|
name: "Test Agent",
|
|
279
|
-
// ...
|
|
280
289
|
tools: { testTool },
|
|
281
290
|
});
|
|
282
291
|
```
|
|
283
292
|
|
|
284
|
-
|
|
293
|
+
:::info
|
|
294
|
+
|
|
295
|
+
Visit [Using Tools](/docs/v1/agents/using-tools) for more information.
|
|
296
|
+
|
|
297
|
+
:::
|
|
285
298
|
|
|
286
299
|
## Using `RequestContext`
|
|
287
300
|
|
|
288
301
|
Use `RequestContext` to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
|
|
289
302
|
|
|
290
|
-
```typescript title="src/mastra/agents/test-agent.ts"
|
|
303
|
+
```typescript title="src/mastra/agents/test-agent.ts"
|
|
291
304
|
export type UserTier = {
|
|
292
305
|
"user-tier": "enterprise" | "pro";
|
|
293
306
|
};
|
|
@@ -295,7 +308,6 @@ export type UserTier = {
|
|
|
295
308
|
export const testAgent = new Agent({
|
|
296
309
|
id: "test-agent",
|
|
297
310
|
name: "Test Agent",
|
|
298
|
-
// ...
|
|
299
311
|
model: ({ requestContext }) => {
|
|
300
312
|
const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
|
|
301
313
|
|
|
@@ -306,7 +318,11 @@ export const testAgent = new Agent({
|
|
|
306
318
|
});
|
|
307
319
|
```
|
|
308
320
|
|
|
309
|
-
|
|
321
|
+
:::info
|
|
322
|
+
|
|
323
|
+
See [Request Context](/docs/v1/server/request-context) for more information.
|
|
324
|
+
|
|
325
|
+
:::
|
|
310
326
|
|
|
311
327
|
## Testing with Studio
|
|
312
328
|
|
|
@@ -316,4 +332,4 @@ Use [Studio](/docs/v1/getting-started/studio) to test agents with different mess
|
|
|
316
332
|
|
|
317
333
|
- [Using Tools](/docs/v1/agents/using-tools)
|
|
318
334
|
- [Agent Memory](/docs/v1/agents/agent-memory)
|
|
319
|
-
- [Request Context](/docs/v1/server
|
|
335
|
+
- [Request Context](/docs/v1/server/request-context)
|