Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Agents vs workflows: who decides the next step?
Every "AI agent" pitch makes autonomy sound like the goal. It isn't — it's a cost. A workflow's fixed path is cheaper, faster, and easier to trust than an agent's open-ended loop, and most tasks don't actually need what only an agent can provide.
The one distinction that decides everything
In a workflow, the control flow — which LLM call happens after which, and with what — is written by you, in code, ahead of time. In an agent, the model itself decides its next action at runtime, in a loop: plan, call a tool, observe the result, decide again, until it judges the task done. The difference isn't capability, it's who's driving.
If you can write down the sequence of steps in advance and have it hold for the vast majority of real cases, that's a workflow. If the right next step genuinely depends on what's discovered along the way and can't be known ahead of time, that's an agent.
Head to head
| Dimension | Workflows | Agents |
|---|---|---|
| Control flow | Fixed by your code | Decided by the model, at runtime |
| Predictability | High — deterministic paths | Lower — harder to test exhaustively |
| Cost & latency | Bounded — known number of LLM calls | Variable — can loop many times, unpredictably |
| Debuggability | Easy — trace step X did Y | Harder — must inspect a whole trajectory |
| Failure mode | Fails at a known step, has a fallback | Can loop unproductively without guardrails |
| Engineering overhead | Lower | Higher — needs sandboxing, step limits, cost caps |
| Best for | Well-defined, repeatable tasks | Open-ended tasks whose path can’t be known upfront |
When to use each
Reach for workflows
- The task is well-understood and repeatable
- Predictability and cost control matter more than flexibility
- You can enumerate the paths the task will take
- Debuggability and easy fallback handling matter
Reach for agents
- The next step genuinely depends on what’s discovered
- The task space is open-ended (research, debugging an unknown issue)
- Hardcoding the path would require anticipating every case
- You’ve confirmed a workflow can’t cover this task’s variability
Autonomy is earned, not defaulted to
Start with the simplest workflow that solves the problem. Reach for full agentic autonomy only when the task's unpredictability genuinely requires it — an agent loop costs more in latency, dollars, and reliability risk than a fixed sequence of calls, so that cost needs to buy you something a workflow structurally can't provide, not just feel more impressive to build.
Ask: can I write down the steps this task needs, even as a handful of branches? If yes, a workflow will be cheaper, faster, and easier to trust than an agent — build that first.
It’s a spectrum, not a binary
"Workflow" and "agent" aren't two discrete categories so much as two ends of a spectrum measured by how much of the control flow you hand to the model. A simple prompt chain (call 1's output feeds call 2, always) is a pure workflow. A router (the model picks one of N predetermined paths, but the path itself is fixed once chosen) hands the model a little control — more agent-like than a chain, but still bounded and enumerable. A full agent loop with an unbounded number of tool calls and no predetermined stopping point sits at the far end, where the model controls not just which path but how many steps it takes and when it's done.
The real engineering decision, then, isn't "workflow or agent" as a one-time architectural choice — it's incrementally deciding, task by task and even sub-task by sub-task, how much of the control flow genuinely needs to be dynamic. Most production systems that call themselves "agents" are actually a workflow with one or two genuinely agentic components embedded in it, not autonomy end to end.
Every increment of autonomy you hand the model buys flexibility and costs predictability — the right amount is exactly as much as the task's real variability demands, no more.
A worked scenario: a support-ticket system
Triaging an incoming support ticket — classify it, route it to one of five fixed handlers (billing, bug report, feature request, account access, other) — is a workflow: the five categories are known in advance, the routing logic is stable, and hardcoding "if billing, go here" is both cheaper and more reliable than letting a model improvise a route it might get wrong in a way that's hard to catch. This handles the large majority of incoming tickets cheaply and predictably.
But "investigate this obscure production bug using logs, code search, and running tests to reproduce it" cannot be hardcoded into a fixed path, because you genuinely don't know what the investigation will find — the next useful action (check this log, grep for that error, run this specific test) depends entirely on what the previous action turned up. That's an agent loop, deliberately reserved for the minority of tickets that actually need open-ended investigation, while the cheap, predictable workflow handles routing for the other 90%.
Most real systems are a workflow with an agent embedded at exactly the one point where the path genuinely can't be predetermined — not an agent end to end.
The picture: a path you wrote vs a loop the model drives
Worked example: what an agent loop costs as it runs
Illustrative but typical sizes. Every call starts from a 2,000-token prompt (instructions, the task, tool definitions). Each agent step appends about 500 tokens: the tool call plus its result. Chat model APIs are stateless, so the whole transcript is re-sent on every call, and step i pays for everything before it. Total input over n steps is n × 2,000 + 500 × n(n − 1)/2. For reliability, assume each step independently goes right 95% of the time.
| Design | LLM calls | Input tokens, total | Largest single prompt | All steps go right (95% each) |
|---|---|---|---|---|
| Workflow: classify, then route | 2 | 4,000 | 2,000 | 90.25% |
| Agent, 3 steps | 3 | 7,500 | 3,000 | 85.7% |
| Agent, 10 steps | 10 | 42,500 | 6,500 | 59.9% |
| Agent, 20 steps | 20 | 135,000 | 11,500 | 35.8% |
Two curves bend the wrong way. Tokens grow quadratically, because every step re-reads all earlier steps: going from 10 steps to 20 multiplies input tokens by 3.18, and the 20-step run uses 33.75× the workflow’s 4,000. Prompt caching lowers the price of a re-sent prefix, but not the growing length of the context the model has to read. Reliability compounds: at 95% per step, a 20-step run gets every step right only 35.8% of the time. Agents survive that by noticing a failed step and trying again, which is real capability, but it means extra steps on top of the ones planned, and it only works if each failure comes back as a clear message. A workflow’s two calls fail where you can see them.
Cost and trade-offs across the spectrum
| Case | Time | Space | Why |
|---|---|---|---|
| Prompt chain | A fixed n calls | Each call sees only what you pass it | The cheapest pattern. Every step can be tested on its own. |
| Router | 1 classify + 1 handler | Small, per call | The model chooses among paths you wrote, so every path is still testable. |
| Parallel fan-out | k calls at once | Separate per branch | Cost grows with k; latency is the slowest branch, not the sum. |
| Evaluator–optimizer loop | 2 calls per round, capped rounds | Grows each round | Draft, critique, revise. A bounded loop: you choose the cap. |
| Orchestrator–workers | 1 planner + workers, how many decided at runtime | The planner sees summaries, not every worker’s transcript | The plan is dynamic; each worker is not. The first real step into agent territory. |
| Full agent loop | n, decided by the model | Per call grows with n; total grows with n² unless trimmed | Needs a step cap, a budget, timeouts and a sandbox before it is safe to run. |
Read down the table and each row hands the model a little more of the control flow, and costs a little more predictability: the spectrum the page describes, with the bill attached. The pattern names follow Anthropic’s engineering post Building effective agents, which draws the same line between workflows (LLMs orchestrated through predefined code paths) and agents (LLMs directing their own process and tool use).
Common mistakes
- No hard stop
An agent with no step cap, token budget or wall-clock timeout will eventually loop: the same tool, the same arguments, the same error. Set all three, and detect repeats (an identical tool call twice in a row is almost always a stuck loop). When a limit trips, return what was found so far, not a crash.
- Pouring raw tool output into the context
A tool that returns a 50,000-line log puts all of it into every later call, which is the quadratic row above at its worst. Make tools return the useful slice (the top matches, the last 50 lines, a summary) plus a way to ask for more. In the worked example, trimming each step from 500 tokens to 200 takes the 20-step run from 135,000 input tokens to 78,000, 42% fewer, without removing a single step.
- Letting the model do deterministic work
Date arithmetic, totals, schema validation and routing on a field you already have are free, exact and testable in code. Put them in code, around the model, and spend LLM calls only on the steps that need judgement.
- Irreversible actions without a gate
Refunds, emails, deletes and deploys should not be one tool call away from a model that is wrong some percentage of the time. Require a confirmation or human approval for side effects, give tools the narrowest credentials that work, and prefer a dry-run mode the agent can call first.
- Vague tools, silent errors and no traces
Overlapping tool names and one-line descriptions make the model guess which tool to use; an error that just says
500makes it guess why it failed. Write descriptions that say when to use each tool, return errors that say how to fix the call, and log every step of every run. You cannot debug an agent from its final answer.
Where this shows up in production and interviews
- Coding agents
Coding assistants that edit files, run the tests and read the failures are the clearest case for a real agent loop: what to do next depends on what the test run printed, which nobody can know in advance. They are also where step caps, sandboxes and approval prompts for risky commands became standard.
- Document pipelines
Invoice extraction, contract clause tagging and ticket summarisation are workflows: the same steps on every document, with an LLM as one or two of them. They run at volume, so the fixed, known cost per item is the feature.
- Agent inside a workflow
The page’s point in production form: a fixed pipeline handles intake, validation and routing, and hands one bounded sub-task (the investigation, the open-ended search) to an agent with its own cap and budget, then takes the result back into fixed code.
- The interview version
Expect “would you build this as an agent?” Answer with the test from the page (can you write the steps down?), then the costs: calls per task, how context grows, how errors compound over steps, and the guardrails (step cap, budget, approval gates, traces) you would ship with any loop.
Which would you pick?
Three situations. Pick the side you'd actually build — the explanation follows.
Support tickets arrive and must be routed to one of five fixed queues: billing, bug, feature request, account access, other. Volume is high and the categories have been stable for two years.
You can write the steps down in advance and they hold for the vast majority of cases, which is the page's own definition of a workflow. The agent version costs more, is harder to debug, and can route wrongly in ways that are hard to catch — while buying you flexibility over a category set that has not changed in two years.
A user reports "the export is broken." The cause could be permissions, a malformed row, a timeout, or a third-party outage — and which one it is only becomes clear as you look.
This is the case the page reserves agents for: the right next action genuinely depends on what is discovered, and enumerating the paths would mean anticipating every failure combination. Checking all four in fixed order is wasteful and still misses the fifth cause nobody listed.
Your team has built an agent for a task. In review, someone shows that a three-step chain with one branch handles 95% of real cases.
The page's rule is that autonomy is earned, not defaulted to: the agent loop costs more in latency, dollars and reliability risk, so it has to buy something a workflow structurally cannot. "The work is already done" is sunk cost, and running both doubles the surface you have to trust and debug.
Quick answers
Agent or workflow — which should I use?
Default to a workflow: fixed code paths are cheaper, faster, and easier to debug. Reach for an agent only when the task’s next step genuinely can’t be known in advance and depends on what’s discovered along the way.
Is an agent just a more advanced workflow?
Not quite — it’s a different control-flow model. A workflow’s path is fixed by your code; an agent’s path is decided by the model at runtime. Think of them as two ends of a spectrum measured by how much control flow you hand to the model, not a strict hierarchy.
Why not just always use an agent for flexibility?
Agent loops cost more in latency and dollars (unbounded LLM calls), are harder to test exhaustively, and can fail by looping unproductively. That cost only pays off when a workflow genuinely can’t cover the task’s real variability — using an agent by default pays that cost for no benefit on predictable tasks.
Can a system mix workflows and agents?
Yes, and most production systems do — a fixed workflow handles the well-understood majority of a task, with an agent embedded at the specific point where the path genuinely can’t be predetermined, rather than either extreme applied end to end.
Agents vs Workflows: who decides the next step?
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Agentic AI Interview HandbookTwenty topics every senior AI engineer should be able to reason about live — from eval pipelines to reliability patterns for generative systems.Read →
- The Agent Evaluations HandbookA self-contained handbook on evaluating AI agents — theory, interactive widgets, and practical guidance. Trajectory evals, tool-use scoring, LLM-as-judge, observability, and reliability for PMs, engineers, and founders.Read →
- The Agent Patterns HandbookThe design patterns behind every LLM agent — the ReAct Thought–Action–Observation loop, tool/function calling, plan-and-execute, reflection, memory, multi-agent orchestration, and the failure modes (loops, hallucinated tools, recovery, human-in-the-loop) that break agents in production.Read →
- The Model Context Protocol (MCP) HandbookThe open standard connecting AI agents to the outside world — why M×N bespoke integrations collapse to M+N, the host/client/server roles over JSON-RPC, the three primitives (tools, resources, prompts), the connect→discover→call session lifecycle, when MCP earns its keep, and the security sharp edges (a server's output is untrusted input).Read →
- The Loop Engineering HandbookStop prompting your agents — design the system that prompts them for you. The inner vs outer loop, the four loop types (heartbeat, cron, hook, goal), the six building blocks (automations, worktrees, skills, MCP connectors, subagents, external memory), stopping conditions and the verification split, state across runs, cost engineering, and the six failure modes that burn tokens at 3am.Read →
- The Context Engineering HandbookThe discipline that replaced prompt-tweaking: curating everything the model sees under a finite attention budget. The anatomy of a production context window, the three taxes on an overstuffed one (context rot, cost, behavioral drift), the four operations (write, select, compress, isolate), agent-specific patterns like compaction and just-in-time retrieval, six production habits, and where it sits in the prompt → context → loop → harness stack.Read →