@mastra/mcp-docs-server 0.13.6 → 0.13.7-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Flance.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Frag.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +8 -8
- package/.docs/organized/changelogs/create-mastra.md +15 -15
- package/.docs/organized/changelogs/mastra.md +43 -43
- package/.docs/organized/code-examples/a2a.md +1 -1
- package/.docs/organized/code-examples/agui.md +2 -2
- package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
- package/.docs/organized/code-examples/ai-sdk-v5.md +1 -1
- package/.docs/organized/code-examples/assistant-ui.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
- package/.docs/organized/code-examples/client-side-tools.md +2 -2
- package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
- package/.docs/organized/code-examples/fireworks-r1.md +1 -1
- package/.docs/organized/code-examples/memory-with-mem0.md +1 -1
- package/.docs/organized/code-examples/memory-with-pg.md +1 -0
- package/.docs/organized/code-examples/openapi-spec-writer.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +1 -1
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +1 -1
- package/.docs/organized/code-examples/workflow-with-memory.md +1 -1
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +1 -1
- package/.docs/organized/code-examples/workflow-with-suspend-resume.md +1 -1
- package/.docs/raw/agents/runtime-variables.mdx +1 -1
- package/.docs/raw/auth/index.mdx +24 -0
- package/.docs/raw/auth/jwt.mdx +99 -0
- package/.docs/raw/community/contributing-templates.mdx +192 -0
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +6 -5
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +84 -14
- package/.docs/raw/evals/custom-eval.mdx +12 -12
- package/.docs/raw/getting-started/installation.mdx +16 -0
- package/.docs/raw/getting-started/templates.mdx +95 -0
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/reference/agents/generate.mdx +18 -1
- package/.docs/raw/reference/agents/stream.mdx +18 -1
- package/.docs/raw/reference/auth/jwt.mdx +42 -0
- package/.docs/raw/reference/client-js/agents.mdx +3 -11
- package/.docs/raw/reference/client-js/error-handling.mdx +1 -21
- package/.docs/raw/reference/client-js/logs.mdx +2 -10
- package/.docs/raw/reference/client-js/mastra-client.mdx +141 -0
- package/.docs/raw/reference/client-js/memory.mdx +6 -18
- package/.docs/raw/reference/client-js/telemetry.mdx +1 -9
- package/.docs/raw/reference/client-js/tools.mdx +2 -10
- package/.docs/raw/reference/client-js/vectors.mdx +1 -9
- package/.docs/raw/reference/client-js/workflows-legacy.mdx +3 -11
- package/.docs/raw/reference/client-js/workflows.mdx +5 -13
- package/.docs/raw/reference/core/mastra-class.mdx +7 -1
- package/.docs/raw/reference/observability/providers/dash0.mdx +2 -2
- package/.docs/raw/reference/scorers/answer-relevancy.mdx +115 -0
- package/.docs/raw/reference/scorers/bias.mdx +127 -0
- package/.docs/raw/reference/scorers/completeness.mdx +89 -0
- package/.docs/raw/reference/scorers/content-similarity.mdx +96 -0
- package/.docs/raw/reference/scorers/custom-code-scorer.mdx +155 -0
- package/.docs/raw/reference/scorers/faithfulness.mdx +123 -0
- package/.docs/raw/reference/scorers/hallucination.mdx +135 -0
- package/.docs/raw/reference/scorers/keyword-coverage.mdx +92 -0
- package/.docs/raw/reference/scorers/llm-scorer.mdx +166 -0
- package/.docs/raw/reference/scorers/mastra-scorer.mdx +218 -0
- package/.docs/raw/reference/scorers/textual-difference.mdx +76 -0
- package/.docs/raw/reference/scorers/tone-consistency.mdx +75 -0
- package/.docs/raw/reference/scorers/toxicity.mdx +109 -0
- package/.docs/raw/reference/templates.mdx +222 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +29 -0
- package/.docs/raw/tools-mcp/overview.mdx +1 -1
- package/package.json +6 -6
- package/.docs/organized/changelogs/%40mastra%2Fagui.md +0 -302
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: MastraScorer | Scorers | Mastra Docs"
|
|
3
|
+
description: Documentation for the MastraScorer base class in Mastra, which provides the foundation for all custom and built-in scorers.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# MastraScorer
|
|
7
|
+
|
|
8
|
+
The `MastraScorer` class is the base class for all scorers in Mastra. It provides a standard `.run()` method for evaluating input/output pairs and supports multi-step scoring workflows. Most users will use `createScorer` or `createLLMScorer`, but advanced users can subclass or instantiate `MastraScorer` directly for full control.
|
|
9
|
+
|
|
10
|
+
## Constructor Options
|
|
11
|
+
|
|
12
|
+
<PropertiesTable
|
|
13
|
+
content={[
|
|
14
|
+
{
|
|
15
|
+
name: "name",
|
|
16
|
+
type: "string",
|
|
17
|
+
required: true,
|
|
18
|
+
description: "Name of the scorer.",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "description",
|
|
22
|
+
type: "string",
|
|
23
|
+
required: true,
|
|
24
|
+
description: "Description of what the scorer does.",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "extract",
|
|
28
|
+
type: "function",
|
|
29
|
+
required: false,
|
|
30
|
+
description: "Optional extraction step. See extract step signature below.",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "analyze",
|
|
34
|
+
type: "function",
|
|
35
|
+
required: true,
|
|
36
|
+
description: "Main scoring logic. See analyze step signature below.",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "reason",
|
|
40
|
+
type: "function",
|
|
41
|
+
required: false,
|
|
42
|
+
description: "Optional reason/explanation step. See reason step signature below.",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "metadata",
|
|
46
|
+
type: "object",
|
|
47
|
+
required: false,
|
|
48
|
+
description: "Optional metadata for the scorer.",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "isLLMScorer",
|
|
52
|
+
type: "boolean",
|
|
53
|
+
required: false,
|
|
54
|
+
description: "(Internal) Used to distinguish LLM scorers.",
|
|
55
|
+
},
|
|
56
|
+
]}
|
|
57
|
+
/>
|
|
58
|
+
|
|
59
|
+
## Step Function Signatures
|
|
60
|
+
|
|
61
|
+
### extract
|
|
62
|
+
<PropertiesTable
|
|
63
|
+
content={[
|
|
64
|
+
{
|
|
65
|
+
name: "input",
|
|
66
|
+
type: "Record<string, any>[]",
|
|
67
|
+
required: false,
|
|
68
|
+
description: "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.",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "output",
|
|
72
|
+
type: "Record<string, any>",
|
|
73
|
+
required: true,
|
|
74
|
+
description: "Output record provided to the scorer. For agents, this is usually the agent's response. For workflows, this is the workflow's output.",
|
|
75
|
+
},
|
|
76
|
+
]}
|
|
77
|
+
/>
|
|
78
|
+
Returns: `{ results: any }`
|
|
79
|
+
The method must return an object with a `results` property. The value of `results` will be passed to the analyze function as `extractStepResult`.
|
|
80
|
+
|
|
81
|
+
### analyze
|
|
82
|
+
<PropertiesTable
|
|
83
|
+
content={[
|
|
84
|
+
{
|
|
85
|
+
name: "input",
|
|
86
|
+
type: "Record<string, any>[]",
|
|
87
|
+
required: true,
|
|
88
|
+
description: "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.",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "output",
|
|
92
|
+
type: "Record<string, any>",
|
|
93
|
+
required: true,
|
|
94
|
+
description: "Output record provided to the scorer. For agents, this is usually the agent's response. For workflows, this is the workflow's output.",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "extractStepResult",
|
|
98
|
+
type: "object",
|
|
99
|
+
required: false,
|
|
100
|
+
description: "Result of the extract step, if defined (optional).",
|
|
101
|
+
},
|
|
102
|
+
]}
|
|
103
|
+
/>
|
|
104
|
+
Returns: `{ score: number, results?: any }`
|
|
105
|
+
The method must return an object with a `score` property (required). Optionally, it may return a `results` property. The value of `results` will be passed to the reason function as `analyzeStepResult`.
|
|
106
|
+
|
|
107
|
+
### reason
|
|
108
|
+
<PropertiesTable
|
|
109
|
+
content={[
|
|
110
|
+
{
|
|
111
|
+
name: "input",
|
|
112
|
+
type: "Record<string, any>[]",
|
|
113
|
+
required: true,
|
|
114
|
+
description: "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.",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "output",
|
|
118
|
+
type: "Record<string, any>",
|
|
119
|
+
required: true,
|
|
120
|
+
description: "Output record provided to the scorer. For agents, this is usually the agent's response. For workflows, this is the workflow's output.",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "score",
|
|
124
|
+
type: "number",
|
|
125
|
+
required: true,
|
|
126
|
+
description: "Score computed by the analyze step.",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "analyzeStepResult",
|
|
130
|
+
type: "object",
|
|
131
|
+
required: true,
|
|
132
|
+
description: "Result of the analyze step.",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "extractStepResult",
|
|
136
|
+
type: "object",
|
|
137
|
+
required: false,
|
|
138
|
+
description: "Result of the extract step, if defined (optional).",
|
|
139
|
+
},
|
|
140
|
+
]}
|
|
141
|
+
/>
|
|
142
|
+
Returns: `{ reason: string }`
|
|
143
|
+
The method must return an object with a `reason` property, which should be a string explaining the score.
|
|
144
|
+
|
|
145
|
+
All step functions can be async.
|
|
146
|
+
|
|
147
|
+
## .run() Input
|
|
148
|
+
|
|
149
|
+
<PropertiesTable
|
|
150
|
+
content={[
|
|
151
|
+
{
|
|
152
|
+
name: "runId",
|
|
153
|
+
type: "string",
|
|
154
|
+
required: false,
|
|
155
|
+
description: "The id of the run (optional).",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "input",
|
|
159
|
+
type: "Record<string, any>[]",
|
|
160
|
+
required: true,
|
|
161
|
+
description: "An array of records. This should contain user messages or the data to be evaluated.",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "output",
|
|
165
|
+
type: "Record<string, any>",
|
|
166
|
+
required: true,
|
|
167
|
+
description: "A record. This should contain the output to be evaluated.",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: "additionalContext",
|
|
171
|
+
type: "Record<string, any>",
|
|
172
|
+
required: false,
|
|
173
|
+
description: "Additional context for the run (optional).",
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "runtimeContext",
|
|
177
|
+
type: "Record<string, any>",
|
|
178
|
+
required: false,
|
|
179
|
+
description: "Runtime context for the run (optional).",
|
|
180
|
+
},
|
|
181
|
+
]}
|
|
182
|
+
/>
|
|
183
|
+
|
|
184
|
+
## .run() Returns
|
|
185
|
+
|
|
186
|
+
<PropertiesTable
|
|
187
|
+
content={[
|
|
188
|
+
{
|
|
189
|
+
name: "runId",
|
|
190
|
+
type: "string",
|
|
191
|
+
description: "The id of the run (optional).",
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "extractStepResult",
|
|
195
|
+
type: "object",
|
|
196
|
+
description: "Result of the extract step, if defined (optional).",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
name: "analyzeStepResult",
|
|
200
|
+
type: "object",
|
|
201
|
+
description: "Result of the analyze step (custom structure defined by your scorer).",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: "score",
|
|
205
|
+
type: "number",
|
|
206
|
+
description: "Score computed by your analyze function.",
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "reason",
|
|
210
|
+
type: "string",
|
|
211
|
+
description: "Reason/explanation for the score, if defined (optional).",
|
|
212
|
+
},
|
|
213
|
+
]}
|
|
214
|
+
/>
|
|
215
|
+
|
|
216
|
+
## Integration
|
|
217
|
+
|
|
218
|
+
MastraScorer instances can be used for agents and workflow steps
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Textual Difference | Scorers | Mastra Docs"
|
|
3
|
+
description: Documentation for the Textual Difference Scorer in Mastra, which measures textual differences between strings using sequence matching.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Textual Difference Scorer
|
|
7
|
+
|
|
8
|
+
The `createTextualDifferenceScorer()` function uses sequence matching to measure the textual differences between two strings. It provides detailed information about changes, including the number of operations needed to transform one text into another.
|
|
9
|
+
|
|
10
|
+
For a usage example, see the [Textual Difference Examples](/examples/scorers/textual-difference).
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
The `createTextualDifferenceScorer()` function does not take any options.
|
|
15
|
+
|
|
16
|
+
This function returns an instance of the MastraScorer class. See the [MastraScorer reference](./mastra-scorer) for details on the `.run()` method and its input/output.
|
|
17
|
+
|
|
18
|
+
## .run() Returns
|
|
19
|
+
|
|
20
|
+
<PropertiesTable
|
|
21
|
+
content={[
|
|
22
|
+
{
|
|
23
|
+
name: "runId",
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "The id of the run (optional).",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "analyzeStepResult",
|
|
29
|
+
type: "object",
|
|
30
|
+
description: "Object with difference metrics: { confidence: number, changes: number, lengthDiff: number }",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "score",
|
|
34
|
+
type: "number",
|
|
35
|
+
description: "Similarity ratio (0-1) where 1 indicates identical texts.",
|
|
36
|
+
},
|
|
37
|
+
]}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
## Scoring Details
|
|
41
|
+
|
|
42
|
+
The scorer calculates several measures:
|
|
43
|
+
|
|
44
|
+
- **Similarity Ratio**: Based on sequence matching between texts (0-1)
|
|
45
|
+
- **Changes**: Count of non-matching operations needed
|
|
46
|
+
- **Length Difference**: Normalized difference in text lengths
|
|
47
|
+
- **Confidence**: Inversely proportional to length difference
|
|
48
|
+
|
|
49
|
+
### Scoring Process
|
|
50
|
+
|
|
51
|
+
1. Analyzes textual differences:
|
|
52
|
+
- Performs sequence matching between input and output
|
|
53
|
+
- Counts the number of change operations required
|
|
54
|
+
- Measures length differences
|
|
55
|
+
2. Calculates metrics:
|
|
56
|
+
- Computes similarity ratio
|
|
57
|
+
- Determines confidence score
|
|
58
|
+
- Combines into weighted score
|
|
59
|
+
|
|
60
|
+
Final score: `(similarity_ratio * confidence) * scale`
|
|
61
|
+
|
|
62
|
+
### Score interpretation
|
|
63
|
+
|
|
64
|
+
(0 to scale, default 0-1)
|
|
65
|
+
|
|
66
|
+
- 1.0: Identical texts - no differences
|
|
67
|
+
- 0.7-0.9: Minor differences - few changes needed
|
|
68
|
+
- 0.4-0.6: Moderate differences - significant changes
|
|
69
|
+
- 0.1-0.3: Major differences - extensive changes
|
|
70
|
+
- 0.0: Completely different texts
|
|
71
|
+
|
|
72
|
+
## Related
|
|
73
|
+
|
|
74
|
+
- [Content Similarity Scorer](./content-similarity)
|
|
75
|
+
- [Completeness Scorer](./completeness)
|
|
76
|
+
- [Keyword Coverage Scorer](./keyword-coverage)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Tone Consistency | Scorers | Mastra Docs"
|
|
3
|
+
description: Documentation for the Tone Consistency Scorer in Mastra, which evaluates emotional tone and sentiment consistency in text.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tone Consistency Scorer
|
|
7
|
+
|
|
8
|
+
The `createToneScorer()` function evaluates the text's emotional tone and sentiment consistency. It can operate in two modes: comparing tone between input/output pairs or analyzing tone stability within a single text.
|
|
9
|
+
|
|
10
|
+
For a usage example, see the [Tone Consistency Examples](/examples/scorers/tone-consistency).
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
The `createToneScorer()` function does not take any options.
|
|
15
|
+
|
|
16
|
+
This function returns an instance of the MastraScorer class. See the [MastraScorer reference](./mastra-scorer) for details on the `.run()` method and its input/output.
|
|
17
|
+
|
|
18
|
+
## .run() Returns
|
|
19
|
+
|
|
20
|
+
<PropertiesTable
|
|
21
|
+
content={[
|
|
22
|
+
{
|
|
23
|
+
name: "runId",
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "The id of the run (optional).",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "analyzeStepResult",
|
|
29
|
+
type: "object",
|
|
30
|
+
description: "Object with tone metrics: { responseSentiment: number, referenceSentiment: number, difference: number } (for comparison mode) OR { avgSentiment: number, sentimentVariance: number } (for stability mode)",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "score",
|
|
34
|
+
type: "number",
|
|
35
|
+
description: "Tone consistency/stability score (0-1).",
|
|
36
|
+
},
|
|
37
|
+
]}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
## Scoring Details
|
|
41
|
+
|
|
42
|
+
The scorer evaluates sentiment consistency through tone pattern analysis and mode-specific scoring.
|
|
43
|
+
|
|
44
|
+
### Scoring Process
|
|
45
|
+
|
|
46
|
+
1. Analyzes tone patterns:
|
|
47
|
+
- Extracts sentiment features
|
|
48
|
+
- Computes sentiment scores
|
|
49
|
+
- Measures tone variations
|
|
50
|
+
2. Calculates mode-specific score:
|
|
51
|
+
**Tone Consistency** (input and output):
|
|
52
|
+
- Compares sentiment between texts
|
|
53
|
+
- Calculates sentiment difference
|
|
54
|
+
- Score = 1 - (sentiment_difference / max_difference)
|
|
55
|
+
**Tone Stability** (single input):
|
|
56
|
+
- Analyzes sentiment across sentences
|
|
57
|
+
- Calculates sentiment variance
|
|
58
|
+
- Score = 1 - (sentiment_variance / max_variance)
|
|
59
|
+
|
|
60
|
+
Final score: `mode_specific_score * scale`
|
|
61
|
+
|
|
62
|
+
### Score interpretation
|
|
63
|
+
|
|
64
|
+
(0 to scale, default 0-1)
|
|
65
|
+
|
|
66
|
+
- 1.0: Perfect tone consistency/stability
|
|
67
|
+
- 0.7-0.9: Strong consistency with minor variations
|
|
68
|
+
- 0.4-0.6: Moderate consistency with noticeable shifts
|
|
69
|
+
- 0.1-0.3: Poor consistency with major tone changes
|
|
70
|
+
- 0.0: No consistency - completely different tones
|
|
71
|
+
|
|
72
|
+
## Related
|
|
73
|
+
|
|
74
|
+
- [Content Similarity Scorer](./content-similarity)
|
|
75
|
+
- [Toxicity Scorer](./toxicity)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Toxicity | Scorers | Mastra Docs"
|
|
3
|
+
description: Documentation for the Toxicity Scorer in Mastra, which evaluates LLM outputs for racist, biased, or toxic elements.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Toxicity Scorer
|
|
7
|
+
|
|
8
|
+
The `createToxicityScorer()` function evaluates whether an LLM's output contains racist, biased, or toxic elements. It uses a judge-based system to analyze responses for various forms of toxicity including personal attacks, mockery, hate speech, dismissive statements, and threats.
|
|
9
|
+
|
|
10
|
+
For a usage example, see the [Toxicity Examples](/examples/scorers/toxicity).
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
The `createToxicityScorer()` function accepts a single options object with the following properties:
|
|
15
|
+
|
|
16
|
+
<PropertiesTable
|
|
17
|
+
content={[
|
|
18
|
+
{
|
|
19
|
+
name: "model",
|
|
20
|
+
type: "LanguageModel",
|
|
21
|
+
required: true,
|
|
22
|
+
description: "Configuration for the model used to evaluate toxicity.",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "scale",
|
|
26
|
+
type: "number",
|
|
27
|
+
required: false,
|
|
28
|
+
defaultValue: "1",
|
|
29
|
+
description: "Maximum score value (default is 1).",
|
|
30
|
+
},
|
|
31
|
+
]}
|
|
32
|
+
/>
|
|
33
|
+
|
|
34
|
+
This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](./mastra-scorer)), but the return value includes LLM-specific fields as documented below.
|
|
35
|
+
|
|
36
|
+
## .run() Returns
|
|
37
|
+
|
|
38
|
+
<PropertiesTable
|
|
39
|
+
content={[
|
|
40
|
+
{
|
|
41
|
+
name: "runId",
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "The id of the run (optional).",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "analyzeStepResult",
|
|
47
|
+
type: "object",
|
|
48
|
+
description: "Object with verdicts: { verdicts: Array<{ verdict: 'yes' | 'no', reason: string }> }",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "analyzePrompt",
|
|
52
|
+
type: "string",
|
|
53
|
+
description: "The prompt sent to the LLM for the analyze step (optional).",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "score",
|
|
57
|
+
type: "number",
|
|
58
|
+
description: "Toxicity score (0 to scale, default 0-1).",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "reason",
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Detailed explanation of the toxicity assessment.",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "reasonPrompt",
|
|
67
|
+
type: "string",
|
|
68
|
+
description: "The prompt sent to the LLM for the reason step (optional).",
|
|
69
|
+
},
|
|
70
|
+
]}
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
## Scoring Details
|
|
74
|
+
|
|
75
|
+
The scorer evaluates toxicity through multiple aspects:
|
|
76
|
+
|
|
77
|
+
- Personal attacks
|
|
78
|
+
- Mockery or sarcasm
|
|
79
|
+
- Hate speech
|
|
80
|
+
- Dismissive statements
|
|
81
|
+
- Threats or intimidation
|
|
82
|
+
|
|
83
|
+
### Scoring Process
|
|
84
|
+
|
|
85
|
+
1. Analyzes toxic elements:
|
|
86
|
+
- Identifies personal attacks and mockery
|
|
87
|
+
- Detects hate speech and threats
|
|
88
|
+
- Evaluates dismissive statements
|
|
89
|
+
- Assesses severity levels
|
|
90
|
+
2. Calculates toxicity score:
|
|
91
|
+
- Weighs detected elements
|
|
92
|
+
- Combines severity ratings
|
|
93
|
+
- Normalizes to scale
|
|
94
|
+
|
|
95
|
+
Final score: `(toxicity_weighted_sum / max_toxicity) * scale`
|
|
96
|
+
|
|
97
|
+
### Score interpretation
|
|
98
|
+
|
|
99
|
+
(0 to scale, default 0-1)
|
|
100
|
+
|
|
101
|
+
- 0.8-1.0: Severe toxicity
|
|
102
|
+
- 0.4-0.7: Moderate toxicity
|
|
103
|
+
- 0.1-0.3: Mild toxicity
|
|
104
|
+
- 0.0: No toxic elements detected
|
|
105
|
+
|
|
106
|
+
## Related
|
|
107
|
+
|
|
108
|
+
- [Tone Consistency Scorer](./tone-consistency)
|
|
109
|
+
- [Bias Scorer](./bias)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Templates Reference"
|
|
3
|
+
description: "Complete guide to creating, using, and contributing Mastra templates"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { FileTree, Tabs, Callout } from 'nextra/components'
|
|
7
|
+
|
|
8
|
+
This reference provides comprehensive information about Mastra templates, including how to use existing templates, create your own, and contribute to the community ecosystem.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
Mastra templates are pre-built project structures that demonstrate specific use cases and patterns. They provide:
|
|
13
|
+
|
|
14
|
+
- **Working examples** - Complete, functional Mastra applications
|
|
15
|
+
- **Best practices** - Proper project structure and coding conventions
|
|
16
|
+
- **Educational resources** - Learn Mastra patterns through real implementations
|
|
17
|
+
- **Quick starts** - Bootstrap projects faster than building from scratch
|
|
18
|
+
|
|
19
|
+
## Using Templates
|
|
20
|
+
|
|
21
|
+
### Installation
|
|
22
|
+
|
|
23
|
+
Install a template using the `create-mastra` command:
|
|
24
|
+
|
|
25
|
+
```bash copy
|
|
26
|
+
npx create-mastra@latest --template template-name
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This creates a complete project with all necessary code and configuration.
|
|
30
|
+
|
|
31
|
+
### Setup Process
|
|
32
|
+
|
|
33
|
+
After installation:
|
|
34
|
+
|
|
35
|
+
1. **Navigate to project directory**:
|
|
36
|
+
|
|
37
|
+
```bash copy
|
|
38
|
+
cd your-project-name
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. **Configure environment variables**:
|
|
42
|
+
|
|
43
|
+
```bash copy
|
|
44
|
+
cp .env.example .env
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Edit `.env` with required API keys as documented in the template's README.
|
|
48
|
+
|
|
49
|
+
3. **Install dependencies** (if not done automatically):
|
|
50
|
+
|
|
51
|
+
```bash copy
|
|
52
|
+
npm install
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
4. **Start development server**:
|
|
56
|
+
|
|
57
|
+
```bash copy
|
|
58
|
+
npm run dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Template Structure
|
|
62
|
+
|
|
63
|
+
All templates follow this standardized structure:
|
|
64
|
+
|
|
65
|
+
<FileTree>
|
|
66
|
+
<FileTree.Folder name="template-name" defaultOpen>
|
|
67
|
+
<FileTree.Folder name="src" defaultOpen>
|
|
68
|
+
<FileTree.Folder name="mastra" defaultOpen>
|
|
69
|
+
<FileTree.Folder name="agents">
|
|
70
|
+
<FileTree.File name="example-agent.ts" />
|
|
71
|
+
</FileTree.Folder>
|
|
72
|
+
<FileTree.Folder name="tools">
|
|
73
|
+
<FileTree.File name="custom-tool.ts" />
|
|
74
|
+
</FileTree.Folder>
|
|
75
|
+
<FileTree.Folder name="workflows">
|
|
76
|
+
<FileTree.File name="example-workflow.ts" />
|
|
77
|
+
</FileTree.Folder>
|
|
78
|
+
<FileTree.File name="index.ts" />
|
|
79
|
+
</FileTree.Folder>
|
|
80
|
+
</FileTree.Folder>
|
|
81
|
+
<FileTree.File name=".env.example" />
|
|
82
|
+
<FileTree.File name="package.json" />
|
|
83
|
+
<FileTree.File name="README.md" />
|
|
84
|
+
<FileTree.File name="tsconfig.json" />
|
|
85
|
+
</FileTree.Folder>
|
|
86
|
+
</FileTree>
|
|
87
|
+
|
|
88
|
+
## Creating Templates
|
|
89
|
+
|
|
90
|
+
### Requirements
|
|
91
|
+
|
|
92
|
+
Templates must meet these technical requirements:
|
|
93
|
+
|
|
94
|
+
#### Project Structure
|
|
95
|
+
|
|
96
|
+
- **Mastra code location**: All Mastra code must be in `src/mastra/` directory
|
|
97
|
+
- **Component organization**:
|
|
98
|
+
- Agents: `src/mastra/agents/`
|
|
99
|
+
- Tools: `src/mastra/tools/`
|
|
100
|
+
- Workflows: `src/mastra/workflows/`
|
|
101
|
+
- Main config: `src/mastra/index.ts`
|
|
102
|
+
|
|
103
|
+
#### TypeScript Configuration
|
|
104
|
+
|
|
105
|
+
Use the standard Mastra TypeScript configuration:
|
|
106
|
+
|
|
107
|
+
```json filename="tsconfig.json"
|
|
108
|
+
{
|
|
109
|
+
"compilerOptions": {
|
|
110
|
+
"target": "ES2022",
|
|
111
|
+
"module": "ES2022",
|
|
112
|
+
"moduleResolution": "bundler",
|
|
113
|
+
"esModuleInterop": true,
|
|
114
|
+
"forceConsistentCasingInFileNames": true,
|
|
115
|
+
"strict": true,
|
|
116
|
+
"skipLibCheck": true,
|
|
117
|
+
"noEmit": true,
|
|
118
|
+
"outDir": "dist"
|
|
119
|
+
},
|
|
120
|
+
"include": ["src/**/*"]
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Environment Configuration
|
|
125
|
+
|
|
126
|
+
Include a `.env.example` file with all required environment variables:
|
|
127
|
+
|
|
128
|
+
```bash filename=".env.example"
|
|
129
|
+
# OpenAI API key for LLM operations
|
|
130
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
|
131
|
+
|
|
132
|
+
# Other service API keys as needed
|
|
133
|
+
OTHER_SERVICE_API_KEY=your_api_key_here
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Code Standards
|
|
137
|
+
|
|
138
|
+
#### LLM Provider
|
|
139
|
+
|
|
140
|
+
Use OpenAI as the default provider unless demonstrating specific integrations:
|
|
141
|
+
|
|
142
|
+
```typescript filename="src/mastra/agents/example-agent.ts"
|
|
143
|
+
import { Agent } from '@mastra/core';
|
|
144
|
+
import { openai } from '@ai-sdk/openai';
|
|
145
|
+
|
|
146
|
+
const agent = new Agent({
|
|
147
|
+
name: 'example-agent',
|
|
148
|
+
model: openai('gpt-4'),
|
|
149
|
+
instructions: 'Your agent instructions here',
|
|
150
|
+
// ... other configuration
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Compatibility Requirements
|
|
155
|
+
|
|
156
|
+
Templates must be:
|
|
157
|
+
|
|
158
|
+
- **Single projects** - Not monorepos with multiple applications
|
|
159
|
+
- **Framework-free** - No Next.js, Express, or other web framework boilerplate
|
|
160
|
+
- **Mastra-focused** - Demonstrate Mastra functionality without additional layers
|
|
161
|
+
- **Mergeable** - Structure code for easy integration into existing projects
|
|
162
|
+
- **Node.js compatible** - Support Node.js 18 and higher
|
|
163
|
+
- **ESM modules** - Use ES modules (`"type": "module"` in package.json)
|
|
164
|
+
|
|
165
|
+
### Documentation Requirements
|
|
166
|
+
|
|
167
|
+
#### README Structure
|
|
168
|
+
|
|
169
|
+
Every template must include a comprehensive README:
|
|
170
|
+
|
|
171
|
+
```markdown filename="README.md"
|
|
172
|
+
# Template Name
|
|
173
|
+
|
|
174
|
+
Brief description of what the template demonstrates.
|
|
175
|
+
|
|
176
|
+
## Overview
|
|
177
|
+
|
|
178
|
+
Detailed explanation of the template's functionality and use case.
|
|
179
|
+
|
|
180
|
+
## Setup
|
|
181
|
+
|
|
182
|
+
1. Copy `.env.example` to `.env` and fill in your API keys
|
|
183
|
+
2. Install dependencies: `npm install`
|
|
184
|
+
3. Run the project: `npm run dev`
|
|
185
|
+
|
|
186
|
+
## Environment Variables
|
|
187
|
+
|
|
188
|
+
- `OPENAI_API_KEY`: Your OpenAI API key. Get one at [OpenAI Platform](https://platform.openai.com/api-keys)
|
|
189
|
+
- `OTHER_API_KEY`: Description of what this key is for
|
|
190
|
+
|
|
191
|
+
## Usage
|
|
192
|
+
|
|
193
|
+
Instructions on how to use the template and examples of expected behavior.
|
|
194
|
+
|
|
195
|
+
## Customization
|
|
196
|
+
|
|
197
|
+
Guidelines for modifying the template for different use cases.
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### Code Comments
|
|
201
|
+
|
|
202
|
+
Include clear comments explaining:
|
|
203
|
+
|
|
204
|
+
- Complex logic or algorithms
|
|
205
|
+
- API integrations and their purpose
|
|
206
|
+
- Configuration options and their effects
|
|
207
|
+
- Example usage patterns
|
|
208
|
+
|
|
209
|
+
### Quality Standards
|
|
210
|
+
|
|
211
|
+
Templates must demonstrate:
|
|
212
|
+
|
|
213
|
+
- **Code quality** - Clean, well-commented, maintainable code
|
|
214
|
+
- **Error handling** - Proper handling for external APIs and user inputs
|
|
215
|
+
- **Type safety** - Full TypeScript typing with Zod validation
|
|
216
|
+
- **Testing** - Verified functionality with fresh installations
|
|
217
|
+
|
|
218
|
+
For information on contributing your own templates to the Mastra ecosystem, see the [Contributing Templates](/docs/community/contributing-templates) guide in the community section.
|
|
219
|
+
|
|
220
|
+
<Callout type="info">
|
|
221
|
+
Templates provide an excellent way to learn Mastra patterns and accelerate development. Contributing templates helps the entire community build better AI applications.
|
|
222
|
+
</Callout>
|