@mastra/core 1.6.0 → 1.7.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 +236 -0
- package/dist/agent/agent.d.ts +6 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +8 -8
- package/dist/agent/index.js +1 -1
- package/dist/{chunk-VJWRJWSC.cjs → chunk-2X66GWF5.cjs} +94 -16
- package/dist/chunk-2X66GWF5.cjs.map +1 -0
- package/dist/{chunk-YM6245EM.js → chunk-6OXW5E2O.js} +3 -3
- package/dist/{chunk-YM6245EM.js.map → chunk-6OXW5E2O.js.map} +1 -1
- package/dist/{chunk-XWZAKKFT.cjs → chunk-6QBN6MZY.cjs} +14 -14
- package/dist/{chunk-XWZAKKFT.cjs.map → chunk-6QBN6MZY.cjs.map} +1 -1
- package/dist/{chunk-AYHSPIT6.cjs → chunk-7UAJ6LMR.cjs} +820 -259
- package/dist/chunk-7UAJ6LMR.cjs.map +1 -0
- package/dist/{chunk-RZNHRIM7.cjs → chunk-A72NTLFT.cjs} +5 -5
- package/dist/{chunk-RZNHRIM7.cjs.map → chunk-A72NTLFT.cjs.map} +1 -1
- package/dist/{chunk-EEU5NHHU.js → chunk-DFCRXDVK.js} +3 -3
- package/dist/{chunk-EEU5NHHU.js.map → chunk-DFCRXDVK.js.map} +1 -1
- package/dist/{chunk-5K45E5VE.js → chunk-GPJGPARM.js} +3 -2
- package/dist/chunk-GPJGPARM.js.map +1 -0
- package/dist/{chunk-LNKS4TJ6.cjs → chunk-HB6T4554.cjs} +8 -7
- package/dist/chunk-HB6T4554.cjs.map +1 -0
- package/dist/{chunk-DGS2KGDI.js → chunk-KUXNBWN7.js} +6 -5
- package/dist/chunk-KUXNBWN7.js.map +1 -0
- package/dist/{chunk-IHDE4CJV.js → chunk-QSHV7GPT.js} +89 -12
- package/dist/chunk-QSHV7GPT.js.map +1 -0
- package/dist/{chunk-3U3XFMGJ.cjs → chunk-QTAS3HND.cjs} +13 -8
- package/dist/chunk-QTAS3HND.cjs.map +1 -0
- package/dist/{chunk-RHKNKJNM.js → chunk-QWTB53GS.js} +4 -4
- package/dist/{chunk-RHKNKJNM.js.map → chunk-QWTB53GS.js.map} +1 -1
- package/dist/{chunk-4WG5K4CK.js → chunk-R4N65TLG.js} +7 -7
- package/dist/{chunk-4WG5K4CK.js.map → chunk-R4N65TLG.js.map} +1 -1
- package/dist/{chunk-5VQPSWPG.cjs → chunk-RABITNTG.cjs} +48 -48
- package/dist/{chunk-5VQPSWPG.cjs.map → chunk-RABITNTG.cjs.map} +1 -1
- package/dist/{chunk-TVPANHLE.cjs → chunk-SBOHDNIZ.cjs} +3 -2
- package/dist/chunk-SBOHDNIZ.cjs.map +1 -0
- package/dist/{chunk-MWGGSA5Q.js → chunk-T6GAM3SQ.js} +10 -5
- package/dist/chunk-T6GAM3SQ.js.map +1 -0
- package/dist/{chunk-TL2TTA4X.cjs → chunk-YQG7NBPR.cjs} +9 -9
- package/dist/{chunk-TL2TTA4X.cjs.map → chunk-YQG7NBPR.cjs.map} +1 -1
- package/dist/{chunk-XB3DA67Q.js → chunk-ZSBM2SVU.js} +818 -259
- package/dist/chunk-ZSBM2SVU.js.map +1 -0
- package/dist/datasets/experiment/scorer.d.ts.map +1 -1
- package/dist/datasets/index.cjs +17 -17
- package/dist/datasets/index.js +2 -2
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +7 -6
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +4 -3
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/harness/harness.d.ts +21 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/index.cjs +422 -5
- package/dist/harness/index.cjs.map +1 -1
- package/dist/harness/index.d.ts +2 -1
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +418 -3
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/types.d.ts +151 -0
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/mastra/hooks.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/processor-provider/index.cjs +10 -10
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +45 -41
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/index.d.ts +1 -0
- package/dist/processors/processors/index.d.ts.map +1 -1
- package/dist/processors/processors/workspace-instructions.d.ts +50 -0
- package/dist/processors/processors/workspace-instructions.d.ts.map +1 -0
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/constants.cjs +56 -56
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/index.cjs +160 -160
- package/dist/storage/index.js +2 -2
- package/dist/storage/types.d.ts +2 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +8 -8
- package/dist/stream/index.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +7 -7
- package/dist/vector/index.js +1 -1
- 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/dist/workspace/constants/index.d.ts +2 -0
- package/dist/workspace/constants/index.d.ts.map +1 -1
- package/dist/workspace/errors.d.ts +1 -1
- package/dist/workspace/errors.d.ts.map +1 -1
- package/dist/workspace/filesystem/composite-filesystem.d.ts +4 -1
- package/dist/workspace/filesystem/composite-filesystem.d.ts.map +1 -1
- package/dist/workspace/filesystem/file-write-lock.d.ts +35 -0
- package/dist/workspace/filesystem/file-write-lock.d.ts.map +1 -0
- package/dist/workspace/filesystem/filesystem.d.ts +5 -1
- package/dist/workspace/filesystem/filesystem.d.ts.map +1 -1
- package/dist/workspace/filesystem/index.d.ts +1 -0
- package/dist/workspace/filesystem/index.d.ts.map +1 -1
- package/dist/workspace/filesystem/local-filesystem.d.ts +17 -1
- package/dist/workspace/filesystem/local-filesystem.d.ts.map +1 -1
- package/dist/workspace/index.cjs +72 -64
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/lifecycle.d.ts +1 -9
- package/dist/workspace/lifecycle.d.ts.map +1 -1
- package/dist/workspace/sandbox/index.d.ts +2 -0
- package/dist/workspace/sandbox/index.d.ts.map +1 -1
- package/dist/workspace/sandbox/local-process-manager.d.ts +18 -0
- package/dist/workspace/sandbox/local-process-manager.d.ts.map +1 -0
- package/dist/workspace/sandbox/local-sandbox.d.ts +49 -35
- package/dist/workspace/sandbox/local-sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/mastra-sandbox.d.ts +45 -11
- package/dist/workspace/sandbox/mastra-sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/native-sandbox/bubblewrap.d.ts +2 -3
- package/dist/workspace/sandbox/native-sandbox/bubblewrap.d.ts.map +1 -1
- package/dist/workspace/sandbox/native-sandbox/seatbelt.d.ts +2 -3
- package/dist/workspace/sandbox/native-sandbox/seatbelt.d.ts.map +1 -1
- package/dist/workspace/sandbox/native-sandbox/wrapper.d.ts +4 -5
- package/dist/workspace/sandbox/native-sandbox/wrapper.d.ts.map +1 -1
- package/dist/workspace/sandbox/process-manager/index.d.ts +4 -0
- package/dist/workspace/sandbox/process-manager/index.d.ts.map +1 -0
- package/dist/workspace/sandbox/process-manager/process-handle.d.ts +107 -0
- package/dist/workspace/sandbox/process-manager/process-handle.d.ts.map +1 -0
- package/dist/workspace/sandbox/process-manager/process-manager.d.ts +59 -0
- package/dist/workspace/sandbox/process-manager/process-manager.d.ts.map +1 -0
- package/dist/workspace/sandbox/process-manager/types.d.ts +24 -0
- package/dist/workspace/sandbox/process-manager/types.d.ts.map +1 -0
- package/dist/workspace/sandbox/sandbox.d.ts +38 -2
- package/dist/workspace/sandbox/sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/types.d.ts +9 -2
- package/dist/workspace/sandbox/types.d.ts.map +1 -1
- package/dist/workspace/sandbox/utils.d.ts +7 -0
- package/dist/workspace/sandbox/utils.d.ts.map +1 -0
- package/dist/workspace/tools/execute-command.d.ts +53 -2
- package/dist/workspace/tools/execute-command.d.ts.map +1 -1
- package/dist/workspace/tools/get-process-output.d.ts +6 -0
- package/dist/workspace/tools/get-process-output.d.ts.map +1 -0
- package/dist/workspace/tools/index.d.ts +4 -1
- package/dist/workspace/tools/index.d.ts.map +1 -1
- package/dist/workspace/tools/kill-process.d.ts +4 -0
- package/dist/workspace/tools/kill-process.d.ts.map +1 -0
- package/dist/workspace/tools/output-helpers.d.ts +21 -0
- package/dist/workspace/tools/output-helpers.d.ts.map +1 -0
- package/dist/workspace/tools/tools.d.ts.map +1 -1
- package/dist/workspace/types.d.ts +31 -0
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/utils.d.ts +11 -0
- package/dist/workspace/utils.d.ts.map +1 -0
- package/dist/workspace/workspace.d.ts +36 -0
- package/dist/workspace/workspace.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-3U3XFMGJ.cjs.map +0 -1
- package/dist/chunk-5K45E5VE.js.map +0 -1
- package/dist/chunk-AYHSPIT6.cjs.map +0 -1
- package/dist/chunk-DGS2KGDI.js.map +0 -1
- package/dist/chunk-IHDE4CJV.js.map +0 -1
- package/dist/chunk-LNKS4TJ6.cjs.map +0 -1
- package/dist/chunk-MWGGSA5Q.js.map +0 -1
- package/dist/chunk-TVPANHLE.cjs.map +0 -1
- package/dist/chunk-VJWRJWSC.cjs.map +0 -1
- package/dist/chunk-XB3DA67Q.js.map +0 -1
- package/dist/docs/SKILL.md +0 -301
- package/dist/docs/assets/SOURCE_MAP.json +0 -1413
- package/dist/docs/references/docs-agents-adding-voice.md +0 -353
- package/dist/docs/references/docs-agents-agent-approval.md +0 -377
- package/dist/docs/references/docs-agents-agent-memory.md +0 -212
- package/dist/docs/references/docs-agents-guardrails.md +0 -382
- package/dist/docs/references/docs-agents-network-approval.md +0 -275
- package/dist/docs/references/docs-agents-networks.md +0 -290
- package/dist/docs/references/docs-agents-overview.md +0 -309
- package/dist/docs/references/docs-agents-processors.md +0 -632
- package/dist/docs/references/docs-agents-structured-output.md +0 -271
- package/dist/docs/references/docs-agents-using-tools.md +0 -214
- package/dist/docs/references/docs-evals-custom-scorers.md +0 -519
- package/dist/docs/references/docs-evals-overview.md +0 -146
- package/dist/docs/references/docs-evals-running-in-ci.md +0 -106
- package/dist/docs/references/docs-mcp-overview.md +0 -370
- package/dist/docs/references/docs-mcp-publishing-mcp-server.md +0 -95
- package/dist/docs/references/docs-memory-memory-processors.md +0 -316
- package/dist/docs/references/docs-memory-observational-memory.md +0 -246
- package/dist/docs/references/docs-memory-overview.md +0 -45
- package/dist/docs/references/docs-memory-semantic-recall.md +0 -272
- package/dist/docs/references/docs-memory-storage.md +0 -261
- package/dist/docs/references/docs-memory-working-memory.md +0 -400
- package/dist/docs/references/docs-observability-datasets-overview.md +0 -188
- package/dist/docs/references/docs-observability-datasets-running-experiments.md +0 -266
- package/dist/docs/references/docs-observability-logging.md +0 -99
- package/dist/docs/references/docs-observability-overview.md +0 -70
- package/dist/docs/references/docs-observability-tracing-bridges-otel.md +0 -209
- package/dist/docs/references/docs-observability-tracing-exporters-arize.md +0 -274
- package/dist/docs/references/docs-observability-tracing-exporters-braintrust.md +0 -111
- package/dist/docs/references/docs-observability-tracing-exporters-cloud.md +0 -129
- package/dist/docs/references/docs-observability-tracing-exporters-datadog.md +0 -187
- package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -211
- package/dist/docs/references/docs-observability-tracing-exporters-laminar.md +0 -100
- package/dist/docs/references/docs-observability-tracing-exporters-langfuse.md +0 -217
- package/dist/docs/references/docs-observability-tracing-exporters-langsmith.md +0 -202
- package/dist/docs/references/docs-observability-tracing-exporters-otel.md +0 -479
- package/dist/docs/references/docs-observability-tracing-exporters-posthog.md +0 -148
- package/dist/docs/references/docs-observability-tracing-overview.md +0 -1114
- package/dist/docs/references/docs-rag-chunking-and-embedding.md +0 -183
- package/dist/docs/references/docs-rag-graph-rag.md +0 -215
- package/dist/docs/references/docs-rag-overview.md +0 -72
- package/dist/docs/references/docs-rag-retrieval.md +0 -521
- package/dist/docs/references/docs-rag-vector-databases.md +0 -648
- package/dist/docs/references/docs-server-auth-auth0.md +0 -222
- package/dist/docs/references/docs-server-auth-clerk.md +0 -132
- package/dist/docs/references/docs-server-auth-composite-auth.md +0 -234
- package/dist/docs/references/docs-server-auth-custom-auth-provider.md +0 -513
- package/dist/docs/references/docs-server-auth-firebase.md +0 -272
- package/dist/docs/references/docs-server-auth-jwt.md +0 -110
- package/dist/docs/references/docs-server-auth-simple-auth.md +0 -178
- package/dist/docs/references/docs-server-auth-supabase.md +0 -117
- package/dist/docs/references/docs-server-auth-workos.md +0 -190
- package/dist/docs/references/docs-server-custom-adapters.md +0 -374
- package/dist/docs/references/docs-server-custom-api-routes.md +0 -267
- package/dist/docs/references/docs-server-mastra-client.md +0 -243
- package/dist/docs/references/docs-server-mastra-server.md +0 -71
- package/dist/docs/references/docs-server-middleware.md +0 -228
- package/dist/docs/references/docs-server-request-context.md +0 -478
- package/dist/docs/references/docs-streaming-events.md +0 -247
- package/dist/docs/references/docs-streaming-tool-streaming.md +0 -178
- package/dist/docs/references/docs-streaming-workflow-streaming.md +0 -109
- package/dist/docs/references/docs-voice-overview.md +0 -979
- package/dist/docs/references/docs-voice-speech-to-speech.md +0 -103
- package/dist/docs/references/docs-voice-speech-to-text.md +0 -80
- package/dist/docs/references/docs-voice-text-to-speech.md +0 -84
- package/dist/docs/references/docs-workflows-agents-and-tools.md +0 -170
- package/dist/docs/references/docs-workflows-control-flow.md +0 -823
- package/dist/docs/references/docs-workflows-error-handling.md +0 -360
- package/dist/docs/references/docs-workflows-human-in-the-loop.md +0 -213
- package/dist/docs/references/docs-workflows-overview.md +0 -372
- package/dist/docs/references/docs-workflows-snapshots.md +0 -238
- package/dist/docs/references/docs-workflows-suspend-and-resume.md +0 -205
- package/dist/docs/references/docs-workflows-time-travel.md +0 -309
- package/dist/docs/references/docs-workflows-workflow-state.md +0 -181
- package/dist/docs/references/docs-workspace-filesystem.md +0 -162
- package/dist/docs/references/docs-workspace-overview.md +0 -239
- package/dist/docs/references/docs-workspace-sandbox.md +0 -63
- package/dist/docs/references/docs-workspace-search.md +0 -219
- package/dist/docs/references/docs-workspace-skills.md +0 -126
- package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +0 -140
- package/dist/docs/references/reference-agents-agent.md +0 -142
- package/dist/docs/references/reference-agents-generate.md +0 -174
- package/dist/docs/references/reference-agents-generateLegacy.md +0 -176
- package/dist/docs/references/reference-agents-getDefaultGenerateOptions.md +0 -36
- package/dist/docs/references/reference-agents-getDefaultOptions.md +0 -34
- package/dist/docs/references/reference-agents-getDefaultStreamOptions.md +0 -36
- package/dist/docs/references/reference-agents-getDescription.md +0 -21
- package/dist/docs/references/reference-agents-getInstructions.md +0 -34
- package/dist/docs/references/reference-agents-getLLM.md +0 -37
- package/dist/docs/references/reference-agents-getMemory.md +0 -34
- package/dist/docs/references/reference-agents-getModel.md +0 -34
- package/dist/docs/references/reference-agents-getTools.md +0 -29
- package/dist/docs/references/reference-agents-getVoice.md +0 -34
- package/dist/docs/references/reference-agents-listAgents.md +0 -35
- package/dist/docs/references/reference-agents-listScorers.md +0 -34
- package/dist/docs/references/reference-agents-listTools.md +0 -34
- package/dist/docs/references/reference-agents-listWorkflows.md +0 -34
- package/dist/docs/references/reference-agents-network.md +0 -134
- package/dist/docs/references/reference-ai-sdk-chat-route.md +0 -82
- package/dist/docs/references/reference-ai-sdk-network-route.md +0 -74
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +0 -232
- package/dist/docs/references/reference-ai-sdk-with-mastra.md +0 -59
- package/dist/docs/references/reference-ai-sdk-workflow-route.md +0 -79
- package/dist/docs/references/reference-auth-auth0.md +0 -73
- package/dist/docs/references/reference-auth-clerk.md +0 -36
- package/dist/docs/references/reference-auth-firebase.md +0 -80
- package/dist/docs/references/reference-auth-jwt.md +0 -26
- package/dist/docs/references/reference-auth-supabase.md +0 -33
- package/dist/docs/references/reference-auth-workos.md +0 -84
- package/dist/docs/references/reference-client-js-agents.md +0 -438
- package/dist/docs/references/reference-configuration.md +0 -749
- package/dist/docs/references/reference-core-addGateway.md +0 -42
- package/dist/docs/references/reference-core-getAgent.md +0 -21
- package/dist/docs/references/reference-core-getAgentById.md +0 -21
- package/dist/docs/references/reference-core-getDeployer.md +0 -22
- package/dist/docs/references/reference-core-getGateway.md +0 -38
- package/dist/docs/references/reference-core-getGatewayById.md +0 -41
- package/dist/docs/references/reference-core-getLogger.md +0 -22
- package/dist/docs/references/reference-core-getMCPServer.md +0 -45
- package/dist/docs/references/reference-core-getMCPServerById.md +0 -53
- package/dist/docs/references/reference-core-getMemory.md +0 -50
- package/dist/docs/references/reference-core-getScorer.md +0 -54
- package/dist/docs/references/reference-core-getScorerById.md +0 -54
- package/dist/docs/references/reference-core-getServer.md +0 -22
- package/dist/docs/references/reference-core-getStorage.md +0 -22
- package/dist/docs/references/reference-core-getStoredAgentById.md +0 -89
- package/dist/docs/references/reference-core-getTelemetry.md +0 -22
- package/dist/docs/references/reference-core-getVector.md +0 -22
- package/dist/docs/references/reference-core-getWorkflow.md +0 -40
- package/dist/docs/references/reference-core-listAgents.md +0 -21
- package/dist/docs/references/reference-core-listGateways.md +0 -40
- package/dist/docs/references/reference-core-listLogs.md +0 -38
- package/dist/docs/references/reference-core-listLogsByRunId.md +0 -36
- package/dist/docs/references/reference-core-listMCPServers.md +0 -51
- package/dist/docs/references/reference-core-listMemory.md +0 -56
- package/dist/docs/references/reference-core-listScorers.md +0 -29
- package/dist/docs/references/reference-core-listStoredAgents.md +0 -93
- package/dist/docs/references/reference-core-listVectors.md +0 -22
- package/dist/docs/references/reference-core-listWorkflows.md +0 -21
- package/dist/docs/references/reference-core-mastra-class.md +0 -66
- package/dist/docs/references/reference-core-mastra-model-gateway.md +0 -153
- package/dist/docs/references/reference-core-setLogger.md +0 -26
- package/dist/docs/references/reference-core-setStorage.md +0 -27
- package/dist/docs/references/reference-datasets-addItem.md +0 -35
- package/dist/docs/references/reference-datasets-addItems.md +0 -33
- package/dist/docs/references/reference-datasets-compareExperiments.md +0 -48
- package/dist/docs/references/reference-datasets-create.md +0 -49
- package/dist/docs/references/reference-datasets-dataset.md +0 -78
- package/dist/docs/references/reference-datasets-datasets-manager.md +0 -84
- package/dist/docs/references/reference-datasets-delete.md +0 -23
- package/dist/docs/references/reference-datasets-deleteExperiment.md +0 -25
- package/dist/docs/references/reference-datasets-deleteItem.md +0 -25
- package/dist/docs/references/reference-datasets-deleteItems.md +0 -27
- package/dist/docs/references/reference-datasets-get.md +0 -29
- package/dist/docs/references/reference-datasets-getDetails.md +0 -45
- package/dist/docs/references/reference-datasets-getExperiment.md +0 -28
- package/dist/docs/references/reference-datasets-getItem.md +0 -31
- package/dist/docs/references/reference-datasets-getItemHistory.md +0 -29
- package/dist/docs/references/reference-datasets-list.md +0 -29
- package/dist/docs/references/reference-datasets-listExperimentResults.md +0 -37
- package/dist/docs/references/reference-datasets-listExperiments.md +0 -31
- package/dist/docs/references/reference-datasets-listItems.md +0 -44
- package/dist/docs/references/reference-datasets-listVersions.md +0 -31
- package/dist/docs/references/reference-datasets-startExperiment.md +0 -60
- package/dist/docs/references/reference-datasets-startExperimentAsync.md +0 -41
- package/dist/docs/references/reference-datasets-update.md +0 -46
- package/dist/docs/references/reference-datasets-updateItem.md +0 -36
- package/dist/docs/references/reference-evals-answer-relevancy.md +0 -105
- package/dist/docs/references/reference-evals-answer-similarity.md +0 -99
- package/dist/docs/references/reference-evals-bias.md +0 -120
- package/dist/docs/references/reference-evals-completeness.md +0 -137
- package/dist/docs/references/reference-evals-content-similarity.md +0 -101
- package/dist/docs/references/reference-evals-context-precision.md +0 -196
- package/dist/docs/references/reference-evals-create-scorer.md +0 -270
- package/dist/docs/references/reference-evals-faithfulness.md +0 -114
- package/dist/docs/references/reference-evals-hallucination.md +0 -220
- package/dist/docs/references/reference-evals-keyword-coverage.md +0 -128
- package/dist/docs/references/reference-evals-mastra-scorer.md +0 -123
- package/dist/docs/references/reference-evals-run-evals.md +0 -138
- package/dist/docs/references/reference-evals-scorer-utils.md +0 -330
- package/dist/docs/references/reference-evals-textual-difference.md +0 -113
- package/dist/docs/references/reference-evals-tone-consistency.md +0 -119
- package/dist/docs/references/reference-evals-toxicity.md +0 -123
- package/dist/docs/references/reference-harness-harness-class.md +0 -645
- package/dist/docs/references/reference-logging-pino-logger.md +0 -117
- package/dist/docs/references/reference-memory-deleteMessages.md +0 -40
- package/dist/docs/references/reference-memory-memory-class.md +0 -147
- package/dist/docs/references/reference-memory-observational-memory.md +0 -565
- package/dist/docs/references/reference-observability-tracing-bridges-otel.md +0 -131
- package/dist/docs/references/reference-observability-tracing-configuration.md +0 -178
- package/dist/docs/references/reference-observability-tracing-exporters-console-exporter.md +0 -138
- package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +0 -116
- package/dist/docs/references/reference-observability-tracing-instances.md +0 -109
- package/dist/docs/references/reference-observability-tracing-interfaces.md +0 -749
- package/dist/docs/references/reference-observability-tracing-processors-sensitive-data-filter.md +0 -144
- package/dist/docs/references/reference-observability-tracing-spans.md +0 -224
- package/dist/docs/references/reference-processors-batch-parts-processor.md +0 -61
- package/dist/docs/references/reference-processors-language-detector.md +0 -81
- package/dist/docs/references/reference-processors-message-history-processor.md +0 -85
- package/dist/docs/references/reference-processors-moderation-processor.md +0 -104
- package/dist/docs/references/reference-processors-pii-detector.md +0 -107
- package/dist/docs/references/reference-processors-processor-interface.md +0 -525
- package/dist/docs/references/reference-processors-prompt-injection-detector.md +0 -71
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +0 -123
- package/dist/docs/references/reference-processors-system-prompt-scrubber.md +0 -80
- package/dist/docs/references/reference-processors-token-limiter-processor.md +0 -113
- package/dist/docs/references/reference-processors-tool-call-filter.md +0 -85
- package/dist/docs/references/reference-processors-tool-search-processor.md +0 -113
- package/dist/docs/references/reference-processors-unicode-normalizer.md +0 -62
- package/dist/docs/references/reference-processors-working-memory-processor.md +0 -154
- package/dist/docs/references/reference-rag-database-config.md +0 -264
- package/dist/docs/references/reference-rag-embeddings.md +0 -92
- package/dist/docs/references/reference-server-mastra-server.md +0 -298
- package/dist/docs/references/reference-server-register-api-route.md +0 -249
- package/dist/docs/references/reference-storage-cloudflare-d1.md +0 -218
- package/dist/docs/references/reference-storage-composite.md +0 -235
- package/dist/docs/references/reference-storage-lance.md +0 -131
- package/dist/docs/references/reference-storage-libsql.md +0 -135
- package/dist/docs/references/reference-storage-mongodb.md +0 -262
- package/dist/docs/references/reference-storage-mssql.md +0 -155
- package/dist/docs/references/reference-storage-overview.md +0 -121
- package/dist/docs/references/reference-storage-postgresql.md +0 -529
- package/dist/docs/references/reference-storage-upstash.md +0 -160
- package/dist/docs/references/reference-streaming-ChunkType.md +0 -292
- package/dist/docs/references/reference-streaming-agents-MastraModelOutput.md +0 -182
- package/dist/docs/references/reference-streaming-agents-streamLegacy.md +0 -142
- package/dist/docs/references/reference-streaming-workflows-observeStream.md +0 -42
- package/dist/docs/references/reference-streaming-workflows-resumeStream.md +0 -61
- package/dist/docs/references/reference-streaming-workflows-stream.md +0 -88
- package/dist/docs/references/reference-streaming-workflows-timeTravelStream.md +0 -142
- package/dist/docs/references/reference-templates-overview.md +0 -194
- package/dist/docs/references/reference-tools-create-tool.md +0 -237
- package/dist/docs/references/reference-tools-graph-rag-tool.md +0 -185
- package/dist/docs/references/reference-tools-mcp-client.md +0 -962
- package/dist/docs/references/reference-tools-mcp-server.md +0 -1275
- package/dist/docs/references/reference-tools-vector-query-tool.md +0 -459
- package/dist/docs/references/reference-vectors-libsql.md +0 -305
- package/dist/docs/references/reference-vectors-mongodb.md +0 -295
- package/dist/docs/references/reference-vectors-pg.md +0 -408
- package/dist/docs/references/reference-vectors-upstash.md +0 -294
- package/dist/docs/references/reference-voice-composite-voice.md +0 -121
- package/dist/docs/references/reference-voice-mastra-voice.md +0 -313
- package/dist/docs/references/reference-voice-voice.addInstructions.md +0 -56
- package/dist/docs/references/reference-voice-voice.addTools.md +0 -67
- package/dist/docs/references/reference-voice-voice.connect.md +0 -94
- package/dist/docs/references/reference-voice-voice.events.md +0 -37
- package/dist/docs/references/reference-voice-voice.listen.md +0 -164
- package/dist/docs/references/reference-voice-voice.on.md +0 -111
- package/dist/docs/references/reference-voice-voice.speak.md +0 -157
- package/dist/docs/references/reference-workflows-run-methods-cancel.md +0 -86
- package/dist/docs/references/reference-workflows-run-methods-restart.md +0 -33
- package/dist/docs/references/reference-workflows-run-methods-resume.md +0 -59
- package/dist/docs/references/reference-workflows-run-methods-start.md +0 -58
- package/dist/docs/references/reference-workflows-run-methods-startAsync.md +0 -67
- package/dist/docs/references/reference-workflows-run-methods-timeTravel.md +0 -142
- package/dist/docs/references/reference-workflows-run.md +0 -59
- package/dist/docs/references/reference-workflows-step.md +0 -119
- package/dist/docs/references/reference-workflows-workflow-methods-branch.md +0 -25
- package/dist/docs/references/reference-workflows-workflow-methods-commit.md +0 -17
- package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +0 -63
- package/dist/docs/references/reference-workflows-workflow-methods-dountil.md +0 -25
- package/dist/docs/references/reference-workflows-workflow-methods-dowhile.md +0 -25
- package/dist/docs/references/reference-workflows-workflow-methods-foreach.md +0 -118
- package/dist/docs/references/reference-workflows-workflow-methods-map.md +0 -93
- package/dist/docs/references/reference-workflows-workflow-methods-parallel.md +0 -21
- package/dist/docs/references/reference-workflows-workflow-methods-sleep.md +0 -35
- package/dist/docs/references/reference-workflows-workflow-methods-sleepUntil.md +0 -35
- package/dist/docs/references/reference-workflows-workflow-methods-then.md +0 -21
- package/dist/docs/references/reference-workflows-workflow.md +0 -157
- package/dist/docs/references/reference-workspace-filesystem.md +0 -202
- package/dist/docs/references/reference-workspace-local-filesystem.md +0 -327
- package/dist/docs/references/reference-workspace-local-sandbox.md +0 -285
- package/dist/docs/references/reference-workspace-sandbox.md +0 -81
- package/dist/docs/references/reference-workspace-workspace-class.md +0 -226
- package/dist/docs/references/reference.md +0 -276
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
# createScorer
|
|
2
|
-
|
|
3
|
-
Mastra provides a unified `createScorer` factory that allows you to define custom scorers for evaluating input/output pairs. You can use either native JavaScript functions or LLM-based prompt objects for each evaluation step. Custom scorers can be added to Agents and Workflow steps.
|
|
4
|
-
|
|
5
|
-
## How to Create a Custom Scorer
|
|
6
|
-
|
|
7
|
-
Use the `createScorer` factory to define your scorer with a name, description, and optional judge configuration. Then chain step methods to build your evaluation pipeline. You must provide at least a `generateScore` step.
|
|
8
|
-
|
|
9
|
-
**Prompt object steps** are step configurations expressed as objects with `description` + `createPrompt` (and `outputSchema` for `preprocess`/`analyze`). These steps invoke the judge LLM. **Function steps** are plain functions and never call the judge.
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
import { createScorer } from "@mastra/core/evals";
|
|
13
|
-
|
|
14
|
-
const scorer = createScorer({
|
|
15
|
-
id: "my-custom-scorer",
|
|
16
|
-
name: "My Custom Scorer", // Optional, defaults to id
|
|
17
|
-
description: "Evaluates responses based on custom criteria",
|
|
18
|
-
type: "agent", // Optional: for agent evaluation with automatic typing
|
|
19
|
-
judge: {
|
|
20
|
-
model: myModel,
|
|
21
|
-
instructions: "You are an expert evaluator...",
|
|
22
|
-
},
|
|
23
|
-
})
|
|
24
|
-
.preprocess({
|
|
25
|
-
/* step config */
|
|
26
|
-
})
|
|
27
|
-
.analyze({
|
|
28
|
-
/* step config */
|
|
29
|
-
})
|
|
30
|
-
.generateScore(({ run, results }) => {
|
|
31
|
-
// Return a number
|
|
32
|
-
})
|
|
33
|
-
.generateReason({
|
|
34
|
-
/* step config */
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## createScorer Options
|
|
39
|
-
|
|
40
|
-
**id:** (`string`): Unique identifier for the scorer. Used as the name if \`name\` is not provided.
|
|
41
|
-
|
|
42
|
-
**name?:** (`string`): Name of the scorer. Defaults to \`id\` if not provided.
|
|
43
|
-
|
|
44
|
-
**description:** (`string`): Description of what the scorer does.
|
|
45
|
-
|
|
46
|
-
**judge?:** (`object`): Optional judge configuration for LLM-based steps. See Judge Object section below.
|
|
47
|
-
|
|
48
|
-
**type?:** (`string`): Type specification for input/output. Use 'agent' for automatic agent types. For custom types, use the generic approach instead.
|
|
49
|
-
|
|
50
|
-
This function returns a scorer builder that you can chain step methods onto. See the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer) for details on the `.run()` method and its input/output.
|
|
51
|
-
|
|
52
|
-
## Judge Object
|
|
53
|
-
|
|
54
|
-
**model:** (`LanguageModel`): The LLM model instance to use for evaluation.
|
|
55
|
-
|
|
56
|
-
**instructions:** (`string`): System prompt/instructions for the LLM.
|
|
57
|
-
|
|
58
|
-
The judge only runs for steps defined as **prompt objects** (`preprocess`, `analyze`, `generateScore`, `generateReason` in prompt mode). If you use function steps only, the judge is never called and there is no LLM output to inspect. In that case, any score/reason must be produced by your functions.
|
|
59
|
-
|
|
60
|
-
When a prompt-object step runs, its structured LLM output is stored in the corresponding result field (`preprocessStepResult`, `analyzeStepResult`, or the value consumed by `calculateScore` in `generateScore`).
|
|
61
|
-
|
|
62
|
-
## Type Safety
|
|
63
|
-
|
|
64
|
-
You can specify input/output types when creating scorers for better type inference and IntelliSense support:
|
|
65
|
-
|
|
66
|
-
### Agent Type Shortcut
|
|
67
|
-
|
|
68
|
-
For evaluating agents, use `type: 'agent'` to automatically get the correct types for agent input/output:
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import { createScorer } from "@mastra/core/evals";
|
|
72
|
-
|
|
73
|
-
// Agent scorer with automatic typing
|
|
74
|
-
const agentScorer = createScorer({
|
|
75
|
-
id: "agent-response-quality",
|
|
76
|
-
description: "Evaluates agent responses",
|
|
77
|
-
type: "agent", // Automatically provides ScorerRunInputForAgent/ScorerRunOutputForAgent
|
|
78
|
-
})
|
|
79
|
-
.preprocess(({ run }) => {
|
|
80
|
-
// run.input is automatically typed as ScorerRunInputForAgent
|
|
81
|
-
const userMessage = run.inputData.inputMessages[0]?.content;
|
|
82
|
-
return { userMessage };
|
|
83
|
-
})
|
|
84
|
-
.generateScore(({ run, results }) => {
|
|
85
|
-
// run.output is automatically typed as ScorerRunOutputForAgent
|
|
86
|
-
const response = run.output[0]?.content;
|
|
87
|
-
return response.length > 10 ? 1.0 : 0.5;
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Custom Types with Generics
|
|
92
|
-
|
|
93
|
-
For custom input/output types, use the generic approach:
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
import { createScorer } from "@mastra/core/evals";
|
|
97
|
-
|
|
98
|
-
type CustomInput = { query: string; context: string[] };
|
|
99
|
-
type CustomOutput = { answer: string; confidence: number };
|
|
100
|
-
|
|
101
|
-
const customScorer = createScorer<CustomInput, CustomOutput>({
|
|
102
|
-
id: "custom-scorer",
|
|
103
|
-
description: "Evaluates custom data",
|
|
104
|
-
}).generateScore(({ run }) => {
|
|
105
|
-
// run.input is typed as CustomInput
|
|
106
|
-
// run.output is typed as CustomOutput
|
|
107
|
-
return run.output.confidence;
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Built-in Agent Types
|
|
112
|
-
|
|
113
|
-
- **`ScorerRunInputForAgent`** - Contains `inputMessages`, `rememberedMessages`, `systemMessages`, and `taggedSystemMessages` for agent evaluation
|
|
114
|
-
- **`ScorerRunOutputForAgent`** - Array of agent response messages
|
|
115
|
-
|
|
116
|
-
Using these types provides autocomplete, compile-time validation, and better documentation for your scoring logic.
|
|
117
|
-
|
|
118
|
-
## Trace Scoring with Agent Types
|
|
119
|
-
|
|
120
|
-
When you use `type: 'agent'`, your scorer is compatible for both adding directly to agents and scoring traces from agent interactions. The scorer automatically transforms trace data into the proper agent input/output format:
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
const agentTraceScorer = createScorer({
|
|
124
|
-
id: "agent-trace-length",
|
|
125
|
-
description: "Evaluates agent response length",
|
|
126
|
-
type: "agent",
|
|
127
|
-
}).generateScore(({ run }) => {
|
|
128
|
-
// Trace data is automatically transformed to agent format
|
|
129
|
-
const userMessages = run.inputData.inputMessages;
|
|
130
|
-
const agentResponse = run.output[0]?.content;
|
|
131
|
-
|
|
132
|
-
// Score based on response length
|
|
133
|
-
return agentResponse?.length > 50 ? 0 : 1;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Register with Mastra for trace scoring
|
|
137
|
-
const mastra = new Mastra({
|
|
138
|
-
scorers: {
|
|
139
|
-
agentTraceScorer,
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## Step Method Signatures
|
|
145
|
-
|
|
146
|
-
### preprocess
|
|
147
|
-
|
|
148
|
-
Optional preprocessing step that can extract or transform data before analysis.
|
|
149
|
-
|
|
150
|
-
**Function Mode:** Function: `({ run, results }) => any`
|
|
151
|
-
|
|
152
|
-
**run.input:** (`any`): Input records provided to the scorer. If the scorer is added to an agent, this will be an array of user messages, e.g. \`\[{ role: 'user', content: 'hello world' }]\`. If the scorer is used in a workflow, this will be the input of the workflow.
|
|
153
|
-
|
|
154
|
-
**run.output:** (`any`): Output record provided to the scorer. For agents, this is usually the agent's response. For workflows, this is the workflow's output.
|
|
155
|
-
|
|
156
|
-
**run.runId:** (`string`): Unique identifier for this scoring run.
|
|
157
|
-
|
|
158
|
-
**run.requestContext?:** (`object`): Request Context from the agent or workflow step being evaluated (optional).
|
|
159
|
-
|
|
160
|
-
**results:** (`object`): Empty object (no previous steps).
|
|
161
|
-
|
|
162
|
-
Returns: `any`\
|
|
163
|
-
The method can return any value. The returned value will be available to subsequent steps as `preprocessStepResult`.
|
|
164
|
-
|
|
165
|
-
**Prompt Object Mode:**
|
|
166
|
-
|
|
167
|
-
**description:** (`string`): Description of what this preprocessing step does.
|
|
168
|
-
|
|
169
|
-
**outputSchema:** (`ZodSchema`): Zod schema for the expected output of the preprocess step.
|
|
170
|
-
|
|
171
|
-
**createPrompt:** (`function`): Function: ({ run, results }) => string. Returns the prompt for the LLM.
|
|
172
|
-
|
|
173
|
-
**judge?:** (`object`): (Optional) LLM judge for this step (can override main judge). See Judge Object section.
|
|
174
|
-
|
|
175
|
-
### analyze
|
|
176
|
-
|
|
177
|
-
Optional analysis step that processes the input/output and any preprocessed data.
|
|
178
|
-
|
|
179
|
-
**Function Mode:** Function: `({ run, results }) => any`
|
|
180
|
-
|
|
181
|
-
**run.input:** (`any`): Input records provided to the scorer. If the scorer is added to an agent, this will be an array of user messages, e.g. \`\[{ role: 'user', content: 'hello world' }]\`. If the scorer is used in a workflow, this will be the input of the workflow.
|
|
182
|
-
|
|
183
|
-
**run.output:** (`any`): Output record provided to the scorer. For agents, this is usually the agent's response. For workflows, this is the workflow's output.
|
|
184
|
-
|
|
185
|
-
**run.runId:** (`string`): Unique identifier for this scoring run.
|
|
186
|
-
|
|
187
|
-
**run.requestContext?:** (`object`): Request Context from the agent or workflow step being evaluated (optional).
|
|
188
|
-
|
|
189
|
-
**results.preprocessStepResult?:** (`any`): Result from preprocess step, if defined (optional).
|
|
190
|
-
|
|
191
|
-
Returns: `any`\
|
|
192
|
-
The method can return any value. The returned value will be available to subsequent steps as `analyzeStepResult`.
|
|
193
|
-
|
|
194
|
-
**Prompt Object Mode:**
|
|
195
|
-
|
|
196
|
-
**description:** (`string`): Description of what this analysis step does.
|
|
197
|
-
|
|
198
|
-
**outputSchema:** (`ZodSchema`): Zod schema for the expected output of the analyze step.
|
|
199
|
-
|
|
200
|
-
**createPrompt:** (`function`): Function: ({ run, results }) => string. Returns the prompt for the LLM.
|
|
201
|
-
|
|
202
|
-
**judge?:** (`object`): (Optional) LLM judge for this step (can override main judge). See Judge Object section.
|
|
203
|
-
|
|
204
|
-
### generateScore
|
|
205
|
-
|
|
206
|
-
**Required** step that computes the final numerical score.
|
|
207
|
-
|
|
208
|
-
**Function Mode:** Function: `({ run, results }) => number`
|
|
209
|
-
|
|
210
|
-
**run.input:** (`any`): Input records provided to the scorer. If the scorer is added to an agent, this will be an array of user messages, e.g. \`\[{ role: 'user', content: 'hello world' }]\`. If the scorer is used in a workflow, this will be the input of the workflow.
|
|
211
|
-
|
|
212
|
-
**run.output:** (`any`): Output record provided to the scorer. For agents, this is usually the agent's response. For workflows, this is the workflow's output.
|
|
213
|
-
|
|
214
|
-
**run.runId:** (`string`): Unique identifier for this scoring run.
|
|
215
|
-
|
|
216
|
-
**run.requestContext?:** (`object`): Request Context from the agent or workflow step being evaluated (optional).
|
|
217
|
-
|
|
218
|
-
**results.preprocessStepResult?:** (`any`): Result from preprocess step, if defined (optional).
|
|
219
|
-
|
|
220
|
-
**results.analyzeStepResult?:** (`any`): Result from analyze step, if defined (optional).
|
|
221
|
-
|
|
222
|
-
Returns: `number`\
|
|
223
|
-
The method must return a numerical score.
|
|
224
|
-
|
|
225
|
-
**Prompt Object Mode:**
|
|
226
|
-
|
|
227
|
-
**description:** (`string`): Description of what this scoring step does.
|
|
228
|
-
|
|
229
|
-
**outputSchema:** (`ZodSchema`): Zod schema for the expected output of the generateScore step.
|
|
230
|
-
|
|
231
|
-
**createPrompt:** (`function`): Function: ({ run, results }) => string. Returns the prompt for the LLM.
|
|
232
|
-
|
|
233
|
-
**judge?:** (`object`): (Optional) LLM judge for this step (can override main judge). See Judge Object section.
|
|
234
|
-
|
|
235
|
-
When using prompt object mode, you must also provide a `calculateScore` function to convert the LLM output to a numerical score:
|
|
236
|
-
|
|
237
|
-
**calculateScore:** (`function`): Function: ({ run, results, analyzeStepResult }) => number. Converts the LLM's structured output into a numerical score.
|
|
238
|
-
|
|
239
|
-
### generateReason
|
|
240
|
-
|
|
241
|
-
Optional step that provides an explanation for the score.
|
|
242
|
-
|
|
243
|
-
**Function Mode:** Function: `({ run, results, score }) => string`
|
|
244
|
-
|
|
245
|
-
**run.input:** (`any`): Input records provided to the scorer. If the scorer is added to an agent, this will be an array of user messages, e.g. \`\[{ role: 'user', content: 'hello world' }]\`. If the scorer is used in a workflow, this will be the input of the workflow.
|
|
246
|
-
|
|
247
|
-
**run.output:** (`any`): Output record provided to the scorer. For agents, this is usually the agent's response. For workflows, this is the workflow's output.
|
|
248
|
-
|
|
249
|
-
**run.runId:** (`string`): Unique identifier for this scoring run.
|
|
250
|
-
|
|
251
|
-
**run.requestContext?:** (`object`): Request Context from the agent or workflow step being evaluated (optional).
|
|
252
|
-
|
|
253
|
-
**results.preprocessStepResult?:** (`any`): Result from preprocess step, if defined (optional).
|
|
254
|
-
|
|
255
|
-
**results.analyzeStepResult?:** (`any`): Result from analyze step, if defined (optional).
|
|
256
|
-
|
|
257
|
-
**score:** (`number`): Score computed by the generateScore step.
|
|
258
|
-
|
|
259
|
-
Returns: `string`\
|
|
260
|
-
The method must return a string explaining the score.
|
|
261
|
-
|
|
262
|
-
**Prompt Object Mode:**
|
|
263
|
-
|
|
264
|
-
**description:** (`string`): Description of what this reasoning step does.
|
|
265
|
-
|
|
266
|
-
**createPrompt:** (`function`): Function: ({ run, results, score }) => string. Returns the prompt for the LLM.
|
|
267
|
-
|
|
268
|
-
**judge?:** (`object`): (Optional) LLM judge for this step (can override main judge). See Judge Object section.
|
|
269
|
-
|
|
270
|
-
All step functions can be async.
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# Faithfulness Scorer
|
|
2
|
-
|
|
3
|
-
The `createFaithfulnessScorer()` function evaluates how factually accurate an LLM's output is compared to the provided context. It extracts claims from the output and verifies them against the context, making it essential to measure RAG pipeline responses' reliability.
|
|
4
|
-
|
|
5
|
-
## Parameters
|
|
6
|
-
|
|
7
|
-
The `createFaithfulnessScorer()` function accepts a single options object with the following properties:
|
|
8
|
-
|
|
9
|
-
**model:** (`LanguageModel`): Configuration for the model used to evaluate faithfulness.
|
|
10
|
-
|
|
11
|
-
**context:** (`string[]`): Array of context chunks against which the output's claims will be verified.
|
|
12
|
-
|
|
13
|
-
**scale:** (`number`): The maximum score value. The final score will be normalized to this scale. (Default: `1`)
|
|
14
|
-
|
|
15
|
-
This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer)), but the return value includes LLM-specific fields as documented below.
|
|
16
|
-
|
|
17
|
-
## .run() Returns
|
|
18
|
-
|
|
19
|
-
**runId:** (`string`): The id of the run (optional).
|
|
20
|
-
|
|
21
|
-
**preprocessStepResult:** (`string[]`): Array of extracted claims from the output.
|
|
22
|
-
|
|
23
|
-
**preprocessPrompt:** (`string`): The prompt sent to the LLM for the preprocess step (optional).
|
|
24
|
-
|
|
25
|
-
**analyzeStepResult:** (`object`): Object with verdicts: { verdicts: Array<{ verdict: 'yes' | 'no' | 'unsure', reason: string }> }
|
|
26
|
-
|
|
27
|
-
**analyzePrompt:** (`string`): The prompt sent to the LLM for the analyze step (optional).
|
|
28
|
-
|
|
29
|
-
**score:** (`number`): A score between 0 and the configured scale, representing the proportion of claims that are supported by the context.
|
|
30
|
-
|
|
31
|
-
**reason:** (`string`): A detailed explanation of the score, including which claims were supported, contradicted, or marked as unsure.
|
|
32
|
-
|
|
33
|
-
**generateReasonPrompt:** (`string`): The prompt sent to the LLM for the generateReason step (optional).
|
|
34
|
-
|
|
35
|
-
## Scoring Details
|
|
36
|
-
|
|
37
|
-
The scorer evaluates faithfulness through claim verification against provided context.
|
|
38
|
-
|
|
39
|
-
### Scoring Process
|
|
40
|
-
|
|
41
|
-
1. Analyzes claims and context:
|
|
42
|
-
|
|
43
|
-
- Extracts all claims (factual and speculative)
|
|
44
|
-
|
|
45
|
-
- Verifies each claim against context
|
|
46
|
-
|
|
47
|
-
- Assigns one of three verdicts:
|
|
48
|
-
|
|
49
|
-
- "yes" - claim supported by context
|
|
50
|
-
- "no" - claim contradicts context
|
|
51
|
-
- "unsure" - claim unverifiable
|
|
52
|
-
|
|
53
|
-
2. Calculates faithfulness score:
|
|
54
|
-
|
|
55
|
-
- Counts supported claims
|
|
56
|
-
- Divides by total claims
|
|
57
|
-
- Scales to configured range
|
|
58
|
-
|
|
59
|
-
Final score: `(supported_claims / total_claims) * scale`
|
|
60
|
-
|
|
61
|
-
### Score interpretation
|
|
62
|
-
|
|
63
|
-
A faithfulness score between 0 and 1:
|
|
64
|
-
|
|
65
|
-
- **1.0**: All claims are accurate and directly supported by the context.
|
|
66
|
-
- **0.7–0.9**: Most claims are correct, with minor additions or omissions.
|
|
67
|
-
- **0.4–0.6**: Some claims are supported, but others are unverifiable.
|
|
68
|
-
- **0.1–0.3**: Most of the content is inaccurate or unsupported.
|
|
69
|
-
- **0.0**: All claims are false or contradict the context.
|
|
70
|
-
|
|
71
|
-
## Example
|
|
72
|
-
|
|
73
|
-
Evaluate agent responses for faithfulness to provided context:
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
import { runEvals } from "@mastra/core/evals";
|
|
77
|
-
import { createFaithfulnessScorer } from "@mastra/evals/scorers/prebuilt";
|
|
78
|
-
import { myAgent } from "./agent";
|
|
79
|
-
|
|
80
|
-
// Context is typically populated from agent tool calls or RAG retrieval
|
|
81
|
-
const scorer = createFaithfulnessScorer({
|
|
82
|
-
model: "openai/gpt-4o",
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const result = await runEvals({
|
|
86
|
-
data: [
|
|
87
|
-
{
|
|
88
|
-
input: "Tell me about the Tesla Model 3.",
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
input: "What are the key features of this electric vehicle?",
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
scorers: [scorer],
|
|
95
|
-
target: myAgent,
|
|
96
|
-
onItemComplete: ({ scorerResults }) => {
|
|
97
|
-
console.log({
|
|
98
|
-
score: scorerResults[scorer.id].score,
|
|
99
|
-
reason: scorerResults[scorer.id].reason,
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
console.log(result.scores);
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
For more details on `runEvals`, see the [runEvals reference](https://mastra.ai/reference/evals/run-evals).
|
|
108
|
-
|
|
109
|
-
To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/docs/evals/overview) guide.
|
|
110
|
-
|
|
111
|
-
## Related
|
|
112
|
-
|
|
113
|
-
- [Answer Relevancy Scorer](https://mastra.ai/reference/evals/answer-relevancy)
|
|
114
|
-
- [Hallucination Scorer](https://mastra.ai/reference/evals/hallucination)
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# Hallucination Scorer
|
|
2
|
-
|
|
3
|
-
The `createHallucinationScorer()` function evaluates whether an LLM generates factually correct information by comparing its output against the provided context. This scorer measures hallucination by identifying direct contradictions between the context and the output.
|
|
4
|
-
|
|
5
|
-
## Parameters
|
|
6
|
-
|
|
7
|
-
The `createHallucinationScorer()` function accepts a single options object with the following properties:
|
|
8
|
-
|
|
9
|
-
**model:** (`LanguageModel`): Configuration for the model used to evaluate hallucination.
|
|
10
|
-
|
|
11
|
-
**options.scale:** (`number`): Maximum score value. (Default: `1`)
|
|
12
|
-
|
|
13
|
-
**options.context:** (`string[]`): Static context strings to use as ground truth for hallucination detection.
|
|
14
|
-
|
|
15
|
-
**options.getContext:** (`(params: GetContextParams) => string[] | Promise<string[]>`): A hook to dynamically resolve context at runtime. Takes priority over static context. Useful for live scoring where context (like tool results) is only available when the scorer runs.
|
|
16
|
-
|
|
17
|
-
This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer)), but the return value includes LLM-specific fields as documented below.
|
|
18
|
-
|
|
19
|
-
### GetContextParams
|
|
20
|
-
|
|
21
|
-
The `getContext` hook receives the following parameters:
|
|
22
|
-
|
|
23
|
-
**run:** (`GetContextRun`): The scorer run containing input, output, runId, requestContext, and tracingContext.
|
|
24
|
-
|
|
25
|
-
**results:** (`Record<string, any>`): Accumulated results from previous steps (e.g., preprocessStepResult with extracted claims).
|
|
26
|
-
|
|
27
|
-
**score:** (`number`): The computed score. Only present when called from the generateReason step.
|
|
28
|
-
|
|
29
|
-
**step:** (`'analyze' | 'generateReason'`): Which step is calling the hook. Useful for caching context between calls.
|
|
30
|
-
|
|
31
|
-
## .run() Returns
|
|
32
|
-
|
|
33
|
-
**runId:** (`string`): The id of the run (optional).
|
|
34
|
-
|
|
35
|
-
**preprocessStepResult:** (`object`): Object with extracted claims: { claims: string\[] }
|
|
36
|
-
|
|
37
|
-
**preprocessPrompt:** (`string`): The prompt sent to the LLM for the preprocess step (optional).
|
|
38
|
-
|
|
39
|
-
**analyzeStepResult:** (`object`): Object with verdicts: { verdicts: Array<{ statement: string, verdict: 'yes' | 'no', reason: string }> }
|
|
40
|
-
|
|
41
|
-
**analyzePrompt:** (`string`): The prompt sent to the LLM for the analyze step (optional).
|
|
42
|
-
|
|
43
|
-
**score:** (`number`): Hallucination score (0 to scale, default 0-1).
|
|
44
|
-
|
|
45
|
-
**reason:** (`string`): Detailed explanation of the score and identified contradictions.
|
|
46
|
-
|
|
47
|
-
**generateReasonPrompt:** (`string`): The prompt sent to the LLM for the generateReason step (optional).
|
|
48
|
-
|
|
49
|
-
## Scoring Details
|
|
50
|
-
|
|
51
|
-
The scorer evaluates hallucination through contradiction detection and unsupported claim analysis.
|
|
52
|
-
|
|
53
|
-
### Scoring Process
|
|
54
|
-
|
|
55
|
-
1. Analyzes factual content:
|
|
56
|
-
|
|
57
|
-
- Extracts statements from context
|
|
58
|
-
- Identifies numerical values and dates
|
|
59
|
-
- Maps statement relationships
|
|
60
|
-
|
|
61
|
-
2. Analyzes output for hallucinations:
|
|
62
|
-
|
|
63
|
-
- Compares against context statements
|
|
64
|
-
- Marks direct conflicts as hallucinations
|
|
65
|
-
- Identifies unsupported claims as hallucinations
|
|
66
|
-
- Evaluates numerical accuracy
|
|
67
|
-
- Considers approximation context
|
|
68
|
-
|
|
69
|
-
3. Calculates hallucination score:
|
|
70
|
-
|
|
71
|
-
- Counts hallucinated statements (contradictions and unsupported claims)
|
|
72
|
-
- Divides by total statements
|
|
73
|
-
- Scales to configured range
|
|
74
|
-
|
|
75
|
-
Final score: `(hallucinated_statements / total_statements) * scale`
|
|
76
|
-
|
|
77
|
-
### Important Considerations
|
|
78
|
-
|
|
79
|
-
- Claims not present in context are treated as hallucinations
|
|
80
|
-
|
|
81
|
-
- Subjective claims are hallucinations unless explicitly supported
|
|
82
|
-
|
|
83
|
-
- Speculative language ("might", "possibly") about facts IN context is allowed
|
|
84
|
-
|
|
85
|
-
- Speculative language about facts NOT in context is treated as hallucination
|
|
86
|
-
|
|
87
|
-
- Empty outputs result in zero hallucinations
|
|
88
|
-
|
|
89
|
-
- Numerical evaluation considers:
|
|
90
|
-
|
|
91
|
-
- Scale-appropriate precision
|
|
92
|
-
- Contextual approximations
|
|
93
|
-
- Explicit precision indicators
|
|
94
|
-
|
|
95
|
-
### Score interpretation
|
|
96
|
-
|
|
97
|
-
A hallucination score between 0 and 1:
|
|
98
|
-
|
|
99
|
-
- **0.0**: No hallucination — all claims match the context.
|
|
100
|
-
- **0.3–0.4**: Low hallucination — a few contradictions.
|
|
101
|
-
- **0.5–0.6**: Mixed hallucination — several contradictions.
|
|
102
|
-
- **0.7–0.8**: High hallucination — many contradictions.
|
|
103
|
-
- **0.9–1.0**: Complete hallucination — most or all claims contradict the context.
|
|
104
|
-
|
|
105
|
-
**Note:** The score represents the degree of hallucination - lower scores indicate better factual alignment with the provided context
|
|
106
|
-
|
|
107
|
-
## Examples
|
|
108
|
-
|
|
109
|
-
### Static Context
|
|
110
|
-
|
|
111
|
-
Use static context when you have known ground truth to compare against:
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
import { createHallucinationScorer } from "@mastra/evals/scorers/prebuilt";
|
|
115
|
-
|
|
116
|
-
const scorer = createHallucinationScorer({
|
|
117
|
-
model: "openai/gpt-4o",
|
|
118
|
-
options: {
|
|
119
|
-
context: [
|
|
120
|
-
"The first iPhone was announced on January 9, 2007.",
|
|
121
|
-
"It was released on June 29, 2007.",
|
|
122
|
-
"Steve Jobs introduced it at Macworld.",
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### Dynamic Context with getContext
|
|
129
|
-
|
|
130
|
-
Use `getContext` for live scoring scenarios where context comes from tool results:
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
import { createHallucinationScorer } from "@mastra/evals/scorers/prebuilt";
|
|
134
|
-
import { extractToolResults } from "@mastra/evals/scorers";
|
|
135
|
-
|
|
136
|
-
const scorer = createHallucinationScorer({
|
|
137
|
-
model: "openai/gpt-4o",
|
|
138
|
-
options: {
|
|
139
|
-
getContext: ({ run, step }) => {
|
|
140
|
-
// Extract tool results as context
|
|
141
|
-
const toolResults = extractToolResults(run.output);
|
|
142
|
-
return toolResults.map((t) =>
|
|
143
|
-
JSON.stringify({ tool: t.toolName, result: t.result })
|
|
144
|
-
);
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### Live Scoring with Agent
|
|
151
|
-
|
|
152
|
-
Attach the scorer to an agent for live evaluation:
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
import { Agent } from "@mastra/core/agent";
|
|
156
|
-
import { createHallucinationScorer } from "@mastra/evals/scorers/prebuilt";
|
|
157
|
-
import { extractToolResults } from "@mastra/evals/scorers";
|
|
158
|
-
|
|
159
|
-
const hallucinationScorer = createHallucinationScorer({
|
|
160
|
-
model: "openai/gpt-4o",
|
|
161
|
-
options: {
|
|
162
|
-
getContext: ({ run }) => {
|
|
163
|
-
const toolResults = extractToolResults(run.output);
|
|
164
|
-
return toolResults.map((t) =>
|
|
165
|
-
JSON.stringify({ tool: t.toolName, result: t.result })
|
|
166
|
-
);
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const agent = new Agent({
|
|
172
|
-
name: "my-agent",
|
|
173
|
-
model: "openai/gpt-4o",
|
|
174
|
-
instructions: "You are a helpful assistant.",
|
|
175
|
-
evals: {
|
|
176
|
-
scorers: [hallucinationScorer],
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Batch Evaluation with runEvals
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
import { runEvals } from "@mastra/core/evals";
|
|
185
|
-
import { createHallucinationScorer } from "@mastra/evals/scorers/prebuilt";
|
|
186
|
-
import { myAgent } from "./agent";
|
|
187
|
-
|
|
188
|
-
const scorer = createHallucinationScorer({
|
|
189
|
-
model: "openai/gpt-4o",
|
|
190
|
-
options: {
|
|
191
|
-
context: ["Known fact 1", "Known fact 2"],
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const result = await runEvals({
|
|
196
|
-
data: [
|
|
197
|
-
{ input: "Tell me about topic A" },
|
|
198
|
-
{ input: "Tell me about topic B" },
|
|
199
|
-
],
|
|
200
|
-
scorers: [scorer],
|
|
201
|
-
target: myAgent,
|
|
202
|
-
onItemComplete: ({ scorerResults }) => {
|
|
203
|
-
console.log({
|
|
204
|
-
score: scorerResults[scorer.id].score,
|
|
205
|
-
reason: scorerResults[scorer.id].reason,
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
console.log(result.scores);
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
For more details on `runEvals`, see the [runEvals reference](https://mastra.ai/reference/evals/run-evals).
|
|
214
|
-
|
|
215
|
-
To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/docs/evals/overview) guide.
|
|
216
|
-
|
|
217
|
-
## Related
|
|
218
|
-
|
|
219
|
-
- [Faithfulness Scorer](https://mastra.ai/reference/evals/faithfulness)
|
|
220
|
-
- [Answer Relevancy Scorer](https://mastra.ai/reference/evals/answer-relevancy)
|