From ac71aac0904518f04007edaf356f51bd7ad4c7bd Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 29 Dec 2025 22:17:51 +0100 Subject: [PATCH] Use structured output format for compaction and branch summarization Both now use consistent sections: - Goal - Constraints & Preferences - Progress (Done/In Progress/Blocked) - Key Decisions - Next Steps - Critical Context (compaction only) Prompts instruct LLM to use EXACT format and preserve file paths/function names. --- .../core/compaction/branch-summarization.ts | 33 +++++++++-- .../src/core/compaction/compaction.ts | 57 ++++++++++++++----- 2 files changed, 69 insertions(+), 21 deletions(-) diff --git a/packages/coding-agent/src/core/compaction/branch-summarization.ts b/packages/coding-agent/src/core/compaction/branch-summarization.ts index 4cb66dbf..5c7dd3af 100644 --- a/packages/coding-agent/src/core/compaction/branch-summarization.ts +++ b/packages/coding-agent/src/core/compaction/branch-summarization.ts @@ -259,13 +259,34 @@ export function prepareBranchEntries(entries: SessionEntry[], tokenBudget: numbe // Summary Generation // ============================================================================ -const BRANCH_SUMMARY_PROMPT = `Summarize this conversation branch concisely for context when returning later: -- Key decisions made and actions taken -- Important context, constraints, or preferences discovered -- Current state and any pending work -- Critical information needed to continue from a different point +const BRANCH_SUMMARY_PROMPT = `Create a structured summary of this conversation branch for context when returning later. -Be brief and focused on what matters for future reference.`; +Use this EXACT format: + +## Goal +[1-2 sentences: What was the user trying to accomplish in this branch?] + +## Constraints & Preferences +- [Any constraints, preferences, or requirements mentioned] +- [Or "(none)" if none were mentioned] + +## Progress +### Done +- [x] [Completed tasks/changes] + +### In Progress +- [ ] [Work that was started but not finished] + +### Blocked +- [Issues preventing progress, if any] + +## Key Decisions +- **[Decision]**: [Brief rationale] + +## Next Steps +1. [What should happen next to continue this work] + +Keep each section concise. Preserve exact file paths, function names, and error messages.`; /** * Convert messages to text for the summarization prompt. diff --git a/packages/coding-agent/src/core/compaction/compaction.ts b/packages/coding-agent/src/core/compaction/compaction.ts index 61e4b950..e7e362ee 100644 --- a/packages/coding-agent/src/core/compaction/compaction.ts +++ b/packages/coding-agent/src/core/compaction/compaction.ts @@ -328,16 +328,38 @@ export function findCutPoint( // Summarization // ============================================================================ -const SUMMARIZATION_PROMPT = `You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task. +const SUMMARIZATION_PROMPT = `Create a structured context checkpoint summary. Another LLM will use this to continue the work. -Include: -- Current progress and key decisions made -- Important context, constraints, or user preferences -- Absolute file paths of any relevant files that were read or modified -- What remains to be done (clear next steps) -- Any critical data, examples, or references needed to continue +Use this EXACT format: -Be concise, structured, and focused on helping the next LLM seamlessly continue the work.`; +## Goal +[1-2 sentences: What is the user trying to accomplish?] + +## Constraints & Preferences +- [Any constraints, preferences, or requirements mentioned by user] +- [Or "(none)" if none were mentioned] + +## Progress +### Done +- [x] [Completed tasks/changes] + +### In Progress +- [ ] [Current work] + +### Blocked +- [Issues preventing progress, if any] + +## Key Decisions +- **[Decision]**: [Brief rationale] + +## Next Steps +1. [Ordered list of what should happen next] + +## Critical Context +- [Any data, examples, or references needed to continue] +- [Or "(none)" if not applicable] + +Keep each section concise. Preserve exact file paths, function names, and error messages.`; /** * Generate a summary of the conversation using the LLM. @@ -451,15 +473,20 @@ export function prepareCompaction( // Main compaction function // ============================================================================ -const TURN_PREFIX_SUMMARIZATION_PROMPT = `You are performing a CONTEXT CHECKPOINT COMPACTION for a split turn. -This is the PREFIX of a turn that was too large to keep in full. The SUFFIX (recent work) is being kept. +const TURN_PREFIX_SUMMARIZATION_PROMPT = `This is the PREFIX of a turn that was too large to keep. The SUFFIX (recent work) is retained. -Create a handoff summary that captures: -- What the user originally asked for in this turn -- Key decisions and progress made early in this turn -- Important context needed to understand the kept suffix +Summarize the prefix to provide context for the retained suffix: -Be concise. Focus on information needed to understand the retained recent work.`; +## Original Request +[What did the user ask for in this turn?] + +## Early Progress +- [Key decisions and work done in the prefix] + +## Context for Suffix +- [Information needed to understand the retained recent work] + +Be concise. Focus on what's needed to understand the kept suffix.`; /** * Calculate compaction and generate summary.