Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(autoresearch): show a training sparkline on the model card (#116690)

posthog[bot]1b6b39273ddc
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 6c6e34cc6d9b..43bae989f1e7 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6607,9 +6607,9 @@ snapshots:
products-autoresearch-model-card--draft--light:
hash: v1.k794b7964.3c616c7e36d5fd229e302e60922969677fe723890f2dbf6c329a705c3ce95669.jsCdOMXuKPoT0RhQQr-_lS4-vQ4JmXgEO5InlxlF5bA
products-autoresearch-model-card--training--dark:
- hash: v1.k794b7964.cd5afd235dacbb2740cdf95a929cdb88eef0fabac1cb10287f578d554e165b99.AxWi1MV4FRxmq-OCiPsM8ZOKC1QUhzqqN2uWiYwIsds
+ hash: v1.k794b7964.c3f8d079b393db8df9623cc8c4d6320e64ab3e656c7512beb24d6a6feb37099d.KeZjOrNDaOjBAv-ncpSG6l9muC3OYJGGtXVcTeL1MYc
products-autoresearch-model-card--training--light:
- hash: v1.k794b7964.8549b3b132dd11b9f618b96e48d41048e478d3de09cb360f4d9367ced26f4131.YQv_5y5fFu_B1cvZPcxGL8TnnvzbEvoBJD5Y-oQvjaM
+ hash: v1.k794b7964.b358f33a0d879e85f4c8bdb4ae65330f392cdaa8a869e8bce7e07cdcb22d13a9.EAfBa_-86ylT0UXKPW7EAqtGV9zNLRT4VdSYkWFWj_M
products-autoresearch-model-detail-scene--accuracy--narrow--dark:
hash: v1.k794b7964.ab6cd49b1bd74e55cdfc33e06cbfaea05af40f5423c9a354f2f0206f0b757755.GrpIVBW2vJXjMK0cAm_bPc0wDJN0yjE_PZ5Sqemb9F8
products-autoresearch-model-detail-scene--accuracy--narrow--light:
diff --git a/products/autoresearch/backend/facade/api.py b/products/autoresearch/backend/facade/api.py
index 89eb26d5b725..b7c02956de45 100644
--- a/products/autoresearch/backend/facade/api.py
+++ b/products/autoresearch/backend/facade/api.py
@@ -13,6 +13,7 @@ import json
import base64
import asyncio
import hashlib
+from collections.abc import Iterable
from datetime import date, datetime
from typing import Any
from uuid import UUID, uuid4
@@ -186,16 +187,29 @@ class _PipelineActivity:
live_training_run: LiveTrainingRun | None
+def _best_so_far_trend(scores: Iterable[tuple[int, float | None]]) -> list[TrainingTrendPoint]:
+ """Best holdout score up to each iteration, oldest first. Iterations before the first score are left out."""
+ trend: list[TrainingTrendPoint] = []
+ best: float | None = None
+ for iteration_number, holdout_score in scores:
+ if holdout_score is not None and (best is None or holdout_score > best):
+ best = holdout_score
+ if best is not None:
+ trend.append(TrainingTrendPoint(iteration_number=iteration_number, best_holdout_score=best))
+ return trend
+
+
def _live_training_run(run: AutoresearchTrainingRun, iterations: list[AutoresearchIteration]) -> LiveTrainingRun:
# The run's own counters land only at completion, so progress comes from the live iteration rows.
- scores = [i.holdout_score for i in iterations if i.holdout_score is not None]
+ trend = _best_so_far_trend((i.iteration_number, i.holdout_score) for i in iterations)
return LiveTrainingRun(
id=run.id,
iteration_budget=run.iteration_budget,
experiment_count=len(iterations),
- best_holdout_score=max(scores) if scores else None,
+ best_holdout_score=trend[-1].best_holdout_score if trend else None,
latest_agent_description=iterations[-1].agent_description if iterations else "",
latest_summary=iterations[-1].summary if iterations else None,
+ trend=trend,
)
@@ -220,21 +234,16 @@ def _champion_training_trends(
) -> dict[UUID, list[TrainingTrendPoint]]:
"""Best-so-far holdout score per iteration of the run that trained each champion, oldest first."""
pipeline_by_run = {c.source_training_run_id: p for p, c in champions.items() if c.source_training_run_id}
- trends: dict[UUID, list[TrainingTrendPoint]] = {}
- best: dict[UUID, float] = {}
+ scores: dict[UUID, list[tuple[int, float | None]]] = {}
for training_run_id, iteration_number, holdout_score in (
AutoresearchIteration.objects.for_team(team_id)
.filter(training_run_id__in=list(pipeline_by_run))
.order_by("training_run_id", "iteration_number")
.values_list("training_run_id", "iteration_number", "holdout_score")
):
- if holdout_score is not None and holdout_score > best.get(training_run_id, -1.0):
- best[training_run_id] = holdout_score
- if training_run_id in best:
- trends.setdefault(pipeline_by_run[training_run_id], []).append(
- TrainingTrendPoint(iteration_number=iteration_number, best_holdout_score=best[training_run_id])
- )
- return trends
+ scores.setdefault(training_run_id, []).append((iteration_number, holdout_score))
+ trends = {pipeline_by_run[run_id]: _best_so_far_trend(run_scores) for run_id, run_scores in scores.items()}
+ return {pipeline_id: trend for pipeline_id, trend in trends.items() if trend}
def _champion_likely_counts(team_id: int, champions: dict[UUID, AutoresearchModel]) -> dict[UUID, tuple[int, float]]:
@@ -319,7 +328,7 @@ def _pipeline_activity(
for iteration in (
AutoresearchIteration.objects.for_team(team_id)
.filter(training_run_id__in=[run.id for run in live_runs.values()])
- .only("training_run_id", "holdout_score", "agent_description", "summary")
+ .only("training_run_id", "iteration_number", "holdout_score", "agent_description", "summary")
.order_by("training_run_id", "iteration_number")
):
live_iterations.setdefault(iteration.training_run_id, []).append(iteration)
diff --git a/products/autoresearch/backend/facade/contracts.py b/products/autoresearch/backend/facade/contracts.py
index 985af0ea28a9..a93491ed0eee 100644
--- a/products/autoresearch/backend/facade/contracts.py
+++ b/products/autoresearch/backend/facade/contracts.py
@@ -71,6 +71,12 @@ class ArtifactStorageUnavailable(RuntimeError):
# ── Model-backed read contracts ────────────────────────────────────────────
+@dataclass(frozen=True)
+class TrainingTrendPoint:
+ iteration_number: int
+ best_holdout_score: float
+
+
@dataclass(frozen=True)
class LiveTrainingRun:
"""Progress of the pipeline's pending or running training run, read from its live iteration rows."""
@@ -81,6 +87,7 @@ class LiveTrainingRun:
best_holdout_score: float | None
latest_agent_description: str
latest_summary: str | None
+ trend: list[TrainingTrendPoint]
@dataclass(frozen=True)
@@ -103,12 +110,6 @@ class RealizedAucPoint:
realized_auc: float
-@dataclass(frozen=True)
-class TrainingTrendPoint:
- iteration_number: int
- best_holdout_score: float
-
-
@dataclass(frozen=True, config={"arbitrary_types_allowed": True})
class Pipeline:
"""One prediction pipeline: a target, a population, and a horizon.
diff --git a/products/autoresearch/backend/presentation/views/serializers.py b/products/autoresearch/backend/presentation/views/serializers.py
index 1839b81650e2..ecd8eb85a013 100644
--- a/products/autoresearch/backend/presentation/views/serializers.py
+++ b/products/autoresearch/backend/presentation/views/serializers.py
@@ -494,6 +494,18 @@ class MetricsBundleField(serializers.JSONField):
# ── Core serializers ------------------------------------------------------
+@extend_schema_serializer(component_name="AutoresearchTrainingTrendPoint")
+class TrainingTrendPointSerializer(DataclassSerializer):
+ iteration_number = serializers.IntegerField(read_only=True, help_text="Iteration number inside the training run.")
+ best_holdout_score = serializers.FloatField(
+ read_only=True, help_text="Best holdout AUC of the run up to and including this iteration."
+ )
+
+ class Meta:
+ dataclass = TrainingTrendPoint
+ fields = ["iteration_number", "best_holdout_score"]
+
+
@extend_schema_serializer(component_name="AutoresearchLiveTrainingRun")
class LiveTrainingRunSerializer(DataclassSerializer):
id = serializers.UUIDField(read_only=True, help_text="Unique UUID of the live training run.")
@@ -512,6 +524,14 @@ class LiveTrainingRunSerializer(DataclassSerializer):
allow_null=True,
help_text="Plain-language sentence on the newest experiment, for people. Null if the agent wrote none.",
)
+ trend = TrainingTrendPointSerializer(
+ many=True,
+ read_only=True,
+ help_text=(
+ "Best-so-far holdout AUC per experiment of this run, oldest first. "
+ "Experiments before the first holdout score are left out."
+ ),
+ )
class Meta:
dataclass = LiveTrainingRun
@@ -522,6 +542,7 @@ class LiveTrainingRunSerializer(DataclassSerializer):
"best_holdout_score",
"latest_agent_description",
"latest_summary",
+ "trend",
]
@@ -585,18 +606,6 @@ class RealizedAucPointSerializer(DataclassSerializer):
fields = ["prediction_date", "realized_auc"]
-@extend_schema_serializer(component_name="AutoresearchTrainingTrendPoint")
-class TrainingTrendPointSerializer(DataclassSerializer):
- iteration_number = serializers.IntegerField(read_only=True, help_text="Iteration number inside the training run.")
- best_holdout_score = serializers.FloatField(
- read_only=True, help_text="Best holdout AUC of the run up to and including this iteration."
- )
-
- class Meta:
- dataclass = TrainingTrendPoint
- fields = ["iteration_number", "best_holdout_score"]
-
-
@extend_schema_serializer(component_name="AutoresearchPipeline")
# Read representation of a pipeline. Every field is declared explicitly so the generated
# AutoresearchPipeline component keeps the shape it had when this was a ModelSerializer.
diff --git a/products/autoresearch/backend/tests/test_api.py b/products/autoresearch/backend/tests/test_api.py
index e2aa021c2c8b..fa99183f5544 100644
--- a/products/autoresearch/backend/tests/test_api.py
+++ b/products/autoresearch/backend/tests/test_api.py
@@ -346,6 +346,10 @@ class TestAutoresearchPipelineAPI(TeamScopedTestMixin, APIBaseTest):
"best_holdout_score": 0.72,
"latest_agent_description": "try fewer features",
"latest_summary": "Plain try fewer features",
+ "trend": [
+ {"iteration_number": 0, "best_holdout_score": 0.72},
+ {"iteration_number": 1, "best_holdout_score": 0.72},
+ ],
},
),
"No positives": (None, 0, 0, [], None),
diff --git a/products/autoresearch/frontend/AutoresearchModelCard.stories.tsx b/products/autoresearch/frontend/AutoresearchModelCard.stories.tsx
index 2c5e2ae24b33..6dee2a36b065 100644
--- a/products/autoresearch/frontend/AutoresearchModelCard.stories.tsx
+++ b/products/autoresearch/frontend/AutoresearchModelCard.stories.tsx
@@ -55,6 +55,7 @@ const LIVE_RUN: AutoresearchPipelineApi['live_training_run'] = {
best_holdout_score: 0.81,
latest_agent_description: 'Add the ratio of shares in the last 7 days to the last 30 days.',
latest_summary: null,
+ trend: [0.74, 0.79, 0.81].map((best_holdout_score, iteration_number) => ({ iteration_number, best_holdout_score })),
}
const CONFIRMED = {
diff --git a/products/autoresearch/frontend/AutoresearchModelCard.tsx b/products/autoresearch/frontend/AutoresearchModelCard.tsx
index 25dc65400951..eaf7d2dca99a 100644
--- a/products/autoresearch/frontend/AutoresearchModelCard.tsx
+++ b/products/autoresearch/frontend/AutoresearchModelCard.tsx
@@ -195,12 +195,19 @@ function TrainingBody({ liveRun }: { liveRun: AutoresearchLiveTrainingRunApi | n
if (!liveRun) {
return <span className="text-secondary">Starting the first training run…</span>
}
+ const trend = liveRun.trend.map((point) => ({
+ date: String(point.iteration_number),
+ value: point.best_holdout_score,
+ }))
return (
<div className="flex flex-col gap-1">
- <Headline
- value={liveRun.best_holdout_score != null ? liveRun.best_holdout_score.toFixed(2) : 'No score yet'}
- label={`Best test AUC so far · experiment ${liveRun.experiment_count} of ${liveRun.iteration_budget}`}
- />
+ <div className="flex items-center justify-between gap-2">
+ <Headline
+ value={liveRun.best_holdout_score != null ? liveRun.best_holdout_score.toFixed(2) : 'No score yet'}
+ label={`Best test AUC so far · experiment ${liveRun.experiment_count} of ${liveRun.iteration_budget}`}
+ />
+ <TrendChart points={trend} color={TEST_DATA_COLOR} title="Best test AUC per experiment of this run" />
+ </div>
<LemonProgress percent={(liveRun.experiment_count / liveRun.iteration_budget) * 100} />
{liveRun.latest_agent_description && (
<span className="text-xs text-secondary truncate" title={liveRun.latest_agent_description}>
diff --git a/products/autoresearch/frontend/generated/api.schemas.ts b/products/autoresearch/frontend/generated/api.schemas.ts
index c16f12da2ba7..485279344701 100644
--- a/products/autoresearch/frontend/generated/api.schemas.ts
+++ b/products/autoresearch/frontend/generated/api.schemas.ts
@@ -148,6 +148,8 @@ export interface AutoresearchLiveTrainingRunApi {
* @nullable
*/
readonly latest_summary: string | null
+ /** Best-so-far holdout AUC per experiment of this run, oldest first. Experiments before the first holdout score are left out. */
+ readonly trend: readonly AutoresearchTrainingTrendPointApi[]
}
/**
diff --git a/products/autoresearch/frontend/modelCardState.test.ts b/products/autoresearch/frontend/modelCardState.test.ts
index 451cefafd21a..2c7d70b54886 100644
--- a/products/autoresearch/frontend/modelCardState.test.ts
+++ b/products/autoresearch/frontend/modelCardState.test.ts
@@ -11,6 +11,7 @@ describe('modelCardState', () => {
best_holdout_score: 0.72,
latest_agent_description: 'baseline',
latest_summary: null,
+ trend: [],
}
const noChampion = { champion_holdout_auc: null, champion_realized_auc: null, champion_is_preliminary: null }
const awaiting = { champion_holdout_auc: 0.81, champion_realized_auc: null, champion_is_preliminary: null }
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index a9938d91387b..e6c5fb92043a 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -13813,6 +13813,13 @@ export namespace Schemas {
readonly created_at: string;
}
+ export interface AutoresearchTrainingTrendPoint {
+ /** Iteration number inside the training run. */
+ readonly iteration_number: number;
+ /** Best holdout AUC of the run up to and including this iteration. */
+ readonly best_holdout_score: number;
+ }
+
export interface AutoresearchLiveTrainingRun {
/** Unique UUID of the live training run. */
readonly id: string;
@@ -13832,6 +13839,8 @@ export namespace Schemas {
* @nullable
*/
readonly latest_summary: string | null;
+ /** Best-so-far holdout AUC per experiment of this run, oldest first. Experiments before the first holdout score are left out. */
+ readonly trend: readonly AutoresearchTrainingTrendPoint[];
}
/**
@@ -14029,13 +14038,6 @@ export namespace Schemas {
readonly realized_auc: number;
}
- export interface AutoresearchTrainingTrendPoint {
- /** Iteration number inside the training run. */
- readonly iteration_number: number;
- /** Best holdout AUC of the run up to and including this iteration. */
- readonly best_holdout_score: number;
- }
-
export interface AutoresearchPredictionCoverage {
/** People in the inference population at the run's cutoff. */
readonly population: number;