Skip to content
Small team, full backlog, zero orders dropped. Support replies are slower than we’d like. Read our status update → Zero orders dropped. Status → 📬 Check your spam folder — most of our replies land there. We do answer. Status update → 📬 Check your spam folder. Status →

Agentic Engineering / Rung 2

Context Engineering

Prompt engineering decides what you ask. Context engineering decides what the agent knows when you ask it. On a real codebase, that second thing is where the failures actually live.

What Context Engineering Actually Means

An agent rarely fails because you phrased the request badly. On a codebase of any real size it fails because it had the wrong picture of the repository. It edited a file that three other files override at runtime. It trusted a note that stopped being true in March. It rewrote a helper that already existed forty lines up.

Context engineering is the discipline of deciding what the model knows at the moment it acts. Not how you word the instruction. What is actually in the window when the instruction lands.

We did not coin the term. Shopify’s CEO Tobi Lütke proposed it publicly in June 2025, describing it as the art of providing all the context for the task to be plausibly solvable by the model. Andrej Karpathy amplified it days later: the delicate art and science of filling the context window with just the right information for the next step. Simon Willison wrote up the naming on 27 June 2025, Cognition’s Walden Yan had been publishing the underlying principles earlier that year, and LangChain shipped a four-part framing on 2 July 2025: write, select, compress, isolate. Anthropic’s applied AI team published Effective context engineering for AI agents on 29 September 2025, defining it as the set of strategies for curating and maintaining the optimal set of tokens during inference, with a rule worth memorising: find the smallest possible set of high-signal tokens that maximise the likelihood of the outcome you want.

This page owns one rung. Wording the instruction, structuring examples and writing acceptance criteria belongs to prompt engineering. Which agent, model, tools and permissions run the job belongs to harness engineering. Everything below is the knowledge itself.

18
Models Chroma tested for context rot
84%
Token cut in Anthropic's 100-turn context-editing eval
4
Named ways a long context fails
29k
PHP files in our own production docroot

A Bigger Window Is Not Better Context

Every vendor advertises window size, because it is the one number that fits on a slide. It is close to the least useful number in agentic coding. A context window is a budget you spend, not a bucket you fill.

The evidence has been public for years. Liu et al. at Stanford published Lost in the Middle in TACL, showing a U-shaped performance curve: models find what they need near the start or end of the input and degrade sharply when the same fact sits in the middle. Chroma’s research team (Kelly Hong, Anton Troynikov, Jeff Huber) published Context Rot on 14 July 2025, evaluating 18 models and finding performance grows non-uniform and unreliable as input length increases, even on tasks as trivial as copying text back. Anthropic frames the same effect as an attention budget: a transformer builds relationships across every token pair, so attention thins as the window grows and recall degrades with it.

The consequence is blunt. A token that does not help is not neutral. It costs money, it costs latency, and it dilutes the attention available to the tokens that mattered. Filling a million-token window with your whole repository is not thoroughness. It is a denial-of-service attack on your own agent.


The Four Ways a Context Fails

Drew Breunig gave the failure modes their working names in June 2025, in How Long Contexts Fail and its companion piece on fixing them. The taxonomy stuck because all four are recognisable after one afternoon of watching an agent work. Learn to name them out loud. A failure you can name is a failure you can fix at the source instead of arguing with the model about it.

Poisoning, Distraction, Confusion, Clash

Context Poisoning

A wrong fact enters the window and is then referenced as established truth for the rest of the session. The model is not hallucinating any more. It is reasoning correctly from a bad premise you handed it, which is far harder to spot.

Context Distraction

The context grows so long that the model over-anchors on it and stops drawing on what it learned in training. Symptom: it keeps repeating the approach already in the transcript instead of trying the obvious better one.

Context Confusion

Irrelevant material is present, so the model uses it. Twenty tool definitions when the task needs three. A stale README next to the live config. Superfluous context does not sit quietly; it gets picked up and acted on.

Context Clash

New information contradicts something already in the window. An old plan versus a revised plan, a deprecated helper versus its replacement. The model has no clean way to decide which one wins, so it splits the difference and produces a hybrid that satisfies neither.

