@mastra/evals 1.7.0 → 1.8.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.
@@ -2543,19 +2543,30 @@ Evaluation Guidelines:
2543
2543
  - Be objective and focus on alignment rather than response quality
2544
2544
 
2545
2545
  Score each dimension from 0.0 (completely misaligned) to 1.0 (perfectly aligned).`;
2546
- function createAnalyzePrompt$2({ userPrompt, systemPrompt, agentResponse, evaluationMode }) {
2547
- let promptContext = "";
2546
+ function createConversationHistoryContext(conversationHistory) {
2547
+ if (!conversationHistory) return "";
2548
+ return `Conversation History (prior turns, for context only):
2549
+ ${conversationHistory}
2550
+
2551
+ `;
2552
+ }
2553
+ const CONVERSATION_HISTORY_GUIDANCE = `
2554
+ Note on conversation history:
2555
+ - The conversation history is provided only to resolve the meaning of the current prompt. Use it to interpret short or referential prompts (e.g. "A", "yes", "the second one") against what was previously asked or offered.
2556
+ - Evaluate only the agent response to the current prompt. Do not score earlier turns, and do not credit or penalise the agent for anything it said in them.`;
2557
+ function createAnalyzePrompt$2({ userPrompt, systemPrompt, agentResponse, evaluationMode, conversationHistory }) {
2558
+ let promptContext = createConversationHistoryContext(conversationHistory);
2548
2559
  let evaluationTarget = "";
2549
2560
  if (evaluationMode === "user") {
2550
- promptContext = `User Prompt:
2561
+ promptContext += `User Prompt:
2551
2562
  ${userPrompt}`;
2552
2563
  evaluationTarget = "the user's prompt";
2553
2564
  } else if (evaluationMode === "system") {
2554
- promptContext = `System Prompt:
2565
+ promptContext += `System Prompt:
2555
2566
  ${systemPrompt}`;
2556
2567
  evaluationTarget = "the system's behavioral guidelines and constraints";
2557
2568
  } else {
2558
- promptContext = `User Prompt:
2569
+ promptContext += `User Prompt:
2559
2570
  ${userPrompt}
2560
2571
 
2561
2572
  System Prompt:
@@ -2568,6 +2579,7 @@ ${promptContext}
2568
2579
 
2569
2580
  Agent Response:
2570
2581
  ${agentResponse}
2582
+ ${conversationHistory ? CONVERSATION_HISTORY_GUIDANCE : ""}
2571
2583
 
2572
2584
  Evaluate the following aspects:
2573
2585
 
@@ -2690,10 +2702,10 @@ Agent Response: "def factorial(n):
2690
2702
  "overallAssessment": "The response perfectly aligns with the prompt, providing a correct Python factorial function with the requested error handling for negative numbers"
2691
2703
  }`;
2692
2704
  }
2693
- function createReasonPrompt$1({ userPrompt, systemPrompt, score, scale, analysis, evaluationMode }) {
2705
+ function createReasonPrompt$1({ userPrompt, systemPrompt, score, scale, analysis, evaluationMode, conversationHistory }) {
2694
2706
  const fulfilledCount = analysis.requirementsFulfillment.requirements.filter((r) => r.isFulfilled).length;
2695
2707
  const totalRequirements = analysis.requirementsFulfillment.requirements.length;
2696
- const promptContext = evaluationMode === "system" ? `System Prompt:\n${systemPrompt}` : evaluationMode === "user" ? `User Prompt:\n${userPrompt}` : `User Prompt:\n${userPrompt}\n\nSystem Prompt:\n${systemPrompt}`;
2708
+ const promptContext = createConversationHistoryContext(conversationHistory) + (evaluationMode === "system" ? `System Prompt:\n${systemPrompt}` : evaluationMode === "user" ? `User Prompt:\n${userPrompt}` : `User Prompt:\n${userPrompt}\n\nSystem Prompt:\n${systemPrompt}`);
2697
2709
  return `Explain the prompt alignment score based on how well the agent's response addresses the ${evaluationMode === "system" ? "system behavioral guidelines and constraints" : evaluationMode === "user" ? "user's prompt" : "both user's prompt and system guidelines"}.
2698
2710
 
2699
2711
  ${promptContext}
@@ -2840,9 +2852,14 @@ const SCORING_WEIGHTS = {
2840
2852
  SYSTEM_WEIGHT: .3
2841
2853
  }
2842
2854
  };
2855
+ function normalizeConversationHistoryOptions(includeConversationHistory) {
2856
+ if (!includeConversationHistory) return void 0;
2857
+ return includeConversationHistory === true ? {} : includeConversationHistory;
2858
+ }
2843
2859
  function createPromptAlignmentScorerLLM({ model, options }) {
2844
2860
  const scale = options?.scale || 1;
2845
2861
  const evaluationMode = options?.evaluationMode || "both";
2862
+ const historyOptions = normalizeConversationHistoryOptions(options?.includeConversationHistory);
2846
2863
  return (0, _mastra_core_evals.createScorer)({
2847
2864
  id: "prompt-alignment-scorer",
2848
2865
  name: "Prompt Alignment (LLM)",
@@ -2866,7 +2883,8 @@ function createPromptAlignmentScorerLLM({ model, options }) {
2866
2883
  userPrompt,
2867
2884
  systemPrompt,
2868
2885
  agentResponse,
2869
- evaluationMode
2886
+ evaluationMode,
2887
+ conversationHistory: historyOptions && require_scorers_utils.getConversationHistoryFromRunInput(run.input, historyOptions)
2870
2888
  });
2871
2889
  }
2872
2890
  }).generateScore(({ results }) => {
@@ -2902,7 +2920,8 @@ function createPromptAlignmentScorerLLM({ model, options }) {
2902
2920
  score,
2903
2921
  scale,
2904
2922
  analysis,
2905
- evaluationMode
2923
+ evaluationMode,
2924
+ conversationHistory: historyOptions && require_scorers_utils.getConversationHistoryFromRunInput(run.input, historyOptions)
2906
2925
  });
2907
2926
  }
2908
2927
  });