AI Agents vs Workflows: Choosing the Right Pattern
Everyone wants to build AI agents. Most should build workflows instead.
Definitions
Workflow: Predefined steps. AI handles specific tasks within a fixed pipeline. Deterministic flow.
Agent: AI decides what to do next. Dynamic planning. The LLM controls the flow.
Workflow: Step A → Step B → Step C → Done
Agent: Observe → Think → Act → Observe → Think → Act → ... → Done (maybe)
When Workflows Win
Predictable processes. Customer support triage, document processing, report generation.
# Workflow: Clear steps, predictable outcome
def process_support_ticket(ticket):
category = classify(ticket) # Step 1: Classify
sentiment = analyze_sentiment(ticket) # Step 2: Analyze
priority = determine_priority( # Step 3: Prioritize
category, sentiment
)
response = generate_response( # Step 4: Respond
ticket, category, priority
)
return route_to_team(category, priority, response) # Step 5: Route
Each step is an LLM call with a specific job. The flow is fixed. Debugging is straightforward.
Why this works: You can test each step independently. You can add guardrails at each stage. You know the cost per execution.
When Agents Win
Open-ended problems. Research tasks, complex analysis, multi-step problem solving where you can’t predict the path.
# Agent: Dynamic planning, unpredictable steps
def research_agent(question):
while not satisfied:
plan = think(question, context) # What should I do?
action = choose_action(plan) # Search? Read? Calculate?
result = execute(action) # Do it
context.add(result) # Learn from it
satisfied = evaluate(context) # Am I done?
return synthesize(context)
The agent decides its own path. Powerful but unpredictable.
Why this is risky: Costs are unbounded. Execution time is unpredictable. Debugging loops is hard. The agent might go in circles.
The Decision Framework
Ask these questions:
Can I define the steps upfront?
- Yes → Workflow
- No → Agent (maybe)
Is cost predictability important?
- Yes → Workflow
- No → Agent is okay
Do I need to debug failures easily?
- Yes → Workflow
- No → Agent is okay
Is the task well-defined?
- Yes → Workflow
- No → Agent
The Hybrid Approach
Most real systems are hybrids. A workflow with agent-like steps.
def smart_document_processor(doc):
# Fixed step: Extract text
text = extract_text(doc)
# Fixed step: Classify document
doc_type = classify(text)
# Agent-like step: Handle based on type
if doc_type == "invoice":
return invoice_workflow(text) # Fixed workflow
elif doc_type == "contract":
return contract_agent(text) # Agent for complex analysis
else:
return general_summary(text) # Simple LLM call
Use workflows for the structure. Use agents for the genuinely complex parts.
Common Mistakes
Building agents for workflow problems. If you can draw a flowchart, you don’t need an agent.
No guardrails on agents. Always set: max iterations, max cost, timeout, and fallback behavior.
Skipping the workflow stage. Build the workflow first. Only add agent capabilities where the workflow fails.
The Reality
Agents are exciting. Workflows are reliable.
In production, reliable wins. Every time.
Start with workflows. Graduate to agents only when you hit problems workflows can’t solve.
Your users don’t care if an agent solved their problem. They care that their problem got solved.