esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Context Engineering vs Prompt Engineering?

What context engineering is, how it differs from prompt engineering, and why agents need it, explained simply for your AI interview.

In short

Prompt engineering is writing the instructions a model gets. Context engineering is choosing everything the model sees on each turn, including those instructions, the tools, the search results and the chat history.

11 min readIntermediateVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Prompt engineering is writing the instructions a model gets. Context engineering is choosing everything the model sees on each turn: the rules, the tools, the search results and the chat so far. Anthropic calls it the natural progression of prompt engineering. A good prompt still matters, but an agent that loops fills its window fast, so I manage what goes in, every turn.

What is context engineering, in plain words?

Prompt engineering is the craft of writing the instructions you give a model: the wording, the examples and the output format you ask for. You do it once, test it, and tweak it when the answers drift.

Context engineering is wider. Context means everything the model can see when it writes its next answer: the standing rules, the tool list, the documents a search pulled up, the customer's record and the chat so far. The engineer's job is to choose what goes in, what gets trimmed and what stays out. That choice runs again on every turn.

Think of a new claims handler on day one. The prompt is the brief from their manager. The context is the whole desk: the policy binder, the open claim file, yesterday's call notes. A good brief helps, but a handler buried under a binder of 300 pages still misses the one clause that matters.

Key words

Context window
The text a model reads in one go. What is in it is what the model can use for this answer, on top of what it learned in training.
System prompt
The standing instructions the developer writes. The user usually cannot see them.
Context rot
Recall gets less reliable as the window fills with more tokens.
Compaction
Summarising a long chat, then starting the window again from that summary.
Tool
A function the model can ask your code to run, such as a policy search. The result comes back as new text.
  • “At Anthropic, we view context engineering as the natural progression of prompt engineering.”

    Anthropic

  • “most people's inferred definition is that it's a laughably pretentious term for typing things into a chatbot”

    Simon Willison

How does this show up in a real product?

Take a card dispute bot at a mid-size bank. Its prompt says to answer only from the fee table and never to promise a refund amount. Prompt engineering makes that wording clear and tests it. Context engineering decides what the bot sees on each turn.

  • Prompt engineering

    Writing the rules

    Wording, examples and output format. Done once, then tested and tuned.

  • Context engineering

    Choosing the input

    Which rules, which records, which search results and how much history, on every turn.

What the model sees on one turn

What could go in

Standing rules

the system prompt, sent every turn

Customer record

tier and open disputes

Search results

policy text matched to this question

Chat so far

forty messages, most of them old

Your app curates

Pick and trim

keep what this turn needs

Summarise old turns

a short block of decisions

Model

reads one window per turn

Grounded reply

cites the rule and the table

  1. 1Your standing rules go in on every turn.
  2. 2The customer's tier and open disputes decide what the bot may promise.
  3. 3Search pulls in the policy paragraphs that match this question.
  4. 4Old messages are folded into a short summary.
  5. 5The summary goes in as one block, so the window stays small.
  6. 6The chosen pieces go in together, nothing else.
  7. 7The model writes a reply grounded in what it was given.
Each turn, the bot's code gathers pieces from several places and trims them to fit. The model sees only that selection and writes a reply grounded in it. The prompt is one of those pieces. Choosing the others is context engineering.

Anthropic defines context engineering as the strategies for curating and maintaining the optimal set of tokens during LLM inference, including everything that lands in the window outside the prompt. That last part is the point: the prompt is only one input.

A worked case: a customer writes, "I was charged twice for the same card payment last week." On turn 12, the window holds the standing rules, the fee table, this customer's open dispute and the last two messages. The forty older messages and a banner about summer offers are cut. The bot can answer, because the right table is there and nothing competes with it.

Why does it matter more as agents run longer?

A one-shot task has one prompt and one answer. An agent loops: it reads, calls a tool, reads the result and calls again. Anthropic's short definition is LLMs autonomously using tools in a loop. Each loop adds text to the window, so the window fills up.

Anthropic describes context as a finite resource with diminishing returns. Its article calls the decline context rot, a concept that needle-in-a-haystack studies uncovered: as the window grows, the model recalls less reliably what is in it. Anthropic expects context pollution, meaning old or irrelevant text crowding out the useful text, to stay a concern for the foreseeable future, at least where the strongest agent performance is wanted.

Keeping a long task on track

Piles up on a long task

Full test log

most lines say nothing new

Old tool results

read once, never needed again

Trimmed on each turn

Decision summary

choices and open bugs

