3 Context fabric: optimizing context for AI agents
This chapter covers
- Why imprecise context leads to errors in AI agents
- The difference between prompt engineering and context engineering
- Strategies for writing, selecting, compressing, and isolating context
- Packaging context as skills and plugins that a whole team can install
- Designing effective planning, execution, and debugging loops with AI agents
- Proven optimization techniques for achieving high code accuracy
An LLM doesn’t read minds - it feeds on the crumbs you throw at it.
You've probably heard about prompt engineering, which focuses on precisely formulating instructions for language models. Unfortunately, prompt engineering alone isn't sufficient. Agents fail for several distinct reasons: the model reaches the edge of its capability, a tool errors out, a permission is missing, the local environment differs from the one the code assumes. But the failure category you have the most direct control over, and the one you will hit most often in daily work, is the context failure — the agent produced the wrong thing because of what it was handed to work with. That happens in four recognizable shapes: too little context (the vacuum), too much of it (context rot), context that is stale or simply wrong (poisoning), and the right context placed where the model has stopped paying attention (lost in the middle).