piagent_
← ~/map

$ cat ~/map/self-compact-pi-agent.md

Self Compact

Gives autonomous pi agents their own context gauge — notice and warning lines first, then a hard cutoff where only self_compact runs.

extensions✓ Sep 21

Facts

repository
github.com/disler/self-compact-pi-agent ↗
GitHub Stars
★ 74
Forks
20
license
MIT
npm / mo
—
last push
Sep 20, 2026

install

Clone the repo, put a provider key in .env (OPENROUTER_API_KEY recommended), and launch with just run --model <model-id>; just demo walks a full cycle with a scripted model and no API key. Prerequisites: pi v0.85.1, Node 24+, and just.

## TL;DR

A pi extension that hands long-running agents their own context gauge: a hint at the notice line, a handoff-note instruction at the warning line, and a hard cutoff where only self_compact runs — the note it writes comes back verbatim as the next message after compaction.

## Key points

## FAQ

Q Why not rely on pi's built-in compaction?

Built-in compaction is reactive: it fires near the wall with a generic summary prompt, the agent gets no warning, and nothing carries the agent's own what-I-was-about-to-do across the boundary. Self Compact makes the thresholds visible and has the agent write the handoff note itself at a clean checkpoint.

Q Does the agent see the gauge, or is it just for the human?

Both, on separate surfaces. The terminal footer belongs to the human; the agent asks view_context and receives the same numbers — used tokens, percent, thresholds, tokens left — as JSON, so it never has to guess where it stands.

## References

## Related entries

## Guides

Last updated: Sep 21, 2026