Part 4 · Engineering Patterns for Reliable Agents

From Prompt Engineering to Context Engineering

Curating the optimal Token combination for each inference round — prompt writing is just one piece

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

What is the key idea behind “From Prompt Engineering to Context Engineering”?

Curating the optimal Token combination for each inference round — prompt writing is just one piece

DECISION RULE

Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.

TRY NEXT

Write one question you could answer with evidence after trying this idea.

WATCH FOR

A conclusion that sounds complete but leaves the key assumption untested.

Conceptual Evolution
Past
Prompt Engineering
Optimizing how prompts are written: wording, structure, Few-shot examples
Now
Context Engineering
Curating all Tokens sent to the model at each inference step: System Prompt, tool definitions, MCP descriptions, conversation history, externally retrieved data...

Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how much of it there is. When your system has a System Prompt, tool descriptions, message history, RAG retrieval results, and user preferences — these can fill up most of the context window. Managing those Tokens is what context engineering is all about.

What's Inside the Context Window
System Prompt — Role definition, rules, constraints
Tool Definitions — Tool names, parameters, descriptions
Conversation History — Multi-turn dialogue history
Retrieved Data — RAG retrieval results, file contents
User State — User preferences, session state, environment info
All of the above combined = the complete information the model sees at each inference step
Why Context Engineering Matters
Context Rot
The longer the context, the lower the model's retrieval accuracy. Key information gets buried in a sea of Tokens.
Limited Attention Budget
Every Token consumes part of the model's attention budget. Irrelevant Tokens take up space = useful information gets diluted.
n-squared Complexity
n Tokens produce n×n attention relationships. Double the context, and compute cost quadruples.
Try It: Context Rot Simulator
1K Tokens
1K Tokens — a short conversation
Attention focused, retrieval accurate
Retrieval Accuracy
95%
0%50%100%
Attention Density
High attention Low attention
Understanding the Cost of Attention
In the Transformer self-attention mechanism, each Token must compute its relationship with every other Token:
Attention Complexity = O(n^2)
This means: extending the context from 50K to 100K Tokens causes attention compute cost to grow 4×, far more than doubling. Context is not free: every extra irrelevant Token wastes attention that could go to other Tokens.
Three Principles for Efficient Context
The Right Height for Your System Prompt
Too vague ("you are a helpful assistant") = the model lacks direction, outputs generic responses.
Too specific (listing 50 edge cases) = the model is over-constrained and can't handle novel situations.
Best practice: provide a clear role and core principles (5–10 items), then trust the model to make its own judgments within that framework. Like a good manager: give direction, not step-by-step instructions.
Too low
Too vague
"You are an assistant"
Just right
Sweet spot
Role + principles + boundaries
Too high
Too specific
50 rules + 100 edge cases
Finding the sweet spot in the middle is the goal for System Prompt length
Keep Your Toolset Lean
Validated in production: if a human can't tell which tool to use, neither can the AI.

Giving an Agent 10 tools with overlapping capabilities and vague descriptions is worse than 5 tools with clear responsibilities and precise naming. Each tool's description should read like good API documentation — the caller (the model) should know immediately when to use it and how.
Curate Few-shot Examples — Don't Pile Them Up
Few-shot examples have the highest ROI of anything in the context, but only if you choose the right ones.

Right approach: curate 2–3 highly representative examples that cover the most common input patterns.
Wrong approach: pile on 10+ edge-case examples, which wastes Tokens and causes the model to over-focus on edge cases while neglecting the main use case.
Context is a scarce resource. Your goal is to find the minimal high-signal Token set. Every Token must contribute to the model's reasoning — the "throw everything in" approach doesn't work. Edit your context the way an editor refines an article: every unnecessary word is noise.

Why “Conceptual Evolution” can find relevant content

“Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how…” moves retrieval beyond storing material: the real question is how to find what is relevant. That decision shapes the input quality of RAG, recommendation, and image-search systems.

Similarity is not the answer

In the flow described by “Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how…”, embeddings place items in a comparable semantic space and a neighbor index narrows the search. The final answer still depends on whether the retrieved chunks cover the question, whether the distance metric fits, and whether the evidence is current.

Separate findable from relevant

Turn “Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how…” into a small test: prepare queries with known answers, record relevance, misses, and distractors, then decide whether chunking, the index, or reranking needs to change.

From “Conceptual Evolution” to “What's Inside the Context Window”

“Conceptual Evolution” grounds the problem in “Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how much of it there is . When you…”. “What's Inside the Context Window” then moves it toward “System Prompt — Role definition, rules, constraints Tool Definitions — Tool names, parameters, descriptions Conversation History — Multi-turn dialogue history Retrieved Data — RAG retrieval results, file conten…”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

The same logic applies to retrieval: define what counts as relevant, check whether recall covers the question, and then inspect whether ranking, chunking, or freshness pushed useful evidence out.

  • “Conceptual Evolution”: Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how much of it there is . When you…
  • “What's Inside the Context Window”: System Prompt — Role definition, rules, constraints Tool Definitions — Tool names, parameters, descriptions Conversation History — Multi-turn dialogue history Retrieved Data — RAG retrieval results, file conten…
  • “The closing point”: Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how much of it there is . When you…

The final “The closing point” brings the discussion to “Prompt engineering focuses on how to write instructions, while context engineering addresses a larger question: what goes into the model's input window, how it's arranged, and how much of it there is . When you…”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing From Prompt Engineering to Context Engineering Engineering Patterns for Reliable Agents
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful