Context Engineering vs Prompt Engineering: What Changes
What context engineering is and how it differs from prompt engineering: what goes into context, budgets, ordering, compaction and how to evaluate it.
Topics:Cost and production
A team spends a week polishing a prompt. The wording is crisp, the instructions are clear, and in testing the assistant answers well. In production it forgets a constraint the user stated ten turns ago, quotes a retrieved document that is out of date and gets slower and more expensive every day. The prompt was fine. What the model was shown around the prompt was not.
TL;DR
Prompt engineering is about writing the instructions. Context engineering is about deciding everything the model sees on each call: instructions, conversation history, retrieved documents, memory, tool results and examples, and how they are selected, ordered, trimmed and refreshed. As systems add retrieval, memory and tools, the context becomes the larger and more fragile part. Treat it as something you design, budget and evaluate, not as a prompt you tune once.
Two layers of the same problem
The terms overlap, and the distinction is about scope. Prompt engineering is the craft of wording instructions and examples so the model behaves as intended. Context engineering is the system around it: gathering, filtering and arranging the information that goes into each request.
Prompt engineering
- Writing the instructions, role and examples
- Mostly static text you edit and test
- Questions: is it clear, specific and well structured?
- Fits a single, self-contained request
Context engineering
- Deciding everything the model sees on each call
- Dynamic: built from retrieval, history, memory and tool output
- Questions: what should be included, excluded, summarised and when?
- Matters most as systems grow beyond one-shot requests
You still need good prompts. Context engineering does not replace them; it recognises that a good prompt surrounded by the wrong context still produces the wrong answer. The prompt engineering chapter covers the first layer and the context engineering chapter covers the second.
What goes into context
Every call assembles a set of inputs. Naming them helps you decide what each deserves.
Step 1: Instructions
The system prompt: role, rules, format and constraints
Step 2: The conversation
Recent turns, and a summary of older ones
Step 3: Retrieved knowledge
Documents or records fetched for this question
Step 4: Memory
Facts about the user or task that persist across sessions
Step 5: Tool results
The output of calls the model or application made
Step 6: Examples
Sample inputs and outputs that show the expected behaviour
Each ingredient has a different lifespan and trust level. Instructions are stable and trusted. Retrieved documents and tool results are dynamic, may be stale and can contain instructions you did not write, which is why prompt injection is a context problem as much as a prompt problem.
The context is a budget
A model can only read so much per call, and every token costs money and time. Treat the context window as a budget you allocate, not a bucket you fill.
If
Stable rules the model must always follow
Choose
Keep in the system prompt, kept short
Because
They apply to every call
If
Recent turns of the conversation
Choose
Keep verbatim
Because
They carry the details of the current exchange
If
Older turns
Choose
Summarise, and regenerate the summary every few turns
Because
Cheaper than the full history, but may lose detail
If
Retrieved documents
Choose
Include only the best few, ranked and trimmed
Because
Extra low-relevance text distracts the model and costs tokens
If
Long tool output
Choose
Extract what matters, or store it and reference it
Because
Raw output can swamp the useful signal
If
Examples
Choose
Include only those that measurably help
Because
Examples added during prototyping may never be revisited
The cost side is covered in how to reduce LLM costs, including summarising history, trimming retrieval and structuring prompts so a stable prefix can benefit from provider caching where it is offered. Check your provider's current documentation for how caching works and what it costs, since details change.
Selection, order and form
Three questions apply to each item you include.
What to include. Relevance beats volume. More context is not better context: irrelevant material can lower answer quality as well as raise cost.
Where to put it. Models may not attend to every part of a long context equally. Put the instructions that matter most where they are least likely to be lost, repeat critical constraints close to the question when it is long, and keep retrieved material clearly separated from instructions. Test arrangements on your own task rather than relying on a general rule, since behaviour varies between models.
In what form. Structure helps. Labelled sections, consistent formats and short, well-named fields are easier for a model to use than a wall of text.
Stuffed context
- The full conversation history is resent every turn
- Ten retrieved chunks are pasted in, most of them marginal
- Raw tool output is included in full
- Cost and latency grow with every turn, and quality drifts
Curated context
- Recent turns are verbatim and older ones summarised
- The three best chunks are included, labelled with their source
- Tool output is reduced to the fields that matter
- Size stays bounded and the model sees what it needs
Keeping context healthy over time
Long conversations and long-running agents face a specific problem: context accumulates. Without deliberate management, early instructions fade, irrelevant history crowds out relevant facts and costs rise.
- Summarise and compact. Replace old turns with a short summary, and verify the summary keeps the facts and constraints that matter.
- Separate memory from history. Store durable facts in structured memory and load only what is relevant, instead of replaying everything.
- Refresh retrieved material. Do not carry stale documents forward from earlier turns; retrieve again when the question changes.
- Reset when a task ends. Do not let one task's leftovers contaminate the next.
The agent loops and stopping conditions post covers how long runs go wrong, and how to build a 24/7 personal AI agent describes profile, task and episodic memory kept separate.
Evaluate context like code
Changes to context are changes to behaviour, so test them. When you change how history is summarised, how many chunks are retrieved or how they are ordered, rerun your evaluation set and compare per case. Include long-conversation cases, because short test questions will not reveal what gets lost over many turns.
Budget
Good: Each part of the context has an intended size, and the total is monitored
Red flag: The context grows until something breaks
Relevance
Good: Retrieved and tool material is filtered and ranked before inclusion
Red flag: Everything retrieved is included
Freshness
Good: Stale history and documents are dropped or refreshed
Red flag: Old material is carried forward by default
Trust
Good: Untrusted content is labelled and kept apart from instructions
Red flag: Retrieved text and instructions are mixed freely
Evaluation
Good: Context changes are tested on an evaluation set including long conversations
Red flag: Changes are judged by a few manual chats
LLM evaluation fundamentals explains how to build that set, and LLM observability shows how to record what was actually in the context for each request, which is the only way to debug a context problem.
Frequently asked questions
What is context engineering? The practice of deciding everything a model sees on each call: instructions, conversation history, retrieved documents, memory, tool results and examples, and how they are selected, ordered, trimmed and refreshed.
How is context engineering different from prompt engineering? Prompt engineering is about wording the instructions and examples. Context engineering is about the whole assembled input, which is dynamic and built from retrieval, history, memory and tools. You need both, and the second grows in importance as systems become more complex.
Does more context always improve answers? No. Extra or irrelevant material costs tokens and time and can distract the model, lowering answer quality. Relevance and structure matter more than volume.
How should I handle long conversations? Keep recent turns verbatim, summarise older ones and check the summary preserves the facts and constraints that matter. Store durable facts in structured memory and load only what is relevant instead of replaying everything.
Where should I put the most important instructions? Models may not attend equally to every part of a long context, so keep critical instructions where they are unlikely to be lost, and consider repeating key constraints near the question. Test arrangements on your own task, since behaviour varies between models.
How do I test context changes? Rerun your evaluation set when you change summarisation, retrieval counts or ordering, and compare per case. Include long-conversation cases, because short questions will not reveal what gets lost over many turns.
Why is context also a security concern? Retrieved documents and tool results can contain instructions the model may follow. Label untrusted content, keep it separate from instructions and limit what the model can do, as described in the prompt injection post.
Related
Prompts and context
Your next step
Reading is the start. Turn it into skill: read the chapter, practise on something real, check the numbers, then follow a path.
More on Cost and production
- LLM Gateways: What They Do and How to Choose OneWhat an LLM gateway does, when you need one and how to choose: authentication, routing, budgets, caching, logging and policy, with a vendor-neutral scorecard.
- Prompting, RAG or Fine-Tuning: A Decision GuideWhich technique first? A decision guide for prompting, RAG and fine-tuning: what each changes, what it costs to maintain and how to decide with an evaluation.
- What an AI Platform Engineer Actually OwnsWhat an AI platform team builds and runs: gateway, serving, evaluation pipelines, observability, cost and security, and where product teams take over.
Discuss this article
Got a question, a counter-example or a correction? Bring it to the community.
Prefer a feed reader? Follow by RSS.