MODULE 3 · LESSON 15 · 13 MIN
Agents and Multi-Step Workflows
By Siten Sanghvi · Published · Updated
In current vendor guides, an AI agent is a program in which a language model chooses the next step in a loop: it reads the goal and the latest result, picks an action (usually a tool call), sees what happened, and repeats until a stopping rule ends the run. A workflow uses the same model and tools, but your code fixes the steps and their order. The difference is who decides what happens next.
Anthropic's Building effective agents (published 2024-12-19) draws that line: workflows follow "predefined code paths", while agents direct their own process and tool use. The page notes that much of the tooling it describes has changed since December 2024. OpenAI's practical guide says a simple chatbot or single-turn call, where the model does not control workflow execution, is not an agent. I use both guides for concepts only.
Anthropic advises the simplest solution that works, which can mean no agent; OpenAI says a deterministic solution may suffice. A loop often costs more and can fail in more ways.
The word is older and wider. The textbook Artificial Intelligence: A Modern Approach calls an agent anything that perceives an environment and acts on it, including a rule-based vacuum. What Is AI? A Systems Thinker's Guide covers that sense, which needs no language model. Here, "agent" means the narrower LLM-directed loop.
One task, two designs
A synthetic task: a user writes "The VPN drops every hour" and needs a reply.
Workflow: your code decides. It has no send tool; a technician reviews the draft.
- Classify the ticket (model call).
- Search the knowledge base with the ticket text (tool call).
- Draft a reply from the top results (model call).
- Queue the draft for a technician.
Agent: the model decides. It gets the goal and five tools: search the knowledge base, read VPN gateway logs, check known outages, queue a draft for a technician, and send a reply to the user. Sending cannot be undone. It might search, see a result about lease times, read this user's logs, then draft and send, or queue a draft instead. Steps vary by run. It stops when it judges the task done, when a limit is hit (for example, 8 steps), or when a person intervenes.
| Fixed workflow | Agent loop | |
|---|---|---|
| Who picks the next step | Your code | The model |
| Steps known in advance | Yes | No: number and order vary |
| Cost and time | Predictable | Varies; Anthropic says agentic systems often trade latency and cost for task performance |
| Tool returns nothing | Only what you coded for | May try another route, or repeat itself |
| Testing | Test each step | Test whole runs, repeatedly |
If you can write the steps down before the request arrives, build the workflow. A workflow can still call a model inside a step where judgment is needed; the question is who orders the steps. Anthropic suggests agents for open-ended problems where the number of steps cannot be predicted. OpenAI points to judgment-heavy decisions with exceptions, tangled rule sets, and unstructured text.
Anthropic's in-between workflow shapes, such as orchestrator-workers (a central model chooses subtasks at run time), already hand the model some decisions, so in my reading it is a spectrum, not two boxes.
EXHIBIT 15 / AGENT
Explore the mechanismWho picks the next step?
A fixed workflow and an agent can use the same tools.
Steps used: 0 / 4
No live model or tools. Independent-step arithmetic is not a measured reliability estimate. Workflow has four coded steps and no send tool; only the agent has a configurable cap and send checkpoint. Changing p or the checkpoint does not change the scripted decision sequence.
Inspect the example data and reasoning
| Element | What to notice |
|---|---|
| 0 | No steps taken yet. |
Scripted traces, not a live agent. p^n is illustrative independent-step arithmetic, not measured reliability or a safety guarantee.
Read the mechanism without interacting
- Decision
- Code selects the workflow route; a model selects the agent’s next step.
- Controls
- Put step limits, budgets and human checkpoints in the application.
- Compounding
- Under an independence assumption, all-step success is p raised to the number of steps.
For a VPN ticket, step through classify, search, draft and send. A scripted repeated search stops at the configured limit.
Try explaining it: If the steps are known in advance, why let a model choose them?
The loop and what stops it
One pass through the loop:
- Observe. The model is given the goal, the history so far and the latest tool result.
- Decide. It writes its next action: a tool call, a question for the user, or a final answer.
- Act. Your application runs the tool and returns the result (Function Calling and Tool Use: Giving AI Hands covers this hand-off; the model only requests).
- Repeat or stop.
For tools your own code runs, the loop lives in your application. In the Claude API docs it is a while loop that continues while the stop reason (the field saying why the model stopped) is tool use and exits on any other (How tool use works, checked 2026-11-09). OpenAI's Agents SDK loops until a final-output tool is called or the model replies without a tool call.
A run can end four main ways: a final answer, a step cap, a budget cap, or a person or guard intervening. Do not assume a cap exists. The Claude Agent SDK's agent loop page lists max_turns and max_budget_usd, both defaulting to no limit, and notes that a spend cap can be passed by the cost of the response that reaches it (checked 2026-11-09). OpenAI recommends retry and action limits that escalate to a human.
Where the plan lives. In ReAct (Yao et al.), the model can write a "thought" between actions (on some tasks it decides when). A thought does not change the outside world; it joins the context for the next decision. The 2022 paper (frozen PaLM-540B, few-shot prompts) reported large gains on two interactive-task benchmarks but slightly trailed plain chain-of-thought prompting (see Prompt Engineering: A Systems Thinker's Framework) on one question-answering test, so explicit reasoning is not a universal win.
Ground truth. Anthropic advises checking the environment at each step (a tool result, a test run).
State. The loop's memory is mostly the context sent again each time. The Agent SDK page says it accumulates and that automatic compaction summarizes older history, so early instructions may not survive. Context Engineering: Memory, Files, and Instruction Design covers managing that.
Multi-agent systems: what the sources show
A multi-agent system runs several model-driven loops, commonly a manager delegating to specialists. The evidence is mixed:
- Anthropic's research system (2025-06-13) used an orchestrator with parallel subagents and beat a single Claude Opus 4 agent by 90.2% on its own internal research evaluation, at about 15x the tokens of a chat (agents alone about 4x). It says this suits parallel, breadth-first work and fits less well where agents share context or depend on each other, and that most coding tasks have fewer parallelizable parts than research.
- Cognition's Don't Build Multi-Agents (2025-06-12) is an opinion post, not a measurement. It argues subagents lacking shared context make conflicting decisions.
- OpenAI's guide recommends maximizing a single agent first.
- A study of 7 frameworks (Cemri et al.) annotated over 1,600 traces into 14 failure modes and says gains on popular benchmarks are often small.
No source here shows multi-agent is generally better. Added agents add cost and coordination risk.
Where errors compound
Each step builds on earlier results, so an early mistake can carry forward. Suppose each step is right with probability p and steps are independent. The chance all n are right is p to the power n.
Illustrative arithmetic, not a measured reliability of any agent:
| Per-step p | 5 steps | 10 steps | 20 steps |
|---|---|---|---|
| 99% | 95.1% | 90.4% | 81.8% |
| 95% | 77.4% | 59.9% | 35.8% |
| 90% | 59.0% | 34.9% | 12.2% |
Real steps are not independent and agents can recover, so use this for shape only.
A separate, measured effect is consistency across repeated runs. In τ-bench (2024), simulated customer-service tasks graded by final database state, pass^k is the chance that all k repeated trials of a task succeed. A gpt-4o function-calling agent solved about 61% of retail tasks in one try but under 25% across eight. That is one 2024 setup about repeating a whole task, not steps inside one run; both effects show why one good run proves little. Latency, Throughput, and Reliability in AI Systems covers keeping a deployed AI service dependable (overload errors, retries, silent quality changes).
Failure patterns, with sources where I have them:
- Early mistakes and repetition. Anthropic lists compounding errors as a cost of agents, and the ReAct authors saw models repeat earlier thoughts and actions without leaving the loop.
- Uninformative tool results. In ReAct's small hand-labelled HotpotQA sample, empty or useless searches were 23% of its failures.
- Tool interface mistakes. Anthropic's coding agent erred on relative file paths; requiring absolute paths fixed it.
- Vague goals. A hypothetical: "improve system performance" gives an agent with delete rights room to remove logs.
Controls that belong in the design
These live in application code, not in the model's judgment:
- Step and budget caps with defined stop-and-report behavior.
- Human checkpoints. OpenAI names two triggers: exceeding a failure threshold, and high-risk actions such as canceling orders, large refunds or payments. In the example, that is the send tool.
- Least privilege and approvals. The Agent SDK has allow and deny lists, permission modes and hooks that can block a call, and reserves bypassing approvals for isolated environments.
- Sandboxing. Anthropic recommends extensive testing in sandboxed environments.
- Reversible-first design (draft before send) is common practice, not a claim from these sources.
Prompt injection and guardrails are in AI Hallucinations, Prompt Injection, and Safety Guardrails Explained. Measuring quality with eval sets, human review and LLM judges, and grading agent runs by outcome: Evaluating AI Outputs: How to Know If Your System Is Working. Following runs step by step: Observability and Monitoring for AI Applications.
What published agent results show, and how to read their dates
- Coding. Anthropic's December 2024 article reports its agent resolving SWE-bench Verified issues (a human-validated 500-task subset) and says human review stays crucial. I give no current score: the leaderboard changes, mixes very different scaffolds, and warns that results across releases of its minimal agent may not be comparable.
- Web tasks. WebArena (2023) reported 14.41% end-to-end success for its best GPT-4 agent against 78.24% for humans: a 2023 gap, not a current score.
- Task length. METR (page last updated 2026-09-08, no longer actively updated) reports the human-time task length at which an agent is predicted to succeed half the time. It cautions that tasks are mostly software, machine-learning and cybersecurity work, that a 2-hour horizon does not mean every 2-hour human task is doable, and that agents did worse on messier tasks.
Anthropic's coding example works partly because tests can check each result; bounding the stakes is a design choice, covered above.
Try it
Pick a repeated task of your own, such as finding why a nightly backup runs slowly.
- Write it as a numbered workflow. If you can finish the list, build that.
- If you cannot, specify the agent: goal, tools (read-only first), stopping rule (done condition, step cap, budget), which action needs a person, and the ground truth checked each step.
- Check the arithmetic: 12 steps at 97% each, independent, is 0.97 to the 12th power, about 69%. Redo it at 90%.
The takeaway
In current LLM usage, an agent is a loop in which the model chooses the next step and a stopping rule ends the run; in a workflow your code chooses the steps. Write the steps down first, and build an agent only when you cannot order them in advance. More steps tend to add cost and ways to fail, so a stopping rule, a human checkpoint before irreversible actions and ground-truth checks belong in the design. Published results are dated, and one good demo does not show consistent reliability.
Related lessons
- Function Calling and Tool Use: Giving AI Hands explains how a model requests a tool call and the application runs it, which each pass of the loop relies on.
- Context Engineering: Memory, Files, and Instruction Design covers what goes into the context a loop sends each step, including history and memory.
- AI Hallucinations, Prompt Injection, and Safety Guardrails Explained covers prompt injection and guardrails, the security side of giving a loop tools.
Up next
AI Infrastructure: APIs, Hosting, and Cost Models: Module 4 turns from working with models to running them: how they are accessed through APIs, where they are hosted, and how token-based pricing works.
VISUAL FIELDNOTES / 15
Keep the big picture.
A one-page visual companion. Save it, print it, or explain it to someone else.
View the full-size sheet ↗Who picks the next step?
A fixed workflow and an agent can use the same tools.
One US Letter page · Vector artwork · Fits A4 when printed to fit
Read the key points as text
- Decision
- Code selects the workflow route; a model selects the agent’s next step.
- Controls
- Put step limits, budgets and human checkpoints in the application.
- Compounding
- Under an independence assumption, all-step success is p raised to the number of steps.
Remember: Code selects the workflow route; a model selects the agent’s next step.
Try it: For a VPN ticket, step through classify, search, draft and send. A scripted repeated search stops at the configured limit.
Recall: If the steps are known in advance, why let a model choose them?
OPTIONAL CHECK
Check your understanding.
The optional check requires JavaScript. You can continue reading the lesson.
A script classifies a ticket, searches the knowledge base, has a model draft a reply, then queues it, always in that order. What is it, in this lesson's terms?
An agent's search tool keeps returning nothing and the agent keeps repeating the same search. Which control limits the damage?
In ReAct, the model can write a 'thought' between actions. What does a thought do?
Each step of a 10-step run is independently right 95% of the time (an illustration, not a measured rate). About how often are all ten right?
A weekly report uses the same three databases, in the same order, with a fixed layout. Which design fits best?
A team splits a tightly coupled coding task across five parallel subagents because multi-agent is 'better'. What do the sources support?
An agent can draft customer replies and also has a tool that sends them to the user. Where does a human checkpoint belong?
A 2023 paper reported a GPT-4-based web agent completing 14.41% of web tasks, against 78.24% for humans. How should a reader use that today?
A vendor demo shows an agent finishing a task once. What does that establish?
A textbook vacuum agent follows a rule: if the square is dirty, suck; otherwise move to the other square. How does it relate to this lesson's use of 'agent'?
Quiz complete
YOUR LEARNING
Keep your place.
Your progress is saved on this device.