Hraness
Theme
Appearance

saved

Automatic Compaction: How Shelley Keeps Going and Going Without Losing the Plot

by Philip Zeyliger and Maisem Aliexe.dev blogpublished

Hraness wrote this summary from a saved copy of the source. Quotations are taken word for word from the source.

gist

Philip Zeyliger and Maisem Ali of exe.dev say their Shelley coding agent compacts its own context in place after about 200k tokens. Compaction means rewriting a long agent conversation into a shorter one. Shelley's harness sends a nudge with a message index, the model calls a tool to trim tool outputs and squish older messages into summaries, and a linter rejects compactions that are too big or too small. The full log stays in SQLite. One Opus 5.5 conversation cost about $25 across four compactions.

ideas

  • Tool output dominates the context. Every agent turn resends the whole message stack, so cost grows quadratically, and most of that stack is tool responses such as files the agent read.
  • The model compacts its own history with a tool. At about 200k tokens the harness inserts a nudge, and the model can truncate specific tool outputs or squish sections of history into rewritten segments that point back to the originals.
  • A linter checks each attempt. The model gets an index of messages by sequential id, proposes what to collapse or trim, and the linter sends back compactions that are too big or too small; the second try usually passes.
  • Compaction is a log entry, not a deletion. A conversation is an append-only message log plus special compaction messages, and the harness substitutes the rewrites when it builds each request; a skill helps the model query SQLite for anything compacted away.
  • This is the third design. The first two started a new generation inside the same conversation, first with a summary and then keeping recent messages; the third keeps one rewritten conversation and is on by default.

quotes

“An agent loop is inherently quadratic: messages accumulate and every iteration you send the full stack of messages to the model.”

Philip Zeyliger and Maisem Ali

“Shelley has a "linter" that verifies that the compaction isn't too big or too little.”

Philip Zeyliger and Maisem Ali

“If the model ever wants to read something that got compacted away, the data is in SQLite”

Philip Zeyliger and Maisem Ali