Foundations9 minLesson 2 of 60

Context Is King: Feeding the Model the Right Things

A model can only reason about what is in its context window. Garbage in, garbage out is not a cliche here, it is the mechanism. Most bad agent runs are not a reasoning failure, they are a context failure: the model never saw the file it needed, or it drowned in noise it did not need.

Anthropic frames the modern version of this as context engineering: deciding what enters the window, in what order, and when to clear it out. The goal is a small, high-signal context, not a giant one.

Three levers you control

  • Selection: which files, docs, and examples the model sees. Fewer and more relevant beats more.
  • Compression: summarize long history into a short note so the window does not fill with stale chatter.
  • Persistence: store durable facts (conventions, gotchas) in a memory file the agent always loads.
More is not better
Dumping your whole repo into the prompt usually hurts. The model spends attention on irrelevant code and loses the thread. Curate ruthlessly.

The order effect

Placement matters. Put the task and the success criteria where they are easy to find, usually near the top or the very end. Bury the instruction in the middle of a long dump and the model is more likely to miss it.

Clear the window when it goes stale

Long sessions accumulate dead ends, abandoned plans, and noise. When the agent starts repeating itself or losing the plot, the fix is often to summarize what matters, drop the rest, and start a fresh window with that summary. A clean context is a sharp context.

Effective context engineering for AI agents (Anthropic)Anthropic's first-party write-up on selecting, compacting, and persisting context for agents.anthropic.com
Finished this lesson? Mark it read to track your progress.