@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
|
@@ -535,7 +535,7 @@ function createAnswerSimilarityScorer({ model, options = ANSWER_SIMILARITY_DEFAU
|
|
|
535
535
|
case "missing": score -= mergedOptions.missingPenalty;
|
|
536
536
|
}
|
|
537
537
|
const maxPossibleScore = totalUnits * (1 + mergedOptions.exactMatchBonus);
|
|
538
|
-
score
|
|
538
|
+
score /= maxPossibleScore;
|
|
539
539
|
const contradictionPenalty = analysis.contradictions.length * mergedOptions.contradictionPenalty;
|
|
540
540
|
score -= contradictionPenalty;
|
|
541
541
|
const extraInfoPenalty = Math.min(analysis.extraInOutput.length * mergedOptions.extraInfoPenalty, .2);
|
|
@@ -1414,17 +1414,19 @@ STRICT EVALUATION CRITERIA:
|
|
|
1414
1414
|
- If the user asked for "A", only tools that provide "A" should be marked appropriate
|
|
1415
1415
|
- Additional tools the agent decided to call without being asked should be marked inappropriate
|
|
1416
1416
|
|
|
1417
|
-
|
|
1417
|
+
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.
|
|
1418
1418
|
`;
|
|
1419
1419
|
};
|
|
1420
|
-
const createReasonPrompt$4 = ({ userInput, score,
|
|
1420
|
+
const createReasonPrompt$4 = ({ userInput, score, actualTools, matchedEvaluations, missingTools }) => {
|
|
1421
1421
|
return `
|
|
1422
1422
|
Explain this tool selection evaluation in ONE SENTENCE.
|
|
1423
1423
|
|
|
1424
1424
|
User Request: "${userInput}"
|
|
1425
1425
|
Score: ${score}/1
|
|
1426
|
-
|
|
1426
|
+
Actual Tool Calls: ${JSON.stringify(actualTools)}
|
|
1427
|
+
Matched Tool Evaluations: ${JSON.stringify(matchedEvaluations)}
|
|
1427
1428
|
Missing Tools: ${JSON.stringify(missingTools)}
|
|
1429
|
+
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.
|
|
1428
1430
|
|
|
1429
1431
|
Provide a single, concise sentence explaining why this score was given.
|
|
1430
1432
|
`;
|
|
@@ -1457,6 +1459,16 @@ const analyzeOutputSchema$6 = {
|
|
|
1457
1459
|
},
|
|
1458
1460
|
"required": ["evaluations"]
|
|
1459
1461
|
};
|
|
1462
|
+
function matchToolEvaluations(actualTools, evaluations) {
|
|
1463
|
+
const remainingCalls = /* @__PURE__ */ new Map();
|
|
1464
|
+
for (const toolName of actualTools) remainingCalls.set(toolName, (remainingCalls.get(toolName) ?? 0) + 1);
|
|
1465
|
+
return evaluations.filter((evaluation) => {
|
|
1466
|
+
const remaining = remainingCalls.get(evaluation.toolCalled) ?? 0;
|
|
1467
|
+
if (remaining === 0) return false;
|
|
1468
|
+
remainingCalls.set(evaluation.toolCalled, remaining - 1);
|
|
1469
|
+
return true;
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1460
1472
|
function createToolCallAccuracyScorerLLM({ model, availableTools }) {
|
|
1461
1473
|
const toolDefinitions = availableTools.map((tool) => `${tool.id}: ${tool.description}`).join("\n");
|
|
1462
1474
|
return createScorer({
|
|
@@ -1494,20 +1506,24 @@ function createToolCallAccuracyScorerLLM({ model, availableTools }) {
|
|
|
1494
1506
|
}
|
|
1495
1507
|
}).generateScore(({ results }) => {
|
|
1496
1508
|
const evaluations = results.analyzeStepResult?.evaluations || [];
|
|
1497
|
-
|
|
1498
|
-
const
|
|
1499
|
-
const totalToolCalls =
|
|
1500
|
-
|
|
1509
|
+
const missingTools = results.analyzeStepResult?.missingTools || [];
|
|
1510
|
+
const actualTools = results.preprocessStepResult?.actualTools || [];
|
|
1511
|
+
const totalToolCalls = actualTools.length;
|
|
1512
|
+
if (totalToolCalls === 0) return missingTools.length > 0 ? 0 : 1;
|
|
1513
|
+
const appropriateToolCalls = matchToolEvaluations(actualTools, evaluations).filter((evaluation) => evaluation.wasAppropriate).length;
|
|
1514
|
+
return roundToTwoDecimals(Math.min(1, appropriateToolCalls / (totalToolCalls + missingTools.length)));
|
|
1501
1515
|
}).generateReason({
|
|
1502
1516
|
description: "Generate human-readable explanation of tool selection evaluation",
|
|
1503
1517
|
createPrompt: ({ run, results, score }) => {
|
|
1504
1518
|
const userInput = getUserMessageFromRunInput(run.input) ?? "";
|
|
1505
1519
|
const evaluations = results.analyzeStepResult?.evaluations || [];
|
|
1506
1520
|
const missingTools = results.analyzeStepResult?.missingTools || [];
|
|
1521
|
+
const actualTools = results.preprocessStepResult?.actualTools || [];
|
|
1507
1522
|
return createReasonPrompt$4({
|
|
1508
1523
|
userInput,
|
|
1509
1524
|
score,
|
|
1510
|
-
|
|
1525
|
+
actualTools,
|
|
1526
|
+
matchedEvaluations: matchToolEvaluations(actualTools, evaluations),
|
|
1511
1527
|
missingTools
|
|
1512
1528
|
});
|
|
1513
1529
|
}
|