Summary
Allow users to customize compaction behavior with three configuration options:
- Custom summarization prompt — instructions for the model performing the summary
- Pre-compaction system message with optional agent turn — notify the agent before compaction and optionally allow a final turn (e.g., to save context to files)
- Post-compaction system message — instructions injected after compaction to guide recovery
Use Case
Agents with persistent memory workflows need:
- Control over what gets preserved in summaries
- Opportunity to save critical context before compaction happens
- Instructions to recover context after compaction
Currently, all of this is hardcoded with no user control.
Proposed Configuration
{
"agents": {
"defaults": {
"compaction": {
"mode": "safeguard",
"summaryPrompt": "Summarize the conversation, preserving: decisions, action items, emotional context, user preferences, and any commitments made.",
"preCompactionMessage": "Compaction will occur after this turn. Save any critical context to memory files now.",
"preCompactionAllowTurn": true,
"postCompactionMessage": "Context was compacted. Before responding, read memory/YYYY-MM-DD.md for today and yesterday to restore full context."
}
}
}
}
Detailed Proposal
1. summaryPrompt
Custom prompt sent to the summarization model. Allows users to prioritize what matters (technical details, emotional context, action items, etc.).
2. preCompactionMessage + preCompactionAllowTurn
preCompactionMessage: System message shown to the agent before compaction begins
preCompactionAllowTurn: If true, the agent gets one turn to respond (e.g., write to memory files) before compaction proceeds
This enables agents to persist critical context that would otherwise be lost in summarization.
3. postCompactionMessage
System message injected after successful compaction. Guides the agent on how to recover (e.g., read memory files, re-establish context).
Template Variables
Support variables in all messages:
{date} — current date
{time} — current time
{tokensBefore} — context size before compaction
{tokensAfter} — context size after compaction
{contextWindow} — model context window size
Current Behavior
- Summarization prompt is hardcoded
- No pre-compaction hook or agent turn
- Post-compaction message is just
System: [timestamp] Compacted • Context X/Y
Why This Matters
- Memory continuity: Agents can save context before compaction and restore it after
- Summarization quality: Different use cases need different priorities
- Graceful degradation: Agents can handle compaction proactively instead of losing context unexpectedly
This would significantly improve long-running agent sessions with file-based memory systems.
Summary
Allow users to customize compaction behavior with three configuration options:
Use Case
Agents with persistent memory workflows need:
Currently, all of this is hardcoded with no user control.
Proposed Configuration
{ "agents": { "defaults": { "compaction": { "mode": "safeguard", "summaryPrompt": "Summarize the conversation, preserving: decisions, action items, emotional context, user preferences, and any commitments made.", "preCompactionMessage": "Compaction will occur after this turn. Save any critical context to memory files now.", "preCompactionAllowTurn": true, "postCompactionMessage": "Context was compacted. Before responding, read memory/YYYY-MM-DD.md for today and yesterday to restore full context." } } } }Detailed Proposal
1.
summaryPromptCustom prompt sent to the summarization model. Allows users to prioritize what matters (technical details, emotional context, action items, etc.).
2.
preCompactionMessage+preCompactionAllowTurnpreCompactionMessage: System message shown to the agent before compaction beginspreCompactionAllowTurn: Iftrue, the agent gets one turn to respond (e.g., write to memory files) before compaction proceedsThis enables agents to persist critical context that would otherwise be lost in summarization.
3.
postCompactionMessageSystem message injected after successful compaction. Guides the agent on how to recover (e.g., read memory files, re-establish context).
Template Variables
Support variables in all messages:
{date}— current date{time}— current time{tokensBefore}— context size before compaction{tokensAfter}— context size after compaction{contextWindow}— model context window sizeCurrent Behavior
System: [timestamp] Compacted • Context X/YWhy This Matters
This would significantly improve long-running agent sessions with file-based memory systems.