: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
feat(signals): preserve agent intent in activity summary lines (#126687)
posthog[bot]fb70cecc825f
diff --git a/products/signals/backend/activity_summary/logic.py b/products/signals/backend/activity_summary/logic.pyindex 4d115f781568..295d7480974e 100644--- a/products/signals/backend/activity_summary/logic.py+++ b/products/signals/backend/activity_summary/logic.py@@ -177,6 +177,8 @@ def _inputs_used(rendered: RenderedInput, limits: RenderLimits) -> dict[str, Any"activity_lines": rendered.n_activity_lines,"view_lines": rendered.n_view_lines,"input_chars": rendered.input_chars,+ "intent_lines": rendered.intent_lines,+ "intent_chars": rendered.intent_chars,"drops": rendered.drops,"limits": dataclasses.asdict(limits),}diff --git a/products/signals/backend/activity_summary/render.py b/products/signals/backend/activity_summary/render.pyindex 828603a20ef7..999ecb6baac4 100644--- a/products/signals/backend/activity_summary/render.py+++ b/products/signals/backend/activity_summary/render.py@@ -24,7 +24,7 @@ from posthog.dataclasses import frozen# Bump on any code change to the filters, the default caps, the sampling or the rendered layout, so summaries# stay comparable. Limits from the flag payload go into `inputs_used` instead.-RENDER_VERSION = 7+RENDER_VERSION = 8WINDOW_DAYS = 28RECENCY_HALF_LIFE_DAYS = 7@@ -51,9 +51,11 @@ TASK_GOAL_CHARS = 180TASK_TITLE_CHARS = 100MAX_TAGS = 5MAX_TAG_CHARS = 30-ACTIVITY_LINE_CHARS = 220+ACTIVITY_LINE_CHARS = 300ACTIVITY_NAME_CHARS = 70-ACTIVITY_INTENT_CHARS = 100+ACTIVITY_INTENT_CHARS = 160+# Distinct agent intents one collapsed line keeps, newest first. They share ACTIVITY_INTENT_CHARS.+ACTIVITY_MAX_INTENTS = 2VIEW_LINE_CHARS = 160SECTIONS_MAX_CHARS = 8000# Hidden reasoning tokens count against the cap too, so a cap near the answer size truncates answers.@@ -237,6 +239,7 @@ class RenderLimits:task_goal_chars: int = _limit(TASK_GOAL_CHARS, max_value=800)activity_line_chars: int = _limit(ACTIVITY_LINE_CHARS, max_value=1000)activity_intent_chars: int = _limit(ACTIVITY_INTENT_CHARS, max_value=500)+ activity_max_intents: int = _limit(ACTIVITY_MAX_INTENTS, max_value=10)profile_max_chars: int = _limit(PROFILE_MAX_CHARS, max_value=20000)max_completion_tokens: int = _limit(MAX_COMPLETION_TOKENS, max_value=16000)@@ -330,6 +333,8 @@ class Unit:at: datetime.datetimetext: str+ # Characters of agent intent on the line.+ intent_chars: int = 0@frozen@@ -340,6 +345,7 @@ class _ActivityLine:text: strcreated: boolrows: int+ intent_chars: int = 0@frozen@@ -357,6 +363,9 @@ class RenderedInput:# Units of each source before its line cap, so a caller can tell when the cap binds.task_pool: intactivity_pool: int+ # Activity lines that carry at least one agent intent, and the intent characters on them.+ intent_lines: int = 0+ intent_chars: int = 0@propertydef units(self) -> int:@@ -492,13 +501,33 @@ def task_units(tasks: Iterable[TaskItem], drops: Counter[str], limits: RenderLimObjectKey = tuple[str, str, str]-def _intent_suffix(rows: Iterable[ActivityItem], max_chars: int) -> str:- intents = [row for row in rows if row.intent and row.intent.strip()]- if not intents:- return ""- intent = max(intents, key=lambda row: row.at).intent or ""- intent_text = cap_line(clean_text(intent, max_chars * 2), max_chars)- return f" (agent: {intent_text})" if intent_text else ""+def _intent_text(rows: Iterable[ActivityItem], limits: RenderLimits) -> str:+ """Up to `limits.activity_max_intents` distinct intents of the rows, newest first, in one shared budget.++ The budget is at most half the line, so the head of the line always keeps some room."""+ max_chars = min(limits.activity_intent_chars, limits.activity_line_chars // 2)+ distinct: dict[str, str] = {}+ for row in sorted(rows, key=lambda row: row.at, reverse=True):+ if len(distinct) >= limits.activity_max_intents:+ break+ text = clean_text(row.intent or "", max_chars * 2)+ if text:+ distinct.setdefault(text.casefold(), text)+ return cap_line("; ".join(distinct.values()), max_chars)+++def _activity_line(head: str, rows: Sequence[ActivityItem], limits: RenderLimits, *, created: bool) -> _ActivityLine:+ """The head cut to the room that the agent intents leave, so a long name cannot push the intents out."""+ intent = _intent_text(rows, limits)+ suffix = f" (agent: {intent})" if intent else ""+ head = cap_line(head, max(limits.activity_line_chars - len(suffix), 1))+ return _ActivityLine(+ at=max(row.at for row in rows),+ text=cap_line(head + suffix, limits.activity_line_chars),+ created=created,+ rows=len(rows),+ intent_chars=len(intent),+ )def _display_name(name: str) -> str:@@ -535,12 +564,7 @@ def _object_line(latest = max(row.at for row in rows)count = f" (x{len(rows)})" if len(rows) > 1 else ""line = f'- {_day(latest).isoformat()} {activity} {scope} "{_display_name(name)}"{context}{count}'- return _ActivityLine(- at=latest,- text=cap_line(line + _intent_suffix(rows, limits.activity_intent_chars), limits.activity_line_chars),- created=activity == "created",- rows=len(rows),- )+ return _activity_line(line, rows, limits, created=activity == "created")def _group_line(@@ -572,14 +596,10 @@ def _group_line(activities = sorted({key[1] for key in children}, key=lambda activity: (activity != "created", activity))head = f"{' and '.join(activities)} {child_text} on {parent_text}: "head = f"- {_day(latest).isoformat()} {head}"- intent = _intent_suffix(rows, limits.activity_intent_chars)- line = head + _quoted_names(names, limits.activity_line_chars - len(head) - len(intent)) + intent- return _ActivityLine(- at=latest,- text=cap_line(line, limits.activity_line_chars),- created=any(row.activity == "created" for row in rows),- rows=len(rows),- )+ intent = _intent_text(rows, limits)+ suffix_chars = len(f" (agent: {intent})") if intent else 0+ line = head + _quoted_names(names, limits.activity_line_chars - len(head) - suffix_chars)+ return _activity_line(line, rows, limits, created=any(row.activity == "created" for row in rows))def _lines_with_parents(@@ -694,8 +714,7 @@ def _object_id(item: ActivityItem) -> str:def _count_line(rows: Sequence[ActivityItem], text: str, limits: RenderLimits) -> _ActivityLine:latest = max(row.at for row in rows)- line = f"- {_day(latest).isoformat()} {text}" + _intent_suffix(rows, limits.activity_intent_chars)- return _ActivityLine(at=latest, text=cap_line(line, limits.activity_line_chars), created=False, rows=len(rows))+ return _activity_line(f"- {_day(latest).isoformat()} {text}", rows, limits, created=False)@frozen@@ -809,7 +828,7 @@ def activity_units() -> list[Unit]:"""Changes collapsed to one line per object, or per parent, creates first, then the most changed, then the newest.- A line carries the newest agent intent of its rows. A day keeps at most `limits.max_activity_lines_per_day`+ A line carries the newest distinct agent intents of its rows, up to `limits.activity_max_intents`. A day keeps at most `limits.max_activity_lines_per_day`lines while other days have lines left, not the `MAX_UNITS_PER_DAY` of tasks: lines are alreadycollapsed per object, and a busy day of changes to different objects is more than three things."""kept, count_lines = person_activity(items, drops, limits)@@ -819,7 +838,10 @@ def activity_units(lines = _lines_with_parents(collapsed, parents or {}, drops, limits) + count_linesranked = sorted(lines, key=lambda line: (not line.created, -line.rows, -line.at.timestamp(), line.text))kept_lines = _spread_across_days(ranked, drops, limits)- return sorted((Unit(at=line.at, text=line.text) for line in kept_lines), key=lambda unit: (unit.at, unit.text))+ return sorted(+ (Unit(at=line.at, text=line.text, intent_chars=line.intent_chars) for line in kept_lines),+ key=lambda unit: (unit.at, unit.text),+ )def _match_product(patterns: Sequence[tuple[re.Pattern[str], Product]], name: str) -> Product | None:@@ -1045,4 +1067,6 @@ def build_input(drops={str(reason): count for reason, count in sorted(drops.items()) if count},task_pool=len(task_pool),activity_pool=activity_pool,+ intent_lines=sum(1 for unit in sections[1][1] if unit.intent_chars),+ intent_chars=sum(unit.intent_chars for unit in sections[1][1]),)diff --git a/products/signals/backend/test/test_activity_summary_render.py b/products/signals/backend/test/test_activity_summary_render.pyindex 77d14a144757..6fc01ee5b092 100644--- a/products/signals/backend/test/test_activity_summary_render.py+++ b/products/signals/backend/test/test_activity_summary_render.py@@ -304,9 +304,9 @@ def test_activity_units_drop_automated_activity('- 2026-10-18 updated Insight "Signup funnel" (agent: Split the funnel by plan)',),(- "collapsed rows carry the newest intent",+ "collapsed rows carry their intents newest first",["Add a breakdown", None, "Split the funnel by plan"],- '- 2026-10-18 updated Insight "Signup funnel" (x3) (agent: Add a breakdown)',+ '- 2026-10-18 updated Insight "Signup funnel" (x3) (agent: Add a breakdown; Split the funnel by plan)',),("an intent keeps only the host of a link",@@ -393,6 +393,64 @@ def test_activity_units_group_children_under_their_parent(assert dict(drops) == expected_drops+def _object_rows(name: str, intents: list[str | None]) -> list[ActivityItem]:+ return [+ _change("Insight", "updated", name, days_ago=1 + n / 100, intent=intent, item_id="1")+ for n, intent in enumerate(intents)+ ]+++def _group_rows(name: str, intents: list[str | None]) -> list[ActivityItem]:+ return [+ _change("Insight", "updated", f"{name} {n % 2}", days_ago=1 + n / 100, intent=intent, item_id=str(n % 2))+ for n, intent in enumerate(intents)+ ]+++def _count_rows(name: str, intents: list[str | None]) -> list[ActivityItem]:+ return [+ _change("Ticket", "updated", f"{name} #{n}", days_ago=0.5 + n / 100, intent=intent, item_id=str(n))+ for n, intent in enumerate(intents)+ ]+++LINE_TYPES = [("object line", _object_rows), ("group line", _group_rows), ("count line", _count_rows)]+GROUP_PARENTS = {("Insight", "0"): (QUALITY,), ("Insight", "1"): (QUALITY,)}++[email protected](LINE_TYPES)+def test_an_activity_line_keeps_the_intent_after_a_long_name(_name: str, rows: Any) -> None:+ intent = "Split the funnel by plan to see which plan dropped after the pricing change"+ items = rows("word " * 60, [intent, None, None, None])++ [unit] = activity_units(items, Counter(), GROUP_PARENTS)++ assert len(unit.text) <= ACTIVITY_LINE_CHARS+ assert unit.text.endswith(f" (agent: {intent})")+ assert unit.intent_chars == len(intent)+++ [+ (f"{line_type}, {case}", rows, max_intents, expected)+ for line_type, rows in LINE_TYPES+ for case, max_intents, expected in [+ ("two intents", 2, "Add a breakdown; Split by plan"),+ ("one intent", 1, "Add a breakdown"),+ ]+ ]+)+def test_an_activity_line_keeps_the_newest_distinct_intents(+ _name: str, rows: Any, max_intents: int, expected: str+) -> None:+ items = rows("Signup funnel", ["Add a breakdown", "Split by plan", "add a BREAKDOWN", "Fix the date range"])+ limits = RenderLimits(activity_max_intents=max_intents)++ [unit] = activity_units(items, Counter(), GROUP_PARENTS, limits)++ assert unit.text.endswith(f" (agent: {expected})")++def test_a_group_line_lists_the_names_that_fit_and_marks_the_rest() -> None:items = [_change(@@ -677,6 +735,7 @@ def test_build_input_stays_inside_its_bounds_for_a_very_active_person(_name: strassert max(len(line) for line in tasks_text.split("\n")[1:]) <= limits.task_line_charsassert max(len(line) for line in activity_text.split("\n")[1:]) <= limits.activity_line_charsassert rendered.input_chars <= limits.sections_max_chars+ assert rendered.intent_lines == limits.activity_lines and rendered.intent_chars > 0assert rendered.drops[Drop.BURST_CAP] > 0 and rendered.drops[Drop.SAMPLE_CAP] > 0