Context Window Packing – Agent Patterns Catalog
The article discusses Context Window Packing, a method for managing the context available to AI models within a fixed token budget. It highlights the challenges of maintaining critical information while avoiding overflow of the context window. The proposed solution involves defining a packing policy that balances the allocation of tokens across various components of the context.
- ▪Context Window Packing helps manage the information within an AI model's context window to prevent overflow.
- ▪The method involves scoring items by recency, relevance, and pinned-status to fit a budgeted subset of information.
- ▪A defined packing policy allows for predictable behavior and efficient use of the context window.
Opening excerpt (first ~120 words) tap to expand
CatalogMemoryContext Window PackingV · MemoryMature★★Context Window Packingalso known as Context Compression, Token Budget Management, Fit in Context, Token Cost ReductionChoose what fits in the context window each turn given a fixed token budget.This pattern helps complete certain larger patterns —used-byReasoning Trace Carry-Forward★— For reasoning models that emit a separate reasoning trace, preserve that trace in context across the same logical task episode (across tool-call/result turns) but drop it at user-turn boundaries.used-byTodo-List-Driven Autonomous Agent★— Have the agent author a plan file (e.g.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at Agent Patterns Catalog.