AssayAssay
07 / 08

Lesson 07 · Agents · 12 min

The agent

Every pattern so far had code deciding the route. The agent hands that decision to the model: it plans, acts on tools, reads the results and decides what to do next, until it judges the task done. The number of steps is not known at the start.

The guide reserves this for open-ended problems with an unpredictable number of steps, where the autonomy is the point — and it attaches conditions. Extensive testing in a sandboxed environment. Guardrails on the actions it can take. A budget, because a loop that decides its own stopping point needs one imposed from outside.

The agent-loops course is this pattern in full: the iteration budget, repeat detection, preconditions on side-effecting tools, and the exit reasons that tell you whether it finished or was stopped. None of that is optional, and the guide's warning is the reason why.

The useful question is not whether to build an agent but which part of the task needs one. A common production shape is a workflow with an agent inside one step — routing and gating around the outside, and autonomy only where the problem is genuinely open-ended. That keeps the unpredictable part small and the predictable parts cheap.

  • If you can draw the flowchart, it is a workflow. Build the workflow.
  • If the steps depend on what you learn along the way, that part is an agent. Keep it as small as possible.
  • Measure the agent's step count in production. A rising tail is the earliest signal that tasks have changed.

The agent is the one pattern this lab does not run, because it already has a whole course. Open the agent-loops lab beside this lesson if you want to see it — the refund task there is an agent doing what no workflow above could: discovering a precondition it was never told about.

Checkpoint

For one task, say which parts are a workflow and which part, if any, actually needs an agent.

“Where is my order 41902? It was due on Tuesday.”

Patterns to compare

Neither of these is an agent — both have code deciding the route. Run them and ask, for each, whether any step genuinely needed the model to choose what came next.

Pick two or more patterns and press Run. They run in turn, and the table fills in as each one finishes.