@mastra/evals 1.10.9-alpha.0 → 1.10.10-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-quick-checks.md +7 -7
- package/dist/docs/references/reference-evals-completeness.md +5 -1
- package/dist/docs/references/reference-evals-context-precision.md +3 -1
- package/dist/docs/references/reference-evals-faithfulness.md +5 -5
- package/dist/docs/references/reference-evals-tool-call-accuracy.md +7 -4
- package/dist/scorers/llm/tool-call-accuracy/index.d.ts.map +1 -1
- package/dist/scorers/llm/tool-call-accuracy/prompts.d.ts +3 -2
- package/dist/scorers/llm/tool-call-accuracy/prompts.d.ts.map +1 -1
- package/dist/scorers/prebuilt/index.cjs +25 -9
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +25 -9
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/package.json +7 -7
package/dist/docs/SKILL.md
CHANGED
|
@@ -43,13 +43,13 @@ Quick Checks fall into these categories:
|
|
|
43
43
|
|
|
44
44
|
These scorers evaluate the agent's text output:
|
|
45
45
|
|
|
46
|
-
| Check | What it does
|
|
47
|
-
| ------------------------ |
|
|
48
|
-
| `checks.includes(str)` | Output contains substring
|
|
49
|
-
| `checks.excludes(str)` | Output doesn't contain substring
|
|
50
|
-
| `checks.equals(str)` | Output
|
|
51
|
-
| `checks.matches(regex)` | Output matches regular expression
|
|
52
|
-
| `checks.similarity(str)` | Dice coefficient similarity to string
|
|
46
|
+
| Check | What it does | Score |
|
|
47
|
+
| ------------------------ | --------------------------------------------------------------------------------------------------- | -------------------------------- |
|
|
48
|
+
| `checks.includes(str)` | Output contains substring | 1 or 0 |
|
|
49
|
+
| `checks.excludes(str)` | Output doesn't contain substring | 1 or 0 |
|
|
50
|
+
| `checks.equals(str)` | Output equals string (case-insensitive by default; pass `{ ignoreCase: false }` for an exact match) | 1 or 0 |
|
|
51
|
+
| `checks.matches(regex)` | Output matches regular expression | 1 or 0 |
|
|
52
|
+
| `checks.similarity(str)` | Dice coefficient similarity to string | 0-1 (or binary with `threshold`) |
|
|
53
53
|
|
|
54
54
|
### Tool call checks
|
|
55
55
|
|
|
@@ -79,7 +79,11 @@ The scorer evaluates completeness through linguistic element coverage analysis.
|
|
|
79
79
|
- Exact matches for short terms (≤3 chars)
|
|
80
80
|
- Substantial overlap (>60%) for longer terms
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
When the input yields no elements, the scorer returns `1` if the output also has no elements and `0` otherwise.
|
|
83
|
+
|
|
84
|
+
Final score: `covered_elements / total_input_elements`
|
|
85
|
+
|
|
86
|
+
The completeness scorer has no `scale` option. The score is always between 0 and 1.
|
|
83
87
|
|
|
84
88
|
### Score interpretation
|
|
85
89
|
|
|
@@ -30,7 +30,9 @@ Use when optimizing context selection for:
|
|
|
30
30
|
|
|
31
31
|
**options** (`ContextPrecisionMetricOptions`): Configuration options for the scorer
|
|
32
32
|
|
|
33
|
-
Either `context` or `contextExtractor` must be provided.
|
|
33
|
+
Either `context` or `contextExtractor` must be provided. `contextExtractor` is only called when the run input and output have agent shapes: the input has `inputMessages`, `rememberedMessages` and `systemMessages` arrays plus a `taggedSystemMessages` object, and the output is an array of messages. For any other input/output shape the scorer uses `context`. When neither is provided, the scorer throws.
|
|
34
|
+
|
|
35
|
+
If you pass `context`, the array must be non-empty. The constructor throws `Context array cannot be empty if provided` even when `contextExtractor` is also configured. When only `contextExtractor` is configured and the run isn't agent-shaped, there's no context to score against and evaluation throws `No context available for evaluation`.
|
|
34
36
|
|
|
35
37
|
## `.run()` returns
|
|
36
38
|
|
|
@@ -16,7 +16,7 @@ The `createFaithfulnessScorer()` function accepts a single options object with t
|
|
|
16
16
|
|
|
17
17
|
**options.context** (`string[]`): Array of context chunks against which the output's claims will be verified. When omitted, the scorer uses the results of tool calls in the run output.
|
|
18
18
|
|
|
19
|
-
**options.scale** (`number`): The maximum score value. The final score will be normalized to this scale.
|
|
19
|
+
**options.scale** (`number`): The maximum score value. The final score will be normalized to this scale. A value of 0 falls back to 1 (the implementation uses scale || 1).
|
|
20
20
|
|
|
21
21
|
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.
|
|
22
22
|
|
|
@@ -32,7 +32,7 @@ This function returns an instance of the MastraScorer class. The `.run()` method
|
|
|
32
32
|
|
|
33
33
|
**analyzePrompt** (`string`): The prompt sent to the LLM for the analyze step (optional).
|
|
34
34
|
|
|
35
|
-
**score** (`number`): A score between 0 and the
|
|
35
|
+
**score** (`number`): A score between 0 and the effective scale, representing the proportion of claims that are supported by the context. The effective scale is scale || 1, so an unset or 0 scale means 1.
|
|
36
36
|
|
|
37
37
|
**reason** (`string`): A detailed explanation of the score, including which claims were supported, contradicted, or marked as unsure.
|
|
38
38
|
|
|
@@ -60,13 +60,13 @@ The scorer evaluates faithfulness through claim verification against provided co
|
|
|
60
60
|
|
|
61
61
|
- Counts supported claims
|
|
62
62
|
- Divides by total claims
|
|
63
|
-
- Scales to
|
|
63
|
+
- Scales to the effective range
|
|
64
64
|
|
|
65
|
-
Final score: `(supported_claims / total_claims) * scale`
|
|
65
|
+
Final score: `(supported_claims / total_claims) * effective_scale`, where `effective_scale` is `scale || 1`
|
|
66
66
|
|
|
67
67
|
### Score interpretation
|
|
68
68
|
|
|
69
|
-
A faithfulness score between 0 and the
|
|
69
|
+
A faithfulness score between 0 and the effective scale (default 1). With the default scale:
|
|
70
70
|
|
|
71
71
|
- **1.0**: All claims are accurate and directly supported by the context.
|
|
72
72
|
- **0.7 to 0.9**: Most claims are correct, with minor additions or omissions.
|
|
@@ -285,6 +285,8 @@ The `createToolCallAccuracyScorerLLM()` function from `@mastra/evals/scorers/pre
|
|
|
285
285
|
|
|
286
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
|
+
Pass the tools available for the specific agent run in `availableTools`. If tool availability changes between runs, create a scorer with each run's tool snapshot. A global superset can cause the judge to report unavailable tools as missing and lower the score.
|
|
289
|
+
|
|
288
290
|
### Features
|
|
289
291
|
|
|
290
292
|
The LLM-based scorer provides:
|
|
@@ -299,12 +301,13 @@ The LLM-based scorer provides:
|
|
|
299
301
|
|
|
300
302
|
1. **Extract Tool Calls**: Identifies tools mentioned in agent output
|
|
301
303
|
2. **Analyze Appropriateness**: Evaluates each tool against user request
|
|
302
|
-
3. **Generate Score**:
|
|
304
|
+
3. **Generate Score**: Divides appropriate calls by the number of actual calls plus judge-reported missing tools
|
|
303
305
|
4. **Generate Reasoning**: Provides human-readable explanation
|
|
304
306
|
|
|
305
307
|
## LLM-based scoring details
|
|
306
308
|
|
|
307
|
-
- **Fractional scores**: Returns values between 0.0 and 1.0
|
|
309
|
+
- **Fractional scores**: Returns values between 0.0 and 1.0, rounded to two decimal places. The score counts appropriate evaluations only when they match actual calls to that tool, so extra evaluations don't increase it. The denominator counts all actual calls plus judge-reported missing tools.
|
|
310
|
+
- **No tool calls**: Returns 0 if the judge reports missing tools, or 1 if no tools were needed.
|
|
308
311
|
- **Context-aware**: Considers user intent and appropriateness
|
|
309
312
|
- **Explanatory**: Provides reasoning for scores
|
|
310
313
|
|
|
@@ -436,8 +439,8 @@ const inappropriateOutput = [
|
|
|
436
439
|
const run = createAgentTestRun({ inputMessages, output: inappropriateOutput })
|
|
437
440
|
const result = await llmScorer.run(run)
|
|
438
441
|
|
|
439
|
-
console.log(result.score) // 0
|
|
440
|
-
console.log(result.reason) //
|
|
442
|
+
console.log(result.score) // 0 - if the judge marks search-tool inappropriate and reports weather-tool as missing
|
|
443
|
+
console.log(result.reason) // The judge explains why search-tool was inappropriate for this weather request.
|
|
441
444
|
```
|
|
442
445
|
|
|
443
446
|
### Evaluating clarification requests
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/tool-call-accuracy/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAU/C,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,iBAAiB,CAAC;IACzB,cAAc,EAAE,IAAI,EAAE,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/tool-call-accuracy/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAU/C,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,iBAAiB,CAAC;IACzB,cAAc,EAAE,IAAI,EAAE,CAAC;CACxB;AA6BD,wBAAgB,+BAA+B,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,uBAAuB;;;;;;;;;;;6FA8EjG"}
|
|
@@ -6,10 +6,11 @@ export declare const createAnalyzePrompt: ({ userInput, agentResponse, toolsCall
|
|
|
6
6
|
toolsCalled: string[];
|
|
7
7
|
availableTools: string;
|
|
8
8
|
}) => string;
|
|
9
|
-
export declare const createReasonPrompt: ({ userInput, score,
|
|
9
|
+
export declare const createReasonPrompt: ({ userInput, score, actualTools, matchedEvaluations, missingTools, }: {
|
|
10
10
|
userInput: string;
|
|
11
11
|
score: number;
|
|
12
|
-
|
|
12
|
+
actualTools: string[];
|
|
13
|
+
matchedEvaluations: Array<{
|
|
13
14
|
toolCalled: string;
|
|
14
15
|
wasAppropriate: boolean;
|
|
15
16
|
reasoning: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/tool-call-accuracy/prompts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oCAAoC,2nCAsBhD,CAAC;AAEF,eAAO,MAAM,wBAAwB,gBAAiB,MAAM,KAAG,MAM9D,CAAC;AAEF,eAAO,MAAM,mBAAmB,+DAK7B;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB,KAAG,MA6CH,CAAC;AAEF,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/tool-call-accuracy/prompts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oCAAoC,2nCAsBhD,CAAC;AAEF,eAAO,MAAM,wBAAwB,gBAAiB,MAAM,KAAG,MAM9D,CAAC;AAEF,eAAO,MAAM,mBAAmB,+DAK7B;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB,KAAG,MA6CH,CAAC;AAEF,eAAO,MAAM,kBAAkB,yEAM5B;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9F,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,KAAG,MAaH,CAAC"}
|
|
@@ -540,7 +540,7 @@ function createAnswerSimilarityScorer({ model, options = ANSWER_SIMILARITY_DEFAU
|
|
|
540
540
|
case "missing": score -= mergedOptions.missingPenalty;
|
|
541
541
|
}
|
|
542
542
|
const maxPossibleScore = totalUnits * (1 + mergedOptions.exactMatchBonus);
|
|
543
|
-
score
|
|
543
|
+
score /= maxPossibleScore;
|
|
544
544
|
const contradictionPenalty = analysis.contradictions.length * mergedOptions.contradictionPenalty;
|
|
545
545
|
score -= contradictionPenalty;
|
|
546
546
|
const extraInfoPenalty = Math.min(analysis.extraInOutput.length * mergedOptions.extraInfoPenalty, .2);
|
|
@@ -1419,17 +1419,19 @@ STRICT EVALUATION CRITERIA:
|
|
|
1419
1419
|
- If the user asked for "A", only tools that provide "A" should be marked appropriate
|
|
1420
1420
|
- Additional tools the agent decided to call without being asked should be marked inappropriate
|
|
1421
1421
|
|
|
1422
|
-
|
|
1422
|
+
If tools were called, return exactly one evaluation per entry in TOOLS THE AGENT ACTUALLY CALLED, including repeated calls, in the same order. Repeated calls with different arguments can each be appropriate when they address the request. If no tools were called, evaluate whether that was the right decision.
|
|
1423
1423
|
`;
|
|
1424
1424
|
};
|
|
1425
|
-
const createReasonPrompt$4 = ({ userInput, score,
|
|
1425
|
+
const createReasonPrompt$4 = ({ userInput, score, actualTools, matchedEvaluations, missingTools }) => {
|
|
1426
1426
|
return `
|
|
1427
1427
|
Explain this tool selection evaluation in ONE SENTENCE.
|
|
1428
1428
|
|
|
1429
1429
|
User Request: "${userInput}"
|
|
1430
1430
|
Score: ${score}/1
|
|
1431
|
-
|
|
1431
|
+
Actual Tool Calls: ${JSON.stringify(actualTools)}
|
|
1432
|
+
Matched Tool Evaluations: ${JSON.stringify(matchedEvaluations)}
|
|
1432
1433
|
Missing Tools: ${JSON.stringify(missingTools)}
|
|
1434
|
+
For called tools, the score counts appropriate matched evaluations divided by actual tool calls plus missing tools. Calls without evaluations lower the score. With no calls, the score is 0 if tools were missing and 1 otherwise.
|
|
1433
1435
|
|
|
1434
1436
|
Provide a single, concise sentence explaining why this score was given.
|
|
1435
1437
|
`;
|
|
@@ -1462,6 +1464,16 @@ const analyzeOutputSchema$6 = {
|
|
|
1462
1464
|
},
|
|
1463
1465
|
"required": ["evaluations"]
|
|
1464
1466
|
};
|
|
1467
|
+
function matchToolEvaluations(actualTools, evaluations) {
|
|
1468
|
+
const remainingCalls = /* @__PURE__ */ new Map();
|
|
1469
|
+
for (const toolName of actualTools) remainingCalls.set(toolName, (remainingCalls.get(toolName) ?? 0) + 1);
|
|
1470
|
+
return evaluations.filter((evaluation) => {
|
|
1471
|
+
const remaining = remainingCalls.get(evaluation.toolCalled) ?? 0;
|
|
1472
|
+
if (remaining === 0) return false;
|
|
1473
|
+
remainingCalls.set(evaluation.toolCalled, remaining - 1);
|
|
1474
|
+
return true;
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1465
1477
|
function createToolCallAccuracyScorerLLM({ model, availableTools }) {
|
|
1466
1478
|
const toolDefinitions = availableTools.map((tool) => `${tool.id}: ${tool.description}`).join("\n");
|
|
1467
1479
|
return (0, _mastra_core_evals.createScorer)({
|
|
@@ -1499,20 +1511,24 @@ function createToolCallAccuracyScorerLLM({ model, availableTools }) {
|
|
|
1499
1511
|
}
|
|
1500
1512
|
}).generateScore(({ results }) => {
|
|
1501
1513
|
const evaluations = results.analyzeStepResult?.evaluations || [];
|
|
1502
|
-
|
|
1503
|
-
const
|
|
1504
|
-
const totalToolCalls =
|
|
1505
|
-
return
|
|
1514
|
+
const missingTools = results.analyzeStepResult?.missingTools || [];
|
|
1515
|
+
const actualTools = results.preprocessStepResult?.actualTools || [];
|
|
1516
|
+
const totalToolCalls = actualTools.length;
|
|
1517
|
+
if (totalToolCalls === 0) return missingTools.length > 0 ? 0 : 1;
|
|
1518
|
+
const appropriateToolCalls = matchToolEvaluations(actualTools, evaluations).filter((evaluation) => evaluation.wasAppropriate).length;
|
|
1519
|
+
return require_scorers_utils.roundToTwoDecimals(Math.min(1, appropriateToolCalls / (totalToolCalls + missingTools.length)));
|
|
1506
1520
|
}).generateReason({
|
|
1507
1521
|
description: "Generate human-readable explanation of tool selection evaluation",
|
|
1508
1522
|
createPrompt: ({ run, results, score }) => {
|
|
1509
1523
|
const userInput = require_scorers_utils.getUserMessageFromRunInput(run.input) ?? "";
|
|
1510
1524
|
const evaluations = results.analyzeStepResult?.evaluations || [];
|
|
1511
1525
|
const missingTools = results.analyzeStepResult?.missingTools || [];
|
|
1526
|
+
const actualTools = results.preprocessStepResult?.actualTools || [];
|
|
1512
1527
|
return createReasonPrompt$4({
|
|
1513
1528
|
userInput,
|
|
1514
1529
|
score,
|
|
1515
|
-
|
|
1530
|
+
actualTools,
|
|
1531
|
+
matchedEvaluations: matchToolEvaluations(actualTools, evaluations),
|
|
1516
1532
|
missingTools
|
|
1517
1533
|
});
|
|
1518
1534
|
}
|