Appendix GWorkbench: code and flowcharts
The two loops, as flowcharts
Two loops run everything in this book: the model's loop, which writes one token at a time, and the agent loop, which lets a model use tools. Here they are on paper.
Predict, pick, repeat (Chapter 2)
- Read everything on the desk (the context window).
- Score every possible next token: how likely is each one?
- Pick one. The temperature setting decides how adventurous the pick is.
- Add it to the text.
- Done? If not, go back to step 2.
The agent loop (Chapter 10 and Chapter 11)
- You ask a question.
- The harness builds the briefing: its instructions, your message, notes it keeps and earlier results.
- The model reads the briefing and predicts a reply: either an answer, or a request for a tool.
- For a tool request, the harness checks the rules, asks you if needed, and runs the tool.
- The result goes back into the briefing, and the model reads it again. This loop repeats until the job is done.
- The harness hands the final answer back to you.
Appendix G · page 3 of 3
Turn pages with the ← and → keys.