正在加载视频...
视频加载失败
New Pi extension: pi-cached-compaction. Pi's built-in compaction swaps the system prompt, drops the tools, and flattens the messages, which breaks the prompt cache. This one keeps all three as they are and just appends the summary request, so ~99% is read from cache. And if you step away, it... show more
20,663 次观看 • 11 天前 •via X (Twitter)
17 条评论

Same result format as the default Pi compaction (recent messages kept, older ones summarized), and the model writing the summary sees the full tool output instead of truncated excerpts. On a 667k-token Opus session, compacting came to $0.19 instead of about $1.40 at API prices.

This is awesome, but why a plugin? It seems to me like a problem that should be fixed in the original library.

I've thought about this so often and was always like "nah, can't be that easy, otherwise everybody would be doing it"... Another day, another case of "Nico already built an extension for that..."

This is great! Also, given that you are using your own summarizer prompt, I wonder if we can customize this. e.g. "/mycompact Focus on the verification steps, ignore the planning" This could be a great substitute to the handoff flow then.

Recommended

sent you a dm about an engineer building a coding harness with constrained subagents i can intro you to

the cache part is right, but the summary is what costs you later. it's the only text that crosses into the next window, and it gets written by the most context-loaded version of the model with a generic "summarize this". the settled calls and the rejected approaches are the first thing to go. keep the decision record outside the window:

I’m going to steal the idea to compact before the cache expires I think (only for models with short cache duration though!)

The exact-request check is the bit I'd keep in core. If a model switch or edited history invalidates the prefix, lose the cache saving rather than guess. The README's fallback gets that right.

Pretty sure this will break compaction because they carefully tuned compaction especially for open models to not go over the free buffer and some arbitrary reasoning budget

the readme's fallback is careful: it checks the summary request repeats the previous request byte for byte up to the appended instruction, and pi's own compaction runs as usual when it can't prove that

cache only hits if the start is byte-for-byte the same so if you change the system prompt it kills everything after. leave it identical and the whole session is one cache hit

I prefer rollovers

This is amazing, thanks!

keep the prefix identical and append the ask, of course that works. 667k session for 19 cents, i'm annoyed i never tried it

Cache reads bill at 10% of base input price, so keeping that prefix byte-identical is where the savings actually come from.

I hope this is implemented in core ASAP!
