@mastra/evals 1.10.5-alpha.0 → 1.10.6-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-evals-built-in-scorers.md +2 -2
- package/dist/docs/references/reference-evals-answer-relevancy.md +4 -2
- package/dist/docs/references/reference-evals-answer-similarity.md +1 -1
- package/dist/docs/references/reference-evals-bias.md +3 -1
- package/dist/docs/references/reference-evals-content-similarity.md +1 -1
- package/dist/docs/references/reference-evals-context-recall.md +1 -1
- package/dist/docs/references/reference-evals-context-relevance.md +6 -6
- package/dist/docs/references/reference-evals-hallucination.md +7 -8
- package/dist/docs/references/reference-evals-keyword-coverage.md +4 -4
- package/dist/docs/references/reference-evals-noise-sensitivity.md +6 -6
- package/dist/docs/references/reference-evals-prompt-alignment.md +1 -1
- package/dist/docs/references/reference-evals-scorer-utils.md +8 -8
- package/dist/docs/references/reference-evals-tone-consistency.md +23 -24
- package/dist/docs/references/reference-evals-tool-call-accuracy.md +19 -15
- package/dist/docs/references/reference-evals-toxicity.md +3 -1
- package/dist/scorers/code/trajectory/index.d.ts +2 -2
- package/dist/scorers/llm/trajectory/index.d.ts +1 -1
- package/dist/scorers/prebuilt/index.cjs +3 -3
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +3 -3
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/dist/scorers/utils.cjs +1 -1
- package/dist/scorers/utils.cjs.map +1 -1
- package/dist/scorers/utils.d.ts +1 -1
- package/dist/scorers/utils.js +1 -1
- package/dist/scorers/utils.js.map +1 -1
- package/package.json +7 -7
package/dist/docs/SKILL.md
CHANGED
|
@@ -24,7 +24,7 @@ These scorers evaluate how correct, truthful, and complete your agent's answers
|
|
|
24
24
|
- [`tool-call-accuracy`](https://mastra.ai/reference/evals/tool-call-accuracy): Evaluates whether the LLM selects the correct tool from available options (`0-1`, higher is better)
|
|
25
25
|
- [`trajectory-accuracy`](https://mastra.ai/reference/evals/trajectory-accuracy): Evaluates the expected action sequence for all span types. Covered spans include tool and model activity plus workflow steps (`0-1`, higher is better)
|
|
26
26
|
- [`prompt-alignment`](https://mastra.ai/reference/evals/prompt-alignment): Measures how well agent responses align with user prompt intent, requirements, completeness, and format (`0-1`, higher is better)
|
|
27
|
-
- [`multi-turn-judge`](https://mastra.ai/reference/evals/multi-turn-judge): Grades every assistant turn of a [multi-turn conversation](https://mastra.ai/docs/evals/multi-turn) against a plain-English criterion (`0` or `1`)
|
|
27
|
+
- [`multi-turn-judge`](https://mastra.ai/reference/evals/multi-turn-judge): Grades every assistant turn of a [multi-turn conversation](https://mastra.ai/docs/evals/multi-turn) against a plain-English criterion (`0` or `scale`, default `1`)
|
|
28
28
|
|
|
29
29
|
### Context quality
|
|
30
30
|
|
|
@@ -58,7 +58,7 @@ Zero-LLM micro-scorers for fast, deterministic assertions. See the [Quick Checks
|
|
|
58
58
|
|
|
59
59
|
- [`checks.includes`](https://mastra.ai/reference/evals/checks): Scores 1 if output contains a substring (`0` or `1`)
|
|
60
60
|
- [`checks.excludes`](https://mastra.ai/reference/evals/checks): Scores 1 if output doesn't contain a substring (`0` or `1`)
|
|
61
|
-
- [`checks.equals`](https://mastra.ai/reference/evals/checks): Scores 1 if output
|
|
61
|
+
- [`checks.equals`](https://mastra.ai/reference/evals/checks): Scores 1 if output matches a string, ignoring case by default (`0` or `1`)
|
|
62
62
|
- [`checks.matches`](https://mastra.ai/reference/evals/checks): Scores 1 if output matches a regex (`0` or `1`)
|
|
63
63
|
- [`checks.similarity`](https://mastra.ai/reference/evals/checks): String similarity via Dice coefficient (`0-1`, or binary with threshold)
|
|
64
64
|
- [`checks.calledTool`](https://mastra.ai/reference/evals/checks): Scores 1 if a tool was called at least N times (`0` or `1`)
|
|
@@ -10,9 +10,11 @@ The `createAnswerRelevancyScorer()` function accepts a single options object wit
|
|
|
10
10
|
|
|
11
11
|
**model** (`LanguageModel`): Configuration for the model used to evaluate relevancy.
|
|
12
12
|
|
|
13
|
-
**
|
|
13
|
+
**options** (`Record<'uncertaintyWeight' | 'scale', number>`): Configuration options for the scorer. (Default: `{ uncertaintyWeight: 0.3, scale: 1 }`)
|
|
14
14
|
|
|
15
|
-
**
|
|
15
|
+
**options.uncertaintyWeight** (`number`): Weight given to 'unsure' verdicts in scoring (0-1).
|
|
16
|
+
|
|
17
|
+
**options.scale** (`number`): Maximum score value.
|
|
16
18
|
|
|
17
19
|
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
20
|
|
|
@@ -26,7 +26,7 @@ The `createAnswerSimilarityScorer()` function creates a scorer that evaluates ho
|
|
|
26
26
|
|
|
27
27
|
**options.scale** (`number`): Score scaling factor.
|
|
28
28
|
|
|
29
|
-
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
|
|
29
|
+
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 expects ground truth to be provided in the run object. When `options.requireGroundTruth` is `true` (the default), a run without ground truth throws an error. Set it to `false` to score runs without ground truth as 0.
|
|
30
30
|
|
|
31
31
|
## `.run()` returns
|
|
32
32
|
|
|
@@ -10,7 +10,9 @@ The `createBiasScorer()` function accepts a single options object with the follo
|
|
|
10
10
|
|
|
11
11
|
**model** (`LanguageModel`): Configuration for the model used to evaluate bias.
|
|
12
12
|
|
|
13
|
-
**
|
|
13
|
+
**options** (`BiasMetricOptions`): Configuration options for the scorer.
|
|
14
|
+
|
|
15
|
+
**options.scale** (`number`): Maximum score value.
|
|
14
16
|
|
|
15
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.
|
|
16
18
|
|
|
@@ -44,7 +44,7 @@ The scorer evaluates textual similarity through character-level matching and con
|
|
|
44
44
|
- Considers relative positions
|
|
45
45
|
- Accounts for length differences
|
|
46
46
|
|
|
47
|
-
Final score: `similarity_value
|
|
47
|
+
Final score: `similarity_value` (0-1, returned directly from the string-similarity comparison)
|
|
48
48
|
|
|
49
49
|
## Example
|
|
50
50
|
|
|
@@ -30,7 +30,7 @@ Use when running evaluations against curated test sets:
|
|
|
30
30
|
|
|
31
31
|
**options** (`ContextRecallMetricOptions`): Configuration options for the scorer
|
|
32
32
|
|
|
33
|
-
Either `context` or `contextExtractor` must be provided. When both are provided, `contextExtractor` is used only if the run input and output are agent-shaped (`MastraDBMessage[]
|
|
33
|
+
Either `context` or `contextExtractor` must be provided. When both are provided, `contextExtractor` is used only if the run input and output are agent-shaped: the input must be an agent run-input object (`{ inputMessages, rememberedMessages, systemMessages, taggedSystemMessages }`) and the output must be a `MastraDBMessage[]`. Otherwise the scorer falls back to `context`.
|
|
34
34
|
|
|
35
35
|
## `.run()` returns
|
|
36
36
|
|
|
@@ -119,7 +119,7 @@ Use results to improve your system:
|
|
|
119
119
|
Control how penalties are applied for unused and missing context:
|
|
120
120
|
|
|
121
121
|
```typescript
|
|
122
|
-
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
122
|
+
import { createContextRelevanceScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
123
123
|
|
|
124
124
|
// Stricter penalty configuration
|
|
125
125
|
const strictScorer = createContextRelevanceScorerLLM({
|
|
@@ -249,7 +249,7 @@ const scorer = createContextRelevanceScorerLLM({
|
|
|
249
249
|
This example shows excellent context relevance where all context directly supports the response:
|
|
250
250
|
|
|
251
251
|
```typescript
|
|
252
|
-
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
252
|
+
import { createContextRelevanceScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
253
253
|
|
|
254
254
|
const scorer = createContextRelevanceScorerLLM({
|
|
255
255
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -296,7 +296,7 @@ console.log(result)
|
|
|
296
296
|
This example shows moderate relevance with some context being irrelevant or unused:
|
|
297
297
|
|
|
298
298
|
```typescript
|
|
299
|
-
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
299
|
+
import { createContextRelevanceScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
300
300
|
|
|
301
301
|
const scorer = createContextRelevanceScorerLLM({
|
|
302
302
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -385,7 +385,7 @@ console.log(customResult)
|
|
|
385
385
|
This example shows poor context relevance with mostly irrelevant information:
|
|
386
386
|
|
|
387
387
|
```typescript
|
|
388
|
-
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
388
|
+
import { createContextRelevanceScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
389
389
|
|
|
390
390
|
const scorer = createContextRelevanceScorerLLM({
|
|
391
391
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -433,7 +433,7 @@ console.log(result)
|
|
|
433
433
|
Extract context at runtime based on the run input:
|
|
434
434
|
|
|
435
435
|
```typescript
|
|
436
|
-
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
436
|
+
import { createContextRelevanceScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
437
437
|
|
|
438
438
|
const scorer = createContextRelevanceScorerLLM({
|
|
439
439
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -476,7 +476,7 @@ const scorer = createContextRelevanceScorerLLM({
|
|
|
476
476
|
Integrate with RAG pipelines to evaluate retrieved context:
|
|
477
477
|
|
|
478
478
|
```typescript
|
|
479
|
-
import { createContextRelevanceScorerLLM } from '@mastra/evals'
|
|
479
|
+
import { createContextRelevanceScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
480
480
|
|
|
481
481
|
const scorer = createContextRelevanceScorerLLM({
|
|
482
482
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -46,15 +46,14 @@ The scorer evaluates hallucination through contradiction detection and unsupport
|
|
|
46
46
|
|
|
47
47
|
### Scoring Process
|
|
48
48
|
|
|
49
|
-
1.
|
|
49
|
+
1. Extracts claims from the output:
|
|
50
50
|
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
- Maps statement relationships
|
|
51
|
+
- Breaks the agent's response into factual claims
|
|
52
|
+
- Includes numerical values and dates
|
|
54
53
|
|
|
55
|
-
2.
|
|
54
|
+
2. Checks each claim against the provided context:
|
|
56
55
|
|
|
57
|
-
- Compares
|
|
56
|
+
- Compares the claim with the context
|
|
58
57
|
- Marks direct conflicts as hallucinations
|
|
59
58
|
- Identifies unsupported claims as hallucinations
|
|
60
59
|
- Evaluates numerical accuracy
|
|
@@ -125,7 +124,7 @@ Use `getContext` for live scoring scenarios where context comes from tool result
|
|
|
125
124
|
|
|
126
125
|
```typescript
|
|
127
126
|
import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
128
|
-
import { extractToolResults } from '@mastra/evals/scorers'
|
|
127
|
+
import { extractToolResults } from '@mastra/evals/scorers/utils'
|
|
129
128
|
|
|
130
129
|
const scorer = createHallucinationScorer({
|
|
131
130
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -146,7 +145,7 @@ Attach the scorer to an agent for live evaluation:
|
|
|
146
145
|
```typescript
|
|
147
146
|
import { Agent } from '@mastra/core/agent'
|
|
148
147
|
import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt'
|
|
149
|
-
import { extractToolResults } from '@mastra/evals/scorers'
|
|
148
|
+
import { extractToolResults } from '@mastra/evals/scorers/utils'
|
|
150
149
|
|
|
151
150
|
const hallucinationScorer = createHallucinationScorer({
|
|
152
151
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -18,7 +18,7 @@ This function returns an instance of the MastraScorer class. See the [MastraScor
|
|
|
18
18
|
|
|
19
19
|
**preprocessStepResult** (`object`): Object with extracted keywords: { referenceKeywords: Set\<string>, responseKeywords: Set\<string> }
|
|
20
20
|
|
|
21
|
-
**analyzeStepResult** (`object`): Object with keyword coverage: {
|
|
21
|
+
**analyzeStepResult** (`object`): Object with keyword coverage: { totalKeywordsLength: number, matchedKeywordsLength: number }
|
|
22
22
|
|
|
23
23
|
**score** (`number`): Coverage score (0-1) representing the proportion of matched keywords.
|
|
24
24
|
|
|
@@ -27,13 +27,13 @@ This function returns an instance of the MastraScorer class. See the [MastraScor
|
|
|
27
27
|
```typescript
|
|
28
28
|
{
|
|
29
29
|
runId: string,
|
|
30
|
-
|
|
30
|
+
preprocessStepResult: {
|
|
31
31
|
referenceKeywords: Set<string>,
|
|
32
32
|
responseKeywords: Set<string>
|
|
33
33
|
},
|
|
34
34
|
analyzeStepResult: {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
totalKeywordsLength: number,
|
|
36
|
+
matchedKeywordsLength: number
|
|
37
37
|
},
|
|
38
38
|
score: number
|
|
39
39
|
}
|
|
@@ -292,7 +292,7 @@ describe('Agent Noise Resistance CI Tests', () => {
|
|
|
292
292
|
This example shows an agent that completely resists misinformation in a test scenario:
|
|
293
293
|
|
|
294
294
|
```typescript
|
|
295
|
-
import { createNoiseSensitivityScorerLLM } from '@mastra/evals'
|
|
295
|
+
import { createNoiseSensitivityScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
296
296
|
|
|
297
297
|
const scorer = createNoiseSensitivityScorerLLM({
|
|
298
298
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -383,7 +383,7 @@ console.log(result)
|
|
|
383
383
|
This example shows an agent that incorporates misinformation:
|
|
384
384
|
|
|
385
385
|
```typescript
|
|
386
|
-
import { createNoiseSensitivityScorerLLM } from '@mastra/evals'
|
|
386
|
+
import { createNoiseSensitivityScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
387
387
|
|
|
388
388
|
const scorer = createNoiseSensitivityScorerLLM({
|
|
389
389
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -428,7 +428,7 @@ console.log(result)
|
|
|
428
428
|
Adjust scoring sensitivity for your specific use case:
|
|
429
429
|
|
|
430
430
|
```typescript
|
|
431
|
-
import { createNoiseSensitivityScorerLLM } from '@mastra/evals'
|
|
431
|
+
import { createNoiseSensitivityScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
432
432
|
|
|
433
433
|
// Lenient scoring - more forgiving of minor issues
|
|
434
434
|
const lenientScorer = createNoiseSensitivityScorerLLM({
|
|
@@ -477,7 +477,7 @@ const strictScorer = createNoiseSensitivityScorerLLM({
|
|
|
477
477
|
Create detailed test suites to evaluate agent performance across noise categories in your CI pipeline:
|
|
478
478
|
|
|
479
479
|
```typescript
|
|
480
|
-
import { createNoiseSensitivityScorerLLM } from '@mastra/evals'
|
|
480
|
+
import { createNoiseSensitivityScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
481
481
|
|
|
482
482
|
const noiseTestCases = [
|
|
483
483
|
{
|
|
@@ -546,7 +546,7 @@ async function evaluateNoiseResistance(testCases) {
|
|
|
546
546
|
Use in your CI pipeline to compare noise resistance across different models before deployment:
|
|
547
547
|
|
|
548
548
|
```typescript
|
|
549
|
-
import { createNoiseSensitivityScorerLLM } from '@mastra/evals'
|
|
549
|
+
import { createNoiseSensitivityScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
550
550
|
|
|
551
551
|
async function compareModelRobustness() {
|
|
552
552
|
const models = [
|
|
@@ -599,7 +599,7 @@ function getGrade(score) {
|
|
|
599
599
|
Include noise sensitivity tests in your security test suite to validate prompt injection resistance:
|
|
600
600
|
|
|
601
601
|
```typescript
|
|
602
|
-
import { createNoiseSensitivityScorerLLM } from '@mastra/evals'
|
|
602
|
+
import { createNoiseSensitivityScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
603
603
|
|
|
604
604
|
const scorer = createNoiseSensitivityScorerLLM({
|
|
605
605
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -308,7 +308,7 @@ for (const agent of agents) {
|
|
|
308
308
|
### Basic Configuration
|
|
309
309
|
|
|
310
310
|
```typescript
|
|
311
|
-
import { createPromptAlignmentScorerLLM } from '@mastra/evals'
|
|
311
|
+
import { createPromptAlignmentScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
312
312
|
|
|
313
313
|
const scorer = createPromptAlignmentScorerLLM({
|
|
314
314
|
model: 'openai/gpt-5.6-sol',
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
|
|
38
38
|
### `getAssistantMessageFromRunOutput`
|
|
39
39
|
|
|
40
|
-
Extracts the text content from the
|
|
40
|
+
Extracts the text content from the last assistant message that contains text in the run output. Trailing assistant messages without text (for example, tool-call-only messages) are skipped.
|
|
41
41
|
|
|
42
42
|
```typescript
|
|
43
43
|
const scorer = createScorer({
|
|
@@ -298,7 +298,7 @@ const trajectory = extractTrajectory(agentOutputMessages)
|
|
|
298
298
|
// trajectory.rawOutput — the original MastraDBMessage[] array
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
-
**Returns:** `Trajectory`: Contains `steps: TrajectoryStep[]
|
|
301
|
+
**Returns:** `Trajectory`: Contains `steps: TrajectoryStep[]` and `rawOutput`.
|
|
302
302
|
|
|
303
303
|
### `extractWorkflowTrajectory`
|
|
304
304
|
|
|
@@ -352,12 +352,12 @@ const trajectory = extractTrajectoryFromTrace(traceData.spans, rootSpanId)
|
|
|
352
352
|
| `AGENT_RUN` | `agent_run` | `agentId` (from entity ID) |
|
|
353
353
|
| `WORKFLOW_RUN` | `workflow_run` | `workflowId` (from entity ID) |
|
|
354
354
|
| `WORKFLOW_STEP` | `workflow_step` | `output` |
|
|
355
|
-
| `WORKFLOW_CONDITIONAL` | `workflow_conditional` | `
|
|
356
|
-
| `WORKFLOW_PARALLEL` | `workflow_parallel` | `
|
|
357
|
-
| `WORKFLOW_LOOP` | `workflow_loop` | `
|
|
358
|
-
| `WORKFLOW_SLEEP` | `workflow_sleep` | `
|
|
359
|
-
| `WORKFLOW_WAIT_EVENT` | `workflow_wait_event` | `
|
|
360
|
-
| `PROCESSOR_RUN` | `processor_run` | `
|
|
355
|
+
| `WORKFLOW_CONDITIONAL` | `workflow_conditional` | Base fields only (`name`, `durationMs`, `metadata`) |
|
|
356
|
+
| `WORKFLOW_PARALLEL` | `workflow_parallel` | Base fields only (`name`, `durationMs`, `metadata`) |
|
|
357
|
+
| `WORKFLOW_LOOP` | `workflow_loop` | Base fields only (`name`, `durationMs`, `metadata`) |
|
|
358
|
+
| `WORKFLOW_SLEEP` | `workflow_sleep` | Base fields only (`name`, `durationMs`, `metadata`) |
|
|
359
|
+
| `WORKFLOW_WAIT_EVENT` | `workflow_wait_event` | Base fields only (`name`, `durationMs`, `metadata`) |
|
|
360
|
+
| `PROCESSOR_RUN` | `processor_run` | Base fields only (`name`, `durationMs`, `metadata`) |
|
|
361
361
|
|
|
362
362
|
Spans with types `GENERIC`, `MODEL_STEP`, `MODEL_CHUNK`, and `WORKFLOW_CONDITIONAL_EVAL` are skipped as noise.
|
|
363
363
|
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
# Tone consistency scorer
|
|
6
6
|
|
|
7
|
-
The `createToneScorer()` function evaluates the text's emotional tone and sentiment consistency. It can operate in two modes: comparing
|
|
7
|
+
The `createToneScorer()` function evaluates the text's emotional tone and sentiment consistency. It can operate in two modes: comparing the agent output's sentiment against a configured `referenceTone`, or analyzing tone stability across the sentences of the agent output.
|
|
8
8
|
|
|
9
9
|
## Parameters
|
|
10
10
|
|
|
11
|
-
The `createToneScorer()` function
|
|
11
|
+
The `createToneScorer()` function accepts an optional config object with the following properties:
|
|
12
|
+
|
|
13
|
+
**referenceTone** (`string`): Reference text whose sentiment the agent output is compared against. When omitted, the scorer measures sentiment stability across the output's sentences instead.
|
|
12
14
|
|
|
13
15
|
This function returns an instance of the MastraScorer class. See the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer) for details on the `.run()` method and its input/output.
|
|
14
16
|
|
|
@@ -16,7 +18,7 @@ This function returns an instance of the MastraScorer class. See the [MastraScor
|
|
|
16
18
|
|
|
17
19
|
**runId** (`string`): The id of the run (optional).
|
|
18
20
|
|
|
19
|
-
**
|
|
21
|
+
**preprocessStepResult** (`object`): Object with tone metrics: { score: number, responseSentiment: number, referenceSentiment: number, difference: number } (for comparison mode) OR { score: number, avgSentiment: number, sentimentVariance: number } (for stability mode)
|
|
20
22
|
|
|
21
23
|
**score** (`number`): Tone consistency/stability score (0-1).
|
|
22
24
|
|
|
@@ -25,7 +27,8 @@ This function returns an instance of the MastraScorer class. See the [MastraScor
|
|
|
25
27
|
```typescript
|
|
26
28
|
{
|
|
27
29
|
runId: string,
|
|
28
|
-
|
|
30
|
+
preprocessStepResult: {
|
|
31
|
+
score: number,
|
|
29
32
|
responseSentiment?: number,
|
|
30
33
|
referenceSentiment?: number,
|
|
31
34
|
difference?: number,
|
|
@@ -48,20 +51,20 @@ The scorer evaluates sentiment consistency through tone pattern analysis and mod
|
|
|
48
51
|
- Computes sentiment scores
|
|
49
52
|
- Measures tone variations
|
|
50
53
|
|
|
51
|
-
2. Calculates mode-specific score: **Tone Consistency** (
|
|
54
|
+
2. Calculates mode-specific score: **Tone Consistency** (`referenceTone` set):
|
|
52
55
|
|
|
53
|
-
- Compares sentiment
|
|
54
|
-
- Calculates sentiment difference
|
|
55
|
-
- Score = 1 -
|
|
56
|
-
- Analyzes sentiment across sentences
|
|
56
|
+
- Compares the output's sentiment with the `referenceTone` sentiment
|
|
57
|
+
- Calculates the absolute sentiment difference
|
|
58
|
+
- Score = max(0, 1 - sentiment\_difference) **Tone Stability** (no `referenceTone`):
|
|
59
|
+
- Analyzes sentiment across the output's sentences
|
|
57
60
|
- Calculates sentiment variance
|
|
58
|
-
- Score = 1 -
|
|
61
|
+
- Score = max(0, 1 - sentiment\_variance)
|
|
59
62
|
|
|
60
|
-
Final score: `mode_specific_score
|
|
63
|
+
Final score: `mode_specific_score`
|
|
61
64
|
|
|
62
65
|
### Score interpretation
|
|
63
66
|
|
|
64
|
-
(0
|
|
67
|
+
(0-1)
|
|
65
68
|
|
|
66
69
|
- 1.0: Perfect tone consistency/stability
|
|
67
70
|
- 0.7-0.9: Strong consistency with minor variations
|
|
@@ -69,37 +72,33 @@ Final score: `mode_specific_score * scale`
|
|
|
69
72
|
- 0.1-0.3: Poor consistency with major tone changes
|
|
70
73
|
- 0.0: No consistency - completely different tones
|
|
71
74
|
|
|
72
|
-
### `
|
|
75
|
+
### `preprocessStepResult`
|
|
73
76
|
|
|
74
77
|
Object with tone metrics:
|
|
75
78
|
|
|
76
79
|
- **responseSentiment**: Sentiment score for the response (comparison mode).
|
|
77
|
-
- **referenceSentiment**: Sentiment score for the
|
|
80
|
+
- **referenceSentiment**: Sentiment score for the `referenceTone` (comparison mode).
|
|
78
81
|
- **difference**: Absolute difference between sentiment scores (comparison mode).
|
|
79
82
|
- **avgSentiment**: Average sentiment across sentences (stability mode).
|
|
80
83
|
- **sentimentVariance**: Variance of sentiment across sentences (stability mode).
|
|
81
84
|
|
|
82
85
|
## Example
|
|
83
86
|
|
|
84
|
-
Evaluate
|
|
87
|
+
Evaluate whether agent responses match a positive reference tone:
|
|
85
88
|
|
|
86
89
|
```typescript
|
|
87
90
|
import { runEvals } from '@mastra/core/evals'
|
|
88
91
|
import { createToneScorer } from '@mastra/evals/scorers/prebuilt'
|
|
89
92
|
import { myAgent } from './agent'
|
|
90
93
|
|
|
91
|
-
const scorer = createToneScorer(
|
|
94
|
+
const scorer = createToneScorer({
|
|
95
|
+
referenceTone: 'We are happy to help and glad you had a great experience!',
|
|
96
|
+
})
|
|
92
97
|
|
|
93
98
|
const result = await runEvals({
|
|
94
99
|
data: [
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
groundTruth: 'The service was excellent and exceeded expectations!',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
input: 'Tell me about the customer support',
|
|
101
|
-
groundTruth: 'The support team was friendly and very helpful.',
|
|
102
|
-
},
|
|
100
|
+
{ input: 'How was your experience with our service?' },
|
|
101
|
+
{ input: 'Tell me about the customer support' },
|
|
103
102
|
],
|
|
104
103
|
scorers: [scorer],
|
|
105
104
|
target: myAgent,
|
|
@@ -94,7 +94,7 @@ const strictOrderScorer = createCodeScorer({
|
|
|
94
94
|
{
|
|
95
95
|
runId: string,
|
|
96
96
|
preprocessStepResult: {
|
|
97
|
-
expectedTool
|
|
97
|
+
expectedTool?: string, // undefined when only expectedToolOrder is configured
|
|
98
98
|
actualTools: string[],
|
|
99
99
|
strictMode: boolean,
|
|
100
100
|
expectedToolOrder?: string[],
|
|
@@ -283,7 +283,7 @@ The `createToolCallAccuracyScorerLLM()` function from `@mastra/evals/scorers/pre
|
|
|
283
283
|
|
|
284
284
|
**model** (`MastraModelConfig`): The LLM model to use for evaluating tool appropriateness
|
|
285
285
|
|
|
286
|
-
**availableTools** (`
|
|
286
|
+
**availableTools** (`Tool[]`): Tools available to the agent, for example created with createTool(). Each tool's id and description are passed to the judge as context.
|
|
287
287
|
|
|
288
288
|
### Features
|
|
289
289
|
|
|
@@ -315,8 +315,8 @@ The LLM-based scorer provides:
|
|
|
315
315
|
const basicLLMScorer = createLLMScorer({
|
|
316
316
|
model: 'openai/gpt-5.6-sol',
|
|
317
317
|
availableTools: [
|
|
318
|
-
{
|
|
319
|
-
{
|
|
318
|
+
createTool({ id: 'tool1', description: 'Description 1' }),
|
|
319
|
+
createTool({ id: 'tool2', description: 'Description 2' })
|
|
320
320
|
]
|
|
321
321
|
});
|
|
322
322
|
|
|
@@ -352,21 +352,24 @@ The LLM-based scorer uses AI to evaluate whether tool selections are appropriate
|
|
|
352
352
|
### Basic LLM evaluation
|
|
353
353
|
|
|
354
354
|
```typescript
|
|
355
|
+
import { createTool } from '@mastra/core/tools'
|
|
356
|
+
import { createToolCallAccuracyScorerLLM } from '@mastra/evals/scorers/prebuilt'
|
|
357
|
+
|
|
355
358
|
const llmScorer = createToolCallAccuracyScorerLLM({
|
|
356
359
|
model: 'openai/gpt-5.6-sol',
|
|
357
360
|
availableTools: [
|
|
358
|
-
{
|
|
359
|
-
|
|
361
|
+
createTool({
|
|
362
|
+
id: 'weather-tool',
|
|
360
363
|
description: 'Get current weather information for any location',
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
|
|
364
|
+
}),
|
|
365
|
+
createTool({
|
|
366
|
+
id: 'calendar-tool',
|
|
364
367
|
description: 'Check calendar events and scheduling',
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
|
|
368
|
+
}),
|
|
369
|
+
createTool({
|
|
370
|
+
id: 'search-tool',
|
|
368
371
|
description: 'Search the web for general information',
|
|
369
|
-
},
|
|
372
|
+
}),
|
|
370
373
|
],
|
|
371
374
|
})
|
|
372
375
|
|
|
@@ -474,6 +477,7 @@ console.log(result.reason); // "The agent appropriately asked for clarification
|
|
|
474
477
|
Here's an example using both scorers on the same data:
|
|
475
478
|
|
|
476
479
|
```typescript
|
|
480
|
+
import { createTool } from '@mastra/core/tools'
|
|
477
481
|
import {
|
|
478
482
|
createToolCallAccuracyScorerCode as createCodeScorer,
|
|
479
483
|
createToolCallAccuracyScorerLLM as createLLMScorer,
|
|
@@ -488,8 +492,8 @@ const codeScorer = createCodeScorer({
|
|
|
488
492
|
const llmScorer = createLLMScorer({
|
|
489
493
|
model: 'openai/gpt-5.6-sol',
|
|
490
494
|
availableTools: [
|
|
491
|
-
{
|
|
492
|
-
{
|
|
495
|
+
createTool({ id: 'weather-tool', description: 'Get weather information' }),
|
|
496
|
+
createTool({ id: 'search-tool', description: 'Search the web' }),
|
|
493
497
|
],
|
|
494
498
|
})
|
|
495
499
|
|
|
@@ -12,7 +12,9 @@ The `createToxicityScorer()` function accepts a single options object with the f
|
|
|
12
12
|
|
|
13
13
|
**model** (`LanguageModel`): Configuration for the model used to evaluate toxicity.
|
|
14
14
|
|
|
15
|
-
**
|
|
15
|
+
**options** (`ToxicityMetricOptions`): Configuration options.
|
|
16
|
+
|
|
17
|
+
**options.scale** (`number`): Maximum score value.
|
|
16
18
|
|
|
17
19
|
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
20
|
|
|
@@ -23,7 +23,7 @@ interface TrajectoryAccuracyScorerCodeOptions {
|
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```ts
|
|
26
|
-
* import { createTrajectoryAccuracyScorerCode } from '@mastra/evals/scorers';
|
|
26
|
+
* import { createTrajectoryAccuracyScorerCode } from '@mastra/evals/scorers/prebuilt';
|
|
27
27
|
*
|
|
28
28
|
* const scorer = createTrajectoryAccuracyScorerCode({
|
|
29
29
|
* expectedTrajectory: {
|
|
@@ -135,7 +135,7 @@ export interface TrajectoryScorerCodeOptions {
|
|
|
135
135
|
*
|
|
136
136
|
* @example
|
|
137
137
|
* ```ts
|
|
138
|
-
* import { createTrajectoryScorerCode } from '@mastra/evals/scorers';
|
|
138
|
+
* import { createTrajectoryScorerCode } from '@mastra/evals/scorers/prebuilt';
|
|
139
139
|
*
|
|
140
140
|
* const scorer = createTrajectoryScorerCode({
|
|
141
141
|
* defaults: {
|
|
@@ -20,7 +20,7 @@ export interface TrajectoryAccuracyLLMOptions {
|
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* ```ts
|
|
23
|
-
* import { createTrajectoryAccuracyScorerLLM } from '@mastra/evals/scorers';
|
|
23
|
+
* import { createTrajectoryAccuracyScorerLLM } from '@mastra/evals/scorers/prebuilt';
|
|
24
24
|
*
|
|
25
25
|
* // Without expected trajectory (evaluates quality based on task)
|
|
26
26
|
* const scorer = createTrajectoryAccuracyScorerLLM({
|
|
@@ -3852,7 +3852,7 @@ function formatExpectedSteps(steps, indent = 0) {
|
|
|
3852
3852
|
*
|
|
3853
3853
|
* @example
|
|
3854
3854
|
* ```ts
|
|
3855
|
-
* import { createTrajectoryAccuracyScorerLLM } from '@mastra/evals/scorers';
|
|
3855
|
+
* import { createTrajectoryAccuracyScorerLLM } from '@mastra/evals/scorers/prebuilt';
|
|
3856
3856
|
*
|
|
3857
3857
|
* // Without expected trajectory (evaluates quality based on task)
|
|
3858
3858
|
* const scorer = createTrajectoryAccuracyScorerLLM({
|
|
@@ -4312,7 +4312,7 @@ function expectationToExpectedSteps(expectation) {
|
|
|
4312
4312
|
*
|
|
4313
4313
|
* @example
|
|
4314
4314
|
* ```ts
|
|
4315
|
-
* import { createTrajectoryAccuracyScorerCode } from '@mastra/evals/scorers';
|
|
4315
|
+
* import { createTrajectoryAccuracyScorerCode } from '@mastra/evals/scorers/prebuilt';
|
|
4316
4316
|
*
|
|
4317
4317
|
* const scorer = createTrajectoryAccuracyScorerCode({
|
|
4318
4318
|
* expectedTrajectory: {
|
|
@@ -4521,7 +4521,7 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4521
4521
|
*
|
|
4522
4522
|
* @example
|
|
4523
4523
|
* ```ts
|
|
4524
|
-
* import { createTrajectoryScorerCode } from '@mastra/evals/scorers';
|
|
4524
|
+
* import { createTrajectoryScorerCode } from '@mastra/evals/scorers/prebuilt';
|
|
4525
4525
|
*
|
|
4526
4526
|
* const scorer = createTrajectoryScorerCode({
|
|
4527
4527
|
* defaults: {
|