# 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.

AI and LLM interview question Q082, Prompt and context engineering. Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/context-engineering-vs-prompt-engineering

## Say it in 30 seconds

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.

## Say it in 2 minutes

Prompt engineering is the craft of writing the instructions a model gets: the wording, the examples and the output format. You write it once, test it and tune it when answers drift. Context engineering is wider. It is the job of choosing everything the model sees on each turn, from the standing rules to the documents a search found and the chat so far.

Why it matters now: a simple chatbot answers one message at a time, but an agent loops. It reads, calls a tool, reads the result and calls again. Every loop adds text, and the window fills. Anthropic's article calls context a finite resource, and it names the decline context rot: recall gets less reliable as the window fills.

So most fixes change the input. Pin the rules, so trimming can't remove them. Load files only when a step needs them. Summarise old turns into a short block of decisions and open bugs. Keep the tool set small and clear. For a card dispute bot, that means the fee table and the open dispute go in, and forty old messages stay out.

My answer in an interview: the prompt is one part of the context. I'd start with a minimal prompt, log exactly what the model receives on each turn, and test long chats, because most failures show up after many turns.

## 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.

- **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.

*Diagram, What the model sees on one turn: 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.*
1. Your standing rules go in on every turn.
2. The customer's tier and open disputes decide what the bot may promise.
3. Search pulls in the policy paragraphs that match this question.
4. Old messages are folded into a short summary.
5. The summary goes in as one block, so the window stays small.
6. The chosen pieces go in together, nothing else.
7. The model writes a reply grounded in what it was given.

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.

*Diagram, Keeping a long task on track: 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. The long test log is cut down to the failing test and its error.
2. Old tool results are swapped for the path of the file they came from.
3. The decision summary goes in as one short block.
4. File paths go in too. The file is opened only when a step needs it.
5. The model keeps its thread through a long task.

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. **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. **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:

```text
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. **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. **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. **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." Better: Anthropic 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." Better: A 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." Better: Anthropic 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?

A. Tone: replies sound stiff. Fix: reword the system prompt.
B. Length: each reply runs to four paragraphs. Fix: add a word limit to the system prompt.
C. Every turn: the full 300-page claims manual and all 80 past chats go in. Fix: keep only the clause and the claim that matter.
D. Greeting: every reply opens with 'Dear valued customer'. Fix: reword the system prompt.

**Answer:** C. The tone, length and greeting problems are wording problems, so a better prompt helps. The third option is a context problem: the one clause that matters is buried under pages and old chats, which is context rot in practice. Fix what goes in, on every turn.

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

A. A bigger model
B. Summarise old turns, and keep the standing rules and the live dispute in the window
C. A longer system prompt with more rules
D. A lower temperature

**Answer:** B. The drift comes from what the window holds. Summarising old turns and keeping the rules and the live dispute changes the input itself. A bigger model or a longer prompt adds more to a window that is already full, and temperature changes randomness, not what the model can see.

## Can you answer these from memory?

**Flash cards**

- **What is prompt engineering?** Writing the instructions a model gets: wording, examples and output format.
- **What is context engineering?** Choosing everything the model sees on each turn, not only the instructions.
- **How does Anthropic describe it?** The natural progression of prompt engineering.
- **What is context rot?** Recall gets less reliable as the context window fills with tokens.
- **What is compaction?** Summarising a long chat, then starting the window again from the summary.
- **Why does it matter for agents?** An agent loops through tools, so the window fills with every step.

## Likely follow-up questions

- Q080 What goes in a system prompt? https://designervenkat.online/interview/ai/what-goes-in-a-system-prompt
- Q081 What makes a good prompt? https://designervenkat.online/interview/ai/what-makes-a-good-prompt
- Q083 What is "context rot"? https://designervenkat.online/interview/ai/what-is-context-rot
- Q084 What is "lost in the middle"? https://designervenkat.online/interview/ai/what-is-lost-in-the-middle
- Q088 What is prompt caching, and how does it save money? https://designervenkat.online/interview/ai/what-is-prompt-caching

## Learn it in depth

- [Context Engineering](https://designervenkat.online/learn/ai-engineering/context-engineering)
- [Context Compaction](https://designervenkat.online/learn/ai-engineering/context-compaction)
- [Context Failure Modes](https://designervenkat.online/learn/ai-engineering/context-failure-modes)
