Loop Engineering · Lesson 2 · Lever 01 — Control flow
🌐 हिंग्लिश version →

The Dial, and the Five Patterns

Lever 01 up close: deciding, at each point, whether your code drives or the model drives — and naming the five shapes the workflow side comes in.

Lesson 1 gave you the map and its master lever: control flow — who decides the next step, your code (a workflow) or the model (an agent). The single most important correction to make to your intuition is this: that choice is not made once for the whole system. It's a dial you set at every decision point.

A production “agent” is usually a mostly-deterministic program with the model dialled in at a few high-leverage spots, and dialled out everywhere reliability is cheaper to get from code.2 Your job this lesson: learn to set the dial deliberately, and to recognise the five named shapes the workflow end comes in.1

The default that beats cleverness

Anthropic’s headline finding, after surveying dozens of production deployments, is almost anticlimactic:

Consistently, the most successful implementations weren't using complex frameworks… they were building with simple, composable patterns. Find the simplest solution possible, and only increase complexity when needed… add complexity only when it demonstrably improves outcomes. — Anthropic, Building Effective Agents

So the dial has a default position, and the default is “toward code.” You earn each click toward the model end by showing it buys you something a deterministic path couldn’t. Before reaching for an autonomous agent, ask two questions:

The two-question gate 1. Can I predict the steps? If yes, write them as code — a workflow.
2. Does handing control to the model demonstrably beat that? If you can’t show it does, don’t. Single model call < workflow < autonomous agent — climb only when the rung below fails.1
capability ↑ · risk ↑ Autonomous agent — the model decides the route Workflow — your code decides the route Single model call ← start
The complexity ladder. Start on the bottom rung; climb only when the one below provably underperforms.

The five workflow patterns

Everything on the workflow side of the dial is a composition of five patterns. Learn them as a vocabulary: when a problem arrives, you want to name the shape, not invent it.1

PATTERN 01

Prompt chaining

Fixed sequential steps; each call works on the last one’s output, with optional code checks (“gates”) between.

PATTERN 02

Routing

Classify the input, then dispatch to a specialised path. Lets you optimise each category — and pick cheap vs. capable models.

PATTERN 03

Parallelization

Run calls at once. Sectioning splits independent subtasks; voting runs the same task several times for confidence.

PATTERN 04

Orchestrator–workers

A lead model breaks a task into subtasks at runtime, delegates to workers, and synthesises. For when you can’t list the subtasks up front.

PATTERN 05

Evaluator–optimizer

A generator produces; a separate critic scores and feeds back; loop until good. Needs clear evaluation criteria to converge.

Reach-for-it-when
When the task…Reach for
splits cleanly into fixed, ordered subtasksPrompt chaining
falls into distinct categories handled differentlyRouting
has independent parts, or needs multiple looks for confidenceParallelization
needs subtasks you can’t predict until you startOrchestrator–workers
has a clear quality bar and improves with critiqueEvaluator–optimizer
Orchestrator–workers vs. a true agent They look alike — both decide subtasks at runtime. The tell: orchestrator–workers keeps a fixed delegate-then-synthesise structure your code owns; a full agent hands the model open control over the whole loop, including when to stop.1

Two of them, in code

Routing and evaluator–optimizer are the two you’ll reach for most. Both keep the structure in code and put the model on a leash — exactly the discipline Lesson 1 called “own your control flow”:

Routing — the model picks a label; YOUR switch dispatches
route = model(classify_prompt(query)).label    # model returns a label only
handler = {                                     # the switch is yours, not the model's
    "refund":    handle_refund,
    "technical": handle_technical,
    "general":   handle_general,
}[route]
return handler(query)                           # specialised path per category
Evaluator–optimizer — generate, critique, repeat until the bar is met
draft = model(generate_prompt(task))
for _ in range(MAX_ROUNDS):                     # bounded loop — see Lesson 4
    verdict = model(critique_prompt(draft))     # a second call grades the draft
    if verdict.passes:
        return draft
    draft = model(revise_prompt(task, draft, verdict.feedback))
return draft                                    # best effort within the budget

Where agents earn their keep

You dial all the way to agent for “open-ended problems where it’s difficult or impossible to predict the required number of steps.”1 That flexibility is bought with cost, latency, and a wider blast radius for mistakes — which is exactly why the later levers (context, budgets, error recovery) exist: they’re the guard-rails that make the agent end of the dial safe to use.

Your win today

Given a task, you can now (1) set the dial with the two-question gate instead of defaulting to “build an agent,” and (2) name which of the five patterns fits — chaining, routing, parallelization, orchestrator–workers, evaluator–optimizer — and say why. That’s the core design skill of Lever 01.

Recall check

Retrieve, don’t re-read. Map each scenario to its pattern from memory.

Primary source — read this next

Anthropic — Building Effective Agents. Re-read the “Workflows” section: each of the five patterns has a diagram and a worked example. ~15 minutes. Notice how every example keeps the structure in code and the model on a leash.

I’m your teacher — use me. Bring me a real decision point from one of your own agents and we’ll set the dial together: is it a workflow or does the model truly need control? Want me to classify the stages of your TradingAgents pipeline into these five patterns? Just ask in the chat.
Lesson 1: The Map 📖 Glossary Next → Lesson 3: The Context lever

Sources

  1. Anthropic — Building Effective Agents. Workflow vs. agent; the five patterns and when to use each; “add complexity only when it demonstrably improves outcomes.”
  2. HumanLayer — 12-Factor Agents. Factor 8: own your control flow — most of a reliable agent is ordinary code with the model at key points.