AI Agent Book: a study map for agent engineering
How the context experiment is structured
Follow messages and tool results through the chapter-1 agent loop.
What you will learn
- Modes alter what is retained
- Tools are part of the state
- The runner checks the contract
Before you start
- Python environment basics
- Access to a supported model provider for live experiments
Turn one context lesson into a documented experiment and design decision.
Key takeaways
- Context modes must be verified in sent messages.
- Tools change the trajectory, not just the final answer.
- The runner separates contract checks from outcomes.
Modes alter what is retained
agent.py defines ContextMode values for full context and several ablations. The experiment compares what happens when history, reasoning, tool calls or tool results are withheld.
These labels describe implementation choices. Check the messages sent to the provider; a label alone cannot establish that a particular piece of information was absent.
Tools are part of the state
The inspected code registers calculator, currency, PDF and code-interpreter tools. Tool calls and results can affect subsequent model turns, so removing one type of message changes the loop itself.
A live provider may behave differently from a stub or mock. Keep the provider and model ID in any comparison report.
The runner checks the contract
run_experiment_1_1.py inspects recorded turns to see whether the intended context condition holds, then summarizes outcomes and token use. That is stronger than comparing final prose alone.
The architecture diagram is derived from source inspection, not a captured runtime trace. We did not execute the runner.
Decision guide
| Criterion | Option A | Option B |
|---|---|---|
| Best when | You need predictable behavior and easy auditing | You need adaptive optimization and have reliable telemetry |
| Main risk | May leave performance on the table | Can become difficult to explain or debug |
Implementation steps
- 1
Find ContextMode and the message assembly branch.
- 2
Trace one tool result back into a later request.
- 3
Read the runner contract check before interpreting scores.
Copy-ready example
Input -> context mode -> model request -> tool call/result -> next request -> evidenceFrequently asked questions
Does no_tool_results remove the tool itself?
Inspect the selected mode and recorded messages; it concerns what results are retained.
Can this diagram prove the experiment works?
No. It is a source-based map that needs a live reproduction.
Sources
- AI Agent Book / chapter1/context/README.mdSource checked 2026-09-26
- AI Agent Book / chapter1/context/agent.pySource checked 2026-09-26
- AI Agent Book / chapter1/context/run_experiment_1_1.pySource checked 2026-09-26