Lesson 03.01 · Phase 03 · The Agent Loop
The agent loop in 120 lines
An agent is a model in a while-loop with a toolbox. Everything else is scaffolding around that loop.
Learning objectives
- Name the three moves of every agent turn (think, act, observe) and what breaks when one is missing.
- Implement a complete agent loop with a tool registry, step budget, and stop conditions using only the standard library.
- Turn every tool failure into an observation the model can recover from, instead of an exception that kills the run.
- Swap a scripted model for a real one (Ollama, OpenAI, or any OpenAI-compatible server) without touching the loop.
Ask a model "How tall is Mount Everest in feet?" and you get a confident sentence back. Maybe it's right, maybe the conversion is off by a few hundred feet. The model can't look anything up or check its own arithmetic. It can only produce text.
Loading the full lesson…