Vibeleaderboard
← All Intel
Intel / article

How Compaction Works in Pi

Source
earendil.com
Publisher
Earendil
Date
Why it matters

Long coding sessions overflow the context window, so harnesses must summarize history. Understanding what each request contains and when compaction fires helps you debug lost context and design your own agent loops.

Key takeaways · AI-distilled
  • Pi checks for auto-compaction after a turn ends, when nears the window limit, so requests within a turn keep reusing the cached prefix; it also compacts mid-turn on a context overflow error, or manually via /compact.
  • Pi keeps recent messages unchanged within a configurable , 20,000 tokens by default (roughly 5 to 20 turns), and summarizes everything before that cut point.
  • Compaction is a standalone request with its own system prompt, a "context summarization assistant", asking for a structured summary with goal, progress and key decisions sections; since it uses no conversation history, it can run on a different model without unnecessary cost.
  • Compaction breaks the prompt cache: caching needs an exact prefix match, and retained turns now follow a new summary, so everything after the first changed token is recomputed before later requests benefit from caching again.
  • Pi stores the compaction summary as plain text in the session, which keeps the compacted context readable and portable: users can switch models and continue from the same summary.
Terms in this piece · Glossary
  • Large language model — A model trained on large amounts of data to process and generate language.
  • Repository instructions — Versioned guidance that tells agents how a repository is structured and verified.
  • Context and context window — Context is the information available for a generation; the context window is the capacity available to hold it.
  • token budget — A cap on how many tokens a task, session, or agent run may consume — the practical control on both cost and how long an agent will grind.

Get the Brief

A cited digest of what matters for people building with AI, every morning. Unsubscribe anytime. See today’s edition

Read the source earendil.com
Tools in this story
Recommended reads