: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): let cloud agents keep a running task summary (#95970)
Andrew Maguire52576fd43c14
diff --git a/docs/internal/task-run-api.md b/docs/internal/task-run-api.mdindex 46c2b6739f66..07a64859823a 100644--- a/docs/internal/task-run-api.md+++ b/docs/internal/task-run-api.md@@ -58,6 +58,7 @@ The Claude adapter forwards partial tool inputs without retaining each intermediSend a JSON object with a `summary` string of 1 to 1,500 characters after trimming whitespace.The endpoint requires permission to control the task. A task-bound sandbox token can update only its own task.The update does not complete the run or change its structured `output`.+Cloud agent runs write the summary through the `task_summary_update` local tool; local Desktop sessions do not have the tool.Generic run-state updates cannot change the summary or its inherited value.A resumed run uses its source run's summary until it saves a new summary.diff --git a/products/desktop/packages/harness/src/extensions/local-tools/local-tools.ts b/products/desktop/packages/harness/src/extensions/local-tools/local-tools.tsindex b909dd9cbc60..3af9512c8115 100644--- a/products/desktop/packages/harness/src/extensions/local-tools/local-tools.ts+++ b/products/desktop/packages/harness/src/extensions/local-tools/local-tools.ts@@ -11,6 +11,7 @@ import { signedCommitTool } from "./tools/signed-commit";import { signedMergeTool } from "./tools/signed-merge";import { signedRewriteTool } from "./tools/signed-rewrite";import { speakTool } from "./tools/speak";+import { taskSummaryUpdateTool } from "./tools/task-summary-update";import { uploadArtifactTool } from "./tools/upload-artifact";export {@@ -33,6 +34,7 @@ export const LOCAL_TOOLS: LocalTool[] = [showActionsTool,uploadArtifactTool,reportActivityTool,+ taskSummaryUpdateTool,finishTool,listAgentsTool,sendAgentMessageTool,diff --git a/products/desktop/packages/harness/src/extensions/local-tools/registry.test.ts b/products/desktop/packages/harness/src/extensions/local-tools/registry.test.tsindex c49d0a018882..df260872ab83 100644--- a/products/desktop/packages/harness/src/extensions/local-tools/registry.test.ts+++ b/products/desktop/packages/harness/src/extensions/local-tools/registry.test.ts@@ -65,6 +65,31 @@ describe("local-tools registry", () => {expect(hasSignedCommit).toBe(expected);});+ it.each([+ {+ name: "cloud run bound to a task run",+ meta: { environment: "cloud" as const },+ ctx: { cwd: "/repo", taskId: "task-1", taskRunId: "run-1" },+ expected: true,+ },+ {+ name: "cloud run without a task run id",+ meta: { environment: "cloud" as const },+ ctx: { cwd: "/repo", taskId: "task-1" },+ expected: false,+ },+ {+ name: "desktop run bound to a task run",+ meta: { environment: "local" as const },+ ctx: { cwd: "/repo", taskId: "task-1", taskRunId: "run-1" },+ expected: false,+ },+ ])("exposes task_summary_update in $name", ({ meta, ctx, expected }) => {+ const tools = enabledLocalTools(ctx, meta);+ const hasSummaryTool = tools.some((t) => t.name === "task_summary_update");+ expect(hasSummaryTool).toBe(expected);+ });+it("does not treat legacy taskRunId-only metadata as cloud", () => {const tools = enabledLocalTools({ cwd: "/repo", token: undefined }, {taskRunId: "run-1",diff --git a/products/desktop/packages/harness/src/extensions/local-tools/task-tools-client.ts b/products/desktop/packages/harness/src/extensions/local-tools/task-tools-client.tsindex 1a98d81d551d..b6dfe3f7a69d 100644--- a/products/desktop/packages/harness/src/extensions/local-tools/task-tools-client.ts+++ b/products/desktop/packages/harness/src/extensions/local-tools/task-tools-client.ts@@ -99,6 +99,19 @@ export class TaskToolsApiClient {return this.http.updateTaskRun(taskId, runId, payload, signal);}+ async setTaskRunSummary(+ taskId: string,+ runId: string,+ summary: string,+ signal?: AbortSignal,+ ): Promise<TaskRun> {+ const teamId = this.http.getTeamId();+ return this.http.request<TaskRun>(+ `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/set_summary/`,+ { method: "PATCH", body: JSON.stringify({ summary }), signal },+ );+ }+async reportAnalysisActivity(taskId: string,runId: string,diff --git a/products/desktop/packages/harness/src/extensions/local-tools/tools/task-summary-update.ts b/products/desktop/packages/harness/src/extensions/local-tools/tools/task-summary-update.tsnew file mode 100644index 000000000000..b817bd464bc0--- /dev/null+++ b/products/desktop/packages/harness/src/extensions/local-tools/tools/task-summary-update.ts@@ -0,0 +1,74 @@+import { z } from "zod";+import {+ TASK_SUMMARY_MAX_CHARS,+ TASK_SUMMARY_TOOL_NAME,+} from "../../task-system-prompt/task-summary";+import { defineLocalTool, type LocalToolResult } from "../registry";+import {+ createSandboxPosthogClient,+ withReportDeadline,+} from "../signed-commit-artefacts";++function errorResult(message: string): LocalToolResult {+ return { content: [{ type: "text", text: message }], isError: true };+}++export const taskSummaryUpdateTool = defineLocalTool({+ name: TASK_SUMMARY_TOOL_NAME,+ description:+ "Replace this task's running summary. Write the goal, reason, current state, important files, branch, pull request, stopped approaches, and required human action. " ++ `The limit is ${TASK_SUMMARY_MAX_CHARS} characters. Each call replaces the prior summary.`,+ schema: {+ summary: z+ .string()+ .min(1)+ .max(TASK_SUMMARY_MAX_CHARS)+ .describe(+ "The complete summary, replacing any previous one. Plain text or short markdown.",+ ),+ },+ alwaysLoad: true,+ // The summary is stored on the cloud task run, so a local session has nowhere to write it.+ isEnabled: (ctx, meta) =>+ meta?.environment === "cloud" && !!ctx.taskId && !!ctx.taskRunId,+ handler: async (ctx, args): Promise<LocalToolResult> => {+ if (!ctx.taskId || !ctx.taskRunId) {+ return errorResult("Task summaries are not available here.");+ }+ const summary = args.summary.trim();+ if (!summary) {+ return errorResult("The summary is empty.");+ }+ const client = createSandboxPosthogClient();+ if (!client) {+ return errorResult(+ "PostHog is not configured in this sandbox; the summary cannot be saved.",+ );+ }+ try {+ await withReportDeadline(+ (signal) =>+ client.setTaskRunSummary(+ ctx.taskId as string,+ ctx.taskRunId as string,+ summary,+ signal,+ ),+ "task summary update",+ );+ } catch (error) {+ const message = error instanceof Error ? error.message : String(error);+ return errorResult(+ `The summary was not saved. Correct it and call ${TASK_SUMMARY_TOOL_NAME} again. Server response: ${message}`,+ );+ }+ return {+ content: [+ {+ type: "text",+ text: "Summary saved. Replace it when the goal or task state changes.",+ },+ ],+ };+ },+});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 fca3f4eb55a6..19c022e8f081 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,6 +5,7 @@ import {SIGNED_REWRITE_QUALIFIED_TOOL_NAME,} from "../local-tools";import { buildStoreSkillsInstructions } from "../skills-store";+import { buildTaskSummaryInstructions } from "./task-summary";export type SlackArtifactDelivery = "none" | "message" | "canvas_file";@@ -273,7 +274,8 @@ Optimize for the fewest shell round trips.When you create a non-code file the user should be able to download (such as a report, chart, image, archive, or data file), call the \`upload_artifact\` tool with its path before your final reply. In your final reply, link to the download URL returned by the tool—never link to the file's local workspace path. Files left in the workspace don't reach the user. Don't upload source code or repository changes—those belong in a commit or PR.`;// Closes out every branch below, so a new section is added once rather than five times.- const commonInstructions = `${signedCommitInstructions}${stackInstructions}${prLinkInstructions}${shellEfficiencyInstructions}${artifactInstructions}${this.buildSlackDeliveryInstructions()}${this.buildGithubAccessInstructions(hasGithubToken)}${buildStoreSkillsInstructions(this.options.storeSkillsInstalledCount)}`;+ const commonInstructions = `${signedCommitInstructions}${stackInstructions}${prLinkInstructions}${shellEfficiencyInstructions}${artifactInstructions}${this.buildSlackDeliveryInstructions()}${this.buildGithubAccessInstructions(hasGithubToken)}${buildStoreSkillsInstructions(this.options.storeSkillsInstalledCount)}+${buildTaskSummaryInstructions()}`;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.`;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 97946bd51a56..5f46a7400ff0 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@@ -23,6 +23,7 @@ describe("buildTaskSystemPrompt", () => {expect(prompt).toContain("<directory>/tmp/<shared></directory>");expect(prompt).toContain("## Channel task");expect(prompt).toContain("Your working directory is `/tmp/task-123`");+ expect(prompt).not.toContain("task_summary_update");});it("describes the repository tools only when the harness registers them", () => {@@ -56,5 +57,7 @@ describe("buildTaskSystemPrompt", () => {expect(prompt).toContain("Task-Id: task-123");expect(prompt).not.toContain('git commit -m "$(cat');expect(prompt).toContain("Use the existing pull request.");+ expect(prompt).toContain("## Keeping the task summary");+ expect(prompt).toContain("task_summary_update");});});diff --git a/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.ts b/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.tsindex 70bd909e569c..e87808a747d6 100644--- a/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.ts+++ b/products/desktop/packages/harness/src/extensions/task-system-prompt/prompt.ts@@ -1,4 +1,5 @@import type { TaskContext } from "@posthog/shared/task-context";+import { buildTaskSummaryInstructions } from "./task-summary";export interface TaskPromptCapabilities {structuredInput?: boolean;@@ -149,6 +150,10 @@ export function buildTaskSystemPrompt(buildShellEfficiencyPrompt(),);+ if (context.environment === "cloud") {+ sections.push(buildTaskSummaryInstructions());+ }+if (context.channelMode) {sections.push(buildChannelPrompt(context.cwd, capabilities.repositoryTools === true),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.tsnew file mode 100644index 000000000000..69654e1a8c32--- /dev/null+++ b/products/desktop/packages/harness/src/extensions/task-system-prompt/task-summary.ts@@ -0,0 +1,9 @@+export const TASK_SUMMARY_TOOL_NAME = "task_summary_update";++// Matches the server-side limit on the set_summary endpoint.+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.`;+}