Topic 5 of 5 · 4 min read
Combining patterns in production pipelines
Goal: Read a pipeline description, name each pattern it uses, and find the step that adds complexity without a measured gain.
Real systems combine the patterns, and the rule for combining them is the same as for a single one: add a step only when a measurement shows it helps. Each pattern adds calls, latency, cost and a new place to fail, so every addition must pay for itself.
Check yourself · 1 of 3
A pipeline classifies a ticket, extracts fields, validates them, drafts a reply, then scores and revises it up to twice. Which patterns does it use?
Why it matters
A typical support pipeline might route a message to a category, run a chain of extract, look up and draft for that category, and finish with an evaluator loop on the draft. All three patterns appear, and each is reasonable alone. Together they can reach ten or more model calls per request. If nobody can say what each call contributes, the team cannot debug a bad answer, cannot cut cost, and cannot tell which step to improve.
How to build up
- Start with one call and a test set of real inputs with expected results.
- Find where it fails. Group the failures: wrong category of input, a skipped step, a poor first draft, a slow check.
- Add the pattern that matches the failure. Mixed input types call for routing. A skipped step calls for a chain with a gate. Weak drafts that a rubric can judge call for an evaluator loop. Slow independent checks call for parallel calls.
- Re-run the test set and keep the step only if the score, cost or latency improved enough to matter. Remove it otherwise.
- Instrument every step. Log input, output, gate result, latency and tokens per step with one trace id for the whole request.
Naming what you read
Given a pipeline description, label each stage. "Classify the email, then pick a template" is routing. "Extract, validate, summarise" with checks between is a chain. "Three reviewers run at once and a merge step combines them" is sectioning. "Draft, score, revise up to twice" is evaluator-optimizer. "A planner assigns file edits to workers" is orchestrator-workers.
Before and after
Before: route -> chain(5 steps) -> evaluator loop(5 rounds) -> translate
No per-step metrics. Quality unchanged when the loop was switched off in a test.
After: route -> chain(3 steps, 2 gates) -> translate
Evaluator loop removed. Cost per request down, quality score the same on 200 test cases.
What goes wrong
- Stacking patterns by default because a diagram looks serious. Complexity without a measured gain.
- No per-step metrics. A wrong answer cannot be traced to a step.
- Patterns that duplicate each other, such as a gate and an evaluator that check the same rule.
- Errors that compound. A small misroute at the start sends every later step down the wrong path.
Examples
Reading a pipeline
A description says: "An incoming claim is classified as auto, home or travel. For auto claims, one call extracts details, code checks the policy number, and another call drafts the reply. Two reviewers score the draft; if either scores under 4, it is revised once." Patterns: routing, a chain with a code gate, and an evaluator-optimizer loop capped at one revision.
Finding the step with no gain
A team switches off the evaluator loop on 200 test claims. The quality score stays at 4.1 and cost per claim falls by a third. The loop was adding calls and latency without a measured gain, so it is removed.
Key points
- Add a pattern only when a measured failure on a test set shows it would help, and remove it if it does not.
- Match the pattern to the failure: routing for mixed inputs, a chain with gates for skipped steps, an evaluator loop for weak drafts.
- Instrument every step with input, output, gate result, latency and tokens under one trace id.
- Naming each stage by its pattern makes a pipeline easier to read, debug and cost.
- Errors early in a pipeline, such as a misroute, compound through every later step.
Common mistakes
- Adding every pattern up front instead of in response to measured failures.
- Shipping a pipeline with no per-step logging or trace id.
- Keeping a step because it seems careful, with no test-set evidence that it helps.
- Ignoring that a wrong route at the start spoils everything after it.
Check yourself · 2 of 3
Switching off one step in a pipeline leaves the test score unchanged and cuts cost by a third. What should the team do?
Check yourself · 3 of 3
A final answer is wrong. What makes the fault easiest to find across a multi-step pipeline?
Practice items, not counted towards your mastery.
Start here
- Building effective agents (Anthropic) (opens in a new tab)ArticleFree
Defines the five workflow patterns in this skill and when each earns its added cost.
- Workflows and agents (LangGraph docs) (opens in a new tab)DocsFree
Runnable code for chaining, routing, parallelization, orchestrator-workers and evaluator-optimizer.
- How we built our multi-agent research system (Anthropic) (opens in a new tab)ArticleFree
A production orchestrator-workers system, with the failures and trade-offs the team met.
More for this topic
- Develop test cases (Claude docs) (opens in a new tab)DocsFree
How to write measurable criteria and test sets, the basis for gates and evaluator rubrics.