Context Engineering: The Skill Behind Reliable LLM Applications
Context engineering explained: deciding what goes into an LLM context window — instructions, examples, retrieved data, tools, memory — and how to keep it lea...
Published December 1, 2026
Prompt engineering focused on wording. As LLM apps became agents with tools, memory and retrieval, a broader skill emerged: context engineering, the discipline of assembling exactly the right information into the model's context window at each step. Most failures of capable models are not intelligence failures but context failures: missing facts, too much noise, contradictory instructions or stale data.
The concept
The context window is a finite, expensive and attention-limited resource. Everything competes for it: system instructions, tool definitions, examples, conversation history, retrieved documents, tool results and memory. Research and practice both show that models can miss relevant details buried in very long contexts, so more is not automatically better.
Context engineering asks, for every step: what does the model need to know to do this well, and what can be left out? Techniques include retrieval instead of preloading, summarising tool output, compacting history, structuring context with clear sections, loading instructions just in time, and isolating sub-tasks in sub-agents with their own clean context.
Anatomy of a context window
Common context failures
| Failure | Symptom | Fix |
|---|---|---|
| Missing context | Confident but wrong answers | Retrieve or provide the needed facts |
| Context overload | Ignores key details, slow, costly | Retrieve less, summarise tool output |
| Conflicting instructions | Inconsistent behaviour | Single source of truth for rules |
| Stale context | Outdated answers | Refresh indexes, timestamp facts |
| Tool overload | Wrong tool chosen | Fewer, clearer tools; load tools per task |
Checklist
- Write down what the model must know for this step
- Prefer retrieving over preloading
- Trim tool results to what matters (fields, top rows)
- Compact history when it grows
- Structure with headings or XML-style tags
- Evaluate: does removing a section change results?
Practical examples
Structured context with tags
Clear sections help the model use each part correctly.
<instructions>You are a support assistant. Answer from <docs> only. Cite doc IDs.</instructions>
<customer>plan=Pro, region=IN, open_tickets=1</customer>
<docs>
<doc id="kb-114">Pro plans include SSO via SAML…</doc>
</docs>
<question>Can I enable SSO on my plan?</question>Trim a tool result before returning it to the model
Return the fields that matter, not the whole API payload.
def get_order(order_id):
o = api.orders.get(order_id) # 4 KB of JSON
return {"id": o["id"], "status": o["status"], "total": o["total_display"],
"items": [i["name"] for i in o["items"]][:10], "updated": o["updated_at"]}Just-in-time instructions
Load detailed guidance only when the task needs it.
if task.type == "sql":
context.append(load("guides/sql_style.md")) # not included for other tasksCommon mistakes
- Dumping entire documents or API responses into context.
- Ever-growing system prompts that accumulate contradictory rules.
- Giving the model 50 tools when the task needs 5.
- Never testing which parts of the context actually help.
Key takeaways
- Context engineering = choosing what the model sees at each step.
- More context is not better; relevant context is.
- Retrieve, trim, compact, structure and isolate.
- Evaluate context changes like code changes.
FAQ
How is this different from prompt engineering?
Prompt engineering is part of it. Context engineering also covers retrieval, tool design, memory and history management across many steps.
Do long-context models remove the need for this?
They raise the ceiling but not the principle: focused context is cheaper, faster and usually more accurate.
What is the "lost in the middle" problem?
A tendency for models to use information at the start and end of long contexts better than information buried in the middle.