Smarter compaction/compression
To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.
Keep head and tail messages and files touched
Instead of summarizing everything, pi for example has a configurable keepRecentTokens
Pi also will include all files touched in the summary:
<read-files>
path/to/file1.ts
path/to/file2.ts
</read-files>
<modified-files>
path/to/changed.ts
</modified-files>
If you're familiar with /handoff, this is something it also does.
Hermes agent is similar, but it keeps some tail and head messages and always removes tool call results (any tool result outside the head/tail >200 chars is replaced with a message that the output was cleared). On second compaction, the first summary is also passed with instructions to update it.
Microcompaction and dynamic context pruning
- Claude Code intelligently microcompacts every turn by, but this will break prompt caching with openai's API (needs anthropic's cache_edits)
- dynamic context pruning - different implementations that call themselves DCP do different things, but here are some of the main things that differ from normal compaction:
- removing errored tool inputs (but not the error message)
- removing deduplicated tools (only keep most recent when multiple have same args)
- compressing specific ranges instead of everything with a tool
- protects recent turns from any proving
- Everything from opencode DCP, for example, breaks prompt caching so it would also only make sense to use when the context window was near full
Simplest changes
- some configurable head/tail saving
- some configurable tool call pruning
- including read/edited files in the summary
- Maybe take some inspiration from hermes' prompt and iterative recompression
I liked the idea of keeping a list of tool calls with some data like files read and modified, wonder how much this affects the LLM quality tho WDYT @zikajk ?