kierangill
3 days ago
Instead of compaction, has anyone seen a successful implementation of pruning? That is, the agent looks at the conversation history and removes any low-value messages.
For example, sometimes context will be taken up by a side tangent, tool call outputs, or low-value codebase exploration.
Much of the time, I prefer to preserve the history of my conversation instead of summarizing it. I find summarized conversations lead to more frustrating future chats because the LLM misses intent and or context. (Or, the presence of paragraphs and paragraphs of LLM output makes the next token predictor dumber? Unsure.)
spott
3 days ago
It is kinda a combination of the two:
https://github.com/spott/pi-task-compaction
I’m still playing with it, but it essentially has the model define a region, and mark it with begin_task, and end_task. End_task also requires a fairly hefty summery of the entire region.
It then pulls that entire region and replaces it with the summary. If the model wants it can actually look into the output that was pruned from the conversation, but in practice the summaries have been good enough it hasn’t needed to.
I’ve been using it with 5.6 sol, and even really long sessions have like 6% context used at the end.
pjm331
3 days ago
I think there are a lot of strategies that will open up when costs come down but right now you take a hit on cache rate and thus costs every time you do anything other than wait until the last minute to compact
charcircuit
3 days ago
You can do things like throwing away or summarizing information from the most recent calls so you fall back to a recent checkpoint that is still cached
jsw97
3 days ago
I built a harness for my own use that allows the agent to fork its own history. So for example it can “compact from” a specific item, replacing a branch with a summary; or do an “excursion”, basically a temporary branch, which is like a subagent but inherits context.
Sounds cool and it does make sensible decisions optically but I haven’t been able to prove that it is meaningfully better than normal compaction. Building harnesses that do interesting things is a lot easier than building more effective harnesses, I guess.
mikepurvis
3 days ago
I'm very interested in this too. I feel like when my Claude session compacts I immediately have to re-alert it to critical aspects of the task, but it should be possible even to have a secondary low-skill agent crawl over the whole context window semi-continuously and nominate pieces for removal or summarization. Or at a higher level, have something able to decompose, like hey I realised we're actually working on three distinct aspects of this problem, let's split the context into those three and I'll just retain a high level summary of what's in the other ones, enough to know if I should pass off control to one of the others for a particular ask.
I feel like this is kind of subagents, but it doesn't have the clear task -> work -> return result -> die model, rather it's more closely aligned to how I myself multitask, maintaining several long-lived threads of execution, and having to intentionally "forget" about the other ones when it's time to lock in and do real work on the most important one.
trueno
3 days ago
yeah ive read so many takes on how people survive compaction amnesia ive wired up my own "protocols" that are okay, have used things like beads, am okay burning a buttload of context right at the beginning of a post-compaction just to get up to speed and oriented.. but i still end up with a decent amount of sprawl and lately the writing style of claude has just gotten so dense and nonsensical that my eyes are starting to glaze over.
this seems to be the fate with all the big grand 'god' projects people are doing with AI. super epic omega knowledge bases, super epic omega personal platforms, etc. I don't think enough people admit that whatever they're working on has evolved into something they don't fully understand.
Schlagbohrer
3 days ago
I have run in to the same thing. Most recently I told my pi-agent to fork a git repo since our work had morphed into two different tasks that shouldn't be packed into the same context and workflow. Git fork is what I will use as a tool for this division in the future.
d4rkp4ttern
3 days ago
I have a few variations of pruning (trimming all long tool outputs, agent-directed trimming, etc) in my aichat collection of session tools:
https://pchalasani.github.io/claude-code-tools/tools/aichat/...
behindsight
3 days ago
OMP has this, it's called "/shake" where bloat from tool calls and such is turned into an artifact ref instead of remaining in the context.
There are other pruning or compaction strategies you can configure too.
You can also use "/btw" to have side tangent conversations with the current context but with the benefit that it will not bloat your current context after the tangent is done.
I wish other harnesses were prioritising this sort of flexibility with context management, but they're likely more incentivised on optimising their cache rates
tyingq
3 days ago
> You can also use "/btw" to have side tangent conversations with the current context
Ah, something I needed, but did not know I needed. Comes up ALL the time. I want to know something that is well off the task, but it's the best time to ask due to the specifically loaded context.
zmgsabst
3 days ago
I do this in my own harness, where a context only exports certain messages when you step out of it — eg, my request for an essay and its final output, while dropping everything from the first draft through various intermediary edits.
That naturally trims a lot of context while removing mistakes from the context to prevent poisoning (ie, every draft but the final negatively contributes in some way — that’s why we edited them).
WhyNotHugo
3 days ago
Potentially: remove thinking blocks, and keep the rest. At least this would ensure that the entire context of the conversation is still there, and anything said isn't lost.
Having a second model also iterate the resulting messages and remove low-value tool calls could also be interesting. Especially failed calls which add no value.
marton78
3 days ago
context-fold does this:
pzo
3 days ago
Wouldn’t that invalidate kv cache and you wouldn’t benefit from much cheaper cache read?
Dayshine
3 days ago
I'm frequently idle for five minutes while I review, at which point the cache has expired
stpedgwdgfhgdd
3 days ago
[dead]
ATMLOTTOBEER
2 days ago
Oh my pi already prunes tool calls on compaction (not sure if normal pi also does this)
toasty228
3 days ago
In oh-my-pi there is the /shake command that gets rids of tool results and some other things
ivanovm
3 days ago
check out this: https://www.morphllm.com/products/compact you can wire it into pi compaction pretty easily
bhaktatejas922
3 days ago
fast :)
0-_-0
3 days ago
I wonder if you could prune the kv cache as well
tosh
3 days ago
when you look at the compaction prompt: in a sense it is doing that pruning but the llm decides what to prune
marton78
3 days ago
[dead]