Phase 3 — Core AI Engineering · Lesson 33 · 20 XP
Agents: the tool-use loop
An agent is an LLM run inside a loop: call the model, let it decide whether to call a tool, execute that tool if requested, feed the result back, and repeat — until the model produces a final answer instead of another tool call. This is Lesson 23's single tool call, extended into a loop instead of one round trip.
Without a stopping condition, a misbehaving loop could call tools forever. Real agent loops need a hard limit — a max number of iterations, or an explicit "done" signal the model returns — so a bad run fails safely instead of running (and costing money) indefinitely.
Exercise
Extend your Lesson 23 tool-use code into a real loop that keeps calling the model and executing tools until it returns a final text answer, with a max-iteration safety limit that stops the loop and reports failure if it's ever hit.
Check yourself
1. What stops an agent loop from running forever, and why is that limit necessary?
2. What's the actual difference between a single tool call (Lesson 23) and an agent?
Evals II: LLM-as-judge and regression testing
Answer the check-yourself questions to unlock this