# 27.2 Workflow patterns (/building-ai-workers/agent-architecture/workflow-patterns)

---
type: Document
title: "27.2 Workflow patterns"
description: "Chaining, routing, running side by side and a loop that checks its own work: what each pattern holds in code, what it costs, and where Brightline's review uses it."
status: stable
order: 327.02
ksor:
  owner: team:panaversity
  audience:
    - public
  approval:
    by: process:panaversity
    at: 2026-11-30T08:16:35Z
chapter: '27'
part: III
expert_status: manager
concepts: [ "27.2" ]
last_verified: '2026-11-30'

sources:
  - id: anthropic-building-effective-agents
    title: Building effective agents (Anthropic, 19 December 2024, verified 2026-11-30)
    resource: https://www.anthropic.com/research/building-effective-agents
generated:
  at: 2026-11-30T08:16:35Z
  by: esl-rewrite/1.2.0+ksor.1
trust_tier: unverified
build_id: sha256:d6ce3f28a2cf8e492a60bae1b426b7cc6466e35e83d70c3b9763db2c55009f4b
dirty: true
ksor_version: 0.0.60
---

**In everyday life.** You visit a small clinic. First the desk, then the nurse, then the doctor: the order is printed on the wall. At the desk, a clerk reads your age and sends you to the children's room or the adults' room. Later, one room takes your blood while another takes an X-ray, because neither needs the other. The doctor reads both results and may send you back for one more test, and after two tries sends you to a specialist. The nurse, the clerk and the doctor each use their own judgment. None of them decides where you go next. The clinic's rules do. And a patient whom no sign covers goes back to the desk, to a person. In this section, the staff are model calls, the clinic's rules are your code, and the patient is one invoice.

**What you will learn.** You practice this in Lab 27, Task 1, where you build the workflow.

- What does it mean that code holds the plan?
- How does a chain hold the order?
- How does a route hold the branch?
- Which steps can run side by side?
- Who holds the stop when a check sends work back?
- What happens to a case that no branch covers?

**Why it matters.** "Code decides" is not one design. Each of the four patterns answers a different part of the auditors' question, and each fails on a different case.

**At work.** It is still Wednesday morning. The workflow's column of the table is filled (27.1). Before your coding agent writes `src/workflows/month-end.ts`, you write its plan in five plain steps:

1. Code calls `list_open_invoices`.
2. For each invoice, code calls `find_vendor` and `get_purchase_order` with the ids on the invoice.
3. Code sends the model one request for that invoice, with what the lookups returned. The model says whether the invoice is a problem and gives the policy line. Its only tool is `search_policy`, and it has a turn limit.
4. Code records the decision.
5. After the last invoice, code runs Lab 26's check.

Every "then" and every "for each" in that plan is a line of your code.

### What does it mean that code holds the plan?

**The order, the branch, what runs side by side, and the stop are all written before the run starts.** Anthropic's essay "Building effective agents" lists these as patterns for workflows.[^anthropic-building-effective-agents]

<!-- FIGURE 27.2: "Four ways for code to hold the plan." Four small diagrams in one row, left to right. Each has a label above it, and each uses rounded boxes for steps (a model call or plain code) and arrows between them. (1) Label "the order" (chain): three boxes in a line, "look up", "judge", "check", with one arrow from each box to the next, left to right. (2) Label "the branch" (route): one box, "which kind of invoice?", with two arrows leaving it to the right, one up to a box "prompt: has a purchase order" and one down to a box "prompt: no purchase order". A small tag on the first box reads "its output picks one arrow: a field, or a model's answer". (3) Label "side by side" (run in parallel): one small square, "code: for each invoice", with three arrows fanning right to three boxes, "invoice 1", "invoice 2", "invoice 3", and three arrows from those boxes joining at a small square, "code: collect". (4) Label "the stop" (evaluator-optimizer, check and retry): a box "write" with an arrow right to a box "judge". From "judge", one arrow right to "pass: record it", and one arrow curving back left to "write", labeled "fail: send what was wrong". On the backward arrow a small counter reads "at most 2 rounds, then a person". A caption strip under all four diagrams: "Code draws every arrow. A model can pick an arrow. It can never add one." Every arrow in the figure is drawn in the one color used for code. The alt text must name all four labels, give each diagram's boxes and the direction of each arrow, say that the round limit sits on the backward arrow, and give the caption strip's three sentences. -->

*Figure 27.2. Four workflow patterns, each named by what code holds. A model's answer can choose between two arrows that code drew. It cannot draw a new one.*

### How does a chain hold the order?

**Each step runs after the one before it, and takes its output.** The essay calls this prompt chaining, which "decomposes a task into a sequence of steps, where each LLM call processes the output of the previous one."[^anthropic-building-effective-agents] In this book a *chain* can mix model calls with plain code. Brightline's chain is: look up, then judge, then check. The first two run for each invoice. The check reads the whole review, so it runs once, after the last invoice.

<!-- EDITOR: is the chain's third step the check? The spec's words are "Chain: look up, then judge, then check", and Figure 27.2's first diagram draws "check" as its third box. But Lab 26's check reads a whole review, so it cannot run for one invoice, and the plan above runs it after the last invoice. This draft keeps the spec's three steps and says that the check runs once. The other option: the chain for one invoice is "look up, then judge, then record", the figure's third box becomes "record", and the check stays outside the chain. -->

