: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(replay-vision): run the summarizer through the base core step (#101125)
Tue Haulund191eb0ebb91e
diff --git a/products/replay_vision/backend/temporal/scanners/base.py b/products/replay_vision/backend/temporal/scanners/base.pyindex a852df883695..a24d804d446a 100644--- a/products/replay_vision/backend/temporal/scanners/base.py+++ b/products/replay_vision/backend/temporal/scanners/base.py@@ -160,8 +160,8 @@ class BaseScanner(BaseModel, frozen=True):"""Common shape for every concrete scanner; subclasses bind `scanner_type`, `core_step_template`, and `llm_response_schema`.A scan is a multi-turn conversation over the cached video: a shared `preamble` (sent/cached once) followed by- the ordered `mission_steps` — one structured turn each. Every scanner type has a single `core` step (the summarizer- names it `summary`); the signals side mission, when enabled, is always the final turn.+ the ordered `mission_steps` — one structured turn each. Every scanner type has a single `core` step; the signals+ side mission, when enabled, is always the final turn."""prompt: str@@ -169,7 +169,7 @@ class BaseScanner(BaseModel, frozen=True):# Shared opening turn (footer, events tool, calibration, session metadata), rendered once and cached with the video.preamble_template: ClassVar[str] = "preamble.jinja"- # Per-scanner-type instruction for the `core` step. Subclasses set this (the summarizer overrides `core_steps`).+ # Per-scanner-type instruction for the `core` step. Subclasses set this.core_step_template: ClassVar[str] = ""# Names of free-text output fields that may contain `(t <sec>)` citations.citation_fields: ClassVar[tuple[str, ...]] = ()diff --git a/products/replay_vision/backend/temporal/scanners/summarizer.py b/products/replay_vision/backend/temporal/scanners/summarizer.pyindex 1bb3c597614f..019de0b3da76 100644--- a/products/replay_vision/backend/temporal/scanners/summarizer.py+++ b/products/replay_vision/backend/temporal/scanners/summarizer.py@@ -1,6 +1,6 @@-"""Summarizer scanner: a single `summary` turn (title + body), embedded whole for free-text search."""+"""Summarizer scanner: one core turn producing a title + body, embedded whole for free-text search."""-from typing import ClassVar, Literal+from typing import Any, ClassVar, Literalfrom pydantic import BaseModel, Field@@ -9,12 +9,9 @@ from products.replay_vision.backend.temporal.scanners.base import (BaseScanner,BaseScannerOutput,EmbeddingDocument,- MissionStep,Segment,- SignalFinding,confidence_field,)-from products.replay_vision.backend.temporal.scanners.prompt_env import render_promptSummaryLength = Literal["short", "medium", "long"]@@ -26,7 +23,7 @@ _LENGTH_GUIDANCE: dict[SummaryLength, str] = {class SummarizerSummaryResponse(BaseModel, frozen=True):- """First turn: the title + body summary. Field order is load-bearing — `confidence` last, after the content."""+ """The core turn: title + body summary. Field order is load-bearing — `confidence` last, after the content."""title: str = Field(max_length=120,@@ -59,20 +56,14 @@ def summary_embedding_text(output: SummarizerOutput) -> str:class SummarizerScanner(BaseScanner, frozen=True):scanner_type: Literal[ScannerType.SUMMARIZER] = ScannerType.SUMMARIZER+ core_step_template: ClassVar[str] = "summarizer_summary_step.jinja"citation_fields: ClassVar[tuple[str, ...]] = ("summary",)output_cls: ClassVar[type[BaseScannerOutput]] = SummarizerOutputlength: SummaryLength = "medium"- def core_steps(self) -> list[MissionStep]:- summary_instruction = render_prompt(- "summarizer_summary_step.jinja",- user_prompt=self.prompt,- length_guidance=_LENGTH_GUIDANCE[self.length],- )- return [- MissionStep(name="summary", instruction=summary_instruction, response_model=SummarizerSummaryResponse),- ]-- def assemble(self, step_outputs: dict[str, BaseModel]) -> tuple[BaseScannerOutput, list[SignalFinding]]:- summary = step_outputs["summary"]- return SummarizerOutput(**summary.model_dump()), self._extract_signals(step_outputs)+ @property+ def llm_response_schema(self) -> type[BaseModel]:+ return SummarizerSummaryResponse++ def prompt_context(self) -> dict[str, Any]:+ return {"length_guidance": _LENGTH_GUIDANCE[self.length]}diff --git a/products/replay_vision/backend/tests/test_scanners.py b/products/replay_vision/backend/tests/test_scanners.pyindex 8dc47da0eed7..d92cfe7131d5 100644--- a/products/replay_vision/backend/tests/test_scanners.py+++ b/products/replay_vision/backend/tests/test_scanners.py@@ -715,15 +715,24 @@ class TestSummarizerScanner:class TestSummarizerScannerSteps:- def test_core_steps_are_a_single_required_summary_turn(self) -> None:+ def test_core_steps_are_a_single_required_core_turn(self) -> None:scanner = scanner_from_db(_build_replay_scanner(scanner_type=ScannerType.SUMMARIZER, scanner_config={"prompt": "p"}))steps = scanner.core_steps()- assert [s.name for s in steps] == ["summary"]+ assert [s.name for s in steps] == ["core"]assert steps[0].response_model is SummarizerSummaryResponseassert steps[0].required is True+ @pytest.mark.parametrize(+ "length,guidance", [("short", "1-2 sentences"), ("medium", "1 paragraph"), ("long", "3-5 paragraphs")]+ )+ def test_core_step_carries_the_configured_length_guidance(self, length: str, guidance: str) -> None:+ scanner = scanner_from_db(+ _build_replay_scanner(scanner_type=ScannerType.SUMMARIZER, scanner_config={"prompt": "p", "length": length})+ )+ assert guidance in scanner.core_steps()[0].instruction+def test_summary_step_makes_title_follow_operator_naming_convention(self) -> None:scanner = scanner_from_db(_build_replay_scanner(scanner_type=ScannerType.SUMMARIZER, scanner_config={"prompt": "p"})@@ -737,12 +746,12 @@ class TestSummarizerScannerSteps:(summary_step,) = scanner.core_steps()assert "(t " in summary_step.instruction- def test_assemble_builds_output_from_summary_turn(self) -> None:+ def test_assemble_builds_output_from_core_turn(self) -> None:scanner = scanner_from_db(_build_replay_scanner(scanner_type=ScannerType.SUMMARIZER, scanner_config={"prompt": "p"}))summary = SummarizerSummaryResponse(title="Onboarding", summary="Walked through demo", confidence=0.8)- out, signals = scanner.assemble({"summary": summary})+ out, signals = scanner.assemble({"core": summary})assert isinstance(out, SummarizerOutput)assert (out.title, out.summary, out.confidence) == ("Onboarding", "Walked through demo", 0.8)assert signals == []