@mastra/evals 1.2.4 → 1.3.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scorers/utils.ts"],"names":["message"],"mappings":";;;;AAsDO,SAAS,kCAAkC,OAAA,EAAkC;AAClF,EAAA,MAAM,UAAU,OAAA,CAAQ,OAAA;AAExB,EAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAC/B,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC1B,IAAA,MAAM,YAAY,OAAA,CAAQ,MAAA,CAAO,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,MAAM,CAAA;AACvD,IAAA,OAAO,SAAA,CAAU,SAAS,CAAA,GAAI,SAAA,CAAU,UAAU,MAAA,GAAS,CAAC,CAAA,EAAG,IAAA,IAAQ,EAAA,GAAK,EAAA;AAAA,EAC9E;AACA,EAAA,IAAI,OAAO,OAAA,EAAS,OAAA,KAAY,QAAA,IAAY,OAAA,CAAQ,YAAY,EAAA,EAAI;AAClE,IAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,EACjB;AACA,EAAA,IAAI,OAAO,OAAA,EAAS,IAAA,KAAS,QAAA,IAAY,OAAA,CAAQ,SAAS,EAAA,EAAI;AAC5D,IAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,EACjB;AACA,EAAA,IAAI,SAAS,KAAA,IAAS,KAAA,CAAM,OAAA,CAAQ,OAAA,CAAQ,KAAK,CAAA,EAAG;AAElD,IAAA,MAAM,SAAA,GAAY,QAAQ,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,KAAW,CAAA,CAAE,SAAS,MAAM,CAAA;AACpE,IAAA,OAAO,SAAA,CAAU,SAAS,CAAA,GAAI,SAAA,CAAU,UAAU,MAAA,GAAS,CAAC,CAAA,EAAG,IAAA,IAAQ,EAAA,GA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C,WAAA,GAAc,kBAAkB,IAAA,GAAO,MAAA;AAAA,QAC5F,mBAAA,EAAqB;AAAA,OACtB,CAAA;AAED,MAAA,YAAA,IAAgB,UAAA;AAAA,IAClB;AAEA,IAAA,CAAA,GAAI,CAAA;AAAA,EACN;AAGA,EAAA,MAAM,mBAAA,GAAsB,QAAA,CAAS,MAAA,CAAO,CAAA,CAAA,KAAK,CAAA,CAAE,UAAA,GAAa,iBAAiB,CAAA,CAAE,GAAA,CAAI,CAAA,CAAA,KAAK,CAAA,CAAE,QAAQ,CAAA;AAEtG,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,IAAI,aAAA,CAAc,SAAS,CAAA,EAAG;AAE5B,IAAA,MAAM,aAAA,GAAgB,QAAA,CAAS,MAAA,CAAO,CAAC,KAAK,CAAA,KAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAA,CAAE,UAAA,GAAa,iBAAiB,GAAG,CAAC,CAAA;AACxG,IAAA,KAAA,GAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAA,GAAI,gBAAgB,GAAG,CAAA;AAAA,EAC7C;AAEA,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,kBAAA,CAAmB,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAC,CAAA;AAAA,IACzD,QAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-XOXUFZEG.js","sourcesContent":["import type { MastraDBMessage } from '@mastra/core/agent';\nimport type {\n ExpectedStep,\n ScorerRunInputForAgent,\n ScorerRunOutputForAgent,\n ScoringInput,\n TrajectoryExpectation,\n TrajectoryStep,\n Trajectory,\n} from '@mastra/core/evals';\nimport { RequestContext } from '@mastra/core/request-context';\n\nexport type ScorerRunInputForLLMJudge =\n | ScorerRunInputForAgent\n | string\n | {\n inputMessages?: unknown[];\n messages?: unknown[];\n prompt?: string;\n text?: string;\n content?: unknown;\n input?: unknown;\n user?: unknown;\n [key: string]: unknown;\n };\n\nexport type ScorerRunOutputForLLMJudge =\n | ScorerRunOutputForAgent\n | string\n | unknown[]\n | {\n text?: string;\n content?: unknown;\n role?: string;\n [key: string]: unknown;\n };\n\n/**\n * Extracts text content from a MastraDBMessage or ModelMessage-like object.\n *\n * @param message - The message to extract text from\n * @returns The extracted text content, or an empty string if no text is found\n *\n * @example\n * ```ts\n * const message: MastraDBMessage = {\n * id: 'msg-1',\n * role: 'assistant',\n * content: { format: 2, parts: [{ type: 'text', text: 'Hello!' }] },\n * createdAt: new Date(),\n * };\n * const text = getTextContentFromMastraDBMessage(message); // 'Hello!'\n * ```\n */\nexport function getTextContentFromMastraDBMessage(message: MastraDBMessage): string {\n const content = message.content as any;\n\n if (typeof content === 'string') {\n return content;\n }\n if (Array.isArray(content)) {\n const textParts = content.filter(p => p.type === 'text');\n return textParts.length > 0 ? textParts[textParts.length - 1]?.text || '' : '';\n }\n if (typeof content?.content === 'string' && content.content !== '') {\n return content.content;\n }\n if (typeof content?.text === 'string' && content.text !== '') {\n return content.text;\n }\n if (content?.parts && Array.isArray(content.parts)) {\n // Return only the last text part like AI SDK does\n const textParts = content.parts.filter((p: any) => p.type === 'text');\n return textParts.length > 0 ? textParts[textParts.length - 1]?.text || '' : '';\n }\n return '';\n}\n\nconst isRecord = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst getTextFromValue = (value: unknown): string | undefined => {\n if (typeof value === 'string') return value;\n if (Array.isArray(value)) {\n const textParts = value\n .filter(part => isRecord(part) && part.type === 'text' && typeof part.text === 'string')\n .map(part => part.text);\n return textParts.length > 0 ? textParts[textParts.length - 1] : undefined;\n }\n if (!isRecord(value)) return undefined;\n\n return (\n getTextFromValue(value.content) ??\n (typeof value.text === 'string' ? value.text : undefined) ??\n (typeof value.body === 'string' ? value.body : undefined)\n );\n};\n\nexport const isScorerRunInputForAgent = (input: unknown): input is ScorerRunInputForAgent => {\n return (\n isRecord(input) &&\n Array.isArray(input.inputMessages) &&\n Array.isArray(input.rememberedMessages) &&\n Array.isArray(input.systemMessages) &&\n isRecord(input.taggedSystemMessages)\n );\n};\n\nconst isMastraDBMessageLike = (message: unknown): message is MastraDBMessage => {\n return (\n isRecord(message) &&\n typeof message.id === 'string' &&\n typeof message.role === 'string' &&\n 'content' in message &&\n 'createdAt' in message\n );\n};\n\nexport const isScorerRunOutputForAgent = (output: unknown): output is ScorerRunOutputForAgent => {\n return Array.isArray(output) && output.every(isMastraDBMessageLike);\n};\n\nconst getTextFromMessages = (messages: unknown, role: string): string | undefined => {\n if (!Array.isArray(messages)) return undefined;\n\n const message = messages.find(message => isRecord(message) && message.role === role);\n return message ? getTextFromValue(message) : undefined;\n};\n\n/**\n * Rounds a number to two decimal places.\n *\n * Uses `Number.EPSILON` to handle floating-point precision issues.\n *\n * @param num - The number to round\n * @returns The number rounded to two decimal places\n *\n * @example\n * ```ts\n * roundToTwoDecimals(0.1 + 0.2); // 0.3\n * roundToTwoDecimals(1.005); // 1.01\n * ```\n */\nexport const roundToTwoDecimals = (num: number) => {\n return Math.round((num + Number.EPSILON) * 100) / 100;\n};\n\n/**\n * Determines if a value is closer to the first target than the second.\n *\n * @param value - The value to compare\n * @param target1 - The first target value\n * @param target2 - The second target value\n * @returns `true` if `value` is closer to `target1` than `target2`\n *\n * @example\n * ```ts\n * isCloserTo(0.6, 1, 0); // true (0.6 is closer to 1)\n * isCloserTo(0.3, 1, 0); // false (0.3 is closer to 0)\n * ```\n */\nexport function isCloserTo(value: number, target1: number, target2: number): boolean {\n return Math.abs(value - target1) < Math.abs(value - target2);\n}\n\n/**\n * Represents a test case for scorer evaluation.\n */\nexport type TestCase = {\n /** The input text to evaluate */\n input: string;\n /** The output text to evaluate */\n output: string;\n /** The expected result of the evaluation */\n expectedResult: {\n /** The expected score */\n score: number;\n /** The optional expected reason */\n reason?: string;\n };\n};\n\n/**\n * Represents a test case with additional context for scorer evaluation.\n */\nexport type TestCaseWithContext = TestCase & {\n /** Additional context strings for the evaluation */\n context: string[];\n};\n\n/**\n * Creates a scoring input object for testing purposes.\n *\n * @param input - The user input text\n * @param output - The assistant output text\n * @param additionalContext - Optional additional context data\n * @param requestContext - Optional request context data\n * @returns A ScoringInput object ready for use in scorer tests\n *\n * @example\n * ```ts\n * const run = createTestRun(\n * 'What is 2+2?',\n * 'The answer is 4.',\n * { topic: 'math' }\n * );\n * ```\n */\nexport const createTestRun = (\n input: string,\n output: string,\n additionalContext?: Record<string, any>,\n requestContext?: Record<string, any>,\n): ScoringInput => {\n return {\n input: [{ role: 'user', content: input }],\n output: { role: 'assistant', text: output },\n additionalContext: additionalContext ?? {},\n requestContext: requestContext ?? {},\n };\n};\n\n/**\n * Extracts the user message text from a scorer run input.\n *\n * Accepts the agent shape (`{ inputMessages }`), `ModelMessage[]`\n * (`{ messages }`), workflow input (`{ prompt }`), and a bare string.\n *\n * @param input - The scorer run input\n * @returns The user message text, or `undefined` if none can be extracted\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const userText = getUserMessageFromRunInput(run.input);\n * return { userText };\n * });\n * ```\n */\nexport const getUserMessageFromRunInput = (input?: unknown): string | undefined => {\n if (typeof input === 'string') return input;\n if (!isRecord(input)) return undefined;\n\n return (\n getTextFromMessages(input.inputMessages, 'user') ??\n getTextFromMessages(input.messages, 'user') ??\n (typeof input.prompt === 'string' ? input.prompt : undefined) ??\n (typeof input.text === 'string' ? input.text : undefined) ??\n getTextFromValue(input.content) ??\n getTextFromValue(input.input) ??\n getTextFromValue(input.user)\n );\n};\n\n/**\n * Extracts all system messages from a scorer run input.\n *\n * Collects text from both standard system messages and tagged system messages\n * (specialized system prompts like memory instructions).\n *\n * @param input - The scorer run input containing system messages\n * @returns An array of system message strings\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemMessages = getSystemMessagesFromRunInput(run.input);\n * return { systemPrompt: systemMessages.join('\\n') };\n * });\n * ```\n */\nexport const getSystemMessagesFromRunInput = (input?: unknown): string[] => {\n const systemMessages: string[] = [];\n if (!isRecord(input)) return systemMessages;\n\n // Add standard system messages\n if (Array.isArray(input.systemMessages)) {\n systemMessages.push(\n ...input.systemMessages\n .map(msg => {\n // Handle different content types - extract text if it's an array of parts\n if (typeof msg.content === 'string') {\n return msg.content;\n } else if (Array.isArray(msg.content)) {\n // Extract text from parts array\n return msg.content\n .filter((part: any) => part.type === 'text')\n .map((part: any) => part.text || '')\n .join(' ');\n }\n return '';\n })\n .filter(content => content),\n );\n }\n\n const addSystemMessages = (messages: unknown) => {\n if (!Array.isArray(messages)) return;\n\n systemMessages.push(\n ...messages\n .filter(message => isRecord(message) && message.role === 'system')\n .map(message => getTextFromValue(message))\n .filter((content): content is string => Boolean(content)),\n );\n };\n\n addSystemMessages(input.inputMessages);\n addSystemMessages(input.messages);\n\n // Add tagged system messages (these are specialized system prompts)\n if (isRecord(input.taggedSystemMessages)) {\n Object.values(input.taggedSystemMessages).forEach(messages => {\n if (!Array.isArray(messages)) return;\n messages.forEach(msg => {\n const content = getTextFromValue(msg);\n if (content) {\n systemMessages.push(content);\n }\n });\n });\n }\n\n return systemMessages;\n};\n\n/**\n * Combines all system messages into a single prompt string.\n *\n * Joins all system messages (standard and tagged) with double newlines.\n *\n * @param input - The scorer run input containing system messages\n * @returns A combined system prompt string\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemPrompt = getCombinedSystemPrompt(run.input);\n * return { systemPrompt };\n * });\n * ```\n */\nexport const getCombinedSystemPrompt = (input?: unknown): string => {\n const systemMessages = getSystemMessagesFromRunInput(input);\n return systemMessages.join('\\n\\n');\n};\n\n/**\n * Extracts the assistant message text from a scorer run output.\n *\n * Accepts the agent shape (`MastraDBMessage[]` / `ModelMessage[]`), workflow\n * output (`{ text }`), task output (`{ content }`), a single assistant message\n * object, and a bare string.\n *\n * @param output - The scorer run output\n * @returns The assistant message text, or `undefined` if none can be extracted\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { response };\n * });\n * ```\n */\nexport const getAssistantMessageFromRunOutput = (output?: unknown) => {\n if (typeof output === 'string') return output;\n if (Array.isArray(output)) return getTextFromMessages(output, 'assistant');\n if (!isRecord(output)) return undefined;\n\n const isAssistantOutput = output.role === undefined || output.role === 'assistant';\n\n if (isAssistantOutput && typeof output.text === 'string') return output.text;\n if (isAssistantOutput && typeof output.content === 'string') return output.content;\n if (isAssistantOutput && (isRecord(output.content) || Array.isArray(output.content))) {\n return (\n getTextContentFromMastraDBMessage(output as MastraDBMessage) ||\n getTextContentFromMastraDBMessage(output.content as MastraDBMessage) ||\n undefined\n );\n }\n if (output.role === 'assistant') return getTextContentFromMastraDBMessage(output as MastraDBMessage) || undefined;\n\n return undefined;\n};\n\n/**\n * Extracts reasoning text from a scorer run output.\n *\n * This function extracts reasoning content from assistant messages, which is\n * produced by reasoning models like `deepseek-reasoner`. The reasoning can be\n * stored in two places:\n * 1. `content.reasoning` - a string field on the message content\n * 2. `content.parts` - as parts with `type: 'reasoning'` containing `details`\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns The reasoning text, or `undefined` if no reasoning is present\n *\n * @example\n * ```ts\n * const reasoningScorer = createScorer({\n * id: 'reasoning-scorer',\n * name: 'Reasoning Quality',\n * description: 'Evaluates the quality of model reasoning',\n * type: 'agent',\n * })\n * .preprocess(({ run }) => {\n * const reasoning = getReasoningFromRunOutput(run.output);\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { reasoning, response };\n * })\n * .generateScore(({ results }) => {\n * // Score based on reasoning quality\n * return results.preprocessStepResult?.reasoning ? 1 : 0;\n * });\n * ```\n */\nexport const getReasoningFromRunOutput = (output?: ScorerRunOutputForAgent): string | undefined => {\n if (!output) return undefined;\n\n const message = output.find(({ role }) => role === 'assistant');\n if (!message) return undefined;\n\n // Check for reasoning in content.reasoning (string format)\n if (message.content.reasoning) {\n return message.content.reasoning;\n }\n\n // Check for reasoning in parts with type 'reasoning'\n // Reasoning models store reasoning in parts as { type: 'reasoning', details: [{ type: 'text', text: '...' }] }\n const reasoningParts = message.content.parts?.filter((p: any) => p.type === 'reasoning');\n if (reasoningParts && reasoningParts.length > 0) {\n const reasoningTexts = reasoningParts\n .map((p: any) => {\n // The reasoning text can be in p.reasoning or in p.details[].text\n if (p.details && Array.isArray(p.details)) {\n return p.details\n .filter((d: any) => d.type === 'text')\n .map((d: any) => d.text)\n .join('');\n }\n return p.reasoning || '';\n })\n .filter(Boolean);\n\n return reasoningTexts.length > 0 ? reasoningTexts.join('\\n') : undefined;\n }\n\n return undefined;\n};\n\n/**\n * Creates a tool invocation object for testing purposes.\n *\n * @param options - The tool invocation configuration\n * @param options.toolCallId - Unique identifier for the tool call\n * @param options.toolName - Name of the tool being called\n * @param options.args - Arguments passed to the tool\n * @param options.result - Result returned by the tool\n * @param options.state - State of the invocation (default: 'result')\n * @returns A tool invocation object\n *\n * @example\n * ```ts\n * const invocation = createToolInvocation({\n * toolCallId: 'call-123',\n * toolName: 'weatherTool',\n * args: { location: 'London' },\n * result: { temperature: 20, condition: 'sunny' },\n * });\n * ```\n */\nexport const createToolInvocation = ({\n toolCallId,\n toolName,\n args,\n result,\n state = 'result',\n}: {\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state?: 'call' | 'partial-call' | 'result';\n}): { toolCallId: string; toolName: string; args: Record<string, any>; result: Record<string, any>; state: string } => {\n return {\n toolCallId,\n toolName,\n args,\n result,\n state,\n };\n};\n\n/**\n * Creates a MastraDBMessage object for testing purposes.\n *\n * Supports optional tool invocations for testing tool call scenarios.\n *\n * @param options - The message configuration\n * @param options.content - The text content of the message\n * @param options.role - The role of the message sender ('user', 'assistant', or 'system')\n * @param options.id - Optional message ID (default: 'test-message')\n * @param options.toolInvocations - Optional array of tool invocations\n * @returns A MastraDBMessage object\n *\n * @example\n * ```ts\n * const message = createTestMessage({\n * content: 'Hello, how can I help?',\n * role: 'assistant',\n * });\n *\n * // With tool invocations\n * const messageWithTools = createTestMessage({\n * content: 'Let me check the weather.',\n * role: 'assistant',\n * toolInvocations: [{\n * toolCallId: 'call-1',\n * toolName: 'weatherTool',\n * args: { location: 'Paris' },\n * result: { temp: 22 },\n * state: 'result',\n * }],\n * });\n * ```\n */\nexport function createTestMessage({\n content,\n role,\n id = 'test-message',\n toolInvocations = [],\n}: {\n content: string;\n role: 'user' | 'assistant' | 'system';\n id?: string;\n toolInvocations?: Array<{\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state: any;\n }>;\n}): MastraDBMessage {\n return {\n id,\n role,\n content: {\n format: 2,\n parts: [{ type: 'text', text: content }],\n content,\n ...(toolInvocations.length > 0 && {\n toolInvocations: toolInvocations.map(ti => ({\n toolCallId: ti.toolCallId,\n toolName: ti.toolName,\n args: ti.args,\n result: ti.result,\n state: ti.state,\n })),\n }),\n },\n createdAt: new Date(),\n };\n}\n\n/**\n * Creates a complete agent test run object for testing scorers.\n *\n * Provides a convenient way to construct the full run object that scorers receive,\n * including input messages, output, system messages, and request context.\n *\n * @param options - The test run configuration\n * @param options.inputMessages - Array of input messages (default: [])\n * @param options.output - The output messages (required)\n * @param options.rememberedMessages - Array of remembered messages from memory (default: [])\n * @param options.systemMessages - Array of system messages (default: [])\n * @param options.taggedSystemMessages - Tagged system messages map (default: {})\n * @param options.requestContext - Request context (default: new RequestContext())\n * @param options.runId - Unique run ID (default: random UUID)\n * @returns A complete test run object\n *\n * @example\n * ```ts\n * const testRun = createAgentTestRun({\n * inputMessages: [createTestMessage({ content: 'Hello', role: 'user' })],\n * output: [createTestMessage({ content: 'Hi there!', role: 'assistant' })],\n * });\n *\n * const result = await scorer.run({\n * input: testRun.input,\n * output: testRun.output,\n * });\n * ```\n */\nexport const createAgentTestRun = ({\n inputMessages = [],\n output,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n requestContext = new RequestContext(),\n runId = crypto.randomUUID(),\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n output: ScorerRunOutputForAgent;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n requestContext?: RequestContext;\n runId?: string;\n}): {\n input: ScorerRunInputForAgent;\n output: ScorerRunOutputForAgent;\n requestContext: RequestContext;\n runId: string;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output,\n requestContext,\n runId,\n };\n};\n\n/**\n * Creates a test run for trajectory scorers where `output` is a `Trajectory`\n * (pre-extracted by the `runEvals` pipeline).\n *\n * @example\n * ```ts\n * const testRun = createTrajectoryTestRun({\n * inputMessages: [createTestMessage({ content: 'Do X', role: 'user', id: 'u1' })],\n * trajectory: {\n * steps: [\n * { stepType: 'tool_call', name: 'search', toolArgs: { q: 'test' } },\n * ],\n * },\n * });\n * ```\n */\nexport const createTrajectoryTestRun = ({\n inputMessages = [],\n trajectory,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n requestContext = new RequestContext(),\n runId = crypto.randomUUID(),\n expectedTrajectory,\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n trajectory: Trajectory;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n requestContext?: RequestContext;\n runId?: string;\n expectedTrajectory?: TrajectoryExpectation;\n}): {\n input: ScorerRunInputForAgent;\n output: Trajectory;\n requestContext: RequestContext;\n runId: string;\n expectedTrajectory?: TrajectoryExpectation;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output: trajectory,\n expectedTrajectory,\n requestContext,\n runId,\n };\n};\n\n/**\n * Information about a tool call extracted from scorer output.\n */\nexport type ToolCallInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Index of the message containing this tool call */\n messageIndex: number;\n /** Index of the invocation within the message's tool invocations */\n invocationIndex: number;\n};\n\n/**\n * Extracts all tool calls from a scorer run output.\n *\n * Iterates through all messages and their tool invocations to collect\n * information about tools that were called (with state 'result' or 'call').\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An object containing tool names and detailed tool call info\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const { tools, toolCallInfos } = extractToolCalls(run.output);\n * return {\n * toolsUsed: tools,\n * toolCount: tools.length,\n * };\n * });\n * ```\n */\nexport function extractToolCalls(output: ScorerRunOutputForAgent): { tools: string[]; toolCallInfos: ToolCallInfo[] } {\n const toolCalls: string[] = [];\n const toolCallInfos: ToolCallInfo[] = [];\n\n for (let messageIndex = 0; messageIndex < output.length; messageIndex++) {\n const message = output[messageIndex];\n // Prefer the legacy toolInvocations array when present; fall back to\n // V2 content.parts for messages that only store tool calls there.\n const legacy = message?.content?.toolInvocations;\n const fromParts = legacy\n ? undefined\n : message?.content?.parts\n ?.filter((p): p is Extract<typeof p, { type: 'tool-invocation' }> => p.type === 'tool-invocation')\n .map(p => p.toolInvocation);\n const toolInvocations = legacy ?? fromParts;\n\n if (!toolInvocations?.length) continue;\n\n for (let invocationIndex = 0; invocationIndex < toolInvocations.length; invocationIndex++) {\n const invocation = toolInvocations[invocationIndex];\n if (invocation && invocation.toolName && (invocation.state === 'result' || invocation.state === 'call')) {\n toolCalls.push(invocation.toolName);\n toolCallInfos.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || `${messageIndex}-${invocationIndex}`,\n messageIndex,\n invocationIndex,\n });\n }\n }\n }\n\n return { tools: toolCalls, toolCallInfos };\n}\n\n/**\n * Extracts text content from all input messages.\n *\n * @param runInput - The scorer run input\n * @returns An array of text strings from each input message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const messages = extractInputMessages(run.input);\n * return { allUserMessages: messages.join('\\n') };\n * });\n * ```\n */\nexport const extractInputMessages = (runInput: ScorerRunInputForAgent | undefined): string[] => {\n return runInput?.inputMessages?.map(msg => getTextContentFromMastraDBMessage(msg)) || [];\n};\n\n/**\n * Extracts text content from all assistant response messages.\n *\n * Filters for messages with role 'assistant' and extracts their text content.\n *\n * @param runOutput - The scorer run output (array of MastraDBMessage)\n * @returns An array of text strings from each assistant message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const responses = extractAgentResponseMessages(run.output);\n * return { allResponses: responses.join('\\n') };\n * });\n * ```\n */\nexport const extractAgentResponseMessages = (runOutput: ScorerRunOutputForAgent): string[] => {\n return runOutput.filter(msg => msg.role === 'assistant').map(msg => getTextContentFromMastraDBMessage(msg));\n};\n\n/**\n * Information about a tool result extracted from scorer output.\n */\nexport type ToolResultInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Arguments passed to the tool */\n args: Record<string, any>;\n /** Result returned by the tool */\n result: any;\n};\n\n/**\n * Extracts tool results from a scorer run output.\n *\n * Returns structured objects that can be used with the hallucination scorer's\n * `getContext` hook or for other scorer logic.\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An array of ToolResultInfo objects\n *\n * @example\n * ```ts\n * import { extractToolResults } from '@mastra/evals/scorers';\n * import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt';\n *\n * const scorer = createHallucinationScorer({\n * model: openai('gpt-4o'),\n * options: {\n * getContext: (run) => {\n * const toolResults = extractToolResults(run.output);\n * return toolResults.map(t => JSON.stringify({ tool: t.toolName, result: t.result }));\n * },\n * },\n * });\n * ```\n */\nexport function extractToolResults(output: ScorerRunOutputForAgent): ToolResultInfo[] {\n const results: ToolResultInfo[] = [];\n\n for (const message of output) {\n // Prefer the legacy toolInvocations array when present; fall back to\n // V2 content.parts for messages that only store tool calls there.\n const legacy = message?.content?.toolInvocations;\n const fromParts = legacy\n ? undefined\n : message?.content?.parts\n ?.filter((p): p is Extract<typeof p, { type: 'tool-invocation' }> => p.type === 'tool-invocation')\n .map(p => p.toolInvocation);\n const toolInvocations = legacy ?? fromParts;\n\n if (!toolInvocations?.length) continue;\n\n for (const invocation of toolInvocations) {\n if (invocation.state === 'result' && invocation.result !== undefined) {\n results.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || '',\n args: invocation.args || {},\n result: invocation.result,\n });\n }\n }\n }\n\n return results;\n}\n\n// Re-export extractTrajectory from core — it's called automatically by runEvals\n// for trajectory scorers, but users may still want it for custom use cases.\nexport { extractTrajectory } from '@mastra/core/evals';\n\n/**\n * Compares two trajectories and returns detailed comparison results.\n *\n * This is the core comparison logic used by trajectory scorers. It supports\n * strict and non-strict ordering, optional step data comparison, and loop detection.\n *\n * @param actual - The trajectory the agent actually took\n * @param expected - The expected trajectory to compare against\n * @param options - Comparison configuration options\n * @returns Detailed comparison results including match scores and diagnostics\n *\n * @example\n * ```ts\n * const result = compareTrajectories(\n * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },\n * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },\n * { ordering: 'strict' }\n * );\n * // result.score = 1.0\n * ```\n */\nexport function compareTrajectories(\n actual: Trajectory,\n expected: Trajectory | { steps: ExpectedStep[] },\n options: {\n ordering?: 'strict' | 'relaxed' | 'unordered';\n allowRepeatedSteps?: boolean;\n } = {},\n): TrajectoryComparisonResult {\n const { allowRepeatedSteps = true, ordering = 'relaxed' } = options;\n\n // Normalize expected to ExpectedStep[]. TrajectoryStep and ExpectedStep share\n // the same field names, so TrajectoryStep[] can be used directly as ExpectedStep[].\n // The only structural difference is `children` (TrajectoryStep[] vs TrajectoryExpectation),\n // but compareTrajectories doesn't recurse into children.\n const normalizedExpected: { steps: ExpectedStep[] } = {\n steps: expected.steps as ExpectedStep[],\n };\n\n if (normalizedExpected.steps.length === 0) {\n return {\n score: actual.steps.length === 0 ? 1 : 0,\n matchedSteps: 0,\n totalExpectedSteps: 0,\n totalActualSteps: actual.steps.length,\n missingSteps: [],\n extraSteps: actual.steps.map((s: TrajectoryStep) => s.name),\n outOfOrderSteps: [],\n repeatedSteps: [],\n };\n }\n\n const actualNames = actual.steps.map((s: TrajectoryStep) => s.name);\n\n // Detect repeated steps\n const nameCounts = new Map<string, number>();\n for (const name of actualNames) {\n nameCounts.set(name, (nameCounts.get(name) || 0) + 1);\n }\n const repeatedSteps = [...nameCounts.entries()]\n .filter(([_, count]: [string, number]) => count > 1)\n .map(([name]: [string, number]) => name);\n\n if (ordering === 'strict') {\n return compareStrictOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n }\n\n if (ordering === 'unordered') {\n return compareUnorderedPresence(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n }\n\n return compareRelaxedOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n}\n\n/**\n * Result of comparing two trajectories.\n */\nexport type TrajectoryComparisonResult = {\n /** Overall match score from 0 to 1 */\n score: number;\n /** Number of expected steps that were matched */\n matchedSteps: number;\n /** Total number of expected steps */\n totalExpectedSteps: number;\n /** Total number of actual steps taken */\n totalActualSteps: number;\n /** Expected steps that were not found in the actual trajectory */\n missingSteps: string[];\n /** Actual steps that were not in the expected trajectory */\n extraSteps: string[];\n /** Steps that appear but not in the expected position */\n outOfOrderSteps: string[];\n /** Steps that were repeated (appeared more than once) */\n repeatedSteps: string[];\n};\n\nfunction compareStrictOrder(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n // Strict: exact same sequence\n let matchedSteps = 0;\n const outOfOrderSteps: string[] = [];\n const matchedExpectedIndices = new Set<number>();\n const maxLen = Math.max(actualNames.length, expectedNames.length);\n\n for (let i = 0; i < maxLen; i++) {\n const actualName = actualNames[i];\n const expectedName = expectedNames[i];\n if (actualName === expectedName) {\n if (actual.steps[i] && expected.steps[i]) {\n if (expectedStepMatches(actual.steps[i]!, expected.steps[i]!)) {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n }\n } else {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n }\n } else if (actualName && expectedNames.includes(actualName)) {\n outOfOrderSteps.push(actualName);\n }\n }\n\n // Missing steps = expected steps that were not matched (accounts for stepType/data mismatches)\n const missingSteps: string[] = expectedNames.filter((_: string, i: number) => !matchedExpectedIndices.has(i));\n const extraSteps: string[] = actualNames.filter((name: string) => !expectedNames.includes(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize extra steps in strict mode\n if (actualNames.length > expectedNames.length) {\n const extraPenalty = (actualNames.length - expectedNames.length) / expectedNames.length;\n score = Math.max(0, score - extraPenalty * 0.5);\n }\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps,\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\nfunction compareRelaxedOrder(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n // Relaxed: expected steps must appear in order but extra steps are allowed\n let matchedSteps = 0;\n let lastMatchedIndex = -1;\n const outOfOrderSteps: string[] = [];\n const matchedExpectedIndices = new Set<number>();\n\n for (let i = 0; i < expectedNames.length; i++) {\n const expectedName = expectedNames[i];\n let found = false;\n\n for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) {\n if (actualNames[j] === expectedName) {\n if (actual.steps[j] && expected.steps[i]) {\n if (expectedStepMatches(actual.steps[j]!, expected.steps[i]!)) {\n matchedSteps++;\n lastMatchedIndex = j;\n matchedExpectedIndices.add(i);\n found = true;\n break;\n }\n } else {\n matchedSteps++;\n lastMatchedIndex = j;\n matchedExpectedIndices.add(i);\n found = true;\n break;\n }\n }\n }\n\n if (!found) {\n // Check if the step exists but is out of order\n if (actualNames.includes(expectedName!)) {\n outOfOrderSteps.push(expectedName!);\n }\n }\n }\n\n // Missing steps = expected steps that were not matched (by name + stepType + data, not just name)\n const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));\n const expectedSet = new Set(expectedNames);\n const extraSteps = actualNames.filter(name => !expectedSet.has(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps,\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\n/**\n * Fields on each ExpectedStep variant that are comparable data (not structural).\n * Used by `expectedStepMatches` to know which fields to compare when `compareData` is true.\n */\nconst COMPARABLE_FIELDS_BY_TYPE: Record<string, string[]> = {\n tool_call: ['toolArgs', 'toolResult', 'success'],\n mcp_tool_call: ['toolArgs', 'toolResult', 'mcpServer', 'success'],\n model_generation: ['modelId', 'promptTokens', 'completionTokens', 'finishReason'],\n agent_run: ['agentId'],\n workflow_step: ['stepId', 'status', 'output'],\n workflow_run: ['workflowId', 'status'],\n workflow_conditional: ['conditionCount', 'selectedSteps'],\n workflow_parallel: ['branchCount', 'parallelSteps'],\n workflow_loop: ['loopType', 'totalIterations'],\n workflow_sleep: ['sleepDurationMs', 'sleepType'],\n workflow_wait_event: ['eventName', 'eventReceived'],\n processor_run: ['processorId'],\n};\n\n/**\n * Check if an actual TrajectoryStep matches an ExpectedStep.\n * Matches by name, optionally by stepType, and auto-compares any variant-specific\n * fields that are present on the expected step.\n */\nfunction expectedStepMatches(actual: TrajectoryStep, expected: ExpectedStep): boolean {\n if (actual.name !== expected.name) return false;\n if (expected.stepType && actual.stepType !== expected.stepType) return false;\n\n if (expected.stepType) {\n const fields = COMPARABLE_FIELDS_BY_TYPE[expected.stepType] ?? [];\n for (const field of fields) {\n const expectedVal = (expected as any)[field];\n if (expectedVal === undefined) continue; // field not specified in expectation, skip\n const actualVal = (actual as any)[field];\n if (actualVal === undefined) return false;\n try {\n if (JSON.stringify(actualVal) !== JSON.stringify(expectedVal)) return false;\n } catch {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction compareUnorderedPresence(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n let matchedSteps = 0;\n const matchedExpectedIndices = new Set<number>();\n const usedIndices = new Set<number>();\n for (let i = 0; i < expected.steps.length; i++) {\n const expectedStep = expected.steps[i]!;\n for (let j = 0; j < actual.steps.length; j++) {\n if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j]!, expectedStep)) {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n usedIndices.add(j);\n break;\n }\n }\n }\n\n // Missing steps = expected steps that were not matched (accounts for stepType/data mismatches)\n const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));\n const expectedSet = new Set(expectedNames);\n const extraSteps = actualNames.filter(name => !expectedSet.has(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps: [], // ordering not checked in unordered mode\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\n// ─── Efficiency evaluation ───\n\n/**\n * Result of checking trajectory efficiency.\n */\nexport type TrajectoryEfficiencyResult = {\n /** Overall efficiency score from 0 to 1 */\n score: number;\n /** Total number of steps taken */\n totalSteps: number;\n /** Whether the step budget was exceeded */\n overStepBudget: boolean;\n /** Total tokens used across model_generation steps */\n totalTokens: number;\n /** Whether the token budget was exceeded */\n overTokenBudget: boolean;\n /** Total duration in milliseconds */\n totalDurationMs: number;\n /** Whether the duration budget was exceeded */\n overDurationBudget: boolean;\n /** Redundant calls detected (same tool + same args consecutively) */\n redundantCalls: Array<{ name: string; index: number }>;\n};\n\n/**\n * Evaluate trajectory efficiency against budgets and redundancy checks.\n */\nexport function checkTrajectoryEfficiency(\n trajectory: Trajectory,\n options: {\n maxSteps?: number;\n maxTotalTokens?: number;\n maxTotalDurationMs?: number;\n noRedundantCalls?: boolean;\n } = {},\n): TrajectoryEfficiencyResult {\n const { maxSteps, maxTotalTokens, maxTotalDurationMs, noRedundantCalls = true } = options;\n\n const totalSteps = trajectory.steps.length;\n\n // Calculate total tokens from model_generation steps\n let totalTokens = 0;\n for (const step of trajectory.steps) {\n if (step.stepType === 'model_generation') {\n totalTokens += (step.promptTokens ?? 0) + (step.completionTokens ?? 0);\n }\n }\n\n // Calculate total duration\n const totalDurationMs =\n trajectory.totalDurationMs ?? trajectory.steps.reduce((sum, s) => sum + (s.durationMs ?? 0), 0);\n\n // Detect redundant calls (same tool name + same args in consecutive calls)\n const redundantCalls: Array<{ name: string; index: number }> = [];\n if (noRedundantCalls) {\n for (let i = 1; i < trajectory.steps.length; i++) {\n const prev = trajectory.steps[i - 1]!;\n const curr = trajectory.steps[i]!;\n if (\n prev.name === curr.name &&\n prev.stepType === curr.stepType &&\n (prev.stepType === 'tool_call' || prev.stepType === 'mcp_tool_call')\n ) {\n const prevArgs = (prev as TrajectoryStep & { toolArgs?: Record<string, unknown> }).toolArgs;\n const currArgs = (curr as TrajectoryStep & { toolArgs?: Record<string, unknown> }).toolArgs;\n try {\n if (JSON.stringify(prevArgs) === JSON.stringify(currArgs)) {\n redundantCalls.push({ name: curr.name, index: i });\n }\n } catch {\n // If serialization fails, don't flag as redundant\n }\n }\n }\n }\n\n const overStepBudget = maxSteps !== undefined && totalSteps > maxSteps;\n const overTokenBudget = maxTotalTokens !== undefined && totalTokens > maxTotalTokens;\n const overDurationBudget = maxTotalDurationMs !== undefined && totalDurationMs > maxTotalDurationMs;\n\n // Calculate score: each dimension contributes equally\n const dimensions: number[] = [];\n\n if (maxSteps !== undefined) {\n dimensions.push(overStepBudget ? Math.max(0, 1 - (totalSteps - maxSteps) / maxSteps) : 1);\n }\n if (maxTotalTokens !== undefined) {\n dimensions.push(overTokenBudget ? Math.max(0, 1 - (totalTokens - maxTotalTokens) / maxTotalTokens) : 1);\n }\n if (maxTotalDurationMs !== undefined) {\n dimensions.push(\n overDurationBudget ? Math.max(0, 1 - (totalDurationMs - maxTotalDurationMs) / maxTotalDurationMs) : 1,\n );\n }\n if (noRedundantCalls) {\n dimensions.push(redundantCalls.length === 0 ? 1 : Math.max(0, 1 - redundantCalls.length * 0.2));\n }\n\n const score = dimensions.length > 0 ? dimensions.reduce((a, b) => a + b, 0) / dimensions.length : 1;\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n totalSteps,\n overStepBudget,\n totalTokens,\n overTokenBudget,\n totalDurationMs,\n overDurationBudget,\n redundantCalls,\n };\n}\n\n// ─── Blacklist evaluation ───\n\n/**\n * Result of checking trajectory against a blacklist.\n */\nexport type TrajectoryBlacklistResult = {\n /** Score: 1.0 if clean, 0.0 if any violation found */\n score: number;\n /** Individual blacklisted tools that were found */\n violatedTools: string[];\n /** Blacklisted sequences that were found */\n violatedSequences: string[][];\n};\n\n/**\n * Check if a trajectory violates any blacklist rules.\n * Returns score 0.0 if any violation is found (hard fail).\n */\nexport function checkTrajectoryBlacklist(\n trajectory: Trajectory,\n options: {\n blacklistedTools?: string[];\n blacklistedSequences?: string[][];\n } = {},\n): TrajectoryBlacklistResult {\n const { blacklistedTools = [], blacklistedSequences = [] } = options;\n const violatedTools: string[] = [];\n const violatedSequences: string[][] = [];\n\n const stepNames = trajectory.steps.map(s => s.name);\n\n // Check blacklisted tools\n for (const forbidden of blacklistedTools) {\n if (stepNames.includes(forbidden)) {\n violatedTools.push(forbidden);\n }\n }\n\n // Check blacklisted sequences (contiguous subsequences)\n for (const sequence of blacklistedSequences) {\n if (sequence.length === 0) continue;\n for (let i = 0; i <= stepNames.length - sequence.length; i++) {\n let match = true;\n for (let j = 0; j < sequence.length; j++) {\n if (stepNames[i + j] !== sequence[j]) {\n match = false;\n break;\n }\n }\n if (match) {\n violatedSequences.push(sequence);\n break; // Only report each sequence once\n }\n }\n }\n\n const hasViolations = violatedTools.length > 0 || violatedSequences.length > 0;\n\n return {\n score: hasViolations ? 0 : 1,\n violatedTools,\n violatedSequences,\n };\n}\n\n// ─── Tool failure analysis ───\n\n/**\n * A detected tool failure pattern in the trajectory.\n */\nexport type ToolFailurePattern = {\n /** The tool name that experienced failure */\n toolName: string;\n /** Number of consecutive retries (same tool, same or similar args) */\n retryCount: number;\n /** Whether the agent fell back to a different tool after failures */\n fellBackToAlternative: boolean;\n /** The alternative tool used, if any */\n alternativeTool?: string;\n /** Whether any retry eventually succeeded */\n eventuallySucceeded: boolean;\n};\n\n/**\n * Result of analyzing tool failure patterns in a trajectory.\n */\nexport type ToolFailureAnalysisResult = {\n /** Score from 0 to 1 (lower = more failures/retries) */\n score: number;\n /** Tool failure patterns detected */\n patterns: ToolFailurePattern[];\n /** Total number of retries across all tools */\n totalRetries: number;\n /** Tools that exceeded the retry threshold */\n excessiveRetryTools: string[];\n};\n\n/**\n * Analyze tool failure and retry patterns in a trajectory.\n */\nexport function analyzeToolFailures(\n trajectory: Trajectory,\n options: {\n maxRetriesPerTool?: number;\n } = {},\n): ToolFailureAnalysisResult {\n const { maxRetriesPerTool = 2 } = options;\n const patterns: ToolFailurePattern[] = [];\n let totalRetries = 0;\n\n const toolCallSteps = trajectory.steps.filter(s => s.stepType === 'tool_call' || s.stepType === 'mcp_tool_call');\n\n if (toolCallSteps.length === 0) {\n return { score: 1, patterns: [], totalRetries: 0, excessiveRetryTools: [] };\n }\n\n // Group consecutive calls to the same tool as potential retry sequences\n let i = 0;\n while (i < toolCallSteps.length) {\n const currentTool = toolCallSteps[i]!;\n let retryCount = 0;\n let j = i + 1;\n\n // Count consecutive calls to the same tool\n // (toolCallSteps is pre-filtered to tool_call/mcp_tool_call, so no stepType checks needed)\n while (j < toolCallSteps.length && toolCallSteps[j]!.name === currentTool.name) {\n const prevStep = toolCallSteps[j - 1]! as TrajectoryStep & { success?: boolean };\n if (prevStep.success === false) {\n retryCount++;\n }\n j++;\n }\n\n if (retryCount > 0) {\n // Check if agent fell back to a different tool after retries\n const nextDifferentTool = j < toolCallSteps.length ? toolCallSteps[j] : undefined;\n const lastRetry = toolCallSteps[j - 1]! as TrajectoryStep & { success?: boolean };\n const lastSuccess = lastRetry.success !== false;\n\n patterns.push({\n toolName: currentTool.name,\n retryCount,\n fellBackToAlternative: nextDifferentTool !== undefined && !lastSuccess,\n alternativeTool: nextDifferentTool !== undefined && !lastSuccess ? nextDifferentTool.name : undefined,\n eventuallySucceeded: lastSuccess,\n });\n\n totalRetries += retryCount;\n }\n\n i = j;\n }\n\n // Score: penalize excessive retries\n const excessiveRetryTools = patterns.filter(p => p.retryCount > maxRetriesPerTool).map(p => p.toolName);\n\n let score = 1;\n if (toolCallSteps.length > 0) {\n // Each retry beyond the threshold costs more\n const excessRetries = patterns.reduce((sum, p) => sum + Math.max(0, p.retryCount - maxRetriesPerTool), 0);\n score = Math.max(0, 1 - excessRetries * 0.2);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n patterns,\n totalRetries,\n excessiveRetryTools,\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/scorers/utils.ts"],"names":["message","requestContext","RequestContext"],"mappings":";;;;;;AAsDO,SAAS,kCAAkC,OAAA,EAAkC;AAClF,EAAA,MAAM,UAAU,OAAA,CAAQ,OAAA;AAExB,EAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAC/B,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC1B,IAAA,MAAM,YAAY,OAAA,CAAQ,MAAA,CAAO,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,MAAM,CAAA;AACvD,IAAA,OAAO,SAAA,CAAU,SAAS,CAAA,GAAI,SAAA,CAAU,UAAU,MAAA,GAAS,CAAC,CAAA,EAAG,IAAA,IAAQ,EAAA,GAAK,EAAA;AAAA,EAC9E;AACA,EAAA,IAAI,OAAO,OAAA,EAAS,OAAA,KAAY,QAAA,IAAY,OAAA,CAAQ,YAAY,EAAA,EAAI;AAClE,IAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,EACjB;AACA,EAAA,IAAI,OAAO,OAAA,EAAS,IAAA,KAAS,QAAA,IAAY,OAAA,CAAQ,SAAS,EAAA,EAAI;AAC5D,IAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,EACjB;AACA,EAAA,IAAI,SAAS,KAAA,IAAS,KAAA,CAAM,OAAA,CAAQ,OAAA,CAAQ,KAAK,CAAA,EAAG;AA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AO;AAAA,IACL,KAAA,EAAO,kBAAA,CAAmB,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAC,CAAA;AAAA,IACzD,QAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-UNQXHPOD.cjs","sourcesContent":["import type { MastraDBMessage } from '@mastra/core/agent';\nimport type {\n ExpectedStep,\n ScorerRunInputForAgent,\n ScorerRunOutputForAgent,\n ScoringInput,\n TrajectoryExpectation,\n TrajectoryStep,\n Trajectory,\n} from '@mastra/core/evals';\nimport { RequestContext } from '@mastra/core/request-context';\n\nexport type ScorerRunInputForLLMJudge =\n | ScorerRunInputForAgent\n | string\n | {\n inputMessages?: unknown[];\n messages?: unknown[];\n prompt?: string;\n text?: string;\n content?: unknown;\n input?: unknown;\n user?: unknown;\n [key: string]: unknown;\n };\n\nexport type ScorerRunOutputForLLMJudge =\n | ScorerRunOutputForAgent\n | string\n | unknown[]\n | {\n text?: string;\n content?: unknown;\n role?: string;\n [key: string]: unknown;\n };\n\n/**\n * Extracts text content from a MastraDBMessage or ModelMessage-like object.\n *\n * @param message - The message to extract text from\n * @returns The extracted text content, or an empty string if no text is found\n *\n * @example\n * ```ts\n * const message: MastraDBMessage = {\n * id: 'msg-1',\n * role: 'assistant',\n * content: { format: 2, parts: [{ type: 'text', text: 'Hello!' }] },\n * createdAt: new Date(),\n * };\n * const text = getTextContentFromMastraDBMessage(message); // 'Hello!'\n * ```\n */\nexport function getTextContentFromMastraDBMessage(message: MastraDBMessage): string {\n const content = message.content as any;\n\n if (typeof content === 'string') {\n return content;\n }\n if (Array.isArray(content)) {\n const textParts = content.filter(p => p.type === 'text');\n return textParts.length > 0 ? textParts[textParts.length - 1]?.text || '' : '';\n }\n if (typeof content?.content === 'string' && content.content !== '') {\n return content.content;\n }\n if (typeof content?.text === 'string' && content.text !== '') {\n return content.text;\n }\n if (content?.parts && Array.isArray(content.parts)) {\n // Return only the last text part like AI SDK does\n const textParts = content.parts.filter((p: any) => p.type === 'text');\n return textParts.length > 0 ? textParts[textParts.length - 1]?.text || '' : '';\n }\n return '';\n}\n\nconst isRecord = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst getTextFromValue = (value: unknown): string | undefined => {\n if (typeof value === 'string') return value === '' ? undefined : value;\n if (Array.isArray(value)) {\n const textParts = value\n .filter(part => isRecord(part) && part.type === 'text' && typeof part.text === 'string')\n .map(part => part.text);\n return textParts.length > 0 ? textParts[textParts.length - 1] : undefined;\n }\n if (!isRecord(value)) return undefined;\n\n const fromParts = Array.isArray(value.parts) ? getTextFromValue(value.parts) : undefined;\n\n return (\n getTextFromValue(value.content) ??\n (typeof value.text === 'string' && value.text !== '' ? value.text : undefined) ??\n (typeof value.body === 'string' && value.body !== '' ? value.body : undefined) ??\n fromParts\n );\n};\n\nexport const isScorerRunInputForAgent = (input: unknown): input is ScorerRunInputForAgent => {\n return (\n isRecord(input) &&\n Array.isArray(input.inputMessages) &&\n Array.isArray(input.rememberedMessages) &&\n Array.isArray(input.systemMessages) &&\n isRecord(input.taggedSystemMessages)\n );\n};\n\nconst isMastraDBMessageLike = (message: unknown): message is MastraDBMessage => {\n return (\n isRecord(message) &&\n typeof message.id === 'string' &&\n typeof message.role === 'string' &&\n 'content' in message &&\n 'createdAt' in message\n );\n};\n\nexport const isScorerRunOutputForAgent = (output: unknown): output is ScorerRunOutputForAgent => {\n return Array.isArray(output) && output.every(isMastraDBMessageLike);\n};\n\nconst getTextFromMessages = (messages: unknown, role: string): string | undefined => {\n if (!Array.isArray(messages)) return undefined;\n\n const message = messages.find(message => isRecord(message) && message.role === role);\n return message ? getTextFromValue(message) : undefined;\n};\n\n/**\n * Rounds a number to two decimal places.\n *\n * Uses `Number.EPSILON` to handle floating-point precision issues.\n *\n * @param num - The number to round\n * @returns The number rounded to two decimal places\n *\n * @example\n * ```ts\n * roundToTwoDecimals(0.1 + 0.2); // 0.3\n * roundToTwoDecimals(1.005); // 1.01\n * ```\n */\nexport const roundToTwoDecimals = (num: number) => {\n return Math.round((num + Number.EPSILON) * 100) / 100;\n};\n\n/**\n * Determines if a value is closer to the first target than the second.\n *\n * @param value - The value to compare\n * @param target1 - The first target value\n * @param target2 - The second target value\n * @returns `true` if `value` is closer to `target1` than `target2`\n *\n * @example\n * ```ts\n * isCloserTo(0.6, 1, 0); // true (0.6 is closer to 1)\n * isCloserTo(0.3, 1, 0); // false (0.3 is closer to 0)\n * ```\n */\nexport function isCloserTo(value: number, target1: number, target2: number): boolean {\n return Math.abs(value - target1) < Math.abs(value - target2);\n}\n\n/**\n * Represents a test case for scorer evaluation.\n */\nexport type TestCase = {\n /** The input text to evaluate */\n input: string;\n /** The output text to evaluate */\n output: string;\n /** The expected result of the evaluation */\n expectedResult: {\n /** The expected score */\n score: number;\n /** The optional expected reason */\n reason?: string;\n };\n};\n\n/**\n * Represents a test case with additional context for scorer evaluation.\n */\nexport type TestCaseWithContext = TestCase & {\n /** Additional context strings for the evaluation */\n context: string[];\n};\n\n/**\n * Creates a scoring input object for testing purposes.\n *\n * @param input - The user input text\n * @param output - The assistant output text\n * @param additionalContext - Optional additional context data\n * @param requestContext - Optional request context data\n * @returns A ScoringInput object ready for use in scorer tests\n *\n * @example\n * ```ts\n * const run = createTestRun(\n * 'What is 2+2?',\n * 'The answer is 4.',\n * { topic: 'math' }\n * );\n * ```\n */\nexport const createTestRun = (\n input: string,\n output: string,\n additionalContext?: Record<string, any>,\n requestContext?: Record<string, any>,\n): ScoringInput => {\n return {\n input: [{ role: 'user', content: input }],\n output: { role: 'assistant', text: output },\n additionalContext: additionalContext ?? {},\n requestContext: requestContext ?? {},\n };\n};\n\n/**\n * Extracts the user message text from a scorer run input.\n *\n * Accepts the agent shape (`{ inputMessages }`), `ModelMessage[]`\n * (`{ messages }`), workflow input (`{ prompt }`), and a bare string.\n *\n * @param input - The scorer run input\n * @returns The user message text, or `undefined` if none can be extracted\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const userText = getUserMessageFromRunInput(run.input);\n * return { userText };\n * });\n * ```\n */\nexport const getUserMessageFromRunInput = (input?: unknown): string | undefined => {\n if (typeof input === 'string') return input;\n if (!isRecord(input)) return undefined;\n\n return (\n getTextFromMessages(input.inputMessages, 'user') ??\n getTextFromMessages(input.messages, 'user') ??\n (typeof input.prompt === 'string' ? input.prompt : undefined) ??\n (typeof input.text === 'string' ? input.text : undefined) ??\n getTextFromValue(input.content) ??\n getTextFromValue(input.input) ??\n getTextFromValue(input.user)\n );\n};\n\n/**\n * Extracts all system messages from a scorer run input.\n *\n * Collects text from both standard system messages and tagged system messages\n * (specialized system prompts like memory instructions).\n *\n * @param input - The scorer run input containing system messages\n * @returns An array of system message strings\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemMessages = getSystemMessagesFromRunInput(run.input);\n * return { systemPrompt: systemMessages.join('\\n') };\n * });\n * ```\n */\nexport const getSystemMessagesFromRunInput = (input?: unknown): string[] => {\n const systemMessages: string[] = [];\n if (!isRecord(input)) return systemMessages;\n\n // Add standard system messages\n if (Array.isArray(input.systemMessages)) {\n systemMessages.push(\n ...input.systemMessages\n .map(msg => {\n // Handle different content types - extract text if it's an array of parts\n if (typeof msg.content === 'string') {\n return msg.content;\n } else if (Array.isArray(msg.content)) {\n // Extract text from parts array\n return msg.content\n .filter((part: any) => part.type === 'text')\n .map((part: any) => part.text || '')\n .join(' ');\n }\n return '';\n })\n .filter(content => content),\n );\n }\n\n const addSystemMessages = (messages: unknown) => {\n if (!Array.isArray(messages)) return;\n\n systemMessages.push(\n ...messages\n .filter(message => isRecord(message) && message.role === 'system')\n .map(message => getTextFromValue(message))\n .filter((content): content is string => Boolean(content)),\n );\n };\n\n addSystemMessages(input.inputMessages);\n addSystemMessages(input.messages);\n\n // Add tagged system messages (these are specialized system prompts)\n if (isRecord(input.taggedSystemMessages)) {\n Object.values(input.taggedSystemMessages).forEach(messages => {\n if (!Array.isArray(messages)) return;\n messages.forEach(msg => {\n const content = getTextFromValue(msg);\n if (content) {\n systemMessages.push(content);\n }\n });\n });\n }\n\n return systemMessages;\n};\n\n/**\n * Combines all system messages into a single prompt string.\n *\n * Joins all system messages (standard and tagged) with double newlines.\n *\n * @param input - The scorer run input containing system messages\n * @returns A combined system prompt string\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemPrompt = getCombinedSystemPrompt(run.input);\n * return { systemPrompt };\n * });\n * ```\n */\nexport const getCombinedSystemPrompt = (input?: unknown): string => {\n const systemMessages = getSystemMessagesFromRunInput(input);\n return systemMessages.join('\\n\\n');\n};\n\n/**\n * Extracts the assistant message text from a scorer run output.\n *\n * Accepts the agent shape (`MastraDBMessage[]` / `ModelMessage[]`), workflow\n * output (`{ text }`), task output (`{ content }`), a single assistant message\n * object, and a bare string.\n *\n * @param output - The scorer run output\n * @returns The assistant message text, or `undefined` if none can be extracted\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { response };\n * });\n * ```\n */\nexport const getAssistantMessageFromRunOutput = (output?: unknown) => {\n if (typeof output === 'string') return output;\n if (Array.isArray(output)) return getTextFromMessages(output, 'assistant');\n if (!isRecord(output)) return undefined;\n\n const isAssistantOutput = output.role === undefined || output.role === 'assistant';\n\n if (isAssistantOutput && typeof output.text === 'string') return output.text;\n if (isAssistantOutput && typeof output.content === 'string') return output.content;\n if (isAssistantOutput && (isRecord(output.content) || Array.isArray(output.content))) {\n return (\n getTextContentFromMastraDBMessage(output as MastraDBMessage) ||\n getTextContentFromMastraDBMessage(output.content as MastraDBMessage) ||\n undefined\n );\n }\n if (output.role === 'assistant') return getTextContentFromMastraDBMessage(output as MastraDBMessage) || undefined;\n\n return undefined;\n};\n\n/**\n * Extracts reasoning text from a scorer run output.\n *\n * This function extracts reasoning content from assistant messages, which is\n * produced by reasoning models like `deepseek-reasoner`. The reasoning can be\n * stored in two places:\n * 1. `content.reasoning` - a string field on the message content\n * 2. `content.parts` - as parts with `type: 'reasoning'` containing `details`\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns The reasoning text, or `undefined` if no reasoning is present\n *\n * @example\n * ```ts\n * const reasoningScorer = createScorer({\n * id: 'reasoning-scorer',\n * name: 'Reasoning Quality',\n * description: 'Evaluates the quality of model reasoning',\n * type: 'agent',\n * })\n * .preprocess(({ run }) => {\n * const reasoning = getReasoningFromRunOutput(run.output);\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { reasoning, response };\n * })\n * .generateScore(({ results }) => {\n * // Score based on reasoning quality\n * return results.preprocessStepResult?.reasoning ? 1 : 0;\n * });\n * ```\n */\nexport const getReasoningFromRunOutput = (output?: ScorerRunOutputForAgent): string | undefined => {\n if (!output) return undefined;\n\n const message = output.find(({ role }) => role === 'assistant');\n if (!message) return undefined;\n\n // Check for reasoning in content.reasoning (string format)\n if (message.content.reasoning) {\n return message.content.reasoning;\n }\n\n // Check for reasoning in parts with type 'reasoning'\n // Reasoning models store reasoning in parts as { type: 'reasoning', details: [{ type: 'text', text: '...' }] }\n const reasoningParts = message.content.parts?.filter((p: any) => p.type === 'reasoning');\n if (reasoningParts && reasoningParts.length > 0) {\n const reasoningTexts = reasoningParts\n .map((p: any) => {\n // The reasoning text can be in p.reasoning or in p.details[].text\n if (p.details && Array.isArray(p.details)) {\n return p.details\n .filter((d: any) => d.type === 'text')\n .map((d: any) => d.text)\n .join('');\n }\n return p.reasoning || '';\n })\n .filter(Boolean);\n\n return reasoningTexts.length > 0 ? reasoningTexts.join('\\n') : undefined;\n }\n\n return undefined;\n};\n\n/**\n * Creates a tool invocation object for testing purposes.\n *\n * @param options - The tool invocation configuration\n * @param options.toolCallId - Unique identifier for the tool call\n * @param options.toolName - Name of the tool being called\n * @param options.args - Arguments passed to the tool\n * @param options.result - Result returned by the tool\n * @param options.state - State of the invocation (default: 'result')\n * @returns A tool invocation object\n *\n * @example\n * ```ts\n * const invocation = createToolInvocation({\n * toolCallId: 'call-123',\n * toolName: 'weatherTool',\n * args: { location: 'London' },\n * result: { temperature: 20, condition: 'sunny' },\n * });\n * ```\n */\nexport const createToolInvocation = ({\n toolCallId,\n toolName,\n args,\n result,\n state = 'result',\n}: {\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state?: 'call' | 'partial-call' | 'result';\n}): { toolCallId: string; toolName: string; args: Record<string, any>; result: Record<string, any>; state: string } => {\n return {\n toolCallId,\n toolName,\n args,\n result,\n state,\n };\n};\n\n/**\n * Creates a MastraDBMessage object for testing purposes.\n *\n * Supports optional tool invocations for testing tool call scenarios.\n *\n * @param options - The message configuration\n * @param options.content - The text content of the message\n * @param options.role - The role of the message sender ('user', 'assistant', or 'system')\n * @param options.id - Optional message ID (default: 'test-message')\n * @param options.toolInvocations - Optional array of tool invocations\n * @returns A MastraDBMessage object\n *\n * @example\n * ```ts\n * const message = createTestMessage({\n * content: 'Hello, how can I help?',\n * role: 'assistant',\n * });\n *\n * // With tool invocations\n * const messageWithTools = createTestMessage({\n * content: 'Let me check the weather.',\n * role: 'assistant',\n * toolInvocations: [{\n * toolCallId: 'call-1',\n * toolName: 'weatherTool',\n * args: { location: 'Paris' },\n * result: { temp: 22 },\n * state: 'result',\n * }],\n * });\n * ```\n */\nexport function createTestMessage({\n content,\n role,\n id = 'test-message',\n toolInvocations = [],\n}: {\n content: string;\n role: 'user' | 'assistant' | 'system';\n id?: string;\n toolInvocations?: Array<{\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state: any;\n }>;\n}): MastraDBMessage {\n return {\n id,\n role,\n content: {\n format: 2,\n parts: [{ type: 'text', text: content }],\n content,\n ...(toolInvocations.length > 0 && {\n toolInvocations: toolInvocations.map(ti => ({\n toolCallId: ti.toolCallId,\n toolName: ti.toolName,\n args: ti.args,\n result: ti.result,\n state: ti.state,\n })),\n }),\n },\n createdAt: new Date(),\n };\n}\n\n/**\n * Creates a complete agent test run object for testing scorers.\n *\n * Provides a convenient way to construct the full run object that scorers receive,\n * including input messages, output, system messages, and request context.\n *\n * @param options - The test run configuration\n * @param options.inputMessages - Array of input messages (default: [])\n * @param options.output - The output messages (required)\n * @param options.rememberedMessages - Array of remembered messages from memory (default: [])\n * @param options.systemMessages - Array of system messages (default: [])\n * @param options.taggedSystemMessages - Tagged system messages map (default: {})\n * @param options.requestContext - Request context (default: new RequestContext())\n * @param options.runId - Unique run ID (default: random UUID)\n * @returns A complete test run object\n *\n * @example\n * ```ts\n * const testRun = createAgentTestRun({\n * inputMessages: [createTestMessage({ content: 'Hello', role: 'user' })],\n * output: [createTestMessage({ content: 'Hi there!', role: 'assistant' })],\n * });\n *\n * const result = await scorer.run({\n * input: testRun.input,\n * output: testRun.output,\n * });\n * ```\n */\nexport const createAgentTestRun = ({\n inputMessages = [],\n output,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n requestContext = new RequestContext(),\n runId = crypto.randomUUID(),\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n output: ScorerRunOutputForAgent;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n requestContext?: RequestContext;\n runId?: string;\n}): {\n input: ScorerRunInputForAgent;\n output: ScorerRunOutputForAgent;\n requestContext: RequestContext;\n runId: string;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output,\n requestContext,\n runId,\n };\n};\n\n/**\n * Creates a test run for trajectory scorers where `output` is a `Trajectory`\n * (pre-extracted by the `runEvals` pipeline).\n *\n * @example\n * ```ts\n * const testRun = createTrajectoryTestRun({\n * inputMessages: [createTestMessage({ content: 'Do X', role: 'user', id: 'u1' })],\n * trajectory: {\n * steps: [\n * { stepType: 'tool_call', name: 'search', toolArgs: { q: 'test' } },\n * ],\n * },\n * });\n * ```\n */\nexport const createTrajectoryTestRun = ({\n inputMessages = [],\n trajectory,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n requestContext = new RequestContext(),\n runId = crypto.randomUUID(),\n expectedTrajectory,\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n trajectory: Trajectory;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n requestContext?: RequestContext;\n runId?: string;\n expectedTrajectory?: TrajectoryExpectation;\n}): {\n input: ScorerRunInputForAgent;\n output: Trajectory;\n requestContext: RequestContext;\n runId: string;\n expectedTrajectory?: TrajectoryExpectation;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output: trajectory,\n expectedTrajectory,\n requestContext,\n runId,\n };\n};\n\n/**\n * Information about a tool call extracted from scorer output.\n */\nexport type ToolCallInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Index of the message containing this tool call */\n messageIndex: number;\n /** Index of the invocation within the message's tool invocations */\n invocationIndex: number;\n};\n\n/**\n * Extracts all tool calls from a scorer run output.\n *\n * Iterates through all messages and their tool invocations to collect\n * information about tools that were called (with state 'result' or 'call').\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An object containing tool names and detailed tool call info\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const { tools, toolCallInfos } = extractToolCalls(run.output);\n * return {\n * toolsUsed: tools,\n * toolCount: tools.length,\n * };\n * });\n * ```\n */\nexport function extractToolCalls(output: ScorerRunOutputForAgent): { tools: string[]; toolCallInfos: ToolCallInfo[] } {\n const toolCalls: string[] = [];\n const toolCallInfos: ToolCallInfo[] = [];\n\n for (let messageIndex = 0; messageIndex < output.length; messageIndex++) {\n const message = output[messageIndex];\n // Prefer the legacy toolInvocations array when present; fall back to\n // V2 content.parts for messages that only store tool calls there.\n const legacy = message?.content?.toolInvocations;\n const fromParts = legacy\n ? undefined\n : message?.content?.parts\n ?.filter((p): p is Extract<typeof p, { type: 'tool-invocation' }> => p.type === 'tool-invocation')\n .map(p => p.toolInvocation);\n const toolInvocations = legacy ?? fromParts;\n\n if (!toolInvocations?.length) continue;\n\n for (let invocationIndex = 0; invocationIndex < toolInvocations.length; invocationIndex++) {\n const invocation = toolInvocations[invocationIndex];\n if (invocation && invocation.toolName && (invocation.state === 'result' || invocation.state === 'call')) {\n toolCalls.push(invocation.toolName);\n toolCallInfos.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || `${messageIndex}-${invocationIndex}`,\n messageIndex,\n invocationIndex,\n });\n }\n }\n }\n\n return { tools: toolCalls, toolCallInfos };\n}\n\n/**\n * Extracts text content from all input messages.\n *\n * @param runInput - The scorer run input\n * @returns An array of text strings from each input message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const messages = extractInputMessages(run.input);\n * return { allUserMessages: messages.join('\\n') };\n * });\n * ```\n */\nexport const extractInputMessages = (runInput: ScorerRunInputForAgent | undefined): string[] => {\n return runInput?.inputMessages?.map(msg => getTextContentFromMastraDBMessage(msg)) || [];\n};\n\n/**\n * Extracts text content from all assistant response messages.\n *\n * Filters for messages with role 'assistant' and extracts their text content.\n *\n * @param runOutput - The scorer run output (array of MastraDBMessage)\n * @returns An array of text strings from each assistant message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const responses = extractAgentResponseMessages(run.output);\n * return { allResponses: responses.join('\\n') };\n * });\n * ```\n */\nexport const extractAgentResponseMessages = (runOutput: ScorerRunOutputForAgent): string[] => {\n return runOutput.filter(msg => msg.role === 'assistant').map(msg => getTextContentFromMastraDBMessage(msg));\n};\n\n/**\n * Information about a tool result extracted from scorer output.\n */\nexport type ToolResultInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Arguments passed to the tool */\n args: Record<string, any>;\n /** Result returned by the tool */\n result: any;\n};\n\n/**\n * Extracts tool results from a scorer run output.\n *\n * Returns structured objects that can be used with the hallucination scorer's\n * `getContext` hook or for other scorer logic.\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An array of ToolResultInfo objects\n *\n * @example\n * ```ts\n * import { extractToolResults } from '@mastra/evals/scorers';\n * import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt';\n *\n * const scorer = createHallucinationScorer({\n * model: openai('gpt-4o'),\n * options: {\n * getContext: (run) => {\n * const toolResults = extractToolResults(run.output);\n * return toolResults.map(t => JSON.stringify({ tool: t.toolName, result: t.result }));\n * },\n * },\n * });\n * ```\n */\nexport function extractToolResults(output: ScorerRunOutputForAgent): ToolResultInfo[] {\n const results: ToolResultInfo[] = [];\n\n for (const message of output) {\n // Prefer the legacy toolInvocations array when present; fall back to\n // V2 content.parts for messages that only store tool calls there.\n const legacy = message?.content?.toolInvocations;\n const fromParts = legacy\n ? undefined\n : message?.content?.parts\n ?.filter((p): p is Extract<typeof p, { type: 'tool-invocation' }> => p.type === 'tool-invocation')\n .map(p => p.toolInvocation);\n const toolInvocations = legacy ?? fromParts;\n\n if (!toolInvocations?.length) continue;\n\n for (const invocation of toolInvocations) {\n if (invocation.state === 'result' && invocation.result !== undefined) {\n results.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || '',\n args: invocation.args || {},\n result: invocation.result,\n });\n }\n }\n }\n\n return results;\n}\n\n// Re-export extractTrajectory from core — it's called automatically by runEvals\n// for trajectory scorers, but users may still want it for custom use cases.\nexport { extractTrajectory } from '@mastra/core/evals';\n\n/**\n * Compares two trajectories and returns detailed comparison results.\n *\n * This is the core comparison logic used by trajectory scorers. It supports\n * strict and non-strict ordering, optional step data comparison, and loop detection.\n *\n * @param actual - The trajectory the agent actually took\n * @param expected - The expected trajectory to compare against\n * @param options - Comparison configuration options\n * @returns Detailed comparison results including match scores and diagnostics\n *\n * @example\n * ```ts\n * const result = compareTrajectories(\n * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },\n * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },\n * { ordering: 'strict' }\n * );\n * // result.score = 1.0\n * ```\n */\nexport function compareTrajectories(\n actual: Trajectory,\n expected: Trajectory | { steps: ExpectedStep[] },\n options: {\n ordering?: 'strict' | 'relaxed' | 'unordered';\n allowRepeatedSteps?: boolean;\n } = {},\n): TrajectoryComparisonResult {\n const { allowRepeatedSteps = true, ordering = 'relaxed' } = options;\n\n // Normalize expected to ExpectedStep[]. TrajectoryStep and ExpectedStep share\n // the same field names, so TrajectoryStep[] can be used directly as ExpectedStep[].\n // The only structural difference is `children` (TrajectoryStep[] vs TrajectoryExpectation),\n // but compareTrajectories doesn't recurse into children.\n const normalizedExpected: { steps: ExpectedStep[] } = {\n steps: expected.steps as ExpectedStep[],\n };\n\n if (normalizedExpected.steps.length === 0) {\n return {\n score: actual.steps.length === 0 ? 1 : 0,\n matchedSteps: 0,\n totalExpectedSteps: 0,\n totalActualSteps: actual.steps.length,\n missingSteps: [],\n extraSteps: actual.steps.map((s: TrajectoryStep) => s.name),\n outOfOrderSteps: [],\n repeatedSteps: [],\n };\n }\n\n const actualNames = actual.steps.map((s: TrajectoryStep) => s.name);\n\n // Detect repeated steps\n const nameCounts = new Map<string, number>();\n for (const name of actualNames) {\n nameCounts.set(name, (nameCounts.get(name) || 0) + 1);\n }\n const repeatedSteps = [...nameCounts.entries()]\n .filter(([_, count]: [string, number]) => count > 1)\n .map(([name]: [string, number]) => name);\n\n if (ordering === 'strict') {\n return compareStrictOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n }\n\n if (ordering === 'unordered') {\n return compareUnorderedPresence(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n }\n\n return compareRelaxedOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n}\n\n/**\n * Result of comparing two trajectories.\n */\nexport type TrajectoryComparisonResult = {\n /** Overall match score from 0 to 1 */\n score: number;\n /** Number of expected steps that were matched */\n matchedSteps: number;\n /** Total number of expected steps */\n totalExpectedSteps: number;\n /** Total number of actual steps taken */\n totalActualSteps: number;\n /** Expected steps that were not found in the actual trajectory */\n missingSteps: string[];\n /** Actual steps that were not in the expected trajectory */\n extraSteps: string[];\n /** Steps that appear but not in the expected position */\n outOfOrderSteps: string[];\n /** Steps that were repeated (appeared more than once) */\n repeatedSteps: string[];\n};\n\nfunction compareStrictOrder(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n // Strict: exact same sequence\n let matchedSteps = 0;\n const outOfOrderSteps: string[] = [];\n const matchedExpectedIndices = new Set<number>();\n const maxLen = Math.max(actualNames.length, expectedNames.length);\n\n for (let i = 0; i < maxLen; i++) {\n const actualName = actualNames[i];\n const expectedName = expectedNames[i];\n if (actualName === expectedName) {\n if (actual.steps[i] && expected.steps[i]) {\n if (expectedStepMatches(actual.steps[i]!, expected.steps[i]!)) {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n }\n } else {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n }\n } else if (actualName && expectedNames.includes(actualName)) {\n outOfOrderSteps.push(actualName);\n }\n }\n\n // Missing steps = expected steps that were not matched (accounts for stepType/data mismatches)\n const missingSteps: string[] = expectedNames.filter((_: string, i: number) => !matchedExpectedIndices.has(i));\n const extraSteps: string[] = actualNames.filter((name: string) => !expectedNames.includes(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize extra steps in strict mode\n if (actualNames.length > expectedNames.length) {\n const extraPenalty = (actualNames.length - expectedNames.length) / expectedNames.length;\n score = Math.max(0, score - extraPenalty * 0.5);\n }\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps,\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\nfunction compareRelaxedOrder(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n // Relaxed: expected steps must appear in order but extra steps are allowed\n let matchedSteps = 0;\n let lastMatchedIndex = -1;\n const outOfOrderSteps: string[] = [];\n const matchedExpectedIndices = new Set<number>();\n\n for (let i = 0; i < expectedNames.length; i++) {\n const expectedName = expectedNames[i];\n let found = false;\n\n for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) {\n if (actualNames[j] === expectedName) {\n if (actual.steps[j] && expected.steps[i]) {\n if (expectedStepMatches(actual.steps[j]!, expected.steps[i]!)) {\n matchedSteps++;\n lastMatchedIndex = j;\n matchedExpectedIndices.add(i);\n found = true;\n break;\n }\n } else {\n matchedSteps++;\n lastMatchedIndex = j;\n matchedExpectedIndices.add(i);\n found = true;\n break;\n }\n }\n }\n\n if (!found) {\n // Check if the step exists but is out of order\n if (actualNames.includes(expectedName!)) {\n outOfOrderSteps.push(expectedName!);\n }\n }\n }\n\n // Missing steps = expected steps that were not matched (by name + stepType + data, not just name)\n const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));\n const expectedSet = new Set(expectedNames);\n const extraSteps = actualNames.filter(name => !expectedSet.has(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps,\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\n/**\n * Fields on each ExpectedStep variant that are comparable data (not structural).\n * Used by `expectedStepMatches` to know which fields to compare when `compareData` is true.\n */\nconst COMPARABLE_FIELDS_BY_TYPE: Record<string, string[]> = {\n tool_call: ['toolArgs', 'toolResult', 'success'],\n mcp_tool_call: ['toolArgs', 'toolResult', 'mcpServer', 'success'],\n model_generation: ['modelId', 'promptTokens', 'completionTokens', 'finishReason'],\n agent_run: ['agentId'],\n workflow_step: ['stepId', 'status', 'output'],\n workflow_run: ['workflowId', 'status'],\n workflow_conditional: ['conditionCount', 'selectedSteps'],\n workflow_parallel: ['branchCount', 'parallelSteps'],\n workflow_loop: ['loopType', 'totalIterations'],\n workflow_sleep: ['sleepDurationMs', 'sleepType'],\n workflow_wait_event: ['eventName', 'eventReceived'],\n processor_run: ['processorId'],\n};\n\n/**\n * Check if an actual TrajectoryStep matches an ExpectedStep.\n * Matches by name, optionally by stepType, and auto-compares any variant-specific\n * fields that are present on the expected step.\n */\nfunction expectedStepMatches(actual: TrajectoryStep, expected: ExpectedStep): boolean {\n if (actual.name !== expected.name) return false;\n if (expected.stepType && actual.stepType !== expected.stepType) return false;\n\n if (expected.stepType) {\n const fields = COMPARABLE_FIELDS_BY_TYPE[expected.stepType] ?? [];\n for (const field of fields) {\n const expectedVal = (expected as any)[field];\n if (expectedVal === undefined) continue; // field not specified in expectation, skip\n const actualVal = (actual as any)[field];\n if (actualVal === undefined) return false;\n try {\n if (JSON.stringify(actualVal) !== JSON.stringify(expectedVal)) return false;\n } catch {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction compareUnorderedPresence(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n let matchedSteps = 0;\n const matchedExpectedIndices = new Set<number>();\n const usedIndices = new Set<number>();\n for (let i = 0; i < expected.steps.length; i++) {\n const expectedStep = expected.steps[i]!;\n for (let j = 0; j < actual.steps.length; j++) {\n if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j]!, expectedStep)) {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n usedIndices.add(j);\n break;\n }\n }\n }\n\n // Missing steps = expected steps that were not matched (accounts for stepType/data mismatches)\n const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));\n const expectedSet = new Set(expectedNames);\n const extraSteps = actualNames.filter(name => !expectedSet.has(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps: [], // ordering not checked in unordered mode\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\n// ─── Efficiency evaluation ───\n\n/**\n * Result of checking trajectory efficiency.\n */\nexport type TrajectoryEfficiencyResult = {\n /** Overall efficiency score from 0 to 1 */\n score: number;\n /** Total number of steps taken */\n totalSteps: number;\n /** Whether the step budget was exceeded */\n overStepBudget: boolean;\n /** Total tokens used across model_generation steps */\n totalTokens: number;\n /** Whether the token budget was exceeded */\n overTokenBudget: boolean;\n /** Total duration in milliseconds */\n totalDurationMs: number;\n /** Whether the duration budget was exceeded */\n overDurationBudget: boolean;\n /** Redundant calls detected (same tool + same args consecutively) */\n redundantCalls: Array<{ name: string; index: number }>;\n};\n\n/**\n * Evaluate trajectory efficiency against budgets and redundancy checks.\n */\nexport function checkTrajectoryEfficiency(\n trajectory: Trajectory,\n options: {\n maxSteps?: number;\n maxTotalTokens?: number;\n maxTotalDurationMs?: number;\n noRedundantCalls?: boolean;\n } = {},\n): TrajectoryEfficiencyResult {\n const { maxSteps, maxTotalTokens, maxTotalDurationMs, noRedundantCalls = true } = options;\n\n const totalSteps = trajectory.steps.length;\n\n // Calculate total tokens from model_generation steps\n let totalTokens = 0;\n for (const step of trajectory.steps) {\n if (step.stepType === 'model_generation') {\n totalTokens += (step.promptTokens ?? 0) + (step.completionTokens ?? 0);\n }\n }\n\n // Calculate total duration\n const totalDurationMs =\n trajectory.totalDurationMs ?? trajectory.steps.reduce((sum, s) => sum + (s.durationMs ?? 0), 0);\n\n // Detect redundant calls (same tool name + same args in consecutive calls)\n const redundantCalls: Array<{ name: string; index: number }> = [];\n if (noRedundantCalls) {\n for (let i = 1; i < trajectory.steps.length; i++) {\n const prev = trajectory.steps[i - 1]!;\n const curr = trajectory.steps[i]!;\n if (\n prev.name === curr.name &&\n prev.stepType === curr.stepType &&\n (prev.stepType === 'tool_call' || prev.stepType === 'mcp_tool_call')\n ) {\n const prevArgs = (prev as TrajectoryStep & { toolArgs?: Record<string, unknown> }).toolArgs;\n const currArgs = (curr as TrajectoryStep & { toolArgs?: Record<string, unknown> }).toolArgs;\n try {\n if (JSON.stringify(prevArgs) === JSON.stringify(currArgs)) {\n redundantCalls.push({ name: curr.name, index: i });\n }\n } catch {\n // If serialization fails, don't flag as redundant\n }\n }\n }\n }\n\n const overStepBudget = maxSteps !== undefined && totalSteps > maxSteps;\n const overTokenBudget = maxTotalTokens !== undefined && totalTokens > maxTotalTokens;\n const overDurationBudget = maxTotalDurationMs !== undefined && totalDurationMs > maxTotalDurationMs;\n\n // Calculate score: each dimension contributes equally\n const dimensions: number[] = [];\n\n if (maxSteps !== undefined) {\n dimensions.push(overStepBudget ? Math.max(0, 1 - (totalSteps - maxSteps) / maxSteps) : 1);\n }\n if (maxTotalTokens !== undefined) {\n dimensions.push(overTokenBudget ? Math.max(0, 1 - (totalTokens - maxTotalTokens) / maxTotalTokens) : 1);\n }\n if (maxTotalDurationMs !== undefined) {\n dimensions.push(\n overDurationBudget ? Math.max(0, 1 - (totalDurationMs - maxTotalDurationMs) / maxTotalDurationMs) : 1,\n );\n }\n if (noRedundantCalls) {\n dimensions.push(redundantCalls.length === 0 ? 1 : Math.max(0, 1 - redundantCalls.length * 0.2));\n }\n\n const score = dimensions.length > 0 ? dimensions.reduce((a, b) => a + b, 0) / dimensions.length : 1;\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n totalSteps,\n overStepBudget,\n totalTokens,\n overTokenBudget,\n totalDurationMs,\n overDurationBudget,\n redundantCalls,\n };\n}\n\n// ─── Blacklist evaluation ───\n\n/**\n * Result of checking trajectory against a blacklist.\n */\nexport type TrajectoryBlacklistResult = {\n /** Score: 1.0 if clean, 0.0 if any violation found */\n score: number;\n /** Individual blacklisted tools that were found */\n violatedTools: string[];\n /** Blacklisted sequences that were found */\n violatedSequences: string[][];\n};\n\n/**\n * Check if a trajectory violates any blacklist rules.\n * Returns score 0.0 if any violation is found (hard fail).\n */\nexport function checkTrajectoryBlacklist(\n trajectory: Trajectory,\n options: {\n blacklistedTools?: string[];\n blacklistedSequences?: string[][];\n } = {},\n): TrajectoryBlacklistResult {\n const { blacklistedTools = [], blacklistedSequences = [] } = options;\n const violatedTools: string[] = [];\n const violatedSequences: string[][] = [];\n\n const stepNames = trajectory.steps.map(s => s.name);\n\n // Check blacklisted tools\n for (const forbidden of blacklistedTools) {\n if (stepNames.includes(forbidden)) {\n violatedTools.push(forbidden);\n }\n }\n\n // Check blacklisted sequences (contiguous subsequences)\n for (const sequence of blacklistedSequences) {\n if (sequence.length === 0) continue;\n for (let i = 0; i <= stepNames.length - sequence.length; i++) {\n let match = true;\n for (let j = 0; j < sequence.length; j++) {\n if (stepNames[i + j] !== sequence[j]) {\n match = false;\n break;\n }\n }\n if (match) {\n violatedSequences.push(sequence);\n break; // Only report each sequence once\n }\n }\n }\n\n const hasViolations = violatedTools.length > 0 || violatedSequences.length > 0;\n\n return {\n score: hasViolations ? 0 : 1,\n violatedTools,\n violatedSequences,\n };\n}\n\n// ─── Tool failure analysis ───\n\n/**\n * A detected tool failure pattern in the trajectory.\n */\nexport type ToolFailurePattern = {\n /** The tool name that experienced failure */\n toolName: string;\n /** Number of consecutive retries (same tool, same or similar args) */\n retryCount: number;\n /** Whether the agent fell back to a different tool after failures */\n fellBackToAlternative: boolean;\n /** The alternative tool used, if any */\n alternativeTool?: string;\n /** Whether any retry eventually succeeded */\n eventuallySucceeded: boolean;\n};\n\n/**\n * Result of analyzing tool failure patterns in a trajectory.\n */\nexport type ToolFailureAnalysisResult = {\n /** Score from 0 to 1 (lower = more failures/retries) */\n score: number;\n /** Tool failure patterns detected */\n patterns: ToolFailurePattern[];\n /** Total number of retries across all tools */\n totalRetries: number;\n /** Tools that exceeded the retry threshold */\n excessiveRetryTools: string[];\n};\n\n/**\n * Analyze tool failure and retry patterns in a trajectory.\n */\nexport function analyzeToolFailures(\n trajectory: Trajectory,\n options: {\n maxRetriesPerTool?: number;\n } = {},\n): ToolFailureAnalysisResult {\n const { maxRetriesPerTool = 2 } = options;\n const patterns: ToolFailurePattern[] = [];\n let totalRetries = 0;\n\n const toolCallSteps = trajectory.steps.filter(s => s.stepType === 'tool_call' || s.stepType === 'mcp_tool_call');\n\n if (toolCallSteps.length === 0) {\n return { score: 1, patterns: [], totalRetries: 0, excessiveRetryTools: [] };\n }\n\n // Group consecutive calls to the same tool as potential retry sequences\n let i = 0;\n while (i < toolCallSteps.length) {\n const currentTool = toolCallSteps[i]!;\n let retryCount = 0;\n let j = i + 1;\n\n // Count consecutive calls to the same tool\n // (toolCallSteps is pre-filtered to tool_call/mcp_tool_call, so no stepType checks needed)\n while (j < toolCallSteps.length && toolCallSteps[j]!.name === currentTool.name) {\n const prevStep = toolCallSteps[j - 1]! as TrajectoryStep & { success?: boolean };\n if (prevStep.success === false) {\n retryCount++;\n }\n j++;\n }\n\n if (retryCount > 0) {\n // Check if agent fell back to a different tool after retries\n const nextDifferentTool = j < toolCallSteps.length ? toolCallSteps[j] : undefined;\n const lastRetry = toolCallSteps[j - 1]! as TrajectoryStep & { success?: boolean };\n const lastSuccess = lastRetry.success !== false;\n\n patterns.push({\n toolName: currentTool.name,\n retryCount,\n fellBackToAlternative: nextDifferentTool !== undefined && !lastSuccess,\n alternativeTool: nextDifferentTool !== undefined && !lastSuccess ? nextDifferentTool.name : undefined,\n eventuallySucceeded: lastSuccess,\n });\n\n totalRetries += retryCount;\n }\n\n i = j;\n }\n\n // Score: penalize excessive retries\n const excessiveRetryTools = patterns.filter(p => p.retryCount > maxRetriesPerTool).map(p => p.toolName);\n\n let score = 1;\n if (toolCallSteps.length > 0) {\n // Each retry beyond the threshold costs more\n const excessRetries = patterns.reduce((sum, p) => sum + Math.max(0, p.retryCount - maxRetriesPerTool), 0);\n score = Math.max(0, 1 - excessRetries * 0.2);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n patterns,\n totalRetries,\n excessiveRetryTools,\n };\n}\n"]}
@@ -3,7 +3,7 @@ name: mastra-evals
3
3
  description: Documentation for @mastra/evals. Use when working with @mastra/evals APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/evals"
6
- version: "1.2.4"
6
+ version: "1.3.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -33,6 +33,7 @@ Read the individual reference documents for detailed explanations and code examp
33
33
  - [Reference: Keyword coverage scorer](references/reference-evals-keyword-coverage.md) - Documentation for the Keyword Coverage Scorer in Mastra, which evaluates how well LLM outputs cover important keywords from the input.
34
34
  - [Reference: Noise sensitivity scorer](references/reference-evals-noise-sensitivity.md) - Documentation for the Noise Sensitivity Scorer in Mastra. A CI/testing scorer that evaluates agent robustness by comparing responses between clean and noisy inputs in controlled test environments.
35
35
  - [Reference: Prompt alignment scorer](references/reference-evals-prompt-alignment.md) - Documentation for the Prompt Alignment Scorer in Mastra. Evaluates how well agent responses align with user prompt intent, requirements, completeness, and appropriateness using multi-dimensional analysis.
36
+ - [Reference: Rubric scorer](references/reference-evals-rubric.md) - Documentation for the Rubric Scorer in Mastra. An LLM-as-judge scorer that grades an agent output against a checklist of criteria and returns a binary verdict with per-criterion feedback, designed to drive isTaskComplete loops.
36
37
  - [Reference: Scorer utils](references/reference-evals-scorer-utils.md) - Utility functions for extracting data from scorer run inputs and outputs, including text content, reasoning, system messages, and tool calls.
37
38
  - [Reference: Textual difference scorer](references/reference-evals-textual-difference.md) - Documentation for the Textual Difference Scorer in Mastra, which measures textual differences between strings using sequence matching.
38
39
  - [Reference: Tone consistency scorer](references/reference-evals-tone-consistency.md) - Documentation for the Tone Consistency Scorer in Mastra, which evaluates emotional tone and sentiment consistency in text.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.4",
2
+ "version": "1.3.0",
3
3
  "package": "@mastra/evals",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -0,0 +1,113 @@
1
+ # Rubric scorer
2
+
3
+ **Added in:** `@mastra/evals@1.3.0`
4
+
5
+ The `createRubricScorer()` function creates an LLM-as-judge scorer that grades an agent's output against a rubric (a checklist of criteria). It returns a **binary** score: `1` only when every required criterion is satisfied, otherwise `0`. The `reason` lists each criterion's verdict so the agent knows exactly what to fix.
6
+
7
+ This scorer is designed to drop into [`isTaskComplete`](https://mastra.ai/reference/streaming/agents/stream). Because `isTaskComplete` treats `score === 1` as "task complete" and injects the `reason` back into the conversation as feedback, the agent keeps iterating until the rubric is satisfied (or `maxSteps` is reached).
8
+
9
+ ## Parameters
10
+
11
+ **model** (`MastraModelConfig`): The language model used to grade the output against the rubric. A smaller, cheaper model is usually sufficient for grading.
12
+
13
+ **criteria** (`RubricCriterion[] | string`): The rubric to grade against. A string is treated as a newline-delimited checklist (each line becomes a required criterion). If omitted, the rubric is read at run time from a \`rubric\` value on request/additional context; if none resolves, the scorer is a no-op and returns 1.
14
+
15
+ **options** (`RubricScorerOptions`): Configuration options for the scorer
16
+
17
+ ## `.run()` returns
18
+
19
+ **score** (`number`): 1 when every required criterion is satisfied, otherwise 0 (multiplied by scale).
20
+
21
+ **reason** (`string`): A per-criterion explanation listing which criteria are met or unmet and why. This is the text that isTaskComplete injects back into the conversation as feedback.
22
+
23
+ ## Usage with isTaskComplete
24
+
25
+ Define the rubric once, attach the scorer to `isTaskComplete`, and the agent self-corrects until the rubric is satisfied:
26
+
27
+ ```typescript
28
+ import { Agent } from '@mastra/core/agent'
29
+ import { createRubricScorer } from '@mastra/evals/scorers/prebuilt'
30
+
31
+ const supervisor = new Agent({
32
+ id: 'supervisor',
33
+ instructions: `You coordinate research and writing using specialized agents. Delegate to research-agent for facts, then writing-agent for content.`,
34
+ model: 'openai/gpt-5.5',
35
+ agents: { researchAgent, writingAgent },
36
+ })
37
+
38
+ const rubricScorer = createRubricScorer({
39
+ model: 'openai/gpt-5-mini',
40
+ criteria: [
41
+ { description: 'The response includes an analysis section' },
42
+ { description: 'The response includes concrete recommendations' },
43
+ ],
44
+ })
45
+
46
+ const stream = await supervisor.stream('Research AI in education', {
47
+ maxSteps: 10,
48
+ isTaskComplete: {
49
+ scorers: [rubricScorer],
50
+ strategy: 'all',
51
+ },
52
+ })
53
+ ```
54
+
55
+ ## String rubric
56
+
57
+ A newline-delimited string is parsed into criteria, with common list markers (`-`, `*`, `1.`) stripped. Every line becomes a required criterion:
58
+
59
+ ```typescript
60
+ const rubricScorer = createRubricScorer({
61
+ model: 'openai/gpt-5-mini',
62
+ criteria: `- All tests pass in the test suite
63
+ - The function is named find_duplicates and accepts a single list argument`,
64
+ })
65
+ ```
66
+
67
+ ## Optional criteria
68
+
69
+ Mark a criterion as optional to have it graded and reported without gating completion:
70
+
71
+ ```typescript
72
+ const rubricScorer = createRubricScorer({
73
+ model: 'openai/gpt-5-mini',
74
+ criteria: [
75
+ { description: 'Includes an analysis section', required: true },
76
+ { description: 'Includes citations', required: false },
77
+ ],
78
+ })
79
+ ```
80
+
81
+ ## Dynamic rubric per run
82
+
83
+ When no `criteria` is passed to the factory, the scorer resolves a `rubric` value from the run's request context, additional context, or input. This lets a single scorer instance grade different rubrics per run without rebuilding it:
84
+
85
+ ```typescript
86
+ const rubricScorer = createRubricScorer({
87
+ model: 'openai/gpt-5-mini',
88
+ })
89
+
90
+ await supervisor.stream('Write find_duplicates', {
91
+ isTaskComplete: { scorers: [rubricScorer] },
92
+ requestContext: {
93
+ rubric: '- All tests pass\n- The function is named find_duplicates',
94
+ },
95
+ })
96
+ ```
97
+
98
+ If no rubric resolves, the scorer returns `1` and doesn't gate the loop.
99
+
100
+ ## Scoring details
101
+
102
+ The scorer runs in two phases:
103
+
104
+ 1. **Grade**: The judge model evaluates each criterion independently and returns a per-criterion verdict (`satisfied` / not) with reasoning.
105
+ 2. **Score**: The result is `1` only when every required criterion is `satisfied`, otherwise `0`. If no criteria are marked required, all criteria are treated as required.
106
+
107
+ The `reason` summarizes the overall result and lists each criterion with its verdict, so a failing grade gives the agent targeted, actionable feedback rather than a generic "try again".
108
+
109
+ ## Related
110
+
111
+ - [isTaskComplete on stream()](https://mastra.ai/reference/streaming/agents/stream)
112
+ - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
113
+ - [createScorer](https://mastra.ai/reference/evals/create-scorer)
@@ -31,7 +31,7 @@ workflow_run
31
31
 
32
32
  ### Fallback extraction
33
33
 
34
- When storage is not available, the pipeline falls back to:
34
+ When storage isn't available, the pipeline falls back to:
35
35
 
36
36
  - **Agents:** `extractTrajectory()` — Extracts `ToolCallStep` entries from `toolInvocations` in the agent's message output. Produces a flat list of tool calls.
37
37
  - **Workflows:** `extractWorkflowTrajectory()` — Extracts `WorkflowStepStep` entries from `stepResults`. Produces a flat list of workflow steps.
@@ -176,7 +176,7 @@ In this example, the parent workflow requires strict ordering of its steps, but
176
176
  ### Use the LLM-based scorer when:
177
177
 
178
178
  - You need **semantic understanding** of whether steps were appropriate
179
- - The optimal trajectory is **not predetermined** (evaluate based on task requirements)
179
+ - The optimal trajectory **isn't predetermined** (evaluate based on task requirements)
180
180
  - You want to detect **unnecessary, redundant, or missing** steps
181
181
  - You need **explanations** for scoring decisions
182
182
  - You are evaluating **production agent behavior**
@@ -360,7 +360,7 @@ console.log(result.scores.trajectory['trajectory-accuracy'])
360
360
 
361
361
  ### Comparing step data
362
362
 
363
- Validates not just the step names but also step-specific data. For tool calls, this compares `toolArgs` and `toolResult`. For workflow steps, this compares `output`.
363
+ Validates the step names and step-specific data. For tool calls, this compares `toolArgs` and `toolResult`. For workflow steps, this compares `output`.
364
364
 
365
365
  ```typescript
366
366
  const scorer = createTrajectoryAccuracyScorerCode({
@@ -9,5 +9,6 @@ export * from './context-relevance/index.js';
9
9
  export * from './context-precision/index.js';
10
10
  export * from './noise-sensitivity/index.js';
11
11
  export * from './prompt-alignment/index.js';
12
+ export * from './rubric/index.js';
12
13
  export * from './trajectory/index.js';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scorers/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scorers/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC"}
@@ -0,0 +1,71 @@
1
+ import type { MastraModelConfig } from '@mastra/core/llm';
2
+ import type { ScorerRunInputForLLMJudge, ScorerRunOutputForLLMJudge } from '../../utils.js';
3
+ /**
4
+ * A single rubric criterion the agent's output is graded against.
5
+ */
6
+ export interface RubricCriterion {
7
+ /** Optional stable identifier for the criterion. */
8
+ id?: string;
9
+ /** What the output must satisfy, e.g. "All tests pass" or "Includes a recommendations section". */
10
+ description: string;
11
+ /**
12
+ * Whether this criterion must be satisfied for the task to be considered complete.
13
+ * Defaults to `true`. Optional criteria are graded and reported but do not gate completion.
14
+ */
15
+ required?: boolean;
16
+ }
17
+ /**
18
+ * Rubric input accepted by the scorer factory and by the dynamic `rubric` context value.
19
+ * A string is treated as a newline-delimited checklist; leading list markers ("-", "*", "1.")
20
+ * are stripped. Every parsed line becomes a required criterion.
21
+ */
22
+ export type RubricInput = RubricCriterion[] | string;
23
+ export interface RubricScorerOptions {
24
+ /** Scale applied to the final score. Defaults to 1. Only relevant for standalone evals — `isTaskComplete` gates on `=== 1`. */
25
+ scale?: number;
26
+ }
27
+ /**
28
+ * Creates an LLM-as-judge scorer that grades an agent's output against a rubric and returns a
29
+ * **binary** score: `1` only when every required criterion is satisfied, otherwise `0`. The
30
+ * `generateReason` output lists each unmet criterion with the judge's reasoning.
31
+ *
32
+ * It is designed to drop into `isTaskComplete`, which treats `score === 1` as "task complete" and
33
+ * injects the reason back into the conversation as feedback, so the agent iterates until the rubric
34
+ * is satisfied (or `maxSteps` is reached):
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { createRubricScorer } from '@mastra/evals/scorers/prebuilt';
39
+ *
40
+ * const rubricScorer = createRubricScorer({
41
+ * model: '__GATEWAY_OPENAI_MODEL_MINI__',
42
+ * criteria: [
43
+ * { description: 'The response includes an analysis section' },
44
+ * { description: 'The response includes concrete recommendations' },
45
+ * ],
46
+ * });
47
+ *
48
+ * await supervisor.stream('Research AI in education', {
49
+ * maxSteps: 10,
50
+ * isTaskComplete: { scorers: [rubricScorer], strategy: 'all' },
51
+ * });
52
+ * ```
53
+ *
54
+ * The rubric can also be supplied dynamically per run via request/additional context under the
55
+ * `rubric` key (string checklist or `RubricCriterion[]`). If no rubric resolves, the scorer is a
56
+ * no-op and returns `1` (so it does not gate the loop), mirroring "if the rubric is absent, do nothing".
57
+ */
58
+ export declare function createRubricScorer({ model, criteria, options, }: {
59
+ model: MastraModelConfig;
60
+ criteria?: RubricInput;
61
+ options?: RubricScorerOptions;
62
+ }): import("@mastra/core/evals").MastraScorer<string, ScorerRunInputForLLMJudge, ScorerRunOutputForLLMJudge, Record<"analyzeStepResult", {
63
+ criteria: {
64
+ criterion: string;
65
+ satisfied: boolean;
66
+ required: boolean;
67
+ reasoning: string;
68
+ }[];
69
+ overallAssessment: string;
70
+ }> & Record<"generateScoreStepResult", number> & Record<"generateReasonStepResult", string>>;
71
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/rubric/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAIzF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oDAAoD;IACpD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mGAAmG;IACnG,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,EAAE,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,mBAAmB;IAClC,+HAA+H;IAC/H,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,OAAO,GACR,EAAE;IACD,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B;;;;;;;;6FA2DA"}