← ELI5 · Nestor G Pestelos Jr

What Is Context Engineering?

Why packing the AI's desk neatly matters more than asking pretty questions.

Card 1 of 5

1. The Desk Problem: The AI Only Sees What Is On Its Desk.

Every time you ask an AI a question, it starts completely fresh. Its desk (the context window) can hold thousands of words, but if you dump mountains of messy papers on it, it gets slow and confused.

🗑️ Messy Dump (50k tokens)
Dumps 20 entire code files. AI misses your bug and costs $0.50 per click.
✨ Engineered Desk (2k tokens)
Places only the exact broken function and rule. AI solves it in 1 second.
What is context engineering?
It is the discipline of carefully selecting, trimming, and arranging the exact pieces of information placed on the model's desk before it runs.
Card 2 of 5

2. The Four Compartments of a Perfect Prompt.

Instead of writing one messy paragraph of text, high-performance prompts are divided into four neat boxes.

1. Who You Are
(Role & Persona)
2. The Mission
(Task & Inputs)
3. The Rules
(Never do X, check Y)
4. The Output
(Exact JSON / Schema)
Why separate rules and task?
When rules are mixed into task descriptions, models often skip them. Putting negative constraints in their own dedicated rules section guarantees high compliance.
Card 3 of 5

3. The "Lost in the Middle" Sandwich.

Language models pay the most attention to the very beginning and the very end of a document. If you hide crucial facts in the middle, it is likely to ignore them.

🍞 Top (First 15%): Rules & Identity ⭐ 98% Recall
🥗 Middle (60%): Massive Raw Notes & Logs ⚠️ 50% Recall (Lost!)
🍞 Bottom (Final 15%): Current Question ⭐ 99% Recall
How to fix the middle?
Never dump giant unsorted files into the middle. Summarize documents into short atomic notes before placing them in the payload.
Card 4 of 5

4. The Three Tiers of Memory.

Smart AI systems don't keep everything in active chat. They organize memory like a human brain across three distinct drawers.

1. Short-Term (Working Chat): The last 5 messages you just typed.
2. Medium-Term (Daily Log): Work logs and git commit summaries of what was done today.
3. Long-Term (Vault Library): Curated atomic notes and encyclopedia rules retrieved only when asked.
Why not keep everything in chat?
Long chats get contaminated with old mistakes. Storing facts in external notes keeps each fresh session fast, clean, and reliable.
Card 5 of 5

5. Clean Chat, Sharp Answers.

When an AI starts repeating errors or hallucinating in a long conversation, the agent didn't get dumber—the chat got contaminated. Clear the desk and re-anchor!

Cluttered 40-Turn Chat
→ Compaction →
Fresh 1-Turn Re-Anchor
The Re-Anchor Rule
Before a critical step, summarize past progress to an external file, wipe the scratch buffer, and start fresh with only the summary.