Agentic Engineering from First Principles All chaptersLecturesLabDownload the book
Part II · Giving Agents Abilities

Chapter 6: Context Engineering

Central questionWhat information should the model see at this decision, and what should be left out?

Lecture

Chapter principle

More context is not better context. Better context contains the information needed for the current decision, while controlling noise, cost, risk, and omission.

Key takeaways

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

This is Chapter 6 of Agentic Engineering from First Principles: thirty chapters, a case study and fifty-nine executable experiments, from a single model call to controlled, self-improving agents.
Download the bookBrowse all chapters
← Chapter 5: ToolsChapter 7: Retrieval and RAG →