Chapter 6: Context Engineering
Lecture
Chapter principle
Key takeaways
- Information can exist in the system without being visible to the model.
- Context engineering is broader than prompt wording.
- Context must be sufficient before it can be considered efficient.
- Selection policies can cause failures independently of model reasoning.
- Ordering, provenance, trust, and budget are part of context design.
Experiments
Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.
Experiment 11: How much context?
Does more context help the model find the answer?
Can order #17 be refunded? It was bought 33 days ago and the refund window is 30 days, so the answer is no. The question is asked with order 17 alone, then with order 17 among 999 similar orders (first, at position 750, and last), and finally with order 17’s refund window left out. Each version is asked three times, and software reads the label each reply starts with. This is a recorded run of a real model. A new run may answer differently, especially at position 750.
Experiment 12: Choosing what goes in
What happens if the wrong facts are chosen for the context?
Four facts are known about order #17, each with a relevance score. A simple selection policy keeps the two highest-scoring facts and hands only those to the model, which answers five times. Then the same policy runs on a corrupted ranking that scores the customer’s Gold tier above the refund window. This is a recorded run of a real model. With the corrupted ranking, a new run may answer quite differently.
All the code for this chapter: github.com/agentic-engineering-book/code
Download the bookBrowse all chapters