# Context Engineering for AI Agents: 4 Failure Modes to Avoid

## Executive summary

As AI context windows grow (potentially to a million tokens or more), agents may become less reliable due to 'context rot.' Context Engineering is the discipline of managing what information enters the context window at each step of an agent's run. The video identifies four major failure modes—Poisoning, Distraction, Confusion, and Clash—and proposes fixes that involve deliberately discarding information to improve agent performance in long-running tasks.

## Key takeaways

- Context Poisoning: This occurs when a mistake or false conclusion (e.g., an agent writing a wrong note based on misreading documentation) is treated as ground truth by the model. The fix is to **Validate** all conclusions against real-world data (e.g., running a quick connection test).
- Context Distraction: The sheer size of the message history can cause the language model to drift, prioritizing past actions over the current task requirements. The fix is to **Compact** the history by summarizing the log, or ideally, moving detailed information to permanent files and only pulling it into the context when needed.
- Context Confusion: Having too many available tools (e.g., 46 tools) makes the agent struggle to select the correct one, even if the task only requires a handful. The fix is to **Curate** the context by providing only the necessary tools for the specific job.
- Context Clash: This happens when the context window contains conflicting information (e.g., an old note stating retries are needed, while the history shows no retries are occurring). The fix is to **Prune** the context by deleting superseded or conflicting information, or starting a fresh window with the corrected state.

## Technical details

- Context Window Components: A typical agent's context window includes the system prompt (standing instructions), the agent task prompt, project instructions (e.g., an agents.md file), tool definitions, the message history (running log), and tool results (file contents, test output, error logs, schema dumps).
- Context Rot: A phenomenon where model reliability decreases as the context window size increases, suggesting that the attention budget is spread too thinly across too many tokens.
- Attention Budget: The core limitation: even if a window holds a million tokens, the attention spread across those tokens is finite, making every token compete for limited focus.

## Practical implications

- When building AI agents for build or migration tasks, actively manage the context window by limiting tool definitions and project documentation to only what is immediately relevant.
- Implement validation steps (e.g., running a quick test) before allowing an agent to write a conclusion or note that will be treated as ground truth.
- For long-running processes, prioritize extracting detailed information (like logs or file contents) into permanent, external files rather than relying solely on the context window history.

## Topics

Context Engineering, AI Agents, Context Rot, Large Language Models (LLMs), Attention Mechanism, Prompt Engineering, IBM Technology, Context Engineering Guide

Source: https://www.youtube.com/watch?v=BwXremQ-i6I
