@mastra/evals 1.10.9 → 1.10.10
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-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 +24 -8
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +24 -8
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/package.json +8 -8
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
|
|
|
@@ -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"}
|
|
@@ -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
|
}
|