r/PiCodingAgent • • Sep 17 '26

Resource al-jaffee - simple cache-preserving fold-in compaction for pi agents

I've been working on a longer-term project and I have a lot of little side tangents and investigations as I work that I don't want the full context to get polluted by. I wrote a little pi plugin that lets agents create markers, then work on a task with their full context. When they're done, they can fold-in their full context to a summary, compacting the work in place.

It's less manual than forking the session and a little less to keep track of than subagents. I thought it was worth sharing. MIT license, 1k lines of code. Cost was maybe a dime worth of GLM 5.3 Flash.

https://github.com/gopherbone/al-jaffee

15 Upvotes

22 comments sorted by

View all comments

3

u/sergeant113 Sep 17 '26

Could share more about the UX? Does it replace pi native compaction, and so i can just install and forget?

And how about agent experience? Can the agent independently trigger compaction? Does the agent know it has access to these folds? How does it discover the folds and read it? Are the folds transferable between sessions - can subagent when given a forked context read the folds as well?

2

u/porkyminch Sep 17 '26

It doesn't replace native compaction, it's a different set of tools. Agents are aware of the folds and know how/when to trigger them themselves, but if you ask them to fold in a task, they'll do it. They get a little summary of the work from the agent (plus file changes, tool calls counted programmatically) when they fold into the marker, which is appended onto their cache prefix so we don't do a total cache bust. To the agent they just look like tool calls, and the markers are all agent-created, so the agents kind of naturally know how to fold into them. It's an install and forget thing and also a thing you can recommend agents use. To the folded agent, the fold looks like this:

… main conversation …
assistant: set_fold_marker({ task: "archive inventory" })
toolResult: [al-jaffee] FOLD COMPLETE — tangent folded into this marker.
            Task: archive inventory
            Folded away: 9 conversation entries … you won't remember doing
            it, and that is expected, not an error. Treat the summary below
            as your own notes…
            Summary (yours, written at fold time): read a.md (kickoff, plan
            B), b.md (budget $12.4k), c.md (roadmap)…
assistant: (continues the main line from here — tangent tokens gone from context)

I'm not sure about forked subagents, but it'll probably work.