Deterministic, on-demand retrieval
Retrieval is deterministic and cheap: the agent searches and extracts what it needs on demand, rather than being fed a pre-built index that was assembled before anyone knew what the task was.
- MCP servers provide structured context (architecture, ownership, SLAs) to agents
- Context is organized across at least 3 of the 5 levels: System, Code, Org, Historical, Operational
- Token budget management is implemented (agents receive context within defined token limits)
- Context sources are versioned and tested for correctness
- Context budgeting policy defines priority order when token limits are reached
- MCP server configuration files listing active context sources
- Token budget configuration in agent settings
- Context coverage audit showing 3+ context levels populated
- Infrastructure L2 (MCP & Tool Integration) - basic MCP servers must exist before structured context delivery
What It Is
Retrieval is deterministic and cheap: the agent searches and extracts what it needs on demand, rather than being fed a pre-built index assembled before anyone knew what the task was. Ask the same question twice and the same material comes back, because the retrieval is a search over the actual artefacts rather than a nearest-neighbour lookup in an embedding space that was built last week.
This is the run-time half of context. What the organisation writes down and keeps current - the docs, the ADRs, the ownership records - belongs to Knowledge Management, and this guide assumes those artefacts exist. The question here is what actually reaches the model when it starts work on a specific task, how it got there, and whether the same task would get the same material tomorrow.
The practical shape of this is agentic search. Instead of embedding the repository into a vector store and retrieving the top-k chunks by similarity, the agent runs the tools an engineer would run - grep, a symbol query, a structural extraction over the parse tree, a scoped subagent that reads a directory and reports back file-and-line citations. Each of these is exact, explicable and repeatable. When it returns the wrong thing you can see why, and fix the query rather than re-tune an index.
Cheap matters as much as deterministic. Assembling context is not free: an overstuffed window degrades reasoning as reliably as a missing file does, and every token of speculatively-retrieved material is a token the model spends attention on. On-demand retrieval means the agent pays for what the task needs, when it needs it, and nothing else - which is also why pruning unused skills and idle MCP servers recovers a meaningful share of the window before any retrieval happens at all.
Knowing what to retrieve still requires knowing what kinds of context exist. Five are worth naming, because each has a different volatility and therefore a different retrieval strategy:
1. System-level context - The architecture and infrastructure of the system: how services are deployed, what infrastructure they run on, how they communicate, what the scalability and reliability constraints are. An agent working on a microservice without system-level context doesn't know whether it's a standalone service or one of two hundred in a mesh. It doesn't know if horizontal scaling is available or if there's a single-region constraint.
2. Code-level context - The codebase itself: module structure, dependency graph, existing abstractions, test patterns, build conventions. Code-level context is what IDE tools naturally provide - file contents, imports, definitions. The agent can read the files, but it can only read what fits in its context window.
3. Org-level context - Team structure, ownership maps, who to contact for what, what teams' current priorities are, what's in-progress vs. completed. An agent that doesn't know that the authentication team owns the auth-service might modify that service in a way that's technically correct but violates a team boundary.
4. Historical context - Why decisions were made: Architecture Decision Records (ADRs), git commit history with meaningful messages, design documents, post-mortems. An agent that doesn't know a particular pattern was explicitly rejected three years ago after a production incident will confidently re-suggest the rejected pattern.
5. Operational context - The current state of the running system: deployment status, error rates, latency metrics, recent incidents, on-call alerts. An agent working on code related to a currently-degraded service needs to know the service is degraded - and why - to make safe suggestions.
The volatility of each level decides how it should be retrieved. System-level and Code-level context lives in the repository and is best searched on demand, because it is exactly the material grep and structural extraction are good at. Org-level and Operational context change faster than any index could track and should be queried live from the systems of record at the moment the agent needs them. Historical context sits in between: stable enough to search, large enough that you want the search to be targeted rather than exhaustive.
At L3 (Systematic), organisations have identified which of these context types they are providing and which they are not, and are retrieving each one by a method that returns the same answer every time.
Why It Matters
Deterministic retrieval is what makes an agent's failures diagnosable. When retrieval is a similarity search over an index, a bad suggestion has no traceable cause: you cannot tell whether the material was absent, present but unranked, or present and ignored. When retrieval is a search the agent ran and logged, the failure is attributable, and it can be classified by context level:
- Agent suggested a pattern we explicitly rejected in 2022 → Historical context gap → fix: ADRs in context
- Agent modified a service owned by another team without coordination → Org-level context gap → fix: ownership data via MCP
- Agent didn't account for the fact that this runs on single-region infrastructure → System-level context gap → fix: infrastructure documentation in CLAUDE.md
- Agent created a utility function that already exists in a shared library → Code-level context gap → fix: better codebase indexing, RAG over the repo
- Agent suggested adding caching to a service that's currently in a degraded state due to a memory leak → Operational context gap → fix: production telemetry in context
Without this vocabulary, context gaps get described as "the AI is bad", which leads to no actionable fix. With it, they become specific infrastructure investments.
The levels also map onto the maturity progression: L2 provides basic Code-level context (an instruction file with project information). L3 retrieves all five deterministically and on demand. L4 automates assembly. L5 keeps what is retrieved fresh.
The industry moved decisively this way during 2026. Anthropic dropped vector search in Claude Code in favour of agentic grep and tool-search, and Microsoft's FastContext (June 15) uses a repo-explorer subagent that returns compact file-line citations and cuts coding-agent tokens by up to 60%. Both are the same bet: an index is a stale, lossy, expensive copy of something the agent could have read directly, and a tool call that reads the real thing beats a retrieval that approximates it.
Run a "context failure audit" with your team. Take the last 10 agent mistakes that made it to code review and classify each one by which context level was missing - and, for each, whether the material was genuinely unavailable or merely not retrieved. The second column is usually the fuller one, and it points at the retrieval strategy rather than at a documentation gap.
Getting Started
- Audit your current context coverage - For each of the five levels, ask two questions: can the agent get this at all, and does it get the same thing every time? Rate each level none, partial, or systematic, and note which ones currently arrive via an index rather than a search.
- Identify your biggest gap - The level with "none" coverage is your starting point. Don't try to address all five levels at once.
- Give the agent search tools before you give it an index - Make sure the agent can grep, list files, query symbols and extract by structure, and that it is instructed to use them. Most teams discover the agent was capable of finding the file all along and had simply been handed a summary instead.
- Retire any index you cannot explain - If a vector store is in the path, test it against plain search on twenty real tasks. Keep it only where it demonstrably wins, and be honest about its cost: a copy of the repository that must be rebuilt, can go stale silently, and cannot tell you why it returned what it did.
- Query the volatile levels live - Org-level and Operational context change faster than any snapshot. Expose service ownership and deployment status through tools the agent calls at the moment it needs them, so the answer is current by construction rather than fresh by luck.
- Validate each level with a probe question, run twice - Ask the agent something that requires each level: "Who owns the auth service?" for Org, "What is the current deployment status of the payments service?" for Operational, "Why don't we use Redis for session storage?" for Historical. Run each probe twice. A different answer the second time is a retrieval defect, and it is invisible to any evaluation that runs each case once.
Common Pitfalls
Treating Code-level context as the only kind that matters. Teams that have done good L2 work often stop there - they've improved autocomplete and basic agent suggestions, and declare success. But for agents tackling larger tasks, the other four context levels are equally important. Code-level context alone doesn't prevent the agent from violating team ownership, ignoring historical decisions, or making unsafe changes to degraded services.
Reaching for an index before exhausting search. A vector database feels like the serious answer to "the agent cannot find things", and it usually is not. It introduces a second copy of the truth that has to be kept in sync, it makes retrieval unrepeatable, and it answers with fragments whose provenance the model cannot check. Try exact search, structural extraction and a scoped subagent first; adopt an index only where you can show it beating them on real tasks.
Confusing context level with information priority. Operational context is not more important than Historical context - they're different dimensions of the same picture. An agent that has excellent operational context but no Historical context will make safe suggestions about the current system state while confidently repeating patterns that were explicitly rejected years ago.
Trying to provide all five levels through static files. System-level and Code-level context can live in CLAUDE.md. Org-level, Historical, and Operational context changes faster than static files can keep up with. Organizations that try to maintain these as static documents spend significant effort on a losing battle. MCP servers are the right infrastructure for dynamic context.
Measuring retrieval quality only once per case. An evaluation that runs each scenario a single time cannot distinguish a retrieval strategy that works from one that worked that time. Run the same probes repeatedly and treat variance as a defect in its own right - it is the difference between a context system you can reason about and one you can only hope about.
Not measuring context quality by level. If you track agent suggestion quality as a single number, you can't tell which context level is causing failures. Separate your quality metrics: how often does the agent make architectural errors (System), violation-of-conventions errors (Code), team boundary violations (Org), repeated historical mistakes (Historical), and operationally unsafe suggestions (Operational)?
How Different Roles See It
Bob has invested in L2 context engineering - most repositories have CLAUDE.md files, and developers are using them. But he's hearing a new category of complaint: "The agent writes good code but it doesn't understand how things fit together." Agents are creating duplicate abstractions, violating service boundaries, and suggesting changes that are technically correct but operationally risky. Bob doesn't know how to categorize or prioritize these issues.
What Bob should do: Bob should run the context failure audit using the 5-level framework. Give it to his tech leads: take the last 10 agent failures in code review and classify each one. The classification will almost certainly reveal that Code-level context is reasonably good (thanks to CLAUDE.md investment) but Org-level, Historical, and Operational context are gaps. This gives Bob a prioritized investment roadmap: which context levels to address next, and in what order.
Sarah has been trying to explain to stakeholders why AI tool ROI varies so much across teams. Some teams are seeing 40% productivity improvements; others are seeing marginal gains at best. She suspects the difference is context engineering maturity but hasn't been able to articulate it precisely enough to be actionable.
What Sarah should do: Sarah should use the 5-level framework as a maturity assessment tool. She can run a quick audit across teams: for each team, which context levels are provided? The teams seeing 40% gains likely have good coverage of multiple levels; the marginal-gain teams likely have only Code-level context at best. This gives Sarah a concrete explanation for stakeholders (the teams with full context coverage perform better) and a specific investment roadmap (the other teams need to build out their missing context levels).
Victor has built a sophisticated context system for his own workflow: he manually assembles context from different sources before starting agent sessions. He has CLAUDE.md, he keeps ADRs, he checks the service registry, he looks at deployment status. It works well but takes 20-30 minutes of preparation per session, and none of it is automated.
What Victor should do: Victor is hand-assembling context that the agent could fetch itself, which is why it costs him half an hour and why nobody else can reproduce it. The move is to convert each step of his preparation into a tool the agent can call at the moment it needs the answer: ownership and deployment status queried live, historical decisions searched in the repository, code found by grep and structural extraction rather than pasted in advance. Victor should also stop pre-loading. Most of what he assembles up front turns out not to be needed for the specific task, and it costs window that the agent would otherwise spend reasoning. He should document the tools rather than the ritual - a manual assembly workflow only ever scales to the one person who remembers it, whereas a set of retrieval tools works for every agent and every task, and returns the same thing each time it is asked.
Further Reading
From the Field
Recent releases, projects, and discussions relevant to this maturity level.
How This Guide Changed
What each edition changed in this guide, newest first.
- V1.6September 2026LATEST
Retrieval, not taxonomy, is what this level turns on now: deterministic and on-demand, returning the same material to the same question, rather than a pre-built index assembled before anyone knew what the task would be. The five context types survive as a way of reasoning about volatility and therefore about how each should be fetched, but what the organisation writes down and keeps current is Knowledge Management's subject and this guide no longer argues it. Determinism is also what makes a bad suggestion diagnosable, because you can see which search returned what and fix the query rather than re-tune an index.
- V1.4July 2026
Changed how Code-level context is best retrieved: memory beyond RAG. Anthropic dropped vector search in Claude Code in favour of agentic grep and tool search, and Microsoft's FastContext (June 15) used a repo-explorer subagent returning compact file-line citations to cut coding-agent tokens by up to 60%. The lesson added here is that assembling more context is not free and an overstuffed window degrades reasoning, so the fast-changing levels favour on-demand retrieval over pre-loading.
- V1.0March 2026
The guide arrived to retire a useless complaint. "The AI needs more context" points at no particular fix, so the first edition split context into five nameable kinds - system, code, org, historical, operational - precisely so that a bad agent suggestion could be traced to a missing one and answered with a specific investment instead of a shrug.
Where does your team actually sit on this?
This guide describes one level of one area. Run the assessment to place your team across all 16 areas, see which gates you have passed, and get a report you can take to your stakeholders.
Context Engineering