A Worked Example From Our Own Infrastructure

Our production web host runs firewalld on nftables, zone public, default deny. Run iptables -L there and it reports policy ACCEPT on every chain, because iptables-legacy is not the active backend and its tables are empty. The output is true. The conclusion a reader draws from it is the exact opposite of reality.

An agent auditing that box reads the output, concludes the firewall is wide open, and writes that down. From that turn onward the wrong fact is in the window, shaping the threat model, the remediation plan and the summary handed to the next stage. Nothing in the transcript contradicts it, because nothing else in the transcript ever looks at the real backend. Two separate agents, on separate days, made that identical misreading on that identical box.

The fix was not a cleverer instruction. It was one durable line in the project’s conventions file, in the place every agent reads before it starts: on this host, iptables -L gives the opposite of the truth, use firewall-cmd --list-all or nft list ruleset. That line costs roughly forty tokens, and it is the highest-yield forty tokens in the file, because it pre-empts the poisoning instead of arguing the model out of it afterward.

That is the whole job in miniature. You are not writing documentation. You are placing the few facts that stop an expensive wrong turn, just before the turn is taken.


The Context Budget Is a Real Economic Constraint

Treat the window as a budget in three currencies. Most teams track only the first, which is why the other two quietly wreck their throughput.

Money and Time

Input tokens are billed, and re-billed on every turn of a loop. A fifty-thousand-token preamble carried across sixty turns is three million tokens of pure carry cost before the agent produces a single line of work. It is latency on every one of those turns too, which is the part your team feels.

Attention

The scarcer currency. Every token spent on a licence header, a minified bundle or a directory listing you did not need is attention not spent on the diff under review. This budget has no invoice, so nobody audits it, and it is the one that decides whether the answer is correct.

Cache Prefix

Prompt caching rewards a stable prefix. Shuffle the order of your context between turns and you invalidate the cache and pay full price again. Anthropic’s context editing beta prunes stale tool results without destroying the cached prefix, which tells you what that prefix is worth.


Curate, Do Not Dump

The most common mistake is the reflex to give the agent everything and hope. Our own WordPress document root holds over 29,000 PHP files. There is no window in which that is a plan, and if there were, it would answer worse than four well-chosen artifacts.

Use a selection rule you can state out loud: something earns a slot only if the next action depends on it. Four categories usually clear that bar. The map. The conventions. The change under review. The one symbol being investigated.

bash
$ # The naive plan: give it the whole repository.
$ find /home/dcentral/public_html -name '*.php' | wc -l
29036

$ # It does not fit, and it would not help if it did.
$ # Curate instead. Four artifacts, in this order:

$ cat AGENTS.md                              # conventions, build, test, do-not-touch
$ cat .dcent/memory/ARCHITECTURE.md          # the map: what lives where, and why
$ git diff --stat origin/main...HEAD         # the change actually under review
$ rg -n 'dc_bypass_cloudflare_cache_for_index_waste' inc/   # the one symbol in question

Repo Maps and Conventions Files

A repo map is a compressed structural summary: the files, the important symbols, and which symbols the rest of the tree leans on. Aider has shipped one of the best public implementations since October 2023. It parses the tree with tree-sitter, builds a graph of definitions and references, ranks it with PageRank so a function called from twenty places outranks a private helper called once, then fits the ranked list to a token budget. The default is one thousand tokens. One thousand tokens to orient an agent inside an entire codebase is a very good trade.

Conventions files carry what the code cannot tell you: the build command with its exact flags, the test invocation, the boundaries you must not cross, the traps that cost someone a day. AGENTS.md emerged as the vendor-neutral convention out of work across OpenAI Codex, Amp, Google’s Jules, Cursor and Factory. It is plain Markdown at the repository root, used by over 60,000 open-source projects by its maintainers’ count, and stewarded by the Agentic AI Foundation under the Linux Foundation. Claude Code reads CLAUDE.md; the usual bridge is a one-line import. Either way the discipline is identical, and how you word the rules inside is a prompt engineering question.

Their failure mode is entropy. They start as a tight page of hard-won traps and become a nine-hundred-line landfill nobody prunes, at which point they are pure distraction cost on every turn. Prune them like code. Every line should be a fact that changed an outcome.

