Workflows vs Agents: When Not to Build an AI Agent
By David Colón on
If you can draw the flowchart for a task before you see the input, the task does not need an agent. Write the flowchart as code and call a language model inside the steps. That design is a workflow. You know what it will cost before it runs, and you can test it one step at a time.
Many systems that are sold as agents are built this way. Dex Horthy's 12-factor agents observes that most products billing themselves as AI agents "are not all that agentic", and that a lot of them are "mostly deterministic code, with LLM steps sprinkled in at just the right points". Anthropic's Building effective agents (December 2024) recommends "finding the simplest solution possible, and only increasing complexity when needed", and adds: "This might mean not building agentic systems at all."
This article covers how to tell a workflow from an agent, the patterns workflows are built from, what an agent costs, and when the cost is worth paying.
Who decides the next step
A workflow and an agent can use the same model and the same tools. What separates them is who decides what happens next.
- In a workflow, your code decides. The steps and their order are written in advance, and the model is called inside them.
- In an agent, the model decides. It works in the thought-action-observation loop, choosing each action from what it has just observed, until it judges the task done.
Those are the definitions in the same Anthropic guide, which groups both under the name agentic systems. In its words, "Workflows are systems where LLMs and tools are orchestrated through predefined code paths", while agents are "systems where LLMs dynamically direct their own processes and tool usage".
A quick test, which is my own shorthand and not part of anyone's definition: try to draw the flowchart, branches included, before you see the input. If you can, build a workflow. If the only drawing you can make is one box labelled "work it out", the task needs an agent.
A workflow in code
Take a support inbox. Refund and shipping questions each have a written policy, and anything else should reach a person. The whole design fits in one drawing:
flowchart TD E[Email arrives] --> C["Classify<br/>model call"] C -->|refund or shipping| D["Draft a reply<br/>model call"] C -->|anything else| P[A person] D --> K["Check against policy<br/>model call"] K -->|passes| S[Send the reply] K -->|fails| P style C fill:#eef2fc,stroke:#1b3fbf,color:#10204f style D fill:#eef2fc,stroke:#1b3fbf,color:#10204f style K fill:#eef2fc,stroke:#1b3fbf,color:#10204f
The shaded steps are model calls. Every arrow is decided by code.
The first step is routing: one model call whose only job is to choose a branch.
// One request to a model API: a prompt in, text out.
export type CallModel = (prompt: string) => Promise<string>;
const CATEGORIES = ['refund', 'shipping', 'other'] as const;
type Category = (typeof CATEGORIES)[number];
// Routing: one call whose only job is to pick a branch.
export async function classify(
email: string,
callModel: CallModel,
): Promise<Category> {
const answer = await callModel(
`Classify this customer email as one of: ${CATEGORIES.join(', ')}. ` +
`Reply with the category and nothing else.\n\n${email}`,
);
const category = CATEGORIES.find((c) => c === answer.trim().toLowerCase());
// Anything the code does not recognise goes to a person, not to a guess.
return category ?? 'other';
}
The rest is a chain. One call drafts the reply, and a second checks the draft against the policy before anything is sent.
const POLICY = {
refund: 'Refunds are available within 30 days of delivery.',
shipping: 'Delivery takes 3 to 5 working days. Never promise a date.',
};
type Outcome =
| { action: 'send'; reply: string }
| { action: 'escalate'; reason: string };
export async function handleEmail(
email: string,
callModel: CallModel,
): Promise<Outcome> {
const category = await classify(email, callModel);
if (category === 'other') {
return { action: 'escalate', reason: 'Not a refund or shipping request.' };
}
const policy = POLICY[category];
// Prompt chaining: each call does one job, and its output feeds the next.
const reply = await callModel(
`Write a short reply to this ${category} request. Follow the policy.` +
`\n\nPolicy: ${policy}\n\nEmail:\n${email}`,
);
// A second call checks the first one's work before anything is sent.
const verdict = await callModel(
`Does this reply promise anything the policy does not allow? ` +
`Answer yes or no.\n\nPolicy: ${policy}\n\nReply:\n${reply}`,
);
if (!/^no\b/i.test(verdict.trim())) {
return { action: 'escalate', reason: 'The reply failed the policy check.' };
}
return { action: 'send', reply };
}
The two blocks make one complete module in plain TypeScript, with no dependencies. callModel is the part you supply: one request to whichever model API you use. handleEmail returns either a reply to send or a reason to hand the email to a person.
Three properties of this code are the reason to prefer it when the task allows:
- The model never chooses the path. It classifies, writes and checks. The
ifstatements decide which of those happens next. - The cost is known before it runs. An email takes at most three model calls, and one that is routed straight to a person takes one. No input can make it take forty.
- Each step can be tested alone. The classifier can be checked against a set of labelled emails without running anything else.
The five workflow patterns
That example uses two of the five patterns Anthropic describes, routing and prompt chaining, and a cut-down version of a third. All five are ways of arranging model calls in code:
| Pattern | What it does | Use it when |
|---|---|---|
| Prompt chaining | Splits a task into a fixed sequence, each call working on the output of the one before | The task divides cleanly into fixed subtasks |
| Routing | Classifies the input and sends it to a specialised follow-up | There are distinct categories that are better handled separately |
| Parallelisation | Runs calls at the same time and combines the results in code: independent parts of one task (sectioning), or the same task several times (voting) | The parts can run in parallel for speed, or several attempts give more confidence |
| Orchestrator-workers | A central model call breaks the task down, hands the parts to worker calls and combines their results | The subtasks cannot be predicted in advance |
| Evaluator-optimizer | One call writes a response and another evaluates it and gives feedback, in a loop | There are clear evaluation criteria and another pass measurably improves the result |
The policy check in the example is the evaluator without the loop: a draft that fails goes to a person instead of back to the writer.
What an agent costs
An agent replaces the if statements with the model's judgement. That buys flexibility, and Anthropic names the price: "The autonomous nature of agents means higher costs, and the potential for compounding errors."
Compounding is the part that is easy to underestimate. Suppose each step of a task succeeds 95% of the time and nothing catches a mistake. The chance that 20 steps in a row all succeed is 0.95 to the power of 20, which is about 36%.
| Success per step | 5 steps | 10 steps | 20 steps | 50 steps |
|---|---|---|---|---|
| 99% | 95.1% | 90.4% | 81.8% | 60.5% |
| 95% | 77.4% | 59.9% | 35.8% | 7.7% |
| 90% | 59.0% | 34.9% | 12.2% | 0.5% |
The table is arithmetic, not a measurement. It assumes that steps fail independently and that no failure is ever noticed. A real agent is not bound by it, because it reads the result of each action and can correct a mistake. What the table does show is where reliability comes from: fewer steps left to the model, and a check after the ones that remain.
When an agent is worth it
An agent is the right design when the path cannot be written in advance. Anthropic's wording is "open-ended problems where it's difficult or impossible to predict the required number of steps". OpenAI's practical guide to building agents names three signs that rules written in advance will fall short:
- Complex decision-making: "nuanced judgment, exceptions, or context-sensitive decisions", such as approving a refund.
- Difficult-to-maintain rules: rule sets that have grown so intricate that updating them is costly or error-prone.
- Heavy reliance on unstructured data: work that depends on interpreting natural language or extracting meaning from documents.
For everything else, the guide says, "a deterministic solution may suffice."
Refund approval is OpenAI's own example of the first sign, and the support workflow above stays on the other side of that line. It answers from the written policy and has no tool for issuing a refund.
Fixing a bug in a large codebase is a clearer case for an agent: nobody can list in advance which files the fix will touch.
The two designs also combine. A workflow can hand one step to an agent, and an agent can call a workflow as one of its tools. The support workflow could send its "anything else" branch to an agent with read-only tools, and keep the person for whatever that agent cannot settle.
What people get wrong
"A workflow is an agent that is not finished yet." They are two designs with different properties. A workflow gives up flexibility and gets predictability in return, and for a task with a known shape that is the better trade. Anthropic's summary is that "workflows offer predictability and consistency for well-defined tasks", while agents suit cases where "flexibility and model-driven decision-making are needed at scale".
"Agents are more capable, so start with one." In my view, starting with the agent means starting with the version that is hardest to debug. Anthropic's order is the reverse. First a single model call, since "optimizing single LLM calls with retrieval and in-context examples is usually enough". Then a workflow. Then an agent, adding complexity "only when it demonstrably improves outcomes".
"The choice is permanent." The line moves as models improve. In March 2025, METR measured the length of software tasks, counted in the time they take a human professional, that models can complete half the time. It found that this length "has been doubling approximately every 7 months for the last 6 years". Half the time is far from dependable: in the same study, models succeeded on nearly every task that takes a person under 4 minutes, and on fewer than 10% of those that take more than about 4 hours. Even so, a sequence you had to write by hand for last year's model may be one the current model can be trusted with. Revisit the decision when you change models.
Where this advice runs out
- Workflows fail on the input nobody planned for. If the "anything else" branch keeps growing, or you add a category every week, the rules have become the thing that is hard to maintain. That is the second sign on OpenAI's list.
- Nothing here is a measurement of your task. The compounding table is arithmetic on an assumption, and the costs quoted are general observations from Anthropic. Failure rates per step differ by model and by task, so measure yours.
- The checks cost something too. The policy check adds a model call to every reply, and it can reject a reply that was fine.
How to decide
- Try a single model call with good context. If it solves the problem, stop.
- If the task has steps, draw the flowchart. If you can draw it, build a workflow from the five patterns.
- Put a check after any step whose mistakes are expensive, and send what fails to a person.
- Use an agent for the parts where the path depends on what is found along the way, and cap its steps in code.
- Measure before and after each increase in complexity. Keep the increase only if the numbers improve.