@mastra/core 1.2.0 → 1.2.1-alpha.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/CHANGELOG.md +10 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +30 -17
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +10 -7
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/{chunk-VBOO4F4D.cjs → chunk-2DMSFLJY.cjs} +5 -5
- package/dist/{chunk-VBOO4F4D.cjs.map → chunk-2DMSFLJY.cjs.map} +1 -1
- package/dist/{chunk-ARQG4ZSD.cjs → chunk-5SOS47PH.cjs} +37 -37
- package/dist/chunk-5SOS47PH.cjs.map +1 -0
- package/dist/{chunk-NRMSZFAU.js → chunk-5YVR7B4R.js} +5 -5
- package/dist/{chunk-NRMSZFAU.js.map → chunk-5YVR7B4R.js.map} +1 -1
- package/dist/{chunk-G5NRZOPO.cjs → chunk-7MDVYPWX.cjs} +4 -4
- package/dist/{chunk-G5NRZOPO.cjs.map → chunk-7MDVYPWX.cjs.map} +1 -1
- package/dist/{chunk-AP3Z4EAP.cjs → chunk-A5QFWX67.cjs} +53 -53
- package/dist/{chunk-AP3Z4EAP.cjs.map → chunk-A5QFWX67.cjs.map} +1 -1
- package/dist/{chunk-4XLGMCCQ.js → chunk-AUF6U2BL.js} +3 -3
- package/dist/{chunk-4XLGMCCQ.js.map → chunk-AUF6U2BL.js.map} +1 -1
- package/dist/{chunk-POKH6N2J.cjs → chunk-AXN5P2GE.cjs} +4 -4
- package/dist/{chunk-POKH6N2J.cjs.map → chunk-AXN5P2GE.cjs.map} +1 -1
- package/dist/{chunk-YL6ETQ5I.cjs → chunk-B4M33FCS.cjs} +9 -9
- package/dist/{chunk-YL6ETQ5I.cjs.map → chunk-B4M33FCS.cjs.map} +1 -1
- package/dist/{chunk-DG6C6ZTL.cjs → chunk-CC3OOESY.cjs} +44 -43
- package/dist/chunk-CC3OOESY.cjs.map +1 -0
- package/dist/{chunk-NYC6PYZF.js → chunk-E3VFKTIA.js} +36 -4
- package/dist/chunk-E3VFKTIA.js.map +1 -0
- package/dist/{chunk-3LRUJTH3.cjs → chunk-GVLPTDJA.cjs} +50 -13
- package/dist/chunk-GVLPTDJA.cjs.map +1 -0
- package/dist/{chunk-SS4AZHZW.cjs → chunk-HU2ONA2W.cjs} +9 -9
- package/dist/{chunk-SS4AZHZW.cjs.map → chunk-HU2ONA2W.cjs.map} +1 -1
- package/dist/chunk-HVG7MWNT.js +439 -0
- package/dist/chunk-HVG7MWNT.js.map +1 -0
- package/dist/chunk-JCEP2VPF.cjs +441 -0
- package/dist/chunk-JCEP2VPF.cjs.map +1 -0
- package/dist/{chunk-PPAJGWVW.js → chunk-MSWXEOZC.js} +3 -3
- package/dist/{chunk-PPAJGWVW.js.map → chunk-MSWXEOZC.js.map} +1 -1
- package/dist/{chunk-AQHO4OC2.cjs → chunk-QOFI2WBM.cjs} +6 -6
- package/dist/{chunk-AQHO4OC2.cjs.map → chunk-QOFI2WBM.cjs.map} +1 -1
- package/dist/{chunk-EY3WXGUD.js → chunk-RXD5EGQF.js} +43 -6
- package/dist/chunk-RXD5EGQF.js.map +1 -0
- package/dist/{chunk-XC7WIZBL.js → chunk-S6BH5HHY.js} +4 -3
- package/dist/chunk-S6BH5HHY.js.map +1 -0
- package/dist/{chunk-IPXNR6RQ.js → chunk-V2MLGA7T.js} +1884 -998
- package/dist/chunk-V2MLGA7T.js.map +1 -0
- package/dist/{chunk-Z4PGSIZ5.cjs → chunk-VTE2OBKS.cjs} +1890 -1004
- package/dist/chunk-VTE2OBKS.cjs.map +1 -0
- package/dist/{chunk-ZODRDMZ7.js → chunk-VX7UA3SO.js} +3 -3
- package/dist/{chunk-ZODRDMZ7.js.map → chunk-VX7UA3SO.js.map} +1 -1
- package/dist/{chunk-5HDIPOLV.js → chunk-WFUNLRQX.js} +6 -6
- package/dist/chunk-WFUNLRQX.js.map +1 -0
- package/dist/{chunk-V3LENMEW.js → chunk-X5ORARLG.js} +4 -4
- package/dist/{chunk-V3LENMEW.js.map → chunk-X5ORARLG.js.map} +1 -1
- package/dist/{chunk-Z2OKCLGV.cjs → chunk-XCPEEIHI.cjs} +41 -8
- package/dist/chunk-XCPEEIHI.cjs.map +1 -0
- package/dist/{chunk-57O4TPB3.js → chunk-Z6NRYYOH.js} +3 -3
- package/dist/{chunk-57O4TPB3.js.map → chunk-Z6NRYYOH.js.map} +1 -1
- package/dist/{chunk-RUMXBL6P.js → chunk-ZWM2CAIM.js} +5 -5
- package/dist/{chunk-RUMXBL6P.js.map → chunk-ZWM2CAIM.js.map} +1 -1
- package/dist/docs/SKILL.md +270 -64
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +156 -152
- package/dist/docs/{agents/10-adding-voice.md → references/docs-agents-adding-voice.md} +6 -5
- package/dist/docs/{agents/08-agent-approval.md → references/docs-agents-agent-approval.md} +19 -19
- package/dist/docs/{agents/03-agent-memory.md → references/docs-agents-agent-memory.md} +57 -55
- package/dist/docs/{agents/07-guardrails.md → references/docs-agents-guardrails.md} +21 -39
- package/dist/docs/{agents/09-network-approval.md → references/docs-agents-network-approval.md} +12 -11
- package/dist/docs/{agents/05-networks.md → references/docs-agents-networks.md} +7 -9
- package/dist/docs/{agents/01-overview.md → references/docs-agents-overview.md} +54 -72
- package/dist/docs/{agents/06-processors.md → references/docs-agents-processors.md} +29 -24
- package/dist/docs/{agents/04-structured-output.md → references/docs-agents-structured-output.md} +13 -22
- package/dist/docs/{agents/02-using-tools.md → references/docs-agents-using-tools.md} +12 -13
- package/dist/docs/{evals/02-custom-scorers.md → references/docs-evals-custom-scorers.md} +5 -7
- package/dist/docs/{evals/01-overview.md → references/docs-evals-overview.md} +26 -17
- package/dist/docs/{evals/03-running-in-ci.md → references/docs-evals-running-in-ci.md} +2 -4
- package/dist/docs/{mcp/01-overview.md → references/docs-mcp-overview.md} +135 -140
- package/dist/docs/references/docs-mcp-publishing-mcp-server.md +95 -0
- package/dist/docs/{memory/05-memory-processors.md → references/docs-memory-memory-processors.md} +6 -8
- package/dist/docs/references/docs-memory-observational-memory.md +166 -0
- package/dist/docs/{memory/01-overview.md → references/docs-memory-overview.md} +8 -8
- package/dist/docs/{memory/04-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
- package/dist/docs/{memory/02-storage.md → references/docs-memory-storage.md} +29 -39
- package/dist/docs/{memory/03-working-memory.md → references/docs-memory-working-memory.md} +16 -27
- package/dist/docs/{observability/02-logging.md → references/docs-observability-logging.md} +6 -10
- package/dist/docs/{observability/01-overview.md → references/docs-observability-overview.md} +4 -10
- package/dist/docs/{observability/04-otel.md → references/docs-observability-tracing-bridges-otel.md} +31 -14
- package/dist/docs/{observability/07-arize.md → references/docs-observability-tracing-exporters-arize.md} +38 -22
- package/dist/docs/{observability/08-braintrust.md → references/docs-observability-tracing-exporters-braintrust.md} +24 -6
- package/dist/docs/{observability/06-cloud.md → references/docs-observability-tracing-exporters-cloud.md} +7 -7
- package/dist/docs/{observability/09-datadog.md → references/docs-observability-tracing-exporters-datadog.md} +26 -8
- package/dist/docs/{observability/05-default.md → references/docs-observability-tracing-exporters-default.md} +11 -14
- package/dist/docs/{observability/10-laminar.md → references/docs-observability-tracing-exporters-laminar.md} +24 -6
- package/dist/docs/{observability/11-langfuse.md → references/docs-observability-tracing-exporters-langfuse.md} +31 -12
- package/dist/docs/{observability/12-langsmith.md → references/docs-observability-tracing-exporters-langsmith.md} +29 -11
- package/dist/docs/{observability/13-otel.md → references/docs-observability-tracing-exporters-otel.md} +107 -63
- package/dist/docs/{observability/14-posthog.md → references/docs-observability-tracing-exporters-posthog.md} +24 -6
- package/dist/docs/{observability/03-overview.md → references/docs-observability-tracing-overview.md} +45 -53
- package/dist/docs/{rag/02-chunking-and-embedding.md → references/docs-rag-chunking-and-embedding.md} +5 -11
- package/dist/docs/{rag/05-graph-rag.md → references/docs-rag-graph-rag.md} +0 -2
- package/dist/docs/{rag/01-overview.md → references/docs-rag-overview.md} +2 -7
- package/dist/docs/{rag/04-retrieval.md → references/docs-rag-retrieval.md} +26 -53
- package/dist/docs/{rag/03-vector-databases.md → references/docs-rag-vector-databases.md} +198 -202
- package/dist/docs/{server/13-auth0.md → references/docs-server-auth-auth0.md} +68 -79
- package/dist/docs/{server/09-clerk.md → references/docs-server-auth-clerk.md} +41 -52
- package/dist/docs/{server/14-composite-auth.md → references/docs-server-auth-composite-auth.md} +1 -3
- package/dist/docs/{server/15-custom-auth-provider.md → references/docs-server-auth-custom-auth-provider.md} +13 -15
- package/dist/docs/{server/11-firebase.md → references/docs-server-auth-firebase.md} +83 -97
- package/dist/docs/{server/08-jwt.md → references/docs-server-auth-jwt.md} +46 -35
- package/dist/docs/{server/07-simple-auth.md → references/docs-server-auth-simple-auth.md} +10 -11
- package/dist/docs/{server/10-supabase.md → references/docs-server-auth-supabase.md} +33 -44
- package/dist/docs/{server/12-workos.md → references/docs-server-auth-workos.md} +45 -56
- package/dist/docs/{server/02-custom-adapters.md → references/docs-server-custom-adapters.md} +25 -31
- package/dist/docs/{server/05-custom-api-routes.md → references/docs-server-custom-api-routes.md} +7 -7
- package/dist/docs/{server/06-mastra-client.md → references/docs-server-mastra-client.md} +32 -20
- package/dist/docs/{server/01-mastra-server.md → references/docs-server-mastra-server.md} +5 -11
- package/dist/docs/{server/03-middleware.md → references/docs-server-middleware.md} +8 -15
- package/dist/docs/{server/04-request-context.md → references/docs-server-request-context.md} +29 -43
- package/dist/docs/{streaming/01-events.md → references/docs-streaming-events.md} +9 -16
- package/dist/docs/{streaming/02-tool-streaming.md → references/docs-streaming-tool-streaming.md} +6 -11
- package/dist/docs/{streaming/03-workflow-streaming.md → references/docs-streaming-workflow-streaming.md} +2 -6
- package/dist/docs/{tools-mcp/03-advanced-usage.md → references/docs-tools-mcp-advanced-usage.md} +23 -5
- package/dist/docs/{tools-mcp/01-mcp-overview.md → references/docs-tools-mcp-mcp-overview.md} +141 -146
- package/dist/docs/{tools-mcp/02-overview.md → references/docs-tools-mcp-overview.md} +4 -12
- package/dist/docs/{voice/01-overview.md → references/docs-voice-overview.md} +37 -81
- package/dist/docs/{voice/04-speech-to-speech.md → references/docs-voice-speech-to-speech.md} +1 -4
- package/dist/docs/{voice/03-speech-to-text.md → references/docs-voice-speech-to-text.md} +8 -11
- package/dist/docs/{voice/02-text-to-speech.md → references/docs-voice-text-to-speech.md} +12 -15
- package/dist/docs/{workflows/04-agents-and-tools.md → references/docs-workflows-agents-and-tools.md} +11 -21
- package/dist/docs/{workflows/03-control-flow.md → references/docs-workflows-control-flow.md} +58 -56
- package/dist/docs/{workflows/09-error-handling.md → references/docs-workflows-error-handling.md} +13 -15
- package/dist/docs/{workflows/07-human-in-the-loop.md → references/docs-workflows-human-in-the-loop.md} +11 -12
- package/dist/docs/{workflows/10-input-data-mapping.md → references/docs-workflows-input-data-mapping.md} +12 -14
- package/dist/docs/{workflows/01-overview.md → references/docs-workflows-overview.md} +31 -52
- package/dist/docs/{workflows/05-snapshots.md → references/docs-workflows-snapshots.md} +3 -5
- package/dist/docs/{workflows/06-suspend-and-resume.md → references/docs-workflows-suspend-and-resume.md} +12 -12
- package/dist/docs/{workflows/08-time-travel.md → references/docs-workflows-time-travel.md} +2 -5
- package/dist/docs/{workflows/02-workflow-state.md → references/docs-workflows-workflow-state.md} +4 -6
- package/dist/docs/{workspace/02-filesystem.md → references/docs-workspace-filesystem.md} +3 -8
- package/dist/docs/{workspace/01-overview.md → references/docs-workspace-overview.md} +10 -16
- package/dist/docs/{workspace/03-sandbox.md → references/docs-workspace-sandbox.md} +2 -4
- package/dist/docs/{workspace/05-search.md → references/docs-workspace-search.md} +20 -22
- package/dist/docs/{workspace/04-skills.md → references/docs-workspace-skills.md} +6 -9
- package/dist/docs/{guides/01-ai-sdk.md → references/guides-agent-frameworks-ai-sdk.md} +25 -9
- package/dist/docs/references/reference-agents-agent.md +142 -0
- package/dist/docs/references/reference-agents-generate.md +174 -0
- package/dist/docs/references/reference-agents-generateLegacy.md +176 -0
- package/dist/docs/references/reference-agents-getDefaultGenerateOptions.md +36 -0
- package/dist/docs/references/reference-agents-getDefaultOptions.md +34 -0
- package/dist/docs/references/reference-agents-getDefaultStreamOptions.md +36 -0
- package/dist/docs/references/reference-agents-getDescription.md +21 -0
- package/dist/docs/references/reference-agents-getInstructions.md +34 -0
- package/dist/docs/references/reference-agents-getLLM.md +37 -0
- package/dist/docs/references/reference-agents-getMemory.md +34 -0
- package/dist/docs/references/reference-agents-getModel.md +34 -0
- package/dist/docs/references/reference-agents-getTools.md +34 -0
- package/dist/docs/references/reference-agents-getVoice.md +34 -0
- package/dist/docs/references/reference-agents-listAgents.md +35 -0
- package/dist/docs/references/reference-agents-listScorers.md +34 -0
- package/dist/docs/references/reference-agents-listTools.md +34 -0
- package/dist/docs/references/reference-agents-listWorkflows.md +34 -0
- package/dist/docs/references/reference-agents-network.md +136 -0
- package/dist/docs/references/reference-ai-sdk-chat-route.md +82 -0
- package/dist/docs/references/reference-ai-sdk-network-route.md +74 -0
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +232 -0
- package/dist/docs/references/reference-ai-sdk-with-mastra.md +59 -0
- package/dist/docs/references/reference-ai-sdk-workflow-route.md +79 -0
- package/dist/docs/references/reference-auth-auth0.md +73 -0
- package/dist/docs/references/reference-auth-clerk.md +36 -0
- package/dist/docs/references/reference-auth-firebase.md +80 -0
- package/dist/docs/references/reference-auth-jwt.md +26 -0
- package/dist/docs/references/reference-auth-supabase.md +33 -0
- package/dist/docs/references/reference-auth-workos.md +84 -0
- package/dist/docs/{cli/01-reference.md → references/reference-cli-mastra.md} +14 -28
- package/dist/docs/{client-js/01-reference.md → references/reference-client-js-agents.md} +3 -12
- package/dist/docs/{configuration.mdx/01-reference.md → references/reference-configuration.md} +71 -91
- package/dist/docs/references/reference-core-addGateway.md +42 -0
- package/dist/docs/references/reference-core-getAgent.md +21 -0
- package/dist/docs/references/reference-core-getAgentById.md +21 -0
- package/dist/docs/references/reference-core-getDeployer.md +22 -0
- package/dist/docs/references/reference-core-getGateway.md +38 -0
- package/dist/docs/references/reference-core-getGatewayById.md +41 -0
- package/dist/docs/references/reference-core-getLogger.md +22 -0
- package/dist/docs/references/reference-core-getMCPServer.md +45 -0
- package/dist/docs/references/reference-core-getMCPServerById.md +53 -0
- package/dist/docs/references/reference-core-getMemory.md +50 -0
- package/dist/docs/references/reference-core-getScorer.md +54 -0
- package/dist/docs/references/reference-core-getScorerById.md +54 -0
- package/dist/docs/references/reference-core-getServer.md +22 -0
- package/dist/docs/references/reference-core-getStorage.md +22 -0
- package/dist/docs/references/reference-core-getStoredAgentById.md +89 -0
- package/dist/docs/references/reference-core-getTelemetry.md +22 -0
- package/dist/docs/references/reference-core-getVector.md +22 -0
- package/dist/docs/references/reference-core-getWorkflow.md +40 -0
- package/dist/docs/references/reference-core-listAgents.md +21 -0
- package/dist/docs/references/reference-core-listGateways.md +40 -0
- package/dist/docs/references/reference-core-listLogs.md +38 -0
- package/dist/docs/references/reference-core-listLogsByRunId.md +36 -0
- package/dist/docs/references/reference-core-listMCPServers.md +51 -0
- package/dist/docs/references/reference-core-listMemory.md +56 -0
- package/dist/docs/references/reference-core-listScorers.md +29 -0
- package/dist/docs/references/reference-core-listStoredAgents.md +93 -0
- package/dist/docs/references/reference-core-listVectors.md +22 -0
- package/dist/docs/references/reference-core-listWorkflows.md +21 -0
- package/dist/docs/references/reference-core-mastra-class.md +66 -0
- package/dist/docs/references/reference-core-mastra-model-gateway.md +153 -0
- package/dist/docs/references/reference-core-setLogger.md +26 -0
- package/dist/docs/references/reference-core-setStorage.md +27 -0
- package/dist/docs/references/reference-deployer-cloudflare.md +56 -0
- package/dist/docs/references/reference-deployer-netlify.md +14 -0
- package/dist/docs/references/reference-deployer-vercel.md +39 -0
- package/dist/docs/references/reference-evals-answer-relevancy.md +105 -0
- package/dist/docs/references/reference-evals-answer-similarity.md +99 -0
- package/dist/docs/references/reference-evals-bias.md +120 -0
- package/dist/docs/references/reference-evals-completeness.md +137 -0
- package/dist/docs/references/reference-evals-content-similarity.md +101 -0
- package/dist/docs/references/reference-evals-context-precision.md +196 -0
- package/dist/docs/references/reference-evals-create-scorer.md +270 -0
- package/dist/docs/references/reference-evals-faithfulness.md +114 -0
- package/dist/docs/references/reference-evals-hallucination.md +220 -0
- package/dist/docs/references/reference-evals-keyword-coverage.md +128 -0
- package/dist/docs/references/reference-evals-mastra-scorer.md +123 -0
- package/dist/docs/references/reference-evals-run-evals.md +138 -0
- package/dist/docs/references/reference-evals-scorer-utils.md +330 -0
- package/dist/docs/references/reference-evals-textual-difference.md +113 -0
- package/dist/docs/references/reference-evals-tone-consistency.md +119 -0
- package/dist/docs/references/reference-evals-toxicity.md +123 -0
- package/dist/docs/{logging/01-reference.md → references/reference-logging-pino-logger.md} +16 -15
- package/dist/docs/references/reference-memory-deleteMessages.md +40 -0
- package/dist/docs/{memory/06-reference.md → references/reference-memory-memory-class.md} +28 -55
- package/dist/docs/references/reference-memory-observational-memory.md +217 -0
- package/dist/docs/references/reference-observability-tracing-bridges-otel.md +131 -0
- package/dist/docs/references/reference-observability-tracing-configuration.md +178 -0
- package/dist/docs/references/reference-observability-tracing-exporters-console-exporter.md +138 -0
- package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +116 -0
- package/dist/docs/references/reference-observability-tracing-instances.md +109 -0
- package/dist/docs/references/reference-observability-tracing-interfaces.md +749 -0
- package/dist/docs/references/reference-observability-tracing-processors-sensitive-data-filter.md +144 -0
- package/dist/docs/references/reference-observability-tracing-spans.md +224 -0
- package/dist/docs/references/reference-processors-batch-parts-processor.md +61 -0
- package/dist/docs/references/reference-processors-language-detector.md +81 -0
- package/dist/docs/references/reference-processors-message-history-processor.md +85 -0
- package/dist/docs/references/reference-processors-moderation-processor.md +104 -0
- package/dist/docs/references/reference-processors-pii-detector.md +107 -0
- package/dist/docs/references/reference-processors-processor-interface.md +521 -0
- package/dist/docs/references/reference-processors-prompt-injection-detector.md +71 -0
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +123 -0
- package/dist/docs/references/reference-processors-system-prompt-scrubber.md +80 -0
- package/dist/docs/references/reference-processors-token-limiter-processor.md +113 -0
- package/dist/docs/references/reference-processors-tool-call-filter.md +85 -0
- package/dist/docs/references/reference-processors-tool-search-processor.md +113 -0
- package/dist/docs/references/reference-processors-unicode-normalizer.md +62 -0
- package/dist/docs/references/reference-processors-working-memory-processor.md +154 -0
- package/dist/docs/references/reference-rag-database-config.md +264 -0
- package/dist/docs/references/reference-rag-embeddings.md +92 -0
- package/dist/docs/references/reference-server-mastra-server.md +298 -0
- package/dist/docs/references/reference-server-register-api-route.md +249 -0
- package/dist/docs/references/reference-storage-cloudflare-d1.md +218 -0
- package/dist/docs/references/reference-storage-composite.md +235 -0
- package/dist/docs/references/reference-storage-lance.md +131 -0
- package/dist/docs/references/reference-storage-libsql.md +135 -0
- package/dist/docs/references/reference-storage-mongodb.md +262 -0
- package/dist/docs/references/reference-storage-mssql.md +155 -0
- package/dist/docs/references/reference-storage-overview.md +121 -0
- package/dist/docs/references/reference-storage-postgresql.md +529 -0
- package/dist/docs/references/reference-storage-upstash.md +160 -0
- package/dist/docs/references/reference-streaming-ChunkType.md +292 -0
- package/dist/docs/references/reference-streaming-agents-MastraModelOutput.md +182 -0
- package/dist/docs/references/reference-streaming-agents-streamLegacy.md +142 -0
- package/dist/docs/references/reference-streaming-workflows-observeStream.md +42 -0
- package/dist/docs/references/reference-streaming-workflows-resumeStream.md +61 -0
- package/dist/docs/references/reference-streaming-workflows-stream.md +87 -0
- package/dist/docs/references/reference-streaming-workflows-timeTravelStream.md +142 -0
- package/dist/docs/{templates/01-reference.md → references/reference-templates-overview.md} +8 -17
- package/dist/docs/references/reference-tools-client.md +228 -0
- package/dist/docs/references/reference-tools-create-tool.md +237 -0
- package/dist/docs/references/reference-tools-graph-rag-tool.md +185 -0
- package/dist/docs/references/reference-tools-mcp-client.md +964 -0
- package/dist/docs/references/reference-tools-mcp-server.md +1275 -0
- package/dist/docs/references/reference-tools-vector-query-tool.md +459 -0
- package/dist/docs/references/reference-vectors-libsql.md +305 -0
- package/dist/docs/references/reference-vectors-mongodb.md +295 -0
- package/dist/docs/references/reference-vectors-pg.md +408 -0
- package/dist/docs/references/reference-vectors-upstash.md +294 -0
- package/dist/docs/references/reference-voice-composite-voice.md +121 -0
- package/dist/docs/references/reference-voice-mastra-voice.md +313 -0
- package/dist/docs/references/reference-voice-voice.addInstructions.md +56 -0
- package/dist/docs/references/reference-voice-voice.addTools.md +67 -0
- package/dist/docs/references/reference-voice-voice.connect.md +94 -0
- package/dist/docs/references/reference-voice-voice.events.md +37 -0
- package/dist/docs/references/reference-voice-voice.listen.md +164 -0
- package/dist/docs/references/reference-voice-voice.on.md +111 -0
- package/dist/docs/references/reference-voice-voice.speak.md +157 -0
- package/dist/docs/references/reference-workflows-run-methods-cancel.md +86 -0
- package/dist/docs/references/reference-workflows-run-methods-restart.md +33 -0
- package/dist/docs/references/reference-workflows-run-methods-resume.md +59 -0
- package/dist/docs/references/reference-workflows-run-methods-start.md +58 -0
- package/dist/docs/references/reference-workflows-run-methods-startAsync.md +67 -0
- package/dist/docs/references/reference-workflows-run-methods-timeTravel.md +142 -0
- package/dist/docs/references/reference-workflows-run.md +59 -0
- package/dist/docs/references/reference-workflows-step.md +117 -0
- package/dist/docs/references/reference-workflows-workflow-methods-branch.md +25 -0
- package/dist/docs/references/reference-workflows-workflow-methods-commit.md +17 -0
- package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +63 -0
- package/dist/docs/references/reference-workflows-workflow-methods-dountil.md +25 -0
- package/dist/docs/references/reference-workflows-workflow-methods-dowhile.md +25 -0
- package/dist/docs/references/reference-workflows-workflow-methods-foreach.md +88 -0
- package/dist/docs/references/reference-workflows-workflow-methods-map.md +93 -0
- package/dist/docs/references/reference-workflows-workflow-methods-parallel.md +21 -0
- package/dist/docs/references/reference-workflows-workflow-methods-sleep.md +35 -0
- package/dist/docs/references/reference-workflows-workflow-methods-sleepUntil.md +35 -0
- package/dist/docs/references/reference-workflows-workflow-methods-then.md +21 -0
- package/dist/docs/references/reference-workflows-workflow.md +157 -0
- package/dist/docs/references/reference-workspace-filesystem.md +200 -0
- package/dist/docs/references/reference-workspace-local-filesystem.md +300 -0
- package/dist/docs/references/reference-workspace-local-sandbox.md +283 -0
- package/dist/docs/references/reference-workspace-sandbox.md +79 -0
- package/dist/docs/references/reference-workspace-workspace-class.md +247 -0
- package/dist/docs/references/reference.md +243 -0
- package/dist/evals/index.cjs +5 -5
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +3 -3
- package/dist/evals/scoreTraces/index.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +2 -2
- package/dist/llm/index.cjs +9 -5
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/model/index.d.ts +1 -1
- package/dist/llm/model/index.d.ts.map +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +17 -0
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/memory/types.d.ts +3 -2
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/processors/index.cjs +41 -41
- package/dist/processors/index.js +1 -1
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/index.cjs +33 -33
- package/dist/storage/index.js +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/test-utils/llm-mock.cjs +12 -12
- package/dist/test-utils/llm-mock.js +3 -3
- package/dist/{token-6GSAFR2W-TOUJCAPY.js → token-APYSY3BW-QJCV2XQG.js} +11 -11
- package/dist/token-APYSY3BW-QJCV2XQG.js.map +1 -0
- package/dist/{token-6GSAFR2W-GERJXNN5.cjs → token-APYSY3BW-UBKUGJQP.cjs} +14 -14
- package/dist/token-APYSY3BW-UBKUGJQP.cjs.map +1 -0
- package/dist/token-util-RMHT2CPJ-S2YMG7N3.js +8 -0
- package/dist/token-util-RMHT2CPJ-S2YMG7N3.js.map +1 -0
- package/dist/token-util-RMHT2CPJ-WV2T74WQ.cjs +10 -0
- package/dist/token-util-RMHT2CPJ-WV2T74WQ.cjs.map +1 -0
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +11 -11
- package/dist/vector/index.js +3 -3
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +25 -25
- package/dist/workflows/index.js +1 -1
- package/package.json +4 -5
- package/dist/chunk-3LRUJTH3.cjs.map +0 -1
- package/dist/chunk-5HDIPOLV.js.map +0 -1
- package/dist/chunk-ARQG4ZSD.cjs.map +0 -1
- package/dist/chunk-DG6C6ZTL.cjs.map +0 -1
- package/dist/chunk-EY3WXGUD.js.map +0 -1
- package/dist/chunk-IPXNR6RQ.js.map +0 -1
- package/dist/chunk-NYC6PYZF.js.map +0 -1
- package/dist/chunk-X5HU5YVN.js +0 -250
- package/dist/chunk-X5HU5YVN.js.map +0 -1
- package/dist/chunk-XC7WIZBL.js.map +0 -1
- package/dist/chunk-Z2OKCLGV.cjs.map +0 -1
- package/dist/chunk-Z4PGSIZ5.cjs.map +0 -1
- package/dist/chunk-ZZF2IKZJ.cjs +0 -252
- package/dist/chunk-ZZF2IKZJ.cjs.map +0 -1
- package/dist/docs/README.md +0 -57
- package/dist/docs/agents/11-reference.md +0 -854
- package/dist/docs/ai-sdk/01-reference.md +0 -490
- package/dist/docs/auth/01-reference.md +0 -308
- package/dist/docs/core/01-reference.md +0 -1283
- package/dist/docs/deployer/01-reference.md +0 -128
- package/dist/docs/evals/04-reference.md +0 -2137
- package/dist/docs/index.mdx/01-reference.md +0 -14
- package/dist/docs/mcp/02-publishing-mcp-server.md +0 -111
- package/dist/docs/observability/15-reference.md +0 -1831
- package/dist/docs/processors/01-reference.md +0 -1418
- package/dist/docs/rag/06-reference.md +0 -342
- package/dist/docs/server/16-reference.md +0 -513
- package/dist/docs/storage/01-reference.md +0 -2022
- package/dist/docs/streaming/04-reference.md +0 -724
- package/dist/docs/tools/01-reference.md +0 -3136
- package/dist/docs/vectors/01-reference.md +0 -942
- package/dist/docs/voice/05-reference.md +0 -1043
- package/dist/docs/workflows/11-reference.md +0 -1044
- package/dist/docs/workspace/06-reference.md +0 -946
- package/dist/token-6GSAFR2W-GERJXNN5.cjs.map +0 -1
- package/dist/token-6GSAFR2W-TOUJCAPY.js.map +0 -1
- package/dist/token-util-NEHG7TUY-R2XAU2MF.cjs +0 -10
- package/dist/token-util-NEHG7TUY-R2XAU2MF.cjs.map +0 -1
- package/dist/token-util-NEHG7TUY-TZ426VZB.js +0 -8
- package/dist/token-util-NEHG7TUY-TZ426VZB.js.map +0 -1
|
@@ -1,61 +1,65 @@
|
|
|
1
|
-
> Overview of agents in Mastra, detailing their capabilities and how they interact with tools, workflows, and external systems.
|
|
2
|
-
|
|
3
|
-
> **Code References:**
|
|
4
|
-
- `Agent`: dist/agent/agent.d.ts → dist/chunk-5HDIPOLV.js:17701
|
|
5
|
-
- `Mastra`: dist/mastra/index.d.ts → dist/chunk-EY3WXGUD.js:24
|
|
6
|
-
|
|
7
1
|
# Using Agents
|
|
8
2
|
|
|
9
3
|
Agents use LLMs and tools to solve open-ended tasks. They reason about goals, decide which tools to use, retain conversation memory, and iterate internally until the model emits a final answer or an optional stop condition is met. Agents produce structured responses you can render in your UI or process programmatically. Use agents directly or compose them into workflows or agent networks.
|
|
10
4
|
|
|
11
|
-

|
|
12
6
|
|
|
13
|
-
> **Watch an introduction
|
|
14
|
-
|
|
15
|
-
An introduction to agents, and how they compare to workflows on [YouTube (7 minutes)](https://youtu.be/0jg2g3sNvgw)
|
|
7
|
+
> **Watch an introduction:** An introduction to agents, and how they compare to workflows on [YouTube (7 minutes)](https://youtu.be/0jg2g3sNvgw)
|
|
16
8
|
|
|
17
9
|
## Setting up agents
|
|
10
|
+
|
|
18
11
|
### Installation
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
1. Add the Mastra core package to your project:
|
|
21
14
|
|
|
22
|
-
|
|
15
|
+
**npm**:
|
|
23
16
|
|
|
24
|
-
```bash
|
|
25
|
-
npm install @mastra/core@latest
|
|
26
|
-
```
|
|
17
|
+
```bash
|
|
18
|
+
npm install @mastra/core@latest
|
|
19
|
+
```
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
**pnpm**:
|
|
29
22
|
|
|
30
|
-
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @mastra/core@latest
|
|
25
|
+
```
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
OPENAI_API_KEY=<your-api-key>
|
|
34
|
-
```
|
|
27
|
+
**Yarn**:
|
|
35
28
|
|
|
36
|
-
|
|
29
|
+
```bash
|
|
30
|
+
yarn add @mastra/core@latest
|
|
31
|
+
```
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
**Bun**:
|
|
39
34
|
|
|
40
|
-
|
|
35
|
+
```bash
|
|
36
|
+
bun add @mastra/core@latest
|
|
37
|
+
```
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
2. Mastra's model router auto-detects environment variables for your chosen provider. For OpenAI, set `OPENAI_API_KEY`:
|
|
43
40
|
|
|
44
|
-
```
|
|
45
|
-
|
|
41
|
+
```bash
|
|
42
|
+
OPENAI_API_KEY=<your-api-key>
|
|
43
|
+
```
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
45
|
+
> **Note:** Mastra supports more than 600 models. Choose from the [full list](https://mastra.ai/models).
|
|
46
|
+
|
|
47
|
+
3. Create an agent by instantiating the `Agent` class with system `instructions` and a `model`:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { Agent } from "@mastra/core/agent";
|
|
51
|
+
|
|
52
|
+
export const testAgent = new Agent({
|
|
53
|
+
id: "test-agent",
|
|
54
|
+
name: "Test Agent",
|
|
55
|
+
instructions: "You are a helpful assistant.",
|
|
56
|
+
model: "openai/gpt-5.1",
|
|
57
|
+
});
|
|
58
|
+
```
|
|
54
59
|
|
|
55
60
|
### Instruction formats
|
|
56
61
|
|
|
57
|
-
Instructions define the agent's behavior, personality, and capabilities.
|
|
58
|
-
They are system-level prompts that establish the agent's core identity and expertise.
|
|
62
|
+
Instructions define the agent's behavior, personality, and capabilities. They are system-level prompts that establish the agent's core identity and expertise.
|
|
59
63
|
|
|
60
64
|
Instructions can be provided in multiple formats for greater flexibility. The examples below illustrate the supported shapes:
|
|
61
65
|
|
|
@@ -94,23 +98,19 @@ instructions: {
|
|
|
94
98
|
}
|
|
95
99
|
```
|
|
96
100
|
|
|
97
|
-
> **
|
|
98
|
-
|
|
99
|
-
Visit [Agent reference](https://mastra.ai/reference/agents/agent) for more information.
|
|
101
|
+
> **Info:** Visit [Agent reference](https://mastra.ai/reference/agents/agent) for more information.
|
|
100
102
|
|
|
101
103
|
### Dynamic instructions
|
|
102
104
|
|
|
103
105
|
Instructions can be provided as an async function, allowing you to resolve prompts at runtime. This enables patterns like personalizing instructions based on user context, fetching prompts from external registry services, and running A/B tests with different variants.
|
|
104
106
|
|
|
105
|
-
> **
|
|
106
|
-
|
|
107
|
-
See [Dynamic instructions](https://mastra.ai/docs/server/request-context#dynamic-instructions) for examples.
|
|
107
|
+
> **Info:** See [Dynamic instructions](https://mastra.ai/docs/server/request-context) for examples.
|
|
108
108
|
|
|
109
109
|
### Registering an agent
|
|
110
110
|
|
|
111
111
|
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:
|
|
112
112
|
|
|
113
|
-
```typescript
|
|
113
|
+
```typescript
|
|
114
114
|
import { Mastra } from "@mastra/core";
|
|
115
115
|
import { testAgent } from "./agents/test-agent";
|
|
116
116
|
|
|
@@ -127,17 +127,13 @@ You can call agents from workflow steps, tools, the Mastra Client, or the comman
|
|
|
127
127
|
const testAgent = mastra.getAgent("testAgent");
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
`mastra.getAgent()` is preferred over a direct import, since it provides access to the Mastra instance configuration (logger, telemetry, storage, registered agents, and vector stores).
|
|
133
|
-
|
|
134
|
-
:
|
|
130
|
+
> **Info:** `mastra.getAgent()` is preferred over a direct import, since it provides access to the Mastra instance configuration (logger, telemetry, storage, registered agents, and vector stores).
|
|
135
131
|
|
|
136
132
|
## Generating responses
|
|
137
133
|
|
|
138
134
|
Agents can return results in two ways: generating the full output before returning it or streaming tokens in real time. Choose the approach that fits your use case: generate for short, internal responses or debugging, and stream to deliver pixels to end users as quickly as possible.
|
|
139
135
|
|
|
140
|
-
|
|
136
|
+
**Generate**:
|
|
141
137
|
|
|
142
138
|
Pass a single string for simple prompts, an array of strings when providing multiple pieces of context, or an array of message objects with `role` and `content`.
|
|
143
139
|
|
|
@@ -157,8 +153,7 @@ const response = await testAgent.generate([
|
|
|
157
153
|
console.log(response.text);
|
|
158
154
|
```
|
|
159
155
|
|
|
160
|
-
|
|
161
|
-
**stream:**
|
|
156
|
+
**Stream**:
|
|
162
157
|
|
|
163
158
|
Pass a single string for simple prompts, an array of strings when providing multiple pieces of context, or an array of message objects with `role` and `content`.
|
|
164
159
|
|
|
@@ -180,10 +175,9 @@ for await (const chunk of stream.textStream) {
|
|
|
180
175
|
}
|
|
181
176
|
```
|
|
182
177
|
|
|
183
|
-
|
|
178
|
+
### Completion using `onFinish()`
|
|
184
179
|
|
|
185
|
-
When streaming responses, the `onFinish()` callback runs after the LLM finishes generating its response and all tool executions are complete.
|
|
186
|
-
It provides the final `text`, execution `steps`, `finishReason`, token `usage` statistics, and other metadata useful for monitoring or logging.
|
|
180
|
+
When streaming responses, the `onFinish()` callback runs after the LLM finishes generating its response and all tool executions are complete. It provides the final `text`, execution `steps`, `finishReason`, token `usage` statistics, and other metadata useful for monitoring or logging.
|
|
187
181
|
|
|
188
182
|
```typescript
|
|
189
183
|
const stream = await testAgent.stream("Help me organize my day", {
|
|
@@ -197,19 +191,13 @@ for await (const chunk of stream.textStream) {
|
|
|
197
191
|
}
|
|
198
192
|
```
|
|
199
193
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
> **Note:**
|
|
203
|
-
|
|
204
|
-
Visit [.generate()](https://mastra.ai/reference/agents/generate) or [.stream()](https://mastra.ai/reference/streaming/agents/stream) for more information.
|
|
194
|
+
> **Info:** Visit [.generate()](https://mastra.ai/reference/agents/generate) or [.stream()](https://mastra.ai/reference/streaming/agents/stream) for more information.
|
|
205
195
|
|
|
206
196
|
## Structured output
|
|
207
197
|
|
|
208
198
|
Agents can return structured, type-safe data using Zod or JSON Schema. The parsed result is available on `response.object`.
|
|
209
199
|
|
|
210
|
-
> **
|
|
211
|
-
|
|
212
|
-
Visit [Structured Output](https://mastra.ai/docs/agents/structured-output) for more information.
|
|
200
|
+
> **Info:** Visit [Structured Output](https://mastra.ai/docs/agents/structured-output) for more information.
|
|
213
201
|
|
|
214
202
|
## Analyzing images
|
|
215
203
|
|
|
@@ -266,7 +254,7 @@ const response = await testAgent.generate("Help me organize my day", {
|
|
|
266
254
|
|
|
267
255
|
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.
|
|
268
256
|
|
|
269
|
-
```typescript
|
|
257
|
+
```typescript
|
|
270
258
|
export const testAgent = new Agent({
|
|
271
259
|
id: "test-agent",
|
|
272
260
|
name: "Test Agent",
|
|
@@ -274,15 +262,13 @@ export const testAgent = new Agent({
|
|
|
274
262
|
});
|
|
275
263
|
```
|
|
276
264
|
|
|
277
|
-
> **
|
|
278
|
-
|
|
279
|
-
Visit [Using Tools](https://mastra.ai/docs/agents/using-tools) for more information.
|
|
265
|
+
> **Info:** Visit [Using Tools](https://mastra.ai/docs/agents/using-tools) for more information.
|
|
280
266
|
|
|
281
267
|
## Using `RequestContext`
|
|
282
268
|
|
|
283
269
|
Use `RequestContext` to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
|
|
284
270
|
|
|
285
|
-
```typescript
|
|
271
|
+
```typescript
|
|
286
272
|
export type UserTier = {
|
|
287
273
|
"user-tier": "enterprise" | "pro";
|
|
288
274
|
};
|
|
@@ -300,13 +286,9 @@ export const testAgent = new Agent({
|
|
|
300
286
|
});
|
|
301
287
|
```
|
|
302
288
|
|
|
303
|
-
> **
|
|
304
|
-
|
|
305
|
-
See [Request Context](https://mastra.ai/docs/server/request-context) for more information.
|
|
306
|
-
|
|
307
|
-
> **Note:**
|
|
289
|
+
> **Info:** See [Request Context](https://mastra.ai/docs/server/request-context) for more information.
|
|
308
290
|
|
|
309
|
-
For type-safe request context schema validation, see [Schema Validation](https://mastra.ai/docs/server/request-context
|
|
291
|
+
> **Tip:** For type-safe request context schema validation, see [Schema Validation](https://mastra.ai/docs/server/request-context).
|
|
310
292
|
|
|
311
293
|
## Testing with Studio
|
|
312
294
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
> Learn how to use input and output processors to transform, validate, and control messages in Mastra agents.
|
|
2
|
-
|
|
3
1
|
# Processors
|
|
4
2
|
|
|
5
3
|
Processors transform, validate, or control messages as they pass through an agent. They run at specific points in the agent's execution pipeline, allowing you to modify inputs before they reach the language model or outputs before they're returned to users.
|
|
@@ -32,7 +30,7 @@ Mastra includes several processors for common use cases. You can also create cus
|
|
|
32
30
|
|
|
33
31
|
Import and instantiate the processor, then pass it to the agent's `inputProcessors` or `outputProcessors` array:
|
|
34
32
|
|
|
35
|
-
```typescript
|
|
33
|
+
```typescript
|
|
36
34
|
import { Agent } from "@mastra/core/agent";
|
|
37
35
|
import { ModerationProcessor } from "@mastra/core/processors";
|
|
38
36
|
|
|
@@ -70,18 +68,22 @@ For output processors, the order determines the sequence of transformations appl
|
|
|
70
68
|
When memory is enabled on an agent, memory processors are automatically added to the pipeline:
|
|
71
69
|
|
|
72
70
|
**Input processors:**
|
|
73
|
-
|
|
71
|
+
|
|
72
|
+
```text
|
|
74
73
|
[Memory Processors] → [Your inputProcessors]
|
|
75
74
|
```
|
|
75
|
+
|
|
76
76
|
Memory loads message history first, then your processors run.
|
|
77
77
|
|
|
78
78
|
**Output processors:**
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
```text
|
|
80
81
|
[Your outputProcessors] → [Memory Processors]
|
|
81
82
|
```
|
|
83
|
+
|
|
82
84
|
Your processors run first, then memory persists messages.
|
|
83
85
|
|
|
84
|
-
This ordering ensures that if your output guardrail calls `abort()`, memory processors are skipped and no messages are saved. See [Memory Processors](https://mastra.ai/docs/memory/memory-processors
|
|
86
|
+
This ordering ensures that if your output guardrail calls `abort()`, memory processors are skipped and no messages are saved. See [Memory Processors](https://mastra.ai/docs/memory/memory-processors) for details.
|
|
85
87
|
|
|
86
88
|
## Creating custom processors
|
|
87
89
|
|
|
@@ -89,7 +91,7 @@ Custom processors implement the `Processor` interface:
|
|
|
89
91
|
|
|
90
92
|
### Custom input processor
|
|
91
93
|
|
|
92
|
-
```typescript
|
|
94
|
+
```typescript
|
|
93
95
|
import type {
|
|
94
96
|
Processor,
|
|
95
97
|
MastraDBMessage,
|
|
@@ -121,6 +123,7 @@ export class CustomInputProcessor implements Processor {
|
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
The `processInput` method receives:
|
|
126
|
+
|
|
124
127
|
- `messages`: User and assistant messages (not system messages)
|
|
125
128
|
- `systemMessages`: All system messages (agent instructions, memory context, user-provided system prompts)
|
|
126
129
|
- `messageList`: The full MessageList instance for advanced use cases
|
|
@@ -128,6 +131,7 @@ The `processInput` method receives:
|
|
|
128
131
|
- `requestContext`: Execution metadata like `threadId` and `resourceId`
|
|
129
132
|
|
|
130
133
|
The method can return:
|
|
134
|
+
|
|
131
135
|
- `MastraDBMessage[]` — Transformed messages array (backward compatible)
|
|
132
136
|
- `{ messages: MastraDBMessage[]; systemMessages: CoreMessage[] }` — Both messages and modified system messages
|
|
133
137
|
|
|
@@ -137,7 +141,7 @@ The framework handles both return formats, so modifying system messages is optio
|
|
|
137
141
|
|
|
138
142
|
To modify system messages (e.g., trim verbose prompts for smaller models), return an object with both `messages` and `systemMessages`:
|
|
139
143
|
|
|
140
|
-
```typescript
|
|
144
|
+
```typescript
|
|
141
145
|
import type { Processor, CoreMessage, MastraDBMessage } from "@mastra/core";
|
|
142
146
|
|
|
143
147
|
export class SystemTrimmer implements Processor {
|
|
@@ -162,6 +166,7 @@ export class SystemTrimmer implements Processor {
|
|
|
162
166
|
```
|
|
163
167
|
|
|
164
168
|
This is useful for:
|
|
169
|
+
|
|
165
170
|
- Trimming verbose system prompts for models with smaller context windows
|
|
166
171
|
- Filtering or modifying semantic recall content to prevent "prompt too long" errors
|
|
167
172
|
- Dynamically adjusting system instructions based on the conversation
|
|
@@ -170,7 +175,7 @@ This is useful for:
|
|
|
170
175
|
|
|
171
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.
|
|
172
177
|
|
|
173
|
-
```typescript
|
|
178
|
+
```typescript
|
|
174
179
|
import type { Processor, ProcessInputStepArgs, ProcessInputStepResult } from "@mastra/core";
|
|
175
180
|
|
|
176
181
|
export class DynamicModelProcessor implements Processor {
|
|
@@ -199,6 +204,7 @@ export class DynamicModelProcessor implements Processor {
|
|
|
199
204
|
```
|
|
200
205
|
|
|
201
206
|
The `processInputStep` method receives:
|
|
207
|
+
|
|
202
208
|
- `stepNumber`: Current step in the agentic loop (0-indexed)
|
|
203
209
|
- `steps`: Results from previous steps
|
|
204
210
|
- `messages`: Current messages snapshot (read-only)
|
|
@@ -213,6 +219,7 @@ The `processInputStep` method receives:
|
|
|
213
219
|
- `structuredOutput`: Structured output configuration
|
|
214
220
|
|
|
215
221
|
The method can return any combination of:
|
|
222
|
+
|
|
216
223
|
- `model`: Change the model for this step
|
|
217
224
|
- `tools`: Replace or add tools (use spread to merge: `{ tools: { ...tools, newTool } }`)
|
|
218
225
|
- `toolChoice`: Change tool selection behavior
|
|
@@ -227,7 +234,7 @@ The method can return any combination of:
|
|
|
227
234
|
|
|
228
235
|
When using `maxSteps` to limit agent execution, the agent may return an empty response if it attempts a tool call on the final step. Use `processInputStep` to force a text response on the last step:
|
|
229
236
|
|
|
230
|
-
```typescript
|
|
237
|
+
```typescript
|
|
231
238
|
import { Processor, ProcessInputStepArgs, ProcessInputStepResult } from "@mastra/core/processors";
|
|
232
239
|
|
|
233
240
|
export class EnsureFinalResponseProcessor implements Processor {
|
|
@@ -262,7 +269,7 @@ export class EnsureFinalResponseProcessor implements Processor {
|
|
|
262
269
|
|
|
263
270
|
Use it with your agent:
|
|
264
271
|
|
|
265
|
-
```typescript
|
|
272
|
+
```typescript
|
|
266
273
|
import { Agent } from "@mastra/core/agent";
|
|
267
274
|
import { EnsureFinalResponseProcessor } from "../processors/ensure-final-response";
|
|
268
275
|
|
|
@@ -301,7 +308,7 @@ await agent.generate("Complex task", {
|
|
|
301
308
|
|
|
302
309
|
### Custom output processor
|
|
303
310
|
|
|
304
|
-
```typescript
|
|
311
|
+
```typescript
|
|
305
312
|
import type {
|
|
306
313
|
Processor,
|
|
307
314
|
MastraDBMessage,
|
|
@@ -339,7 +346,7 @@ export class CustomOutputProcessor implements Processor {
|
|
|
339
346
|
|
|
340
347
|
You can add custom metadata to messages in `processOutputResult`. This metadata is accessible via the response object:
|
|
341
348
|
|
|
342
|
-
```typescript
|
|
349
|
+
```typescript
|
|
343
350
|
import type { Processor, MastraDBMessage } from "@mastra/core";
|
|
344
351
|
|
|
345
352
|
export class MetadataProcessor implements Processor {
|
|
@@ -403,14 +410,13 @@ console.log(response.uiMessages);
|
|
|
403
410
|
|
|
404
411
|
Mastra provides utility processors for common tasks:
|
|
405
412
|
|
|
406
|
-
**For security and validation processors**, see the [Guardrails](https://mastra.ai/docs/agents/guardrails) page for input/output guardrails and moderation processors.
|
|
407
|
-
**For memory-specific processors**, see the [Memory Processors](https://mastra.ai/docs/memory/memory-processors) page for processors that handle message history, semantic recall, and working memory.
|
|
413
|
+
**For security and validation processors**, see the [Guardrails](https://mastra.ai/docs/agents/guardrails) page for input/output guardrails and moderation processors. **For memory-specific processors**, see the [Memory Processors](https://mastra.ai/docs/memory/memory-processors) page for processors that handle message history, semantic recall, and working memory.
|
|
408
414
|
|
|
409
415
|
### TokenLimiter
|
|
410
416
|
|
|
411
417
|
Prevents context window overflow by removing older messages when the total token count exceeds a specified limit.
|
|
412
418
|
|
|
413
|
-
```typescript
|
|
419
|
+
```typescript
|
|
414
420
|
import { Agent } from "@mastra/core/agent";
|
|
415
421
|
import { TokenLimiter } from "@mastra/core/processors";
|
|
416
422
|
|
|
@@ -426,7 +432,7 @@ const agent = new Agent({
|
|
|
426
432
|
|
|
427
433
|
The `TokenLimiter` uses the `o200k_base` encoding by default (suitable for GPT-4o). You can specify other encodings for different models:
|
|
428
434
|
|
|
429
|
-
```typescript
|
|
435
|
+
```typescript
|
|
430
436
|
import cl100k_base from "js-tiktoken/ranks/cl100k_base";
|
|
431
437
|
|
|
432
438
|
const agent = new Agent({
|
|
@@ -444,7 +450,7 @@ const agent = new Agent({
|
|
|
444
450
|
|
|
445
451
|
Removes tool calls from messages sent to the LLM, saving tokens by excluding potentially verbose tool interactions.
|
|
446
452
|
|
|
447
|
-
```typescript
|
|
453
|
+
```typescript
|
|
448
454
|
import { Agent } from "@mastra/core/agent";
|
|
449
455
|
import { ToolCallFilter, TokenLimiter } from "@mastra/core/processors";
|
|
450
456
|
|
|
@@ -464,15 +470,13 @@ const agent = new Agent({
|
|
|
464
470
|
});
|
|
465
471
|
```
|
|
466
472
|
|
|
467
|
-
> **Note:**
|
|
468
|
-
|
|
469
|
-
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](https://mastra.ai/docs/memory/memory-processors#manual-control-and-deduplication) for details.
|
|
473
|
+
> **Note:** 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](https://mastra.ai/docs/memory/memory-processors) for details.
|
|
470
474
|
|
|
471
475
|
### ToolSearchProcessor
|
|
472
476
|
|
|
473
477
|
Enables dynamic tool discovery and loading for agents with large tool libraries. Instead of providing all tools upfront, the agent searches for tools by keyword and loads them on demand, reducing context token usage.
|
|
474
478
|
|
|
475
|
-
```typescript
|
|
479
|
+
```typescript
|
|
476
480
|
import { Agent } from "@mastra/core/agent";
|
|
477
481
|
import { ToolSearchProcessor } from "@mastra/core/processors";
|
|
478
482
|
|
|
@@ -498,7 +502,7 @@ The processor gives the agent two meta-tools: `search_tools` to find tools by ke
|
|
|
498
502
|
|
|
499
503
|
You can use Mastra workflows as processors to create complex processing pipelines with parallel execution, conditional branching, and error handling:
|
|
500
504
|
|
|
501
|
-
```typescript
|
|
505
|
+
```typescript
|
|
502
506
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
503
507
|
import { ProcessorStepSchema } from "@mastra/core/processors";
|
|
504
508
|
import { Agent } from "@mastra/core/agent";
|
|
@@ -531,7 +535,7 @@ When an agent is registered with Mastra, processor workflows are automatically r
|
|
|
531
535
|
|
|
532
536
|
Processors can request that the LLM retry its response with feedback. This is useful for implementing quality checks, output validation, or iterative refinement:
|
|
533
537
|
|
|
534
|
-
```typescript
|
|
538
|
+
```typescript
|
|
535
539
|
import type { Processor } from "@mastra/core";
|
|
536
540
|
|
|
537
541
|
export class QualityChecker implements Processor {
|
|
@@ -562,6 +566,7 @@ const agent = new Agent({
|
|
|
562
566
|
```
|
|
563
567
|
|
|
564
568
|
The retry mechanism:
|
|
569
|
+
|
|
565
570
|
- Only works in `processOutputStep` and `processInputStep` methods
|
|
566
571
|
- Replays the step with the abort reason added as context for the LLM
|
|
567
572
|
- Tracks retry count via the `retryCount` parameter
|
package/dist/docs/{agents/04-structured-output.md → references/docs-agents-structured-output.md}
RENAMED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
> Learn how to generate structured data from agents using schemas and validation.
|
|
2
|
-
|
|
3
1
|
# Structured Output
|
|
4
2
|
|
|
5
3
|
Structured output lets an agent return an object that matches the shape defined by a schema instead of returning text. The schema tells the model what fields to produce, and the model ensures the final result fits that shape.
|
|
@@ -12,7 +10,7 @@ Use structured output when you need an agent to return a data object rather than
|
|
|
12
10
|
|
|
13
11
|
Agents can return structured data by defining the expected output with either [Zod](https://zod.dev/) or [JSON Schema](https://json-schema.org/). Zod is recommended because it provides TypeScript type inference and runtime validation, while JSON Schema is useful when you need a language agnostic format.
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
**Zod**:
|
|
16
14
|
|
|
17
15
|
Define the `output` shape using [Zod](https://zod.dev/):
|
|
18
16
|
|
|
@@ -33,8 +31,7 @@ const response = await testAgent.generate("Help me plan my day.", {
|
|
|
33
31
|
console.log(response.object);
|
|
34
32
|
```
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
**json-schema:**
|
|
34
|
+
**JSON Schema**:
|
|
38
35
|
|
|
39
36
|
You can also use JSON Schema to define your output structure:
|
|
40
37
|
|
|
@@ -61,11 +58,7 @@ const response = await testAgent.generate("Help me plan my day.", {
|
|
|
61
58
|
console.log(response.object);
|
|
62
59
|
```
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
> **Note:**
|
|
67
|
-
|
|
68
|
-
Visit [.generate()](https://mastra.ai/reference/agents/generate) for a full list of configuration options.
|
|
61
|
+
> **Info:** Visit [.generate()](https://mastra.ai/reference/agents/generate) for a full list of configuration options.
|
|
69
62
|
|
|
70
63
|
### Example output
|
|
71
64
|
|
|
@@ -193,18 +186,16 @@ const response = await testAgent.generate("Help me plan my day.", {
|
|
|
193
186
|
console.log(response.object);
|
|
194
187
|
```
|
|
195
188
|
|
|
196
|
-
> **Gemini 2.5 with tools
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
});
|
|
207
|
-
```
|
|
189
|
+
> **Gemini 2.5 with tools:** Gemini 2.5 models do not support combining `response_format` (structured output) with function calling (tools) in the same API call. If your agent has tools and you're using `structuredOutput` with a Gemini 2.5 model, you must set `jsonPromptInjection: true` to avoid the error `Function calling with a response mime type: 'application/json' is unsupported`.
|
|
190
|
+
>
|
|
191
|
+
> ```typescript
|
|
192
|
+
> const response = await agentWithTools.generate("Your prompt", {
|
|
193
|
+
> structuredOutput: {
|
|
194
|
+
> schema: yourSchema,
|
|
195
|
+
> jsonPromptInjection: true, // Required for Gemini 2.5 when tools are present
|
|
196
|
+
> },
|
|
197
|
+
> });
|
|
198
|
+
> ```
|
|
208
199
|
|
|
209
200
|
### Using a separate structuring model
|
|
210
201
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
> Learn how to create tools and add them to agents to extend capabilities beyond text generation.
|
|
2
|
-
|
|
3
1
|
# Using Tools
|
|
4
2
|
|
|
5
3
|
Agents use tools to call APIs, query databases, or run custom functions from your codebase. Tools give agents capabilities beyond language generation by providing structured access to data and performing clearly defined operations. You can also load tools from remote [MCP servers](https://mastra.ai/docs/mcp/overview) to expand an agent's capabilities.
|
|
@@ -14,7 +12,7 @@ When creating tools, keep descriptions simple and focused on what the tool does,
|
|
|
14
12
|
|
|
15
13
|
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.
|
|
16
14
|
|
|
17
|
-
```typescript
|
|
15
|
+
```typescript
|
|
18
16
|
import { createTool } from "@mastra/core/tools";
|
|
19
17
|
import { z } from "zod";
|
|
20
18
|
|
|
@@ -44,7 +42,7 @@ To make a tool available to an agent, add it to `tools`. Mentioning available to
|
|
|
44
42
|
|
|
45
43
|
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.
|
|
46
44
|
|
|
47
|
-
```typescript
|
|
45
|
+
```typescript
|
|
48
46
|
import { Agent } from "@mastra/core/agent";
|
|
49
47
|
import { weatherTool } from "../tools/weather-tool";
|
|
50
48
|
|
|
@@ -89,10 +87,10 @@ This lets you specify how tools are identified in the stream. If you want the `t
|
|
|
89
87
|
|
|
90
88
|
Sub-agents and workflows follow the same pattern. They are converted to tools with a prefix followed by your object key:
|
|
91
89
|
|
|
92
|
-
| Property
|
|
93
|
-
|
|
94
|
-
| `agents`
|
|
95
|
-
| `workflows` | `workflow-` | `research`
|
|
90
|
+
| Property | Prefix | Example key | `toolName` |
|
|
91
|
+
| ----------- | ----------- | ----------- | ------------------- |
|
|
92
|
+
| `agents` | `agent-` | `weather` | `agent-weather` |
|
|
93
|
+
| `workflows` | `workflow-` | `research` | `workflow-research` |
|
|
96
94
|
|
|
97
95
|
```typescript
|
|
98
96
|
const orchestrator = new Agent({
|
|
@@ -107,6 +105,7 @@ const orchestrator = new Agent({
|
|
|
107
105
|
```
|
|
108
106
|
|
|
109
107
|
Note that for sub-agents, you'll see two different identifiers in stream responses:
|
|
108
|
+
|
|
110
109
|
- `toolName: "agent-weather"` in tool call events — the generated tool wrapper name
|
|
111
110
|
- `id: "weather-agent"` in `data-tool-agent` chunks — the sub-agent's actual `id` property
|
|
112
111
|
|
|
@@ -114,7 +113,7 @@ Note that for sub-agents, you'll see two different identifiers in stream respons
|
|
|
114
113
|
|
|
115
114
|
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.
|
|
116
115
|
|
|
117
|
-
```typescript
|
|
116
|
+
```typescript
|
|
118
117
|
import { mastra } from "./mastra";
|
|
119
118
|
|
|
120
119
|
const agent = mastra.getAgent("weatherAgent");
|
|
@@ -126,7 +125,7 @@ const result = await agent.generate("What's the weather in London?");
|
|
|
126
125
|
|
|
127
126
|
When multiple tools are available, the agent may choose to use one, several, or none, depending on what's needed to answer the query.
|
|
128
127
|
|
|
129
|
-
```typescript
|
|
128
|
+
```typescript
|
|
130
129
|
import { weatherTool } from "../tools/weather-tool";
|
|
131
130
|
import { activitiesTool } from "../tools/activities-tool";
|
|
132
131
|
|
|
@@ -141,7 +140,7 @@ export const weatherAgent = new Agent({
|
|
|
141
140
|
|
|
142
141
|
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`.
|
|
143
142
|
|
|
144
|
-
```typescript
|
|
143
|
+
```typescript
|
|
145
144
|
import { Agent } from "@mastra/core/agent";
|
|
146
145
|
import { researchWorkflow } from "../workflows/research-workflow";
|
|
147
146
|
|
|
@@ -163,7 +162,7 @@ export const researchAgent = new Agent({
|
|
|
163
162
|
|
|
164
163
|
The workflow should include a `description` to help the agent understand when to use it:
|
|
165
164
|
|
|
166
|
-
```typescript
|
|
165
|
+
```typescript
|
|
167
166
|
import { createWorkflow } from "@mastra/core/workflows";
|
|
168
167
|
import { z } from "zod";
|
|
169
168
|
|
|
@@ -194,7 +193,7 @@ When the agent calls the workflow tool, it receives a response containing the wo
|
|
|
194
193
|
|
|
195
194
|
## Tools with structured output
|
|
196
195
|
|
|
197
|
-
When using tools with [structured output](https://mastra.ai/docs/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](https://mastra.ai/docs/agents/structured-output
|
|
196
|
+
When using tools with [structured output](https://mastra.ai/docs/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](https://mastra.ai/docs/agents/structured-output) for model compatibility information and workarounds.
|
|
198
197
|
|
|
199
198
|
## Related
|
|
200
199
|
|
|
@@ -281,11 +281,9 @@ A custom scorer in Mastra uses `createScorer` with four core components:
|
|
|
281
281
|
|
|
282
282
|
Together, these components allow you to define custom evaluation logic using LLMs as judges.
|
|
283
283
|
|
|
284
|
-
> **
|
|
284
|
+
> **Info:** Visit [createScorer](https://mastra.ai/reference/evals/create-scorer) for the full API and configuration options.
|
|
285
285
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
```typescript title="src/mastra/scorers/gluten-checker.ts"
|
|
286
|
+
```typescript
|
|
289
287
|
import { createScorer } from "@mastra/core/evals";
|
|
290
288
|
import { z } from "zod";
|
|
291
289
|
|
|
@@ -439,7 +437,7 @@ The reason generation step creates explanations that help users understand why a
|
|
|
439
437
|
|
|
440
438
|
## High gluten-free example
|
|
441
439
|
|
|
442
|
-
```typescript
|
|
440
|
+
```typescript
|
|
443
441
|
const result = await glutenCheckerScorer.run({
|
|
444
442
|
input: [{ role: 'user', content: 'Mix rice, beans, and vegetables' }],
|
|
445
443
|
output: { text: 'Mix rice, beans, and vegetables' },
|
|
@@ -465,7 +463,7 @@ console.log('Reason:', result.reason);
|
|
|
465
463
|
|
|
466
464
|
## Partial gluten example
|
|
467
465
|
|
|
468
|
-
```typescript
|
|
466
|
+
```typescript
|
|
469
467
|
const result = await glutenCheckerScorer.run({
|
|
470
468
|
input: [{ role: "user", content: "Mix flour and water to make dough" }],
|
|
471
469
|
output: { text: "Mix flour and water to make dough" },
|
|
@@ -491,7 +489,7 @@ console.log("Reason:", result.reason);
|
|
|
491
489
|
|
|
492
490
|
## Low gluten-free example
|
|
493
491
|
|
|
494
|
-
```typescript
|
|
492
|
+
```typescript
|
|
495
493
|
const result = await glutenCheckerScorer.run({
|
|
496
494
|
input: [{ role: "user", content: "Add soy sauce and noodles" }],
|
|
497
495
|
output: { text: "Add soy sauce and noodles" },
|