@mastra/evals 1.10.8-alpha.1 → 1.10.8

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.
@@ -1,5 +1,5 @@
1
1
  import type { MastraDBMessage } from '@mastra/core/agent';
2
- import type { ExpectedStep, ScorerRunInputForAgent, ScorerRunOutputForAgent, ScoringInput, TrajectoryExpectation, Trajectory } from '@mastra/core/evals';
2
+ import type { ExpectedStep, ScorerRunInputForAgent, ScorerRunOutputForAgent, ScoringInput, TrajectoryExpectation, TrajectoryStep, Trajectory } from '@mastra/core/evals';
3
3
  import { RequestContext } from '@mastra/core/request-context';
4
4
  export type ScorerRunInputForLLMJudge = ScorerRunInputForAgent | string | {
5
5
  inputMessages?: unknown[];
@@ -571,13 +571,24 @@ export type ToolResultInfo = {
571
571
  */
572
572
  export declare function extractToolResults(output: ScorerRunOutputForAgent): ToolResultInfo[];
573
573
  export { extractTrajectory } from '@mastra/core/evals';
574
+ /**
575
+ * Returns the tool-level view of one sibling list of trajectory steps.
576
+ *
577
+ * Trace-derived trajectories (`extractTrajectoryFromTrace`) wrap tool calls in
578
+ * `model_generation` steps and interleave `processor_run` steps, while message-derived
579
+ * trajectories list tool calls flat. This drops `processor_run` steps and replaces each
580
+ * `model_generation` step with its (recursively flattened) children, so both shapes yield
581
+ * the same list. Other steps are returned as the same objects, with their children untouched.
582
+ */
583
+ export declare function toToolLevelSteps(steps: TrajectoryStep[]): TrajectoryStep[];
574
584
  /**
575
585
  * Compares two trajectories and returns detailed comparison results.
576
586
  *
577
587
  * This is the core comparison logic used by trajectory scorers. It supports
578
588
  * strict and non-strict ordering, optional step data comparison, and loop detection.
579
589
  *
580
- * @param actual - The trajectory the agent actually took
590
+ * @param rawActual - The trajectory the agent actually took. Trace-derived trajectories are
591
+ * compared at tool level (see {@link toToolLevelSteps}).
581
592
  * @param expected - The expected trajectory to compare against
582
593
  * @param options - Comparison configuration options
583
594
  * @returns Detailed comparison results including match scores and diagnostics
@@ -592,7 +603,7 @@ export { extractTrajectory } from '@mastra/core/evals';
592
603
  * // result.score = 1.0
593
604
  * ```
594
605
  */
595
- export declare function compareTrajectories(actual: Trajectory, expected: Trajectory | {
606
+ export declare function compareTrajectories(rawActual: Trajectory, expected: Trajectory | {
596
607
  steps: ExpectedStep[];
597
608
  }, options?: {
598
609
  ordering?: 'strict' | 'relaxed' | 'unordered';
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/scorers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,qBAAqB,EAErB,UAAU,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,MAAM,yBAAyB,GACjC,sBAAsB,GACtB,MAAM,GACN;IACE,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEN,MAAM,MAAM,0BAA0B,GAClC,uBAAuB,GACvB,MAAM,GACN,OAAO,EAAE,GACT;IACE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEN;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,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
705
705
  /**
706
+ * Returns the tool-level view of one sibling list of trajectory steps.
707
+ *
708
+ * Trace-derived trajectories (`extractTrajectoryFromTrace`) wrap tool calls in
709
+ * `model_generation` steps and interleave `processor_run` steps, while message-derived
710
+ * trajectories list tool calls flat. This drops `processor_run` steps and replaces each
711
+ * `model_generation` step with its (recursively flattened) children, so both shapes yield
712
+ * the same list. Other steps are returned as the same objects, with their children untouched.
713
+ */
714
+ function toToolLevelSteps(steps) {
715
+ const result = [];
716
+ for (const step of steps) {
717
+ if (step.stepType === "processor_run") continue;
718
+ if (step.stepType === "model_generation") {
719
+ if (step.children?.length) result.push(...toToolLevelSteps(step.children));
720
+ continue;
721
+ }
722
+ result.push(step);
723
+ }
724
+ return result;
725
+ }
726
+ /**
706
727
  * Compares two trajectories and returns detailed comparison results.
707
728
  *
708
729
  * This is the core comparison logic used by trajectory scorers. It supports
709
730
  * strict and non-strict ordering, optional step data comparison, and loop detection.
710
731
  *
711
- * @param actual - The trajectory the agent actually took
732
+ * @param rawActual - The trajectory the agent actually took. Trace-derived trajectories are
733
+ * compared at tool level (see {@link toToolLevelSteps}).
712
734
  * @param expected - The expected trajectory to compare against
713
735
  * @param options - Comparison configuration options
714
736
  * @returns Detailed comparison results including match scores and diagnostics
@@ -723,9 +745,14 @@ function extractToolResults(output) {
723
745
  * // result.score = 1.0
724
746
  * ```
725
747
  */
726
- function compareTrajectories(actual, expected, options = {}) {
748
+ function compareTrajectories(rawActual, expected, options = {}) {
727
749
  const { allowRepeatedSteps = true, ordering = "relaxed" } = options;
728
750
  const normalizedExpected = { steps: expected.steps };
751
+ const containerNames = new Set(rawActual.steps.filter((s) => s.stepType === "model_generation" || s.stepType === "processor_run").map((s) => s.name));
752
+ const actual = normalizedExpected.steps.some((s) => s.stepType === "model_generation" || s.stepType === "processor_run" || !s.stepType && containerNames.has(s.name)) ? rawActual : {
753
+ ...rawActual,
754
+ steps: toToolLevelSteps(rawActual.steps)
755
+ };
729
756
  if (normalizedExpected.steps.length === 0) return {
730
757
  score: actual.steps.length === 0 ? 1 : 0,
731
758
  matchedSteps: 0,
@@ -762,16 +789,17 @@ function compareStrictOrder(actual, expected, opts) {
762
789
  const maxLen = Math.max(actualNames.length, expectedNames.length);
763
790
  for (let i = 0; i < maxLen; i++) {
764
791
  const actualName = actualNames[i];
765
- if (actualName === expectedNames[i]) if (actual.steps[i] && expected.steps[i]) {
766
- if (expectedStepMatches(actual.steps[i], expected.steps[i])) {
792
+ if (actualName === expectedNames[i]) {
793
+ if (actual.steps[i] && expected.steps[i]) {
794
+ if (expectedStepMatches(actual.steps[i], expected.steps[i])) {
795
+ matchedSteps++;
796
+ matchedExpectedIndices.add(i);
797
+ }
798
+ } else {
767
799
  matchedSteps++;
768
800
  matchedExpectedIndices.add(i);
769
801
  }
770
- } else {
771
- matchedSteps++;
772
- matchedExpectedIndices.add(i);
773
- }
774
- else if (actualName && expectedNames.includes(actualName)) outOfOrderSteps.push(actualName);
802
+ } else if (actualName && expectedNames.includes(actualName)) outOfOrderSteps.push(actualName);
775
803
  }
776
804
  const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));
777
805
  const extraSteps = actualNames.filter((name) => !expectedNames.includes(name));
@@ -802,20 +830,22 @@ function compareRelaxedOrder(actual, expected, opts) {
802
830
  for (let i = 0; i < expectedNames.length; i++) {
803
831
  const expectedName = expectedNames[i];
804
832
  let found = false;
805
- for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) if (actualNames[j] === expectedName) if (actual.steps[j] && expected.steps[i]) {
806
- if (expectedStepMatches(actual.steps[j], expected.steps[i])) {
833
+ for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) if (actualNames[j] === expectedName) {
834
+ if (actual.steps[j] && expected.steps[i]) {
835
+ if (expectedStepMatches(actual.steps[j], expected.steps[i])) {
836
+ matchedSteps++;
837
+ lastMatchedIndex = j;
838
+ matchedExpectedIndices.add(i);
839
+ found = true;
840
+ break;
841
+ }
842
+ } else {
807
843
  matchedSteps++;
808
844
  lastMatchedIndex = j;
809
845
  matchedExpectedIndices.add(i);
810
846
  found = true;
811
847
  break;
812
848
  }
813
- } else {
814
- matchedSteps++;
815
- lastMatchedIndex = j;
816
- matchedExpectedIndices.add(i);
817
- found = true;
818
- break;
819
849
  }
820
850
  if (!found) {
821
851
  if (actualNames.includes(expectedName)) outOfOrderSteps.push(expectedName);
@@ -945,7 +975,7 @@ function checkTrajectoryEfficiency(trajectory, options = {}) {
945
975
  maxTotalTokens,
946
976
  maxTotalDurationMs
947
977
  })) if (limit !== void 0 && !isMeasurement(limit)) throw new Error(`Invalid ${name} budget: expected a finite nonnegative number`);
948
- const totalSteps = trajectory.steps.length;
978
+ const totalSteps = toToolLevelSteps(trajectory.steps).length;
949
979
  let totalTokens = 0;
950
980
  let modelGenerations = 0;
951
981
  const remaining = [...trajectory.steps];
@@ -966,12 +996,11 @@ function checkTrajectoryEfficiency(trajectory, options = {}) {
966
996
  const redundantCalls = [];
967
997
  const siblingLists = noRedundantCalls ? [trajectory.steps] : [];
968
998
  while (siblingLists.length > 0) {
969
- const steps = siblingLists.pop();
999
+ const steps = toToolLevelSteps(siblingLists.pop());
970
1000
  for (const step of steps) if (step.children?.length) siblingLists.push(step.children);
971
1001
  let prev;
972
1002
  for (let i = 0; i < steps.length; i++) {
973
1003
  const curr = steps[i];
974
- if (curr.stepType === "processor_run" || curr.stepType === "model_generation") continue;
975
1004
  if (prev && prev.name === curr.name && prev.stepType === curr.stepType && (prev.stepType === "tool_call" || prev.stepType === "mcp_tool_call")) {
976
1005
  const prevArgs = prev.toolArgs;
977
1006
  const currArgs = curr.toolArgs;
@@ -1013,16 +1042,19 @@ function checkTrajectoryBlacklist(trajectory, options = {}) {
1013
1042
  const { blacklistedTools = [], blacklistedSequences = [] } = options;
1014
1043
  const violatedTools = [];
1015
1044
  const violatedSequences = [];
1016
- const siblingLists = [];
1017
1045
  const allNames = /* @__PURE__ */ new Set();
1018
- const pending = [trajectory.steps];
1046
+ const pending = [...trajectory.steps];
1019
1047
  while (pending.length > 0) {
1020
- const steps = pending.pop();
1048
+ const step = pending.pop();
1049
+ allNames.add(step.name);
1050
+ if (step.children?.length) pending.push(...step.children);
1051
+ }
1052
+ const siblingLists = [];
1053
+ const pendingLists = [trajectory.steps];
1054
+ while (pendingLists.length > 0) {
1055
+ const steps = toToolLevelSteps(pendingLists.pop());
1021
1056
  siblingLists.push(steps.map((s) => s.name));
1022
- for (const step of steps) {
1023
- allNames.add(step.name);
1024
- if (step.children?.length) pending.push(step.children);
1025
- }
1057
+ for (const step of steps) if (step.children?.length) pendingLists.push(step.children);
1026
1058
  }
1027
1059
  for (const forbidden of blacklistedTools) if (allNames.has(forbidden)) violatedTools.push(forbidden);
1028
1060
  const containsSequence = (names, sequence) => {
@@ -1053,42 +1085,46 @@ function analyzeToolFailures(trajectory, options = {}) {
1053
1085
  const { maxRetriesPerTool = 2 } = options;
1054
1086
  const patterns = [];
1055
1087
  let totalRetries = 0;
1056
- const toolCallSteps = trajectory.steps.filter((s) => s.stepType === "tool_call" || s.stepType === "mcp_tool_call");
1057
- if (toolCallSteps.length === 0) return {
1088
+ let totalToolCalls = 0;
1089
+ const pending = [trajectory.steps];
1090
+ while (pending.length > 0) {
1091
+ const steps = toToolLevelSteps(pending.shift());
1092
+ for (const step of steps) if (step.children?.length) pending.push(step.children);
1093
+ const toolCallSteps = steps.filter((s) => s.stepType === "tool_call" || s.stepType === "mcp_tool_call");
1094
+ totalToolCalls += toolCallSteps.length;
1095
+ let i = 0;
1096
+ while (i < toolCallSteps.length) {
1097
+ const currentTool = toolCallSteps[i];
1098
+ let retryCount = 0;
1099
+ let j = i + 1;
1100
+ while (j < toolCallSteps.length && toolCallSteps[j].name === currentTool.name) {
1101
+ if (toolCallSteps[j - 1].success === false) retryCount++;
1102
+ j++;
1103
+ }
1104
+ if (retryCount > 0) {
1105
+ const nextDifferentTool = j < toolCallSteps.length ? toolCallSteps[j] : void 0;
1106
+ const lastSuccess = toolCallSteps[j - 1].success !== false;
1107
+ patterns.push({
1108
+ toolName: currentTool.name,
1109
+ retryCount,
1110
+ fellBackToAlternative: nextDifferentTool !== void 0 && !lastSuccess,
1111
+ alternativeTool: nextDifferentTool !== void 0 && !lastSuccess ? nextDifferentTool.name : void 0,
1112
+ eventuallySucceeded: lastSuccess
1113
+ });
1114
+ totalRetries += retryCount;
1115
+ }
1116
+ i = j;
1117
+ }
1118
+ }
1119
+ if (totalToolCalls === 0) return {
1058
1120
  score: 1,
1059
1121
  patterns: [],
1060
1122
  totalRetries: 0,
1061
1123
  excessiveRetryTools: []
1062
1124
  };
1063
- let i = 0;
1064
- while (i < toolCallSteps.length) {
1065
- const currentTool = toolCallSteps[i];
1066
- let retryCount = 0;
1067
- let j = i + 1;
1068
- while (j < toolCallSteps.length && toolCallSteps[j].name === currentTool.name) {
1069
- if (toolCallSteps[j - 1].success === false) retryCount++;
1070
- j++;
1071
- }
1072
- if (retryCount > 0) {
1073
- const nextDifferentTool = j < toolCallSteps.length ? toolCallSteps[j] : void 0;
1074
- const lastSuccess = toolCallSteps[j - 1].success !== false;
1075
- patterns.push({
1076
- toolName: currentTool.name,
1077
- retryCount,
1078
- fellBackToAlternative: nextDifferentTool !== void 0 && !lastSuccess,
1079
- alternativeTool: nextDifferentTool !== void 0 && !lastSuccess ? nextDifferentTool.name : void 0,
1080
- eventuallySucceeded: lastSuccess
1081
- });
1082
- totalRetries += retryCount;
1083
- }
1084
- i = j;
1085
- }
1086
1125
  const excessiveRetryTools = patterns.filter((p) => p.retryCount > maxRetriesPerTool).map((p) => p.toolName);
1087
- let score = 1;
1088
- if (toolCallSteps.length > 0) {
1089
- const excessRetries = patterns.reduce((sum, p) => sum + Math.max(0, p.retryCount - maxRetriesPerTool), 0);
1090
- score = Math.max(0, 1 - excessRetries * .2);
1091
- }
1126
+ const excessRetries = patterns.reduce((sum, p) => sum + Math.max(0, p.retryCount - maxRetriesPerTool), 0);
1127
+ const score = Math.max(0, 1 - excessRetries * .2);
1092
1128
  return {
1093
1129
  score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),
1094
1130
  patterns,
@@ -1097,6 +1133,6 @@ function analyzeToolFailures(trajectory, options = {}) {
1097
1133
  };
1098
1134
  }
1099
1135
  //#endregion
1100
- export { analyzeToolFailures, checkTrajectoryBlacklist, checkTrajectoryEfficiency, compareTrajectories, createAgentTestRun, createTestMessage, createTestRun, createToolInvocation, createTrajectoryTestRun, extractAgentResponseMessages, extractInputMessages, extractToolCalls, extractToolResults, extractTrajectory, getAssistantMessageFromRunOutput, getCombinedSystemPrompt, getConversationHistoryFromRunInput, getReasoningFromRunOutput, getSystemMessagesFromRunInput, getTextContentFromMastraDBMessage, getUserMessageFromRunInput, isCloserTo, isScorerRunInputForAgent, isScorerRunOutputForAgent, mergeToolInvocations, roundToTwoDecimals };
1136
+ export { analyzeToolFailures, checkTrajectoryBlacklist, checkTrajectoryEfficiency, compareTrajectories, createAgentTestRun, createTestMessage, createTestRun, createToolInvocation, createTrajectoryTestRun, extractAgentResponseMessages, extractInputMessages, extractToolCalls, extractToolResults, extractTrajectory, getAssistantMessageFromRunOutput, getCombinedSystemPrompt, getConversationHistoryFromRunInput, getReasoningFromRunOutput, getSystemMessagesFromRunInput, getTextContentFromMastraDBMessage, getUserMessageFromRunInput, isCloserTo, isScorerRunInputForAgent, isScorerRunOutputForAgent, mergeToolInvocations, roundToTwoDecimals, toToolLevelSteps };
1101
1137
 
1102
1138
  //# sourceMappingURL=utils.js.map