Skip to content

structured compaction prompt for session summarization #2389

@jeonsworld

Description

Checked other resources

  • This is a feature request, not a bug report.
  • I searched existing issues and didn't find this feature.
  • I checked the docs and README for existing functionality.
  • This request applies to this repo (deepagents) and not an external package.

Area (Required)

  • deepagents (SDK)
  • cli

Feature description

The current SummarizationMiddleware uses a generic LLM prompt to summarize conversations during context window compaction. This produces unstructured summaries that lose critical technical context — file paths, code snippets, error history, user feedback, and pending tasks — making it difficult for the agent to resume work accurately in long sessions.

Proposed solution (optional)

Replace the default summarization prompt with a structured 9-section compaction prompt that guides the LLM to systematically preserve:

  1. Primary Request and Intent
  2. Key Technical Concepts
  3. Files and Code Sections (with code snippets)
  4. Errors and Fixes (with user feedback)
  5. Problem Solving
  6. All User Messages (non-tool-result)
  7. Pending Tasks
  8. Current Work
  9. Optional Next Step

Additionally, update the post-compaction continuation message to:

  • Include a transcript path reference for retrieving pre-compaction details
  • Add a direct resume instruction so the agent picks up exactly where it left off without recapping

The LLM is also instructed to use an scratchpad block for internal reasoning, which is stripped from the final summary to save tokens while improving summary quality.

Additional context (optional)

  • Long coding sessions (20+ turns) frequently trigger compaction, and the current generic summary loses context that is essential for continuing development work
  • The structured prompt ensures the LLM covers all critical dimensions systematically rather than producing a freeform summary
  • The continuation message format enables seamless session resumption
  • Backward-compatible: callers who provide a custom summary_prompt are unaffected

Metadata

Metadata

Assignees

No one assigned

    Labels

    deepagentsRelated to the `deepagents` SDK / agent harnessexternalUser is not a member of the `langchain-ai` GitHub organization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions