@mastra/evals 1.10.1 → 1.10.2-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/dist/{checks-DGTgg-nW.cjs → checks-CGRgwpDb.cjs} +20 -9
- package/dist/checks-CGRgwpDb.cjs.map +1 -0
- package/dist/{checks-64AonnEK.js → checks-DX9-p5w0.js} +21 -10
- package/dist/checks-DX9-p5w0.js.map +1 -0
- package/dist/checks.cjs +1 -1
- package/dist/checks.js +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/scorers/code/checks/index.d.ts +5 -2
- package/dist/scorers/code/checks/index.d.ts.map +1 -1
- package/dist/scorers/code/trajectory/index.d.ts.map +1 -1
- package/dist/scorers/prebuilt/index.cjs +15 -13
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +15 -13
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/dist/scorers/utils.cjs +91 -16
- package/dist/scorers/utils.cjs.map +1 -1
- package/dist/scorers/utils.d.ts +72 -10
- package/dist/scorers/utils.d.ts.map +1 -1
- package/dist/scorers/utils.js +91 -17
- package/dist/scorers/utils.js.map +1 -1
- package/package.json +4 -4
- package/dist/checks-64AonnEK.js.map +0 -1
- package/dist/checks-DGTgg-nW.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { analyzeToolFailures, checkTrajectoryBlacklist, checkTrajectoryEfficiency, compareTrajectories, extractAgentResponseMessages, extractToolCalls, getAssistantMessageFromRunOutput, getCombinedSystemPrompt, getConversationHistoryFromRunInput, getTextContentFromMastraDBMessage, getUserMessageFromRunInput, isScorerRunInputForAgent, isScorerRunOutputForAgent, roundToTwoDecimals } from "../utils.js";
|
|
2
|
-
import { a as excludes, c as maxToolCalls, d as toolOrder, f as usedNoTools, i as equals, l as noToolErrors, n as checks, o as includes, r as didNotCall, s as matches, t as calledTool, u as similarity } from "../../checks-
|
|
2
|
+
import { a as excludes, c as maxToolCalls, d as toolOrder, f as usedNoTools, i as equals, l as noToolErrors, n as checks, o as includes, r as didNotCall, s as matches, t as calledTool, u as similarity } from "../../checks-DX9-p5w0.js";
|
|
3
3
|
import { createScorer } from "@mastra/core/evals";
|
|
4
4
|
import nlp from "compromise";
|
|
5
5
|
import keyword_extractor from "keyword-extractor";
|
|
@@ -4290,7 +4290,6 @@ function trajectoryStepToExpectedStep(step) {
|
|
|
4290
4290
|
* suitable for comparison.
|
|
4291
4291
|
*/
|
|
4292
4292
|
function expectationToExpectedSteps(expectation) {
|
|
4293
|
-
if (!expectation.steps || expectation.steps.length === 0) return void 0;
|
|
4294
4293
|
return expectation.steps;
|
|
4295
4294
|
}
|
|
4296
4295
|
/**
|
|
@@ -4329,7 +4328,7 @@ function expectationToExpectedSteps(expectation) {
|
|
|
4329
4328
|
function createTrajectoryAccuracyScorerCode(options = {}) {
|
|
4330
4329
|
const { expectedTrajectory: staticExpectedTrajectory, comparisonOptions = {} } = options;
|
|
4331
4330
|
const { ordering = "relaxed", allowRepeatedSteps = true } = comparisonOptions;
|
|
4332
|
-
const staticExpectedSteps =
|
|
4331
|
+
const staticExpectedSteps = Array.isArray(staticExpectedTrajectory) ? staticExpectedTrajectory : staticExpectedTrajectory?.steps.map(trajectoryStepToExpectedStep);
|
|
4333
4332
|
const getDescription = () => {
|
|
4334
4333
|
if (staticExpectedSteps) return `Evaluates whether the trajectory matches the expected path: [${staticExpectedSteps.map((s) => s.name).join(" → ")}] (${ordering} ordering)`;
|
|
4335
4334
|
return `Evaluates trajectory accuracy against expected trajectory from dataset items (${ordering} ordering)`;
|
|
@@ -4346,7 +4345,7 @@ function createTrajectoryAccuracyScorerCode(options = {}) {
|
|
|
4346
4345
|
const expectation = run.expectedTrajectory;
|
|
4347
4346
|
resolvedExpectedSteps = expectationToExpectedSteps(expectation);
|
|
4348
4347
|
}
|
|
4349
|
-
if (!resolvedExpectedSteps
|
|
4348
|
+
if (!resolvedExpectedSteps) return {
|
|
4350
4349
|
actualTrajectory,
|
|
4351
4350
|
expectedTrajectory: void 0,
|
|
4352
4351
|
comparison: void 0,
|
|
@@ -4374,6 +4373,9 @@ function createTrajectoryAccuracyScorerCode(options = {}) {
|
|
|
4374
4373
|
return preprocessResult.comparison.score;
|
|
4375
4374
|
});
|
|
4376
4375
|
}
|
|
4376
|
+
function hasBlacklistViolation(results) {
|
|
4377
|
+
return results.some((result) => result.blacklist?.score === 0 || hasBlacklistViolation(result.nested ?? []));
|
|
4378
|
+
}
|
|
4377
4379
|
/**
|
|
4378
4380
|
* Evaluates nested expectations: for each expected step with a `children` config,
|
|
4379
4381
|
* finds the matching actual step and recursively evaluates its children.
|
|
@@ -4391,7 +4393,7 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4391
4393
|
const matchIndex = actualSteps.findIndex((s, i) => !matchedIndices.has(i) && s.name === expectedStep.name && (!expectedStep.stepType || s.stepType === expectedStep.stepType));
|
|
4392
4394
|
const actualStep = matchIndex >= 0 ? actualSteps[matchIndex] : void 0;
|
|
4393
4395
|
if (matchIndex >= 0) matchedIndices.add(matchIndex);
|
|
4394
|
-
if (!actualStep
|
|
4396
|
+
if (!actualStep) {
|
|
4395
4397
|
const expectedStepCount = expectedStep.children.steps?.length ?? 0;
|
|
4396
4398
|
results.push({
|
|
4397
4399
|
stepName: expectedStep.name,
|
|
@@ -4410,12 +4412,12 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4410
4412
|
continue;
|
|
4411
4413
|
}
|
|
4412
4414
|
const childTrajectory = {
|
|
4413
|
-
steps: actualStep.children,
|
|
4415
|
+
steps: actualStep.children ?? [],
|
|
4414
4416
|
totalDurationMs: actualStep.durationMs
|
|
4415
4417
|
};
|
|
4416
4418
|
const childConfig = expectedStep.children;
|
|
4417
4419
|
let accuracy;
|
|
4418
|
-
if (childConfig.steps
|
|
4420
|
+
if (childConfig.steps) accuracy = compareTrajectories(childTrajectory, { steps: childConfig.steps }, {
|
|
4419
4421
|
ordering: childConfig.ordering ?? "relaxed",
|
|
4420
4422
|
allowRepeatedSteps: childConfig.allowRepeatedSteps ?? true
|
|
4421
4423
|
});
|
|
@@ -4430,7 +4432,7 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4430
4432
|
blacklistedSequences: childConfig.blacklistedSequences
|
|
4431
4433
|
}) : void 0;
|
|
4432
4434
|
const toolFailures = analyzeToolFailures(childTrajectory, { maxRetriesPerTool: childConfig.maxRetriesPerTool ?? 2 });
|
|
4433
|
-
const nested = childConfig.steps ? evaluateNestedExpectations(childConfig.steps,
|
|
4435
|
+
const nested = childConfig.steps ? evaluateNestedExpectations(childConfig.steps, childTrajectory.steps, weights) : [];
|
|
4434
4436
|
const scores = [];
|
|
4435
4437
|
if (accuracy) scores.push({
|
|
4436
4438
|
weight: weights.accuracy,
|
|
@@ -4469,7 +4471,7 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4469
4471
|
}
|
|
4470
4472
|
let finalScore = levelScore;
|
|
4471
4473
|
if (nested.length > 0) {
|
|
4472
|
-
if (nested
|
|
4474
|
+
if (hasBlacklistViolation(nested)) {
|
|
4473
4475
|
results.push({
|
|
4474
4476
|
stepName: expectedStep.name,
|
|
4475
4477
|
score: 0,
|
|
@@ -4551,7 +4553,7 @@ function createTrajectoryScorerCode(options = {}) {
|
|
|
4551
4553
|
};
|
|
4552
4554
|
if (itemExpectation.steps !== void 0) config.steps = itemExpectation.steps;
|
|
4553
4555
|
let accuracy;
|
|
4554
|
-
if (config.steps
|
|
4556
|
+
if (config.steps) accuracy = compareTrajectories(actualTrajectory, { steps: config.steps }, {
|
|
4555
4557
|
ordering: config.ordering ?? "relaxed",
|
|
4556
4558
|
allowRepeatedSteps: config.allowRepeatedSteps ?? true
|
|
4557
4559
|
});
|
|
@@ -4602,7 +4604,7 @@ function createTrajectoryScorerCode(options = {}) {
|
|
|
4602
4604
|
levelScore = totalWeight > 0 ? scores.reduce((sum, s) => sum + s.weight / totalWeight * s.value, 0) : 1;
|
|
4603
4605
|
}
|
|
4604
4606
|
if (nested && nested.length > 0) {
|
|
4605
|
-
if (nested
|
|
4607
|
+
if (hasBlacklistViolation(nested)) return 0;
|
|
4606
4608
|
const nestedAvg = nested.reduce((sum, r) => sum + r.score, 0) / nested.length;
|
|
4607
4609
|
levelScore = .7 * levelScore + .3 * nestedAvg;
|
|
4608
4610
|
}
|
|
@@ -4618,8 +4620,8 @@ function createTrajectoryScorerCode(options = {}) {
|
|
|
4618
4620
|
parts.push(`Blacklist violation: ${violations.join(". ")}.`);
|
|
4619
4621
|
return parts.join("\n");
|
|
4620
4622
|
}
|
|
4621
|
-
if (nested && nested
|
|
4622
|
-
const violating = nested.filter((r) => r
|
|
4623
|
+
if (nested && hasBlacklistViolation(nested)) {
|
|
4624
|
+
const violating = nested.filter((r) => hasBlacklistViolation([r])).map((r) => r.stepName);
|
|
4623
4625
|
parts.push(`Nested blacklist violation in: ${violating.join(", ")}.`);
|
|
4624
4626
|
return parts.join("\n");
|
|
4625
4627
|
}
|