Skip to content
The AI Builder's Newsletter

Why agents need context

Code tells an agent what the system does. It does not tell it why, or what the product is for.

Give a capable coding agent access to a repository and it will do an impressive job of understanding the code. It will find the patterns, follow the conventions and work out how the pieces fit. What it will not find, because it is not there, is what the business is trying to do and why.

Code is the answer to a set of questions the team asked over years. The questions are nowhere in it. When an agent only has the code, it has to guess at them, and it guesses confidently.

This post is about the context that code alone does not capture, and how to make it available without burying every task under a mountain of documentation.

read the rest, free

Enter your email to unlock the article. You will also get the AI Builder's Newsletter with practical notes on building & shipping products with AI.

No payment, no card, nothing else to fill in. Unsubscribe any time.

Code alone does not explain the product

Consider a rule like "orders over a certain value need a second approval, from someone in a different team". The code can enforce that, and the tests can check it. What they do not say is why: that the rule followed a fraud incident two years ago, and that finance owns the threshold. An agent asked to "simplify the approval flow" sees a cumbersome step with no explanation, and may remove exactly the thing that matters, rewriting the tests to match. It needs the reason to recognise a safeguard rather than treat it as unnecessary complexity.

Agents need to understand what the business is trying to accomplish, not only what the system currently does.

Provide business and product context

The first layer is the domain. Which concepts exist and what the team calls them. The business rules and where they come from. The main user journeys. The constraints that are not negotiable, whether legal, commercial or simply decided. A short document that explains these does more for an agent's output than a thousand lines of comments.

Keep it in the language the business uses. Terminology matters: if the product calls them "members" and the code calls them "users", say so.

Provide technical context

The second layer is the engineering. The high-level architecture and why it is shaped that way. Architecture decision records for the choices that were hard. The patterns the codebase follows and the ones it deliberately avoids. Dependencies, integration points, environments, how things are deployed.

Much of this can be inferred from the code, slowly and imperfectly. Writing it down once saves every agent, on every task, from working it out again. It also stops them from "fixing" a deliberate choice.

Provide design context

The third layer is often forgotten. If the product has a design system, a component library, UI conventions or accessibility expectations, agents need to know. Otherwise you get a new screen that works and looks like it belongs to a different product.

Point agents at the design system, the component library and any specifications that matter, and say which conventions are rules and which are preferences.

Make it findable, not enormous

The temptation is to put all of this in one giant instruction file that goes into every prompt. That does not scale, and it wastes the context window on things irrelevant to the task at hand.

Better: keep the documentation in the repository, structured so that an agent can find what it needs when it needs it. A short entry point that says what exists and where. Separate documents for the domain, the architecture, the design and the conventions. The agent reads the entry point, then reads what is relevant. Our own setup is a short AGENTS.md as the entry point, with separate documents for the business, the product, the architecture and the design, and a decision record for each choice that would be hard to reverse. It is part of our workflow, described in Introducing Supercharge.

Permanent context and task context

Draw a clear line between the two. Project-wide knowledge, the business rules, the architecture, the conventions, belongs in persistent documentation that every task can reach. The requirements for one feature belong in a short brief for that feature, linked from its issue, not in the project-wide instructions. When a feature settles something that will outlast it, such as a new business rule or an architectural decision, move it into the permanent docs and link to it from the brief, rather than repeating it.

Mixing them is how projects end up with a permanent instruction file full of one-off notes from tasks long finished. It is also how feature-specific requirements go missing, because they were in a prompt rather than in the tracker. We wrote about where requirements should live in How to plan features for AI coding agents.

Keep it accurate

Outdated documentation can be worse than none. An agent that reads a stale architecture note will follow it, and will produce code consistent with a system that no longer exists. Contradictory documents are as bad. In one of our test runs, the business document said a receipt's currency was never assumed to be Hong Kong dollars, the product document said to default to Hong Kong dollars when the currency was unreadable, and the plan quietly followed the second.

So give agents a rule for conflicts. In ours, the code says what the system does today, anything a human wrote or approved says what it should do, and every disagreement is flagged for a person rather than quietly resolved.

So the standard is not "write it once". It is "keep it true". If a document cannot be kept current, delete it rather than let it mislead.

Do not over-engineer it

It is easy to turn this into a project of its own: elaborate documentation structures, templates for every kind of note, a process for maintaining the process. Resist that. Supply what is useful, in the simplest form that works, and add more only when a missing piece of context actually causes a problem.

The question to ask of every document is: would an agent, or a new engineer, make a better decision for having read it? If not, it is noise.

Use agents to maintain it

Finally, this is work agents are good at. When a change to the code alters the architecture, a business rule or a convention, the same task can update the corresponding document. Build that into the workflow, as a step the implementing or reviewing agent performs, rather than hoping someone remembers. In ours, updated docs are part of the definition of done for every slice, and when a feature is finished, an agent checks the docs against what actually shipped. That belongs in your own skills, which we cover in Why we built our own coding skills.

Code shows an agent what exists. Current, findable context tells it what should change and what must be preserved.