← All posts

Context Engineering · 5 min read

Context engineering: the skill that replaced prompt engineering

Agents rarely fail because the model is weak. They fail because they saw the wrong things. Here is a practical framework for deciding what an agent sees, remembers and forgets.

Subhash Nunna ·

A prompt is one message. An agent’s context is everything the model can see when it decides what to do next: the system instructions, the tool definitions, retrieved documents, earlier tool results, conversation history and whatever it remembers from last week.

Prompt engineering asks, “How do I phrase this?” Context engineering asks a harder question: “What should the model be looking at, right now, to make this one decision well?”

Once you build agents that take many steps, that second question matters far more. A recent paper on the topic puts it bluntly: many agent failures come from poor context design, not from weak models.

Why prompts stopped being enough

With a single question and answer, you control almost everything the model sees. With an agent, the context grows by itself. Every tool call adds output, every turn adds history, and retrieval adds documents. After 20 steps, the instructions you carefully wrote are a small fraction of what the model is reading.

Three problems appear:

  • Relevance: the model sees a lot, but not the thing it needs for this step.
  • Memory: something important happened 15 steps ago and has scrolled out of view, or is buried.
  • Budget: every token costs money and latency, and long contexts can make answers worse, not better.

Five quality checks for any context

The paper proposes five criteria. We find them a useful checklist before shipping any agent:

  1. Relevance: is everything here useful for the current step?
  2. Sufficiency: is anything the model needs missing?
  3. Isolation: is each sub-task seeing only its own slice, not everyone else’s noise?
  4. Economy: could the same decision be made with fewer tokens?
  5. Provenance: do we know where each piece came from, and how much to trust it?

The fifth one is the one teams skip most often. When an agent makes a strange decision, provenance is what lets you trace it back to the document, tool result or memory that caused it.

The four operations: write, select, compress, isolate

A popular way to organise the work, credited to LangChain and adopted by the paper, is four operations.

Operation What it means Example
Write Save information outside the context window for later A scratchpad file, a task plan, long-term memory
Select Pull in only what this step needs Retrieval, choosing which tools to expose, loading one memory
Compress Keep the meaning, drop the tokens Summarising old turns, trimming tool output, prompt compression
Isolate Split work so each part has a clean context Sub-agents, sandboxed tool runs, separate threads

Most context bugs map neatly onto one of these. An agent that forgets its plan needs better write. One that drowns in search results needs better select and compress. One whose sub-tasks contaminate each other needs isolate.

How long contexts go wrong

It is tempting to think a bigger context window solves everything. In practice, long contexts fail in recognisable ways, often summarised as four failure modes:

  • Poisoning: a mistake (for example, a hallucinated fact) gets into the context and is repeated in later steps.
  • Distraction: so much history that the model leans on it instead of thinking about the current task.
  • Confusion: irrelevant material, such as too many tool definitions, pulls the model off course.
  • Clash: two pieces of context contradict each other, and the model has to guess.

A small, well-chosen context usually beats a large, loosely assembled one, even when the window could hold more.

A practical recipe

Here is the order we work in when building or fixing an agent.

1. Separate stable and changing parts. System instructions and tool definitions rarely change, so put them first and let your provider cache them. Changing material — the current task, retrieved data, recent turns — goes after.

2. Load just in time. Don’t preload every document “in case”. Give the agent tools to fetch what it needs, and include a short index of what is available so it knows what to ask for.

3. Keep a running plan outside the chat. For long tasks, have the agent write its plan and progress to a file or structured note, and read it back at each step. This survives summarisation and keeps the goal in view.

4. Compress history deliberately. After a set number of turns, replace older turns with a summary that keeps decisions, facts and open questions. Keep the most recent turns verbatim.

5. Trim tool output. A database query that returns 2,000 rows should not land in the context as 2,000 rows. Return a count, a sample and a way to fetch more.

6. Give sub-agents their own context. When you delegate, pass the sub-agent a focused brief, not the whole conversation. Pass back a short result, not its full transcript.

7. Tag everything with its source. Mark each retrieved chunk or memory with where it came from. It makes debugging, and trust, much easier.

A minimal structure for a single agent step might look like this:

[stable — cached]
  system instructions
  tool definitions (only the tools this agent needs)

[task]
  goal and success criteria
  current plan and progress (read from the plan file)

[selected context]
  3–5 retrieved chunks, each with source + date
  summary of earlier turns
  last 4 turns verbatim

[current input]

Context engineering is necessary, not sufficient

One honest caveat from the paper: perfect context does not guarantee good decisions. An agent can see exactly the right data and still optimise the wrong goal. That is why clear goals, success criteria and checks on the agent’s output still matter. Context engineering makes good behaviour possible. It doesn’t make it automatic.

Where to start

  • Pick one agent you already have and log its full context at a few steps. Most teams are surprised by what is actually in there.
  • Run the five-point checklist on each logged context and note which criterion fails most.
  • Fix the biggest offender first. It is usually oversized tool output or unsummarised history.
  • Add a small evaluation set so you can see whether each change actually helps.

In the next posts we go deeper on two of the four operations: compression, and how agents orchestrate sub-agents with isolated contexts.

context engineeringAI agentsmemoryRAG