58 of 58
ContentsAppendix G

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)

  1. Read everything on the desk (the context window).
  2. Score every possible next token: how likely is each one?
  3. Pick one. The temperature setting decides how adventurous the pick is.
  4. Add it to the text.
  5. Done? If not, go back to step 2.

The agent loop (Chapter 10 and Chapter 11)

  1. You ask a question.
  2. The harness builds the briefing: its instructions, your message, notes it keeps and earlier results.
  3. The model reads the briefing and predicts a reply: either an answer, or a request for a tool.
  4. For a tool request, the harness checks the rules, asks you if needed, and runs the tool.
  5. The result goes back into the briefing, and the model reads it again. This loop repeats until the job is done.
  6. The harness hands the final answer back to you.

Appendix G · page 3 of 3

Turn pages with the ← and → keys.

Cite this page

Using this book

© 2026 Steve Sparks. All rights reserved. You're welcome to quote short passages and cite any page, with a link back. To reuse diagrams or larger parts, ask through GitHub.

Quoted material and figures from other sources remain their owners'.