Context Engineering

Prompt engineering asked "how do I phrase it?" Context engineering asks "what belongs in the window at all?" The window is a budget — spend it deliberately.

Anatomy of the Window

≈ budget
System Prompt
Stable identity & rules — keep it short, keep it cacheable
~5%
Tool Definitions
Only the tools this task needs — not the whole catalog
~10%
Retrieved Knowledge
Top-k, reranked, deduplicated — relevance beats volume
~25%
Memory
Durable facts & preferences worth carrying across sessions
~10%
Conversation History
Recent turns verbatim, older turns compacted to summaries
~35%
Current Request + Headroom
The actual task — plus room left for the model to think & answer
~15%
Percentages are a discipline, not a law — the point is that every token in is a token someone chose.

Write

Persist what matters outside the window: scratchpads, notes, long-term memory. Don't make the model re-derive what it already figured out.

Example: agent writes progress notes to a file between steps

Select

Pull in only what this turn needs: RAG for knowledge, memory lookup for facts, just-in-time tool loading for capabilities.

Example: load 3 relevant tools, not all 40

Compress

Summarize old history, trim tool outputs, compact aggressively as the session grows. Recent stays verbatim; ancient becomes a summary.

Example: compact turns 1–40 into one paragraph, keep 41–50 raw

Isolate

Delegate noisy work to subagents with their own windows. The searcher reads 100 files; the main thread gets one clean answer back.

Example: research subagent returns findings, not transcripts
The four operations — write, select, compress, isolate — are how you spend the budget on purpose.

Four Ways Context Goes Bad

☠️ Poisoning A hallucination gets into context and every later turn treats it as fact
🌫️ Distraction Context grows so long the model over-focuses on it, neglecting what it learned in training
🌀 Confusion Superfluous tools & docs steer the model to a low-quality response
⚔️ Clash New info & tools in the window conflict with what's already there
Don't ask "how much can I fit?" — ask "what does this turn actually need?"
Curate, don't cram. The best context window is the smallest one that still wins.