Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(evals): revamp decision model results (#18523)

Tobias Wochinger6e820abf6111
diff --git a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.stories.tsx b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.stories.tsx
index 4c2668f463..96568e78e5 100644
--- a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.stories.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.stories.tsx
@@ -11,7 +11,6 @@ const meta = preview.meta({ component: DecisionModelQuestionCard });
const STATE_KEYS = ["input", "output"];
const base = {
- index: 0,
stateKeys: STATE_KEYS,
expanded: true,
onExpandedChange: fn(),
diff --git a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.tsx b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.tsx
index aaee96eba7..8c827101c0 100644
--- a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionCard/DecisionModelQuestionCard.tsx
@@ -26,7 +26,6 @@ import { cn } from "@/src/utils/tailwind";
export type DecisionModelQuestionCardProps = {
question: DecisionModelQuestionDraft;
- index: number;
stateKeys: string[];
expanded: boolean;
onExpandedChange: (expanded: boolean) => void;
@@ -91,7 +90,6 @@ function CriteriaEditor({
*/
export function DecisionModelQuestionCard({
question,
- index,
stateKeys,
expanded,
onExpandedChange,
@@ -113,9 +111,6 @@ export function DecisionModelQuestionCard({
triggerTitle={expanded ? "Collapse question" : "Expand question"}
header={
<span className="flex min-w-0 items-center gap-2">
- <span className="text-muted-foreground shrink-0 font-mono text-xs leading-none">
- {index + 1}
- </span>
<copy.icon className="icon-base shrink-0" aria-label={copy.label} />
<Badge
variant="secondary"
diff --git a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionList/DecisionModelQuestionList.tsx b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionList/DecisionModelQuestionList.tsx
index 711de7626e..10d18d0287 100644
--- a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionList/DecisionModelQuestionList.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelQuestionList/DecisionModelQuestionList.tsx
@@ -170,10 +170,9 @@ export function DecisionModelQuestionList({
}
onReorder={onReorder}
gap="md"
- renderItem={(question, index) => (
+ renderItem={(question) => (
<DecisionModelQuestionCard
question={question}
- index={index}
stateKeys={stateKeys}
expanded={expandedId === question.id}
onExpandedChange={(expanded) =>
diff --git a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.stories.tsx b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.stories.tsx
index d85ec06f11..6b940e95c2 100644
--- a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.stories.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.stories.tsx
@@ -5,7 +5,7 @@ import { DecisionModelResultView } from "./DecisionModelResultView";
const meta = preview.meta({ component: DecisionModelResultView });
-export const AllTypes = meta.story({
+export const VariantMatrix = meta.story({
args: {
results: [
{
@@ -36,7 +36,7 @@ export const AllTypes = meta.story({
type: "noul",
scoreName: "refund_requested",
instructions: "Does `input` request a refund?",
- probability: 0.97,
+ probability: 0.03,
},
],
},
@@ -65,6 +65,62 @@ export const LowConfidence = meta.story({
},
});
+export const LongQuestion = meta.story({
+ args: {
+ results: [
+ {
+ questionId: "q1",
+ type: "choice",
+ scoreName: "primary_topic_user",
+ instructions:
+ "What is the primary topic of the user input when it includes several unrelated requests and a large amount of supporting context?",
+ choice: "implementation",
+ probabilities: {
+ unrelated: 0.01,
+ implementation: 0.94,
+ competition: 0.03,
+ feedback: 0.02,
+ },
+ confidence: 0.91,
+ },
+ ],
+ },
+});
+
+export const LongAnswer = meta.story({
+ args: {
+ results: [
+ {
+ questionId: "q1",
+ type: "choice",
+ scoreName: "routing_destination",
+ instructions: "Where should this request be routed?",
+ choice:
+ "enterprise_customer_success_team_for_complex_implementation_requests",
+ probabilities: {
+ enterprise_customer_success_team_for_complex_implementation_requests: 0.92,
+ support: 0.08,
+ },
+ confidence: 0.84,
+ },
+ {
+ questionId: "q2",
+ type: "score",
+ scoreName: "technical_depth",
+ instructions: "How technical is the response?",
+ score: 1.28,
+ levels: [
+ "Not technical",
+ "Somewhat technical with a detailed explanation of implementation constraints",
+ "Very technical",
+ ],
+ probabilities: { "0": 0.08, "1": 0.56, "2": 0.36 },
+ confidence: 0.61,
+ },
+ ],
+ },
+});
+
/** Scores at the ends of the scale highlight that level's bar. */
export const ScoreAtEdges = meta.story({
args: {
@@ -140,7 +196,7 @@ export const TenLevels = meta.story({
const canvas = within(canvasElement);
await expect(canvas.getByText("No technical detail")).toBeInTheDocument();
await expect(
- canvas.getByText("Explains system behavior"),
+ canvas.getByTitle("Explains system behavior"),
).toBeInTheDocument();
},
});
diff --git a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.tsx b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.tsx
index 45814186d6..4e5d0bfc0f 100644
--- a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelResultView/DecisionModelResultView.tsx
@@ -2,46 +2,118 @@ import { Badge } from "@/src/components/ui/badge";
import { QUESTION_TYPE_COPY } from "@/src/features/evals/v2/components/Evaluators/DecisionModel/QuestionTypeSelector/QuestionTypeSelector";
import { cn } from "@/src/utils/tailwind";
-export type DecisionModelQuestionResult = {
- questionId: string;
- scoreName: string;
- instructions: string;
-} & (
- | {
- type: "choice";
- choice: string;
- probabilities: Record<string, number>;
- confidence: number | null;
- }
- | {
- type: "score";
- score: number;
- levels: string[];
- probabilities: Record<string, number>;
- confidence: number | null;
- }
- | { type: "noul"; probability: number }
-);
-
-const percent = (value: number) => `${Math.round(value * 100)}%`;
+/**
+ * Test result of a decision-model evaluator: one row per question with the
+ * full probability distribution, since the model returns no rationale.
+ */
+export function DecisionModelResultView({
+ results,
+}: {
+ results: DecisionModelQuestionResult[];
+}) {
+ return (
+ <ul className="flex flex-col gap-2">
+ {results.map((result) => (
+ <ResultRow key={result.questionId} result={result} />
+ ))}
+ </ul>
+ );
+}
-function confidenceTone(confidence: number) {
- if (confidence >= 0.8) return "text-dark-green";
- if (confidence >= 0.5) return "text-dark-yellow";
- return "text-destructive";
+function ResultRow({ result }: { result: DecisionModelQuestionResult }) {
+ const copy = QUESTION_TYPE_COPY[result.type];
+ return (
+ <li className="flex flex-col gap-2 rounded-md border p-3">
+ <div className="flex items-center justify-between gap-2">
+ <Badge variant="secondary" className="min-w-0 font-mono">
+ <copy.icon className="icon-base shrink-0" aria-label={copy.label} />
+ <span className="truncate" title={result.scoreName}>
+ {result.scoreName}
+ </span>
+ </Badge>
+ {result.type !== "noul" && result.confidence !== null ? (
+ <ConfidenceBadge confidence={result.confidence} />
+ ) : null}
+ </div>
+ <div className="flex min-w-0 items-baseline gap-2 text-sm">
+ <span
+ className="text-muted-foreground min-w-0 truncate"
+ title={result.instructions}
+ >
+ {result.instructions}
+ </span>
+ <div
+ className="border-border min-w-4 flex-1 border-t border-dashed"
+ aria-hidden="true"
+ />
+ <ResultAnswer result={result} />
+ </div>
+ <ResultVisual result={result} />
+ </li>
+ );
}
function ConfidenceBadge({ confidence }: { confidence: number }) {
return (
<span
- className={cn("font-mono text-xs", confidenceTone(confidence))}
+ className="text-muted-foreground shrink-0 font-mono text-xs"
title="How concentrated the distribution is (0–1). Not the winner's probability."
>
- confidence {confidence.toFixed(2)}
+ confidence {percent(confidence)}
</span>
);
}
+function ResultAnswer({ result }: { result: DecisionModelQuestionResult }) {
+ const value = resultValue(result);
+ const detail = resultDetail(result);
+
+ return (
+ <span
+ className="max-w-1/2 min-w-0 shrink-0 truncate font-mono text-sm font-bold"
+ title={detail ? `${value} (${detail})` : value}
+ >
+ {value}
+ {detail ? (
+ <span className="text-muted-foreground font-normal"> ({detail})</span>
+ ) : null}
+ </span>
+ );
+}
+
+function ResultVisual({ result }: { result: DecisionModelQuestionResult }) {
+ switch (result.type) {
+ case "choice":
+ return (
+ <ProbabilityBars
+ entries={Object.entries(result.probabilities)
+ .sort(([, a], [, b]) => b - a)
+ .map(([label, value]) => ({ label, value }))}
+ highlight={result.choice}
+ />
+ );
+ case "score": {
+ const nearest = Math.min(
+ Math.max(Math.round(result.score), 0),
+ Math.max(result.levels.length - 1, 0),
+ );
+ return (
+ <ProbabilityBars
+ entries={result.levels
+ .map((description, index) => ({
+ label: description || String(index),
+ value: result.probabilities[String(index)] ?? 0,
+ }))
+ .sort((left, right) => right.value - left.value)}
+ highlight={result.levels[nearest] || String(nearest)}
+ />
+ );
+ }
+ case "noul":
+ return <NoulGauge probability={result.probability} />;
+ }
+}
+
function ProbabilityBars({
entries,
highlight,
@@ -96,11 +168,16 @@ function NoulGauge({ probability }: { probability: number }) {
return (
<div className="flex flex-col gap-1 text-xs">
<div className="flex items-center justify-between font-mono">
- <span className="text-muted-foreground">no</span>
- <span className="font-bold">
- P(yes) = {probability.toFixed(2)} → leaning {leaning}
+ <span
+ className={leaning === "no" ? "font-bold" : "text-muted-foreground"}
+ >
+ no
+ </span>
+ <span
+ className={leaning === "yes" ? "font-bold" : "text-muted-foreground"}
+ >
+ yes
</span>
- <span className="text-muted-foreground">yes</span>
</div>
<div className="bg-muted relative h-2 rounded-full">
<span
@@ -116,95 +193,54 @@ function NoulGauge({ probability }: { probability: number }) {
);
}
-function resultValue(
- result: Exclude<DecisionModelQuestionResult, { type: "score" }>,
-) {
+function resultValue(result: DecisionModelQuestionResult) {
switch (result.type) {
case "choice":
return result.choice;
- case "noul":
- return result.probability.toFixed(2);
- }
-}
-
-function ResultVisual({ result }: { result: DecisionModelQuestionResult }) {
- switch (result.type) {
- case "choice":
- return (
- <ProbabilityBars
- entries={Object.entries(result.probabilities)
- .sort(([, a], [, b]) => b - a)
- .map(([label, value]) => ({ label, value }))}
- highlight={result.choice}
- />
- );
case "score": {
const nearest = Math.min(
Math.max(Math.round(result.score), 0),
Math.max(result.levels.length - 1, 0),
);
- return (
- <ProbabilityBars
- entries={result.levels
- .map((description, index) => ({
- label: description || String(index),
- value: result.probabilities[String(index)] ?? 0,
- }))
- .sort((left, right) => right.value - left.value)}
- highlight={result.levels[nearest] || String(nearest)}
- />
- );
+ return result.levels[nearest] || String(nearest);
}
case "noul":
- return <NoulGauge probability={result.probability} />;
+ return result.probability >= 0.5 ? "yes" : "no";
}
}
-function ResultRow({ result }: { result: DecisionModelQuestionResult }) {
- const copy = QUESTION_TYPE_COPY[result.type];
- return (
- <li className="flex flex-col gap-2 rounded-md border p-3">
- <div className="flex flex-wrap items-center justify-between gap-2">
- <span className="flex min-w-0 items-center gap-2 text-sm">
- <copy.icon className="icon-base shrink-0" aria-label={copy.label} />
- <Badge variant="secondary" className="font-mono">
- {result.scoreName}
- </Badge>
- <span
- className="text-muted-foreground truncate"
- title={result.instructions}
- >
- {result.instructions}
- </span>
- </span>
- <span className="flex items-center gap-3">
- {result.type !== "noul" && result.confidence !== null ? (
- <ConfidenceBadge confidence={result.confidence} />
- ) : null}
- {result.type === "score" ? null : (
- <Badge className="font-mono">{resultValue(result)}</Badge>
- )}
- </span>
- </div>
- <ResultVisual result={result} />
- </li>
- );
+function resultDetail(result: DecisionModelQuestionResult) {
+ switch (result.type) {
+ case "choice":
+ return null;
+ case "score":
+ return String(result.score);
+ case "noul":
+ return percent(Math.max(result.probability, 1 - result.probability));
+ }
}
-/**
- * Test result of a decision-model evaluator: one row per question with the
- * full probability distribution, since the model returns no rationale.
- */
-export function DecisionModelResultView({
- results,
-}: {
- results: DecisionModelQuestionResult[];
-}) {
- return (
- <ul className="flex flex-col gap-2">
- {results.map((result) => (
- <ResultRow key={result.questionId} result={result} />
- ))}
- </ul>
- );
+function percent(value: number) {
+ return `${Math.round(value * 100)}%`;
}
+
+export type DecisionModelQuestionResult = {
+ questionId: string;
+ scoreName: string;
+ instructions: string;
+} & (
+ | {
+ type: "choice";
+ choice: string;
+ probabilities: Record<string, number>;
+ confidence: number | null;
+ }
+ | {
+ type: "score";
+ score: number;
+ levels: string[];
+ probabilities: Record<string, number>;
+ confidence: number | null;
+ }
+ | { type: "noul"; probability: number }
+);
diff --git a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelStatePreview/DecisionModelStatePreview.tsx b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelStatePreview/DecisionModelStatePreview.tsx
index fea8fcdf8a..b4f90bff87 100644
--- a/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelStatePreview/DecisionModelStatePreview.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/DecisionModel/DecisionModelStatePreview/DecisionModelStatePreview.tsx
@@ -65,7 +65,7 @@ export function DecisionModelStatePreview({
aria-expanded={open}
onClick={() => setOpen((current) => !current)}
>
- <span className="flex items-center gap-2">
+ <span className="flex items-baseline gap-2">
<span className="font-bold">{title}</span>
{statePreview ? (
<span
diff --git a/web/src/features/evals/v2/components/Evaluators/Testing/components/TestResultPanelView/TestResultPanelView.tsx b/web/src/features/evals/v2/components/Evaluators/Testing/components/TestResultPanelView/TestResultPanelView.tsx
index 40ba59bcb0..afb86c5fa9 100644
--- a/web/src/features/evals/v2/components/Evaluators/Testing/components/TestResultPanelView/TestResultPanelView.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/Testing/components/TestResultPanelView/TestResultPanelView.tsx
@@ -46,11 +46,11 @@ function ResultStat({
}) {
return (
<span
- className="text-muted-foreground flex items-center gap-1 font-mono text-xs leading-none tabular-nums"
+ className="text-muted-foreground inline-flex items-baseline gap-1 font-mono text-xs leading-none tabular-nums"
title={title}
>
- <Icon className="icon-sm shrink-0" />
- {children}
+ <Icon className="icon-sm shrink-0 self-center" />
+ <span>{children}</span>
</span>
);
}
@@ -72,20 +72,22 @@ function TestResultHeader({
}) {
return (
<div className="bg-secondary text-secondary-foreground flex flex-wrap items-center gap-2 border-b px-3 py-2">
- <p className="text-sm leading-none font-bold">{title}</p>
- {durationMs !== null ? (
- <ResultStat icon={Clock} title="Duration of the test call">
- {(durationMs / 1000).toFixed(2)}s
- </ResultStat>
- ) : null}
- {estimatedCostUsd !== null ? (
- <ResultStat
- icon={Coins}
- title="Estimated cost of the test call — also feeds the daily projection when saving"
- >
- {usdFormatter(estimatedCostUsd)}
- </ResultStat>
- ) : null}
+ <div className="flex flex-wrap items-baseline gap-2">
+ <p className="text-sm leading-none font-bold">{title}</p>
+ {durationMs !== null ? (
+ <ResultStat icon={Clock} title="Duration of the test call">
+ {(durationMs / 1000).toFixed(2)}s
+ </ResultStat>
+ ) : null}
+ {estimatedCostUsd !== null ? (
+ <ResultStat
+ icon={Coins}
+ title="Estimated cost of the test call — also feeds the daily projection when saving"
+ >
+ {usdFormatter(estimatedCostUsd)}
+ </ResultStat>
+ ) : null}
+ </div>
<span className="ml-auto flex shrink-0 items-center gap-2">
<label className="text-muted-foreground flex cursor-pointer items-center gap-1.5 text-xs">
<Switch