Live data from Hacker News

How Compaction Works in Pi

earendil.com

41–50 of 100 posts

Re: How Compaction Works in Pi

#42

Opencodes dynamic context pruning works by labeling tools and chat and the rest and the agent can collapse and expand summaries. I get it into 1M+ routinely on local models with operations between 50k-85k

That dynamic pruning sounds bad for prompt caching though.

sure, it's the price you pay, but you have to considered that context poisoning is basically a statistical certainty approaching 1 regardless of model size. As you grow the context, the likelihood of vague details getting conflated increases, so if you're _not_ cutting down the context you're increasing the probabilities of just basic random jitter in your logic and code.

The pruning does evict cache but not from the start, and only up till the last time you pruned it, as it's just adding messages on top.

but yes, it takes some additional tests and docs to keep it from just becoming hollowed out on tasks; I'd say about 10-20% of the time is just horribly loses what it's doing.

Re: How Compaction Works in Pi

#43
post #12

I don't like any of current solutions when it comes to compaction. I'd love to have a way to say what exactly should be summarized, because most of the time I just need to compact some noisy MCP tool calls, test runs and things like that. Just let me pick what should be summarized and keep the rest as is.

I think /handoff on pi (or at least oh my pi) is what you are looking for

Re: How Compaction Works in Pi

#44

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 le…

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/...

Re: How Compaction Works in Pi

#46

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 le…

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.

Re: How Compaction Works in Pi

#47
post #23

OMP changed the default compaction to images ! Kinda nuts to read about. Saves the generation cost of the traditional compaction step and writes the context as tiny text to an image, if I was following correctly.

What's helpful about that?

Re: How Compaction Works in Pi

#48
post #40
post #39

Earlier quoted context omitted.

It is not. Their approach is minimalism. If you need something pi doesn’t have, the recommendation is to ask pi about it and have it build an extension for you, or look for a plugin. That said, try it. You may find you didn’t need everything in those ecosystems.

I also find the SDK really valuable. Being able embed a truly minimal agent wherever you can run node/typescript is very powerful. Any model, any provider, full control over what it’s doing. Not a shill.. I just really like pi.

You said it!

Re: How Compaction Works in Pi

#49

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 le…

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

https://github.com/can1357/oh-my-pi

Re: How Compaction Works in Pi

#50
In my experience, the best approach to compaction is to never get to the point where you need compaction and to generally stay below about 30% context window utilization. Even for long agentic workflows this can be accomplished for quite a while, much longer than most people might think.

Here's what I do for each of my sessions:

1. For asides, off-topic work, or repetitive work that has already been done in the session, branch backwards (with /tree) and summarize.

2. If I've exceeded 30% or the 'price-doubling' multi-tier pricing, prune (my custom extension).

3. If I've already pruned and I'm still close to 30%, 'prune all' (more extensive prune).

Definition:

'/prune': Removes ~50% context on a fresh session (not previously pruned)

  - Keeps: User messages, normal assistant prose, commands/status markers, extension receipts, model settings, and a plain-text receipt for each tool call.
  - Removes: Thinking, signatures, actual tool calls/results, tool output, images, compaction summaries, and other extensions’ state.

'/prune-extended': Removes ~80% context on a fresh session

  - Keeps: User messages, normal assistant prose and conclusions, commands/status markers, extension receipts, and model settings.
  - Removes: Thinking, signatures, all tool calls/results and output, images, compaction summaries, other extensions’ state, and any tool-activity receipts created by /prune.

Both create a new session and delete the old one after a successful switch.

Using these I can keep a session going for weeks (or longer), even with extensive use and almost all the important context is preserved while dumping the less important context. Neither command requires an LLM summarization so they execute quickly.

Post reply on HN