← All courses

A Hands-On Course · 24 lessons

Context Engineering

Shape what your agent sees — attention, caching, compression, retrieval, and drift. The smallest set of high-signal tokens.

Short lessons (~5–8 min each), each with one tangible win and a retrieval-practice quiz. Built for engineers who already use AI coding tools and want the non-obvious mechanics.

Grounded in the agentpatterns.ai corpus (CC BY 4.0). Keep the Glossary open as you go.

Part 1 · Shaping the Prefix

1 The Dumb Zone Your agent gets dumber long before it runs out of room — and the safety net fires too late to help. 2 Lost in the Middle A perfectly-written rule in the wrong position is a rule the model is statistically likely to ignore. 3 Audit Your Harness Against the Curve A repeatable method for catching buried guardrails — run today on your own content/ harness. 4 The Five Moves Every completed turn is a fork in the road. Picking the right move is the core skill of context management. 5 Discoverable or Not The one test that decides whether a line earns a place in an always-loaded instruction file. 6 The Layer Stack Your instructions arrive from four sources at once. Knowing which one wins — and where it physically lands — is how you stop an agent from "ignoring" a rule. 7 The Immutable Prefix The same assembly order that shapes attention also sets your bill — and one careless byte in the prefix silently charges you full price on every turn. 8 Signal Per Token Compression isn't "write less." It's removing words that carry no meaning — and the curve that punishes you for stopping halfway.

Part 2 · Taming the Tail

9 Masking the Tail Most of what fills a long session is tool output you read once and never need again. Strip it, keep a breadcrumb. 10 Offload vs Summarise Two different moves get called "compaction." One is recoverable; one is lossy. Knowing which to reach for is the skill. 11 Just-in-Time Retrieval Don't preload what the agent can fetch when it actually needs it — but know the trade you're making. 12 Staying on Target Long sessions drift. Two defenses, mirror images of each other: push the goal forward, keep the failures behind. 13 Breaking the Stack A sub-agent starts from nothing. It inherits none of your project rules, skills, or history — unless you hand them over at the door.

Part 3 · Loading & Economics

14 Maps & Breadcrumbs Don't hand the agent raw files. Hand it topology to orient by, and plant the hints it will trip over on the way in. 15 Mind the Version Gap The model writes against the API it learned, not the one you've installed. Tell it which version is real, and the failures stop. 16 Every Token Has a Cost Context isn't free space to fill — it's a finite budget. Every token you preload is a token you can't spend on reasoning. 17 Assembling the Prompt A monolithic system prompt pays for every section on every turn. Build the context deliberately instead — per mode, per phase, by delta. 18 Measure Before You Optimize Every token-saving trick looks free on a token counter. On a real task, most of them quietly cost you accuracy — measure that, not just the savings.

Part 4 · Integrity & Operations

19 When the Window Lies Every lesson so far assumed the tokens in your window were honest. Some aren't — and the agent treats a hallucination or a planted instruction with exactly the same trust as your own words. 20 What's Eating the Window "Context is 80% full" tells you that you have a problem. It doesn't tell you which tool call caused it — so you prune blindly and often cut the wrong thing. 21 Prime the Pump Just-in-time retrieval pulls context when the agent needs it. Priming is the opposite move — deliberately loading the right files before you ask. Both are right; the trick is knowing which. 22 Remember, Don't Re-Read A long agent loop that replays its whole transcript every turn re-bills every prior observation on every call. Lift the record out of the transcript and the cost curve bends from quadratic to linear. 23 The Anxious Agent The dumb zone is the model getting worse as the window fills. This is the model acting like it's out of room — rushing to finish while plenty of space remains.

Capstone

24 The Whole Discipline Twenty-three lessons collapse into one sentence and one habit. Here's the whole map, and how to use it.