Where Knowledge Can Live
Mechanism Lives where Survives a fresh session Typical failure
Instruction in the turn The message itself No Retyped by hand each time, drifts out of sync with the repo
Conventions file (AGENTS.md, CLAUDE.md) The repo, in git Yes Grows into a landfill nobody prunes
Repo map Generated at run time Yes, regenerated Stale the moment the tree changes
Retrieval at run time (grep, search tools) Nowhere until needed Yes A bad query returns confident garbage, silently
Workspace memory (Markdown on disk) The workspace, human-readable Yes Contradicts itself if nobody corrects it
Vendor conversation history A provider database Depends on the vendor Opaque, not diffable, not portable off the platform
Sub-agent with a fresh window A separate context Not applicable The returned summary drops the detail the parent needed

Memory That Lives With the Project

Persistent memory answers the obvious problem: a context window ends, and everything learned inside it ends with it. The question is where the memory goes. Most of the industry puts it in a provider’s conversation database, where you cannot read it, diff it, review it or take it with you.

DCENT_ADE takes the other road. Memory is workspace-scoped Markdown on your disk, inside the project it describes. Open it in an editor. Put it under version control. Correct a wrong line the way you correct a wrong line of code, where a human sees the correction in a diff.

The operations are deliberately small: read, write, append, list, search. They are scoped by the native host rather than by the model, and bounded on purpose. Each bound exists because of a specific way agent memory goes wrong.

Unsafe Roots and Traversal

Memory is a tool the model calls with a path argument. Give it enough turns and it will eventually name a path outside the workspace, usually while being helpful. Rejecting unsafe roots and traversal keeps a memory write from becoming an arbitrary file write on your machine.

Oversized Documents

An unbounded memory file grows every session and is loaded every session. Left alone, the one artifact built to save your window becomes the thing that consumes it. A hard size bound forces the summarisation that discipline would otherwise have to supply.

Stale Writes

Run several agents at once and two will hold the same memory file. If the second write lands blind, it erases the first agent’s finding and nobody is told. Rejecting a write made against an outdated version turns a silent lost update into a visible, retryable error.

Anthropic’s platform moved the same direction in September 2025 with a memory tool that treats memory as files an agent creates, reads, updates and deletes in a directory you control. The file-based approach is not our idea, and we think it is right for the same reason they do. Files are inspectable, and inspectable beats magic.

Context Is Not Just the Transcript

Treating context as the chat log is the last big mistake. The agent’s real context is the environment it acts inside: the files on disk, the working tree, the mission, the claim it holds, the mail from another agent, the diff it is about to defend. If those live in five disconnected places, no window size reconciles them.

DCENT_ADE builds around that. Files, sessions, mission state, prompts and diffs are one shared environment rather than five loosely coupled tools. Orion, the local-first coordination layer, holds the boards, missions, mailbox, claims and memory, and its awareness layer decides whether an agent is busy, idle, awaiting input or finished from real terminal behaviour rather than from an optimistic status flag. That matters here, because a wrong status is itself a poisoning event for whatever reads it next.

Cognition makes the related point for multi-agent work: share full traces, not isolated messages, because an agent handed a summary of a decision has not been handed the reasons for it. Splitting work across a fleet splits context, and every split silently drops knowledge. Designing those splits is graph engineering.


Compaction, and What It Destroys

When a session outgrows its window, something has to give. Compaction is the standard answer: summarise the history, start a fresh window from the summary, keep going. Claude Code’s auto-compact does this. Anthropic’s context editing, in public beta since 29 September 2025, does a more surgical version by clearing stale tool calls and results as you approach the limit. On their internal agentic-search evaluation they reported context editing alone improving performance by 29 percent over baseline, 39 percent combined with the memory tool, and a 100-turn web search run finishing with 84 percent fewer tokens where it would otherwise have died of context exhaustion. Those are their numbers on their evaluation, not ours.

