context engineering treats the finite context window as a scarce resource to manage systematically — three pillars: (1) system prompts — fixed role, behavior rules, and format constraints stable across turns, versioned over time (e.g. "say so when unsure", output JSON structure); (2) memory tiers — layered by stability and recency: system rules > current user intent > conversation history > retrieved evidence and tool results, with long histories compressed (summarization-style context compaction) or truncated by relevance; (3) token budgets — explicit allocation of the window
W: instruction, history, retrieval, and reserved output
Wout such that
∑iti+Wout≤W, with cost approximated by
cost=cin⋅tin+cout⋅tout — over budget means truncation or summarization.