Context Packing

Context packing is the process of selecting, ordering, and formatting information for a model call. It decides what evidence and state enter the context window.

Given candidate context items with utility and token cost , context packing resembles a constrained selection problem:

where is the available token budget after reserving instructions and output.

Context Item Types

  • User request and current goal.
  • System or repository rules.
  • Current file excerpts.
  • Retrieved documents.
  • Tool results.
  • Prior decisions and summaries.
  • Output schema or examples.

Ordering Principles

  • Put durable rules before task data.
  • Put fresh task evidence near the action it supports.
  • Separate untrusted content from instructions.
  • Label sources and timestamps when relevance depends on freshness.
  • Prefer concise excerpts over full dumps.

Checks

  • Does each context item support the next decision?
  • Are source boundaries clear?
  • Is any private or irrelevant information included?
  • Is the model being asked to infer from missing evidence?
  • Would a smaller context produce a more reliable answer?