Session 7· 00· 8 min

Chains vs Workflows vs Agents

What you'll learn
  • Define chains, workflows, and agents as three distinct execution patterns
  • Identify the trade-off between control and autonomy
  • Know when each pattern is the right choice

Before you can choose an architecture, you need a shared vocabulary. The AI engineering world throws around "chain", "workflow", and "agent" loosely, but they describe three fundamentally different execution models. Let's nail them down.

Pattern 1 — Chains (fixed pipeline)

A chain is the simplest pattern: a sequence of steps that always runs in the same order. Think of the story pipeline from Session 1 — generate text, then generate an image, then generate speech. No branching, no decisions, no loops.

Chain: A then B then C
Step A
Generate text
Step B
Generate image
Step C
Generate speech
Chains are deterministic
Given the same input, a chain always follows the same path. The LLM output may vary, but the flow itself never does. This makes chains easy to debug, test, and monitor.

Pattern 2 — Workflows (predetermined steps with gates)

A workflow adds decision points (gates) between steps. The overall set of steps is still predetermined by the developer, but which steps actually run depends on the output of previous steps. Think of an if/else branch after each LLM call — "if the classification is X, go left; if Y, go right."

Workflow: steps with conditional gates
Step A
Classify input
Gate
Route by class
Step B
Handle class X
Gate
Quality check
Step C
Final output

Workflows give you more flexibility than chains while keeping the developer in control. You define every possible path — the LLM just decides which path to take based on the data.

Pattern 3 — Agents (autonomous tool loops)

An agent is fundamentally different: the LLM itself decides what to do next. It observes the current state, thinks about what action to take, acts (usually by calling a tool), and then observes the result. This is the ReAct loop you learned about in Session 6.

Agent: autonomous observe-think-act loop
ReAct Loop
User Input
messages[]
LLM Reasoning
model.invoke()
Tool calls?
YES
Execute Tool
your Python function
Tool Result
role: "tool"
Loop back to LLM
NO
Final Answer
response.content
Done
return to user

The key difference: in chains and workflows, you write the control flow. In agents, the LLM writes the control flow at runtime. This makes agents powerful but harder to predict and debug.

Side-by-side comparison

Chains
Fixed pipeline
  • Control: Developer controls all steps
  • Flexibility: None — always same path
  • Complexity: Very low
  • Debugging: Easy — linear trace
  • Use case: ETL, simple pipelines, batch jobs
Workflows
Predetermined with gates
  • Control: Developer defines all paths
  • Flexibility: Medium — branches on data
  • Complexity: Moderate
  • Debugging: Moderate — trace each gate
  • Use case: Classification routing, multi-step with validation
Agents
Autonomous tool loops
  • Control: LLM decides next action
  • Flexibility: High — open-ended
  • Complexity: High
  • Debugging: Hard — non-deterministic
  • Use case: Open-ended tasks, complex tool use, research
Start simple, escalate when needed
A common mistake is reaching for agents when a chain or workflow would do. Agents add latency, cost, and unpredictability. Only use them when the task genuinely requires the LLM to decide the next step — not just to look sophisticated.

Check your understanding

Knowledge Check
A script that always runs: (1) summarize text, (2) translate summary, (3) save to database — which pattern is this?
Knowledge Check
When should you reach for an agent instead of a workflow?
Up next
Now that you know the three execution models, the next lesson dives into the 5 specific workflow patterns — the sweet spot between simple chains and full agents.