The agent loop: reason, act, observe
The engine every agent runs on, and the ground-truth feedback that makes it work.
Strip away the frameworks and an agent is, in Anthropic's words, "just LLMs using tools based on environmental feedback in a loop." That loop is the engine. Understand it directly before you touch any library.
The cycle is reason → act → observe → repeat:
- Reason — the model looks at the goal and current state and decides the next action.
- Act — it calls a tool (search, run code, hit an API).
- Observe — your code executes the tool and feeds the real result back into the model's context.
- Repeat — with that new information, the model reasons again — until it decides it's done or hits a stop condition.
The word that makes this work is observe. Anthropic stresses that agents must gain "ground truth" from the environment at each step — a tool result, a code-execution output, an error. That grounding is what separates an agent from a model spinning a plausible story: reality gets injected every cycle and corrects course.
Mechanically, tool use is the pivot. You call the model with a list of available tools; it returns a tool-use request with a tool name and arguments; your code runs it and returns the result; the model continues. A small runner repeats this until there's a final answer with no tool call. That's it — the "magic" of agents is a while loop around a model that can request tool calls.
One concrete trap to bank now: frameworks reset the tool choice to "auto" after each call for a reason. If you force the model to call a specific tool and then feed the result back, it will call that tool again — and again — forever. Forced tool choice inside a loop is a classic infinite-loop source. We'll return to failure modes in Module 3, but notice how early the sharp edges appear.
Because the loop is so simple, the interesting engineering isn't the loop itself — it's everything around it: what tools you provide, how you manage the growing context, when you stop, and how you verify. The rest of the course is those decisions.
On paper, trace the loop for 'find the cheapest flight and summarize it': write the reason/act/observe steps for two iterations. Mark where 'ground truth' enters and where the loop could fail to terminate.
Enjoying the free lessons? Get an email when we publish new courses and updates — no spam, unsubscribe anytime.
Discussion (0)
Ask a question or share what worked for you. Comments are reviewed before they appear.
No comments yet. Be the first to start the discussion!