An agent isn't magic — it's a loop: Reason → Act (call a tool) → Observe, repeat until it can answer. Step through a real trace below; the tools actually run.
A plain LLM has two weaknesses for real tasks. It can't act on the world — it can't run code, query a database, hit an API, or look something up — and it's unreliable at things like exact arithmetic or fresh facts, because it's generating text, not computing. An agent fixes this by giving the model tools and a loop: the model decides what to do, a tool actually does it, and the result is fed back so the model can decide the next step.
"ReAct" stands for Reason + Act. Instead of answering in one shot, the model alternates between thinking out loud and taking actions:
calculator("23 * 19").Then it loops: the new observation informs the next thought. The model never does the arithmetic or lookup itself — it orchestrates. Crucially, the scratchpad (the growing transcript of thoughts/actions/observations) is fed back every step, so the model always sees what it has learned so far.
One more essential: a max_steps cap. Because the model controls the loop, a confused model
could loop forever. The cap forces a stop — a small detail that matters a lot in production.
Pick a task and press ▶ — or step one beat at a time and scrub the timeline backwards to replay any phase. Watch three things: the loop diagram highlights which phase you're in; the scratchpad grows with each Thought / Action / Observation (and shrinks again when you scrub back); and the tools genuinely execute — the calculator really evaluates the expression, the search really looks it up. The two-step task is the interesting one: the first Observation gets substituted into the second tool call, exactly how a real agent chains steps together.
Agents are powerful when a task needs multiple steps, real tools, or decisions the model can't make in one shot: research that requires several lookups, workflows that branch on intermediate results, or anything touching live systems. But that power comes with costs you should respect:
max_steps (and ideally a budget), a stuck model loops
forever. Always cap it.A good rule from Anthropic's Building Effective Agents: use the simplest thing that works. Many "agent" problems are better solved by a fixed workflow (a predetermined sequence of steps); reach for a true autonomous agent only when you genuinely need the model to decide the path at runtime.