Every pattern so far is a workflow: you decide the route, the model fills in the steps. The agent loop flips that. You give a goal, tools, and the model itself decides what to do, does it, looks at the result, and decides again — until the job is done. This is what powers coding agents like Copilot’s or Claude Code.
The analogy
GPS navigation, not a printed itinerary. A workflow is the printed route: perfect while reality matches the plan. An agent is the GPS: it looks at where it actually is after every turn and recalculates. Wrong exit? It doesn’t panic — it observes and reroutes.
The principle
flowchart TB
GOAL([goal]) --> T["LLM: think & pick the next action"]
T -->|tool call| X[execute tool]
X --> O[observe result]
O --> T
T -->|done| OUT([final answer])
- Each turn, the model sees the full history of actions and results, and picks the next move — a tool call or a final answer.
- The environment pushes back: failing tests, error messages, file contents. That grounding is what keeps the loop honest (see grounding).
- The harness enforces the frame: available tools, permissions, stop conditions, budget.
A concrete example
“Fix the failing test in this repo”:
1. think → "let's see what fails" → run: npm test
2. observe→ "TypeError in cart.js:42"
3. think → "read that file" → read: cart.js
4. observe→ finds a null price path
5. think → "patch + verify" → edit, then npm test
6. observe→ all green → answer: "fixed, here's the diff"
Nobody scripted those six steps — a different bug would produce a different path. That’s the point.
When to use it
- The path is unpredictable: it depends on what each step reveals (debugging, research, multi-file changes).
- The environment gives verifiable feedback the loop can react to — tests, compilers, APIs.
- The task justifies the cost: each turn re-sends the whole history as input tokens.
When to avoid it
- The steps are known in advance → a workflow is cheaper, faster and more predictable.
- No good feedback signal exists: an agent that can’t check itself is a very confident random walk.
The classic trap
The runaway loop. An agent stuck retrying the same broken idea can burn tokens for hours. Always set budgets and stop conditions (max turns, max cost, timeouts) — and for anything irreversible, add a human in the loop.