← @bgSponge

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

Summary

Philip Zeyliger and Maisem Ali of exe.dev say their Shelley coding agent compacts its own context in place after about 200k tokens.

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

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

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

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

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

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

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

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

Read the original ↗Save to Sponge

Summarized with Sponge. Quotes are the author’s own words.

More from @bg

All readings →