File paths only

opened when a step needs them

Model

reads a small, relevant window

Stays on task

fewer wrong turns late on

  1. 1The long test log is cut down to the failing test and its error.
  2. 2Old tool results are swapped for the path of the file they came from.
  3. 3The decision summary goes in as one short block.
  4. 4File paths go in too. The file is opened only when a step needs it.
  5. 5The model keeps its thread through a long task.
On a long task, raw tool output piles up. Trimming keeps a short summary and file paths, so the model reads a small, relevant window and keeps its thread.
  1. 1

    Compact old turns

    When the window nears its limit, summarise the chat. Claude Code, Anthropic's coding agent, passes the history to the model to compress it, and the model keeps decisions and open bugs while dropping repeated tool output.

  2. 2

    Load on demand

    Keep file paths and search queries in the window, and open a file only when a step needs it. Anthropic notes the trade-off: runtime exploration is slower than retrieving pre-computed data, so the choice depends on the task.

  3. 3

    Keep the tool set small

    A bloated tool set is one of the most common failure modes. If a person can't say which tool to use, the agent can't either.

Here is a small demo. A made-up support bot has six pieces of text competing for one turn's budget. The curator keeps the highest-scoring pieces that fit. The numbers are invented; a real system scores pieces with search and rules.

Python
# A made-up support bot's budget for one turn: keep the most useful pieces that fit.
BUDGET = 1000
pieces = [
    ("Standing rules", 300, 10),
    ("Customer's open dispute", 200, 9),
    ("Fee table paragraph", 250, 8),
    ("Last 2 messages", 150, 7),
    ("Old chat from 3 weeks ago", 400, 2),
    ("Marketing banner text", 180, 1),
]

def curate(pieces, budget):
    kept, used = [], 0
    for name, tokens, score in sorted(pieces, key=lambda p: -p[2]):
        if used + tokens <= budget:
            kept.append(name)
            used += tokens
        else:
            print("Dropped:", name)
    return kept, used

kept, used = curate(pieces, BUDGET)
print("Kept:", ", ".join(kept))
print("Used", used, "of", BUDGET, "tokens")

Output

Dropped: Old chat from 3 weeks ago
Dropped: Marketing banner text
Kept: Standing rules, Customer's open dispute, Fee table paragraph, Last 2 messages
Used 900 of 1000 tokens

How would you fix an agent that forgets a rule after 40 turns?

  1. 1

    Log what the model received

    On the failing turn, print exactly what went into the window. Sometimes the rule was trimmed away, not forgotten by the model.

  2. 2

    Pin the rule

    Put the refund rule in the standing instructions, not in a chat message, so no summary or trim can remove it.

  3. 3

    Replay the long chat

    Run the same 40 turns in an automatic test and check the rule is still applied. Keep the test, so the next change can't break it quietly.

Tip

Say honestly that a longer window alone won't fix it. Choosing what goes in, and testing long chats, is what fixes it.

What does the interviewer want to hear?

A strong answer covers

  • Prompt engineering is the wording of the instructions. Context engineering is everything the model sees on each turn.
  • Why it is wider: agents loop, so the window keeps filling.
  • Context rot: recall falls as the window grows.
  • Tools: keep the set small and clear, since each result adds text.
  • Compaction and loading on demand: how long tasks stay on track.
  • A real case from your own work, with the trade-off you chose.

Common traps

  • Trap"Context engineering is just a new name for prompt engineering."

    BetterAnthropic calls it the natural progression, but the job is wider: it covers the whole input on every turn.

  • Trap"A longer system prompt fixes the memory problem."

    BetterA longer prompt adds to a window that is already filling up. Trim, pin and test instead.

  • Trap"Bigger context windows make this problem go away."

    BetterAnthropic expects context pollution to stay a concern for the foreseeable future, so choosing what goes in still matters.

Can you spot the problem?

Spot the problem

A claims agent answers well on day one and badly on day two. Which setup shows the problem?

Quick check

A card dispute bot is fine for one question but drifts after 40 turns of chat. What is the best fix?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q080What goes in a system prompt?11 min
  2. Q081What makes a good prompt?13 min
  3. Q083What is "context rot"?10 min
  4. Q084What is "lost in the middle"?11 min
  5. Q088What is prompt caching, and how does it save money?13 min

Learn it in depth

Last updated on 26 November 2026

Building an agent that runs for hours?

I design and build AI products and agents, including the context and the system behind them. Book a short call and tell me what your agent has to remember and what it must never see.