Compaction works. It is also lossy in a predictable way, and knowing which way is the difference between using it and being wrecked by it. A summary keeps the plot and drops the evidence. What survives is what happened. What disappears is the exact error string, the flag that failed, the reason a path was rejected, the measured number, and the thing already tried that must not be tried again. Two turns after a compaction you will watch an agent confidently retry the approach it disproved an hour earlier, because the disproof was compressed into a sentence and the sentence lost the detail.

The discipline follows directly. If a fact took a measurement to learn, it does not belong only in the conversation. Write it to durable memory when you learn it, not when you run out of room. Our own rule is that anything expensive to discover gets one line on disk, phrased as the trap and its counter. Those lines are why a fresh session starts competent instead of starting over.

Retrieval Beats Stuffing, With One Condition

The stronger pattern is just-in-time: load identifiers up front and full content only on demand. The agent gets file paths, a repo map and search tools, then pulls the bytes when it needs them. Anthropic describes this as mirroring how people work, since nobody memorises a codebase before opening it. In coding, retrieval needs no vector database. A well-targeted rg is retrieval, and on source code it usually beats embedding search, because code has exact identifiers and exact identifiers are what you are hunting.

The condition is this: retrieval fails silently. A search that returns nothing looks identical to a search that proves nothing exists, and an agent will happily conclude the second from the first. We have watched a verification step pass because it was checking a surface that could not fail. The counter is evidence discipline: treat an empty result as unproven, and run a positive control to confirm the check can fail at all. That belongs to loop engineering, and it is why our own build method sends every result to an independent critic with a fresh context that is allowed to reject it.

The full ladder sits at the agentic engineering hub. The environment we built around these ideas is DCENT_ADE.


No. Retrieval is one technique inside it. Context engineering also covers what is in the conventions file, what the repo map contains, how much of the transcript survives compaction, what persists to memory between sessions, which tool definitions are loaded, and what gets deliberately left out. Retrieval answers how to fetch something. Context engineering answers whether it should be in the window at all.
They have not so far, and the published evidence argues they will not. Chroma tested 18 models and found performance becomes non-uniform as input length grows, even on trivial tasks. Stanford research on long contexts found a U-shaped curve where facts in the middle of a long input are recalled worst. Bigger windows raise the ceiling on what is possible; they do not change the fact that signal density decides the answer. Cost and latency also scale with every token you carry.
Put in what the code cannot tell you: exact build and test commands, hard boundaries, environment quirks, and traps that already cost someone real time. Leave out anything the agent can derive by reading the tree, anything already obvious from the framework, and any aspiration you are not actually enforcing. If a line has never changed an outcome, it is pure distraction cost on every turn. Prune it like code.
Pasted notes are ephemeral and manual. They die with the session and they are only as current as your last copy-paste. Real memory is durable, scoped, and written by the agent itself as it learns, so the next session starts from what the last one discovered rather than from zero. The important part is that it is bounded and inspectable, because unbounded self-written memory eventually accumulates a wrong fact and then repeats it forever.
Because you can read it, diff it, correct it, review it and take it with you. A wrong line in a Markdown memory file is a two-second edit and shows up in a pull request. A wrong belief inside an opaque provider database is something you can only discover by watching your agent behave strangely. Human-readable memory that lives with the project also survives changing harnesses, which is the whole point of keeping the knowledge and not the vendor.
Do not argue with it in the same window. Once a wrong premise is in the context it will keep being referenced, and each correction turn adds more conflicting material rather than less. Start a fresh context, fix the source that fed it the wrong fact, and write the correction where the next run reads it before it starts. Poisoning is fixed upstream, never in the transcript.

Free, Open, As-Is

DCENT_ADE is free and open, released as-is. No paid tier, no gated feature, no telemetry on ordinary local work. We stand on other people’s work to build it and we say so: Anthropic’s Claude Code, OpenAI’s Codex, the AGENTS.md community, Aider’s repo map, tmux, and the open-weight model ecosystem our own workflows lean on daily.

If you use it commercially, or it saves you time you would otherwise have paid for, a voluntary subscription or donation is expected and never enforced. That is the whole arrangement: fund the sovereign stack.

Context Is Infrastructure

Curate what the agent knows, keep the memory human-readable and in the project, and stop paying attention tax on tokens that never helped. Then decide which agent runs it.