Workflows vs agents: what is the difference, and when would you use each?
Advertisement
🧩 Scenario
Concept Walkthrough
The one-line difference: who decides the next step?
Anthropic's "Building effective agents" post draws the line clearly. In a workflow, LLMs and tools are orchestrated "through predefined code paths". In an agent, LLMs "dynamically direct their own processes and tool usage".
A frontend analogy: a workflow is like a multi-step form wizard. You wrote the steps, the order and the branching rules. An agent is like handing someone the whole admin panel and a goal. They pick which screens to open and in what order. Both are useful, but you would not hand the admin panel to someone who only needs to fill a form.
Common workflow patterns
These are the patterns Anthropic lists, and the AI SDK docs show each one in TypeScript:
- Prompt chaining: the output of one call feeds the next, with code checks in between. Example: draft release notes, then check tone, then shorten.
- Routing: classify the input first, then send it to a specialised prompt or a cheaper model. Example: ticket triage.
- Parallelisation: run independent calls together with
Promise.all, or run the same call several times and vote. - Orchestrator-workers: one call plans subtasks, workers run them. The subtasks are decided at runtime, which already moves you towards agent territory.
- Evaluator-optimizer: one call generates, another critiques, loop until it passes or you hit a retry cap.
When an agent earns its place
An agent makes sense when you cannot predict how many steps a task needs or in what order. "Find why this customer was double charged" might need one lookup or six. You cannot hardcode that path, so you give the model tools and a loop with limits.
The cost of flexibility
Agents trade latency and cost for better results on open-ended tasks. Every extra step is another model call with the whole conversation as input, and a wrong decision early on can compound. A workflow is easier to test because each step has a known input and output, the same way a pure function is easier to test than a component with ten effects.
The practical answer
Start with the simplest thing: a single call. Move to a workflow when you need multiple steps you can describe. Add an agentic step only for the part that is genuinely open-ended, and keep the rest fixed.
Key Code Explained
import { generateText, Output, ToolLoopAgent, isStepCount } from 'ai';
import { z } from 'zod';
const model = 'anthropic/claude-sonnet-5.5'; // example id, use your own
// Step 1 (workflow): classify the ticket with a fixed, cheap call
async function classify(ticket: string) {
const { output } = await generateText({
model,
output: Output.object({
schema: z.object({
route: z.enum(['faq', 'billing', 'investigate']),
}),
}),
prompt: `Classify this support ticket:\n${ticket}`,
});
return output.route;
}
// Only the open-ended route gets an agent, with a hard step cap
const investigator = new ToolLoopAgent({
model,
instructions: 'Investigate the ticket using the tools, then write a short reply draft.',
tools: { /* getOrders, searchPastTickets ... */ },
stopWhen: isStepCount(6),
});
export async function handleTicket(ticket: string) {
const route = await classify(ticket);
// Plain TypeScript decides the path: this is the workflow part
if (route === 'faq') {
const { text } = await generateText({ model, prompt: `Answer from our FAQ style guide:\n${ticket}` });
return text;
}
if (route === 'billing') {
const { text } = await generateText({ model, prompt: `Draft a polite billing reply:\n${ticket}` });
return text;
}
// The model decides the path only here: this is the agent part
const result = await investigator.generate({ prompt: ticket });
return result.text;
}
The if statements are your code making decisions, just like a reducer switching on an action type. Only the investigate branch hands control to the model, and even there isStepCount(6) caps how far it can go.
Tradeoffs
| Aspect | Workflow | Agent |
|---|---|---|
| Who picks the next step | Your code | The model |
| Cost and latency | Predictable | Varies per request |
| Testing | Each step in isolation | Needs evals across whole runs |
| Handles unexpected inputs | Only paths you designed | Can adapt |
| Failure mode | Wrong branch, easy to spot | Wanders, loops, compounding errors |
| Good for | Triage, chains, form-like tasks | Open-ended research, debugging, multi-tool lookups |
What Interviewers Actually Check
- Whether you define the difference by control flow, not by buzzwords
- Whether you default to the simplest option and justify adding autonomy
- Whether you can name concrete workflow patterns
- Whether you think about cost, latency and testability
- Whether you would mix both in one feature
Follow-Up Questions
- Where does orchestrator-workers sit on the line between workflow and agent?
- How would you test a routing workflow compared with an agent?
- What signals in production would tell you a workflow should become an agent, or the reverse?
- How would you add a human approval step to the workflow above?
- How would you cap the retries in an evaluator-optimizer loop, and what does the UI show when it gives up?
Common Candidate Mistakes
- Saying "agent" for anything that calls an LLM.
- Picking an agent because it sounds more advanced, without a reason tied to the task.
- Forgetting step limits on the agentic part.
- Not mentioning that agents are harder to test and debug.
- Treating frameworks as required, when a workflow is often just async functions.
Interview Readiness Checklist
Before you leave this question, make sure you can answer:
- Can you define workflow and agent by who controls the next step?
- Can you name and explain three workflow patterns?
- Can you explain the cost and latency trade-off of agents?
- Can you design a feature that uses a workflow with one agentic step?
- Can you explain why workflows are easier to test?
Summary
A workflow is a path you write in code, with LLM calls as steps. An agent is a model in a loop that chooses its own steps and tools. Workflows give you predictable cost, latency and testing, so they suit tasks you can describe step by step. Agents suit open-ended tasks where the number and order of steps depend on the input, at the price of more calls and harder debugging. Start simple, use workflow patterns like routing and chaining, and add an agentic step only where the task truly needs it, with a step limit on it.
Is an agent always better than a workflow because it is more flexible?
No. Flexibility costs you extra model calls, less predictable latency and a higher chance of compounding errors. Anthropic recommends finding the simplest solution possible and only adding complexity when needed. Many production "AI agents" are really workflows, and that is a good thing.
Can a workflow contain an agent?
Yes, and it is common. A workflow can route a request, run one agentic step for the open-ended part (for example researching a bug), then continue with fixed steps such as formatting and saving the result. Mixing both gives you control where you need it and flexibility where you need it.
Do I need a framework to build a workflow?
Usually not. A workflow is plain TypeScript: async functions, if statements, Promise.all and a loop with a max count. The AI SDK docs show the common patterns with generateText and Zod schemas. Reach for a workflow engine when you need durability, retries across restarts or long waits for human input.
Advertisement
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.
Advertisement