Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
Before the deep dives, it helps to hold the whole map in your head: the levers you can pull and the order to reach for them. The levers are select (what to include), order (where to place it), compress (shrink what you keep), cache (reuse what's stable), and measure (know if it worked). Most teams reach for 'bigger model' or 'better prompt' first; experienced context engineers reach for select and order first, because they're cheap and high-impact. This mental model is the spine of the rest of the course.
The toolkit as a priority list, encoded. When answer quality is poor, walk the levers top-down: is the right content selected? Is it ordered well? Only then consider compression, caching, and finally model/prompt changes. The function returns the next lever to try.
Use these three in order. Each builds on the one before.
What are the five core levers of context engineering (select, order, compress, cache, measure) and what does each one do?
Explain why 'select' and 'order' should usually be tried before 'bigger model' or 'better prompt' when answer quality is poor.
Turn the five levers into a production runbook: given a quality complaint, what do I check and in what order, and what evidence tells me to move from one lever to the next?
def next_lever(diagnosis: dict) -> str:
if not diagnosis["right_content_present"]:
return "SELECT: fix retrieval/inclusion — the evidence isn't even in the window"
if diagnosis["evidence_buried_in_middle"]:
return "ORDER: move key evidence to the start/end of context"
if diagnosis["over_budget"]:
return "COMPRESS: summarize history / prune low-value blocks"
if diagnosis["latency_or_cost_too_high"]:
return "CACHE: cache the stable prefix (system + tools + corpus)"
if not diagnosis["have_eval"]:
return "MEASURE: you can't tune what you can't see — build an eval first"
return "Only now consider a bigger model or prompt rewrite"
print(next_lever({"right_content_present": False, "evidence_buried_in_middle": False,
"over_budget": False, "latency_or_cost_too_high": False, "have_eval": False}))python3 main.py