A chain is what answers the auditors. The same invoice goes through the same steps in the same order, because the order is not the model's to change.

Its price is time, and a fixed shape. The essay says a chain will "trade off latency for higher accuracy".[^anthropic-building-effective-agents] Latency is the time you wait for an answer. The essay adds that a chain fits a task that "can be easily and cleanly decomposed into fixed subtasks."[^anthropic-building-effective-agents] An invoice that needs a step the chain does not have gets no such step.

### How does a route hold the branch?

**Code sends each input down one of a fixed set of paths.** The essay's routing "classifies an input and directs it to a specialized followup task."[^anthropic-building-effective-agents] To *route* is to sort first, and then use the prompt written for that kind.

At Brightline, an invoice with no purchase order is its own kind. The connector says so. It answers with a tool error that names the missing purchase order and quotes the policy line, `po-matching.md:9` ([17.3](../connectors-and-mcp/errors-that-say-what-to-do-next.md)). So code sends that invoice to a second prompt, written for it.

The sorting can also be a model call. The essay allows classification "either by an LLM or a more traditional classification model/algorithm."[^anthropic-building-effective-agents] Then the model picks among branches, and code fixed which branches exist.

Its price: a route knows only the kinds you wrote a branch for.

### Which steps can run side by side?

**Steps that do not depend on each other.** Code can start several such steps at the same time, which is to **run in parallel**. The essay's name is parallelization, and its first kind is "Breaking a task into independent subtasks run in parallel."[^anthropic-building-effective-agents] Looking up two different invoices is the simple case: neither lookup needs the other's result.

Code decides what runs side by side, and how many. That is the difference from an orchestrator, where the model decides it (27.3).

Its price: a step that needs another step's result cannot run beside it. In a review, a late invoice can depend on an earlier decision ([26.1](../context-engineering/why-long-sessions-drift-and-bloat.md)). Those decisions must stay in order.

In this book's lab, the workflow judges each invoice alone, in a request of its own. So it cannot see an earlier decision. An invoice whose answer depends on one is a case that no branch covers ([below](#what-happens-to-a-case-that-no-branch-covers)).

<!-- EDITOR: what the workflow's model step receives. 26.1 keeps the review in one session because a late invoice can depend on an earlier decision, and this workflow sends the model one request for one invoice (the plan under "At work", and Task 1's step 6), so no request holds an earlier decision. The spec's raised point 8 proposes one Messages API call for each invoice and says nothing of earlier decisions. This draft keeps one invoice alone in each request, as closest to the spec, and names the price in the paragraph above. It does not say how code would notice such an invoice. The other option: the request also carries the decisions recorded so far, written into step 3 of the plan and into Task 1's step 6. -->

The essay names a second kind, voting: "Running the same task multiple times to get diverse outputs."[^anthropic-building-effective-agents]

### Who holds the stop when a check sends work back?

**Code does, as a round limit.** In the essay's **evaluator-optimizer** pattern, "one LLM call generates a response while another provides evaluation and feedback in a loop."[^anthropic-building-effective-agents] The plain name is check and retry: one call writes, a judge reads, and a failure goes back with what was wrong.

You have built this loop already, with code as the judge. In 23.16, the check by code reads the report, sends the specific failure back, and stops after two corrections. In 23.17, the outcome is the same loop with a grader. A grader is a model that judges against a rubric, a written list of what a good answer has. In both, the judge may ask for another round. It never decides how many rounds there are. Your code holds that number, and what happens when it is reached.

The essay says when the pattern fits: "when we have clear evaluation criteria, and when iterative refinement provides measurable value."[^anthropic-building-effective-agents] Its price is one more round of model calls for each failure. And a judge catches only what it tests.

### What happens to a case that no branch covers?

**It stops, and it is marked for a person.** This is the price of every pattern above: a workflow handles only what its builder planned for. When an invoice fits no branch, the workflow does not guess. It marks the invoice `needs_review`, and the invoice waits for Ana. `needs_review` is Lab 24's status for a result that code would not accept.

<!-- OPEN: who receives a review's `needs_review`, and whether an invoice so marked passes Lab 26's check. For the first, the spec proposes Ana Morales, as in Lab 24, and this draft says so. The other option is Dave Kowalski, who asked for the review. For the second, the spec proposes that the invoice counts as an entry, so the check passes it (raised points 3d and 20). The other option: the check fails the review until a person has decided the invoice. This section says nothing of the second. -->

The other fair choice is a step the model decides. An orchestrator can take that invoice by a path of its own. It does so at a higher cost, and with no promise of the same path (27.3). In Lab 27, Task 2, you give both builds such an invoice and record what each does.

**The operating rule:** in a workflow, a model's answer may choose among the arrows your code drew. If you need the model to draw a new arrow, that step is an agent's, and it needs a stop, a boundary and a check.

**Do this now.** Ask your coding agent to find the plan in code you already have. Copy this line:

> Read the code that runs this project's worker. List each place where the code fixes the order of two steps, picks a branch, starts steps at the same time, or stops a retry loop, with the file and line for each. Then list each place where a model's answer picks what happens next. Say which of those have no limit in code. Change no file.

[^anthropic-building-effective-agents]: Building effective agents, Anthropic.
