Context engineering for agents
What information the agent receives at each moment, why more is not always better, and how to give it just enough: the essentials up front and the rest when it needs them.
Before you start
- Task framing for agentsTechnique
How to turn an idea into a request the agent can carry out and you can review: goal, context, boundaries, expected result, and how to know it is done.
Published
Key idea: the agent only “knows” what is in front of it right now. Your job is to make sure it has what it needs for the current decision, and nothing more.
The problem
A model does not remember your project. At each step it works with what is in its context window: your instructions, the conversation, the files it has read, and the results of the tools it has used. Everything else does not exist for it.
That leads to two opposite failures:
- Missing context. The agent has not read the file that holds the important convention, so it ignores it or makes one up.
- Too much context. It receives generated folders, old logs, and repeated documentation. The window fills up, what matters gets buried, and the agent may rely on stale data.
More information does not mean more understanding. Anthropic sums up the goal like this: find the smallest set of useful information that makes the result you want most likely.
How it works
Think of context in three levels:
| Level | What it is | Example |
|---|---|---|
| Always present | What the agent needs in almost every task | Project goal, commands, conventions (AGENTS.md) |
| On demand | What is only needed sometimes | A specific file, a library’s documentation |
| Out | What never helps the decision | node_modules/, dist/, old logs |
The strategy that best fits coding agents is just-in-time context: instead of loading everything at the start, the agent receives a map —file names, folders, an index— and uses its tools (search, list, read) to bring in each piece when it needs it. That is what a new person on a project does: they don’t read the whole repository; they look at the structure and open what is relevant.
A practical cycle:
- Start small: the task and a map of where things are.
- Let the agent explore: it searches and reads files as it needs them.
- Remove noise: exclude generated folders and results that are no longer useful.
- Learn from failures: when the agent gets something wrong, ask whether it was missing a piece or had too much noise, and adjust.
Practical example
For the task of adding summarizeReading, a reasonable starting context would be:
Goal: implement summarizeReading in src/reading.js.
Read first:
- README.md → test command and project boundaries.
- src/reading.js → the API you must keep.
Check only if needed:
- src/reading.test.js → style of the existing tests.
Ignore:
- node_modules/, dist/, and old logs.
It is not a universal rule, just a starting map. The agent can explore further, but it begins with what matters.
Where each piece belongs
Context engineering is also deciding where each piece of information lives. This table sums up the rest of the learning path:
| If the information is… | It goes in… |
|---|---|
| Specific to this task | The request |
| Stable and useful in almost every task | AGENTS.md |
| A procedure for one kind of task | A Skill |
| External data or actions | A tool or an MCP server |
| Progress that must survive between sessions | State and memory |
Common mistakes
- Loading everything “just in case”. It costs more, takes longer, and can make decisions worse.
- Assuming the agent knows the project. If a convention is not written anywhere the agent reads, it does not exist for the agent.
- Leaving stale information around. A result from twenty steps ago or an old version of a file can contradict the current state.
- Treating all text the same way. A web page or a tool result is data to check, not instructions to obey. You will see why in Safe agent execution.
When to use it
In every task, even small ones: just think about what the agent should read first and what it should ignore. You don’t need to build a search engine, an index, or a memory system before you have seen a real problem.
Next step
Context has a limit: when a task is long, the window fills up or the session ends and the agent forgets everything. State and memory explains how to keep progress outside the model.
Sources
Accessed on 2026-10-05.
- Effective context engineering for AI agents, Anthropic.
Related content
- State and memoryTechnique
How to make a long task survive the end of a session: keep progress outside the model, in files and in Git, and tell task state apart from long-term memory.
Published - AGENTS.md: persistent project instructionsTechnique
A Markdown file at the root of the repository that tells the agent how your project works: commands, conventions, and how to check changes. It is a guide, not a control mechanism.
Published