Agents vs workflows
Workflow: your code fixes the path and the LLM fills in steps. Agent: the LLM picks each next step and tool in a loop. Go single call → workflow → agent, climbing only when needed.
Analogy: A workflow is a recipe a line cook follows step by step. An agent is a chef handed a full fridge and told "dinner for six": more adaptable, but slower, pricier and harder to predict.
How it works
- Both are built from one block: an LLM augmented with retrieval, tool calling and memory.
- The five workflow patterns: chaining, routing, parallelization, orchestrator-workers and evaluator-optimizer.
- Agents trade latency, cost and predictability for flexibility, using ~4× the tokens of a chat interaction.
- Pick an agent only if steps can't be hardcoded, errors are detectable and runs can be capped.
- Most production "agents" are really workflows with one bounded agentic step inside.
Check yourself
Answer to mark it learned; your answers aren't scored.
A PM asks for an AI agent that reads supplier invoices (PDF) and writes vendor, total and due date into the ERP. Latency must stay ~1–2 s and every run must be auditable. What do you build?
Go deeper
Full explanation
Anthropic's Building effective agents (Dec 2024) draws the standard line. Both are agentic systems:
- Workflow: LLMs and tools orchestrated through predefined code paths. Your code owns the control flow; the model fills in each step.
- Agent: the LLM dynamically directs its own process and tool use. It picks the next action from the last result, in a loop (ReAct: the agent loop), until it decides it is done.
Both are built from one block: an LLM augmented with retrieval, Tool / function calling and memory. The five workflow patterns:
- Pattern: prompt chaining: fixed sequence, code gates between steps.
- Pattern: routing: classify, then send to a specialized path.
- Pattern: parallelization: independent subtasks at once, or N runs and a vote.
- Pattern: orchestrator–workers: an LLM splits the task at runtime and delegates.
- Pattern: evaluator–optimizer: one LLM drafts, another critiques, repeat.
Climb one rung at a time: one call with good retrieval and examples → workflow → agent. Agents trade latency, cost and predictability for flexibility. Reach for one only if all of these hold:
- The steps can't be known in advance or hardcoded.
- Errors are detectable: tests, a verifier, a human approval.
- Value per task pays for many calls and seconds to minutes of wait.
- You can bound it: step cap, budget, scoped permissions.
Most production "agents" are workflows with one bounded agentic step inside.
Code The same job as a workflow, an agent, and both
# WORKFLOW: your code owns the control flow; every path is known and testable
def refund_status_workflow(ticket: str) -> str:
order_id = llm(f"Extract the order id, or NONE:\n{ticket}") # step 1
if order_id == "NONE":
return ask_user("Which order is this about?") # code gate
order = orders_api.get(order_id) # step 2: plain code
return llm(f"Explain this refund status to the customer:\n{order}") # step 3
# AGENT: the model owns the control flow; your code owns tools, budget and stop
def support_agent(ticket: str, max_steps: int = 12) -> str:
messages = [{"role": "user", "content": ticket}]
for _ in range(max_steps):
reply = llm_with_tools(messages, tools=[search_kb, get_order, issue_refund])
if not reply.tool_calls: # the model decided it is done
return reply.text
messages += execute(reply.tool_calls) # results steer the next step
return escalate_to_human(ticket) # budget hit: fail safe, not silent
# Production shape: predictable intents go to workflows, the long tail to the agent
WORKFLOWS = {"refund_status": refund_status_workflow}
def handle(ticket: str) -> str:
intent = classify(ticket) # cheap model, closed label set
return WORKFLOWS.get(intent, support_agent)(ticket)Real example
A fintech shipped a 14-tool support agent: p50 ~40 s, ~$0.20 per ticket, and two runs on the same ticket often took different paths. Traces showed 80% of tickets were 5 intents (refund status, card block, statements, address change, fees). They rebuilt those as Pattern: routing plus fixed workflows: 2–3 calls, ~4 s, ~$0.02, each step with its own eval. The agent now handles only the ~20% long tail, behind a 12-step cap and human approval for any money movement.
Trade-offs +3 · −3
+ You gain
- Workflows are predictable: each step can be tested, cached and evaluated on its own.
- Agents handle open-ended tasks whose steps can't be hardcoded: coding, research, debugging.
- Agents adapt mid-task: a failed call or a surprising result becomes input for the next step.
− You pay
- Agents are slower and pricier: many sequential calls, each re-sending a growing transcript.
- Agents compound errors: an early wrong step poisons every later one, and two runs can diverge.
- Workflows are brittle outside the paths you anticipated: they fail by rigidity.
Use it when
An agent for open-ended, multi-step tasks where the path depends on what you find (coding, research, incident triage), success is checkable, and each task's value justifies many calls and minutes of latency.
Avoid it when
When the steps are known (extraction, classification, RAG Q&A), latency must stay ~1–2 s, runs must be identical and auditable, or a mistake is costly and can't be caught before it lands.
Numbers to know 3
- Anthropic (2025): agents use ~4× the tokens of a chat interaction; multi-agent systems ~15×.
- Compounding: at 95% per-step reliability a 10-step run succeeds ~60% of the time (0.95¹⁰ ≈ 0.60); at 99%, ~90%.
- Anthropic's 49% on SWE-bench Verified (Claude 3.5 Sonnet, Oct 2024) used a minimal agent: one prompt, a bash tool, an edit tool, a loop.
Common pitfalls 4
- Building an agent first because it demos well, then spending months making it as predictable as a workflow would have been on day one.
- Adopting a heavy framework before writing the loop yourself: abstractions hide the prompts and responses you need to debug.
- No step cap, budget or kill switch: an agent stuck in a loop burns money silently.
- All-or-nothing thinking: the best design is often a workflow with one bounded agentic step, like an agentic search inside a fixed pipeline.
Interview questions 3
Answer out loud first, then reveal.
When would you choose an agent over a workflow?Show answer
I default to the simplest thing that passes the eval: one well-prompted call with retrieval, then a workflow if the task splits into known steps. I move to an agent only when the path depends on intermediate results so I can't hardcode it, success is checkable with tests, a verifier or human approval, and the task's value covers several times the tokens and much higher latency. Even then I bound it: step cap, budget, scoped tools and human approval for irreversible actions.
Your team's agent is slow, expensive and flaky in production. What do you do?Show answer
I read traces before touching prompts. Usually most traffic follows a handful of paths that the agent rediscovers at full price every time. I cluster the trajectories, hardcode the frequent ones as workflows behind a router, and keep the agent for the long tail. Each workflow step then gets its own eval and SLO, cost and latency drop, and the agent's remaining traffic is small enough to supervise. I measure flakiness as pass^k across repeated runs, not single-run accuracy.
Do you need a framework like LangGraph to build agents?Show answer
Not to start. The core loop is about 20 lines against the provider API, and early on I want to see every prompt and response while I learn the failure modes. I adopt a framework when I need what it actually provides: durable state, checkpoints, retries, human-in-the-loop interrupts, tracing. And I make sure I can still inspect the raw prompts underneath, because abstractions that hide them make debugging slower, which is Anthropic's main warning too.