: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(tasks): ask chat and scout runs for a task summary (#104565)
posthog[bot]dd8522a580cf
diff --git a/products/desktop/packages/agent/src/server/agent-server.test.ts b/products/desktop/packages/agent/src/server/agent-server.test.tsindex 3681e5612822..0494c4ff360b 100644--- a/products/desktop/packages/agent/src/server/agent-server.test.ts+++ b/products/desktop/packages/agent/src/server/agent-server.test.ts@@ -6811,6 +6811,7 @@ describe("AgentServer HTTP Mode", () => {"If the user explicitly asks you to open a pull request",);expect(prompt).not.toContain("No Repository Mode");+ expect(prompt).not.toContain("## Summarizing a question you answered");});it("returns review-first prompt for existing PRs on non-Slack runs", () => {@@ -6867,6 +6868,7 @@ describe("AgentServer HTTP Mode", () => {config: { repositoryPath: undefined },shouldContain: ["Cloud Task Execution — No Repository Mode",+ "## Summarizing a question you answered","call `list_repos`","Call `clone_repo`","It creates a shallow clone",@@ -6908,6 +6910,7 @@ describe("AgentServer HTTP Mode", () => {config: { repositoryPath: undefined, createPr: false },shouldContain: ["Cloud Task Execution — No Repository Mode",+ "## Summarizing a question you answered","Call `clone_repo`","You may make local edits in a repository cloned with `clone_repo`","Do NOT create branches, commits, push changes, or open pull requests in this run",diff --git a/products/desktop/packages/harness/src/extensions/task-system-prompt/cloud.ts b/products/desktop/packages/harness/src/extensions/task-system-prompt/cloud.tsindex 19c022e8f081..8f668b3c8a73 100644--- a/products/desktop/packages/harness/src/extensions/task-system-prompt/cloud.ts+++ b/products/desktop/packages/harness/src/extensions/task-system-prompt/cloud.ts@@ -5,7 +5,10 @@ import {SIGNED_REWRITE_QUALIFIED_TOOL_NAME,} from "../local-tools";import { buildStoreSkillsInstructions } from "../skills-store";-import { buildTaskSummaryInstructions } from "./task-summary";+import {+ buildTaskSummaryInstructions,+ TASK_SUMMARY_TOOL_NAME,+} from "./task-summary";export type SlackArtifactDelivery = "none" | "message" | "canvas_file";@@ -277,6 +280,13 @@ When you create a non-code file the user should be able to download (such as a rconst commonInstructions = `${signedCommitInstructions}${stackInstructions}${prLinkInstructions}${shellEfficiencyInstructions}${artifactInstructions}${this.buildSlackDeliveryInstructions()}${this.buildGithubAccessInstructions(hasGithubToken)}${buildStoreSkillsInstructions(this.options.storeSkillsInstalledCount)}${buildTaskSummaryInstructions()}`;+ // The shared block above is shaped for a run that ends with work landed. A+ // repo-less run often only answers a question, so it needs to hear that the+ // answer itself is what the summary has to carry.+ const chatTaskSummaryInstructions = `+## Summarizing a question you answered+The answer is the work of this run, so the run still needs a summary. Call the \`${TASK_SUMMARY_TOOL_NAME}\` tool before your final reply, even when the run is one question and one answer. Lead with what was asked and what you found, then the numbers, entities, or links the answer rests on. A teammate reads that summary from the run row instead of opening the transcript, so it has to stand on its own.`;+const whyContextInstruction = ` - Add a brief **Why** to the body — one or two sentences capturing the reason the user asked for this change (the motivation, not a restatement of the diff). Keep it short.`;const publicRepoSafetyInstruction = ` - **Public-repo safety.** Treat the target repository as public-readable unless you have verified otherwise. The PR title, description, and commit messages must not contain private operational scale (exact event counts, internal row volumes, customer-usage percentages), customer names / emails / companies, references to internal tickets or incidents, the contents of Slack threads (do not quote or paraphrase what was said), or unreleased roadmap details. Linking to the originating Slack thread is fine and encouraged — Slack links are auth-gated and useful as context — as are channel references like "raised in #team-foo". Describe findings qualitatively ("present on nearly all X events, absent from Y") rather than with quantitative figures pulled from analytics queries — the reasoning that uses those numbers can stay in the thread; the PR copy cannot.`;const prMentionSafetyInstruction = ` - **Never guess a GitHub identity.** Do NOT \`@\`-mention, tag, assign, request review from, or attribute the PR to a person (in the title, description, commit message, or reviewers) using a name or handle taken from Slack or this thread. A Slack display name or handle is NOT a GitHub username. Finding a similar-looking handle in the repo's git history, CODEOWNERS, or existing PRs/issues does NOT confirm it belongs to this person: repository presence proves the handle exists, not that it is the person you mean, so treating it as a match still \`@\`-tags an unrelated account (e.g. Slack "Ross" is not necessarily GitHub \`@ross\`, even if some \`@ross\` has committed to the repo). Only \`@\`-mention a GitHub \`@handle\` the user gave you explicitly in this thread, or one you read from \`gh api user --jq .login\`, which authenticates as the person you are working for. Otherwise refer to people by plain-text name, or omit the mention entirely.`;@@ -394,6 +404,7 @@ ${repositoryInstructions}${publishInstructions}Important:- Prefer using MCP tools to answer questions with real data over giving generic advice.${commonInstructions}+${chatTaskSummaryInstructions}`;}diff --git a/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.test.ts b/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.test.tsindex 5f46a7400ff0..c98de652c155 100644--- a/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.test.ts+++ b/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.test.ts@@ -59,5 +59,6 @@ describe("buildTaskSystemPrompt", () => {expect(prompt).toContain("Use the existing pull request.");expect(prompt).toContain("## Keeping the task summary");expect(prompt).toContain("task_summary_update");+ expect(prompt).toContain("A turn that only answers a question counts.");});});diff --git a/products/desktop/packages/harness/src/extensions/task-system-prompt/task-summary.ts b/products/desktop/packages/harness/src/extensions/task-system-prompt/task-summary.tsindex 69654e1a8c32..e3233d8f4573 100644--- a/products/desktop/packages/harness/src/extensions/task-system-prompt/task-summary.ts+++ b/products/desktop/packages/harness/src/extensions/task-system-prompt/task-summary.ts@@ -5,5 +5,5 @@ export const TASK_SUMMARY_MAX_CHARS = 1500;export function buildTaskSummaryInstructions(): string {return `## Keeping the task summary-Call the \`${TASK_SUMMARY_TOOL_NAME}\` tool when the goal changes, when you stop one approach, about every ten turns, and before you end a turn. Each call replaces the prior summary. Write the current state and remove details that no longer matter. Keep the summary to a few sentences.`;+Call the \`${TASK_SUMMARY_TOOL_NAME}\` tool when the goal changes, when you stop one approach, about every ten turns, and before you end any turn. A turn that only answers a question counts. Each call replaces the prior summary. Write the current state and remove details that no longer matter. Keep the summary to a few sentences.`;}diff --git a/products/signals/backend/scout_harness/prompt.py b/products/signals/backend/scout_harness/prompt.pyindex 4fe10cacad47..8f189a2fa3fe 100644--- a/products/signals/backend/scout_harness/prompt.py+++ b/products/signals/backend/scout_harness/prompt.py@@ -173,7 +173,7 @@ def _governed_metrics_section(project_has_governed_metrics: bool) -> str:# The close-out step is identical on every channel bar the word for what the run produces, and it is# numbered differently (the report channel has an extra search step), so both are rendered from here.-_CLOSE_OUT_STEP_TEMPLATE = """{number}. **Close out.** End your turn with a JSON object matching the schema in *Output format* below. Its `summary` field is your run close-out; see *Writing the summary* for how to structure it. A quiet day is a real outcome: "looked, found nothing meaningful" is a genuine, useful summary, not a failure, so don't manufacture {output} to fill space. The harness parses the JSON and writes `summary` to the run row as searchable prose."""+_CLOSE_OUT_STEP_TEMPLATE = """{number}. **Close out.** End your turn with a JSON object matching the schema in *Output format* below. Its `summary` field is your run close-out; see *Writing the summary* for how to structure it. A quiet day is a real outcome: "looked, found nothing meaningful" is a genuine, useful summary, not a failure, so don't manufacture {output} to fill space. The harness parses the JSON and writes `summary` to the run row as searchable prose. Before that, call `task_summary_update` with the same close-out text, per *Writing the summary*."""_HOW_A_RUN_WORKS_SIGNAL_STEPS = """4. **Decide.** For each hypothesis, decide whether to:- **Emit** a finding (call `scout-emit-signal`). This includes building on a prior finding when new evidence materially advances the picture: emit a fresh finding citing the prior one's `finding_id` in your description.@@ -710,7 +710,9 @@ Everything you write for a reader follows one rule: {_FRONT_LOAD_RULE}. WhateverYour close-out `summary` renders in the scout's run history **collapsed to the first ~2 lines** until expanded, so applied here that means one or two sentences stating the outcome (what was found, with the key number, or that the run was quiet), a blank line, then two to five short bullets for what you checked, what you skipped and why, and what you wrote to memory.-Keep it a close-out, not a transcript: methodology and tool-by-tool narration belong in the task log."""+Keep it a close-out, not a transcript: methodology and tool-by-tool narration belong in the task log.++The `task_summary_update` tool holds the same close-out for the task run row, which is what a reader sees without opening the transcript. Send it the same verdict-first text you put in `summary`. Run ritual does not belong there: your skill version, the emit-eligibility gate, and a list of scratchpad keys tell a reader nothing about what you found."""# Rendered only for a team whose knowledge base is reachable and looks maintained — the runner# resolves `business_knowledge.is_maintained_for_team` per run (`business_knowledge_maintained`).diff --git a/products/signals/backend/test/test_scout_harness.py b/products/signals/backend/test/test_scout_harness.pyindex f77af557ad11..3ac1ed630553 100644--- a/products/signals/backend/test/test_scout_harness.py+++ b/products/signals/backend/test/test_scout_harness.py@@ -497,6 +497,46 @@ class TestCheckoutSection(SimpleTestCase):assert "git blame" in section+class TestCloseOutTaskSummary(SimpleTestCase):+ @parameterized.expand(+ [+ ("signal", []),+ ("report_both", ["emit_report", "edit_report"]),+ ("report_emit_only", ["emit_report"]),+ ("report_edit_only", ["edit_report"]),+ ]+ )+ def test_close_out_asks_for_the_run_row_summary_on_every_channel(+ self, _name: str, allowed_tools: list[str]+ ) -> None:+ # The run row is what a reader sees without opening the transcript, and the harness only+ # writes it when the scout calls the tool. Each channel renders its own close-out step, so+ # a channel that drops the instruction leaves its scouts with a blank run row and nothing+ # in the rendered prompt to show why.+ prompt = build_run_prompt(+ LoadedSkill(+ name="signals-scout-close-out",+ version=1,+ body="watch",+ description="d",+ allowed_tools=allowed_tools,+ files=[],+ skill_id="skill-1",+ origin="canonical",+ authors=[],+ ),+ run_id="00000000-0000-0000-0000-000000000abc",+ team_id=1,+ started_at=datetime(2026, 5, 1, 12, 34, 56, tzinfo=UTC),+ )++ close_out_step = next(line for line in prompt.splitlines() if "**Close out.**" in line)+ writing_summary = prompt.split("# Writing the summary")[1].split("\n# ")[0]++ assert "task_summary_update" in close_out_step+ assert "task_summary_update" in writing_summary++class TestPromptCrossReferences(SimpleTestCase):@parameterized.expand([