Pipeline Pattern
Agents arranged as fixed stages with typed hand-offs (Research → Analyze → Write → Review) trade flexibility for per-stage evaluation, replaceability and predictable cost.
You have not marked these as done yet. Read on anyway if they feel familiar; come back to them if something here does not land.
Key points
- Stages communicate through explicit typed artifacts; that schema is the test fixture.
- Any stage can be swapped for cheaper models or deterministic code.
- Bound every back-edge; persist artifacts between stages.
- Latency is additive and predictable — good for batch, bad for chat.
- Validate between stages to stop error compounding.
Shape
A pipeline is the multi-agent version of a Unix pipe. Each stage receives a typed artifact, produces the next one, and knows nothing about stages beyond its neighbours. Research emits {sources: [...], notes}; Analyze emits {claims: [{text, support}]}; Write emits a draft; Review emits {approved, issues}.
Because the contracts are explicit, any stage can be a cheap model, an expensive model, or plain code. Review is often the stage that becomes deterministic first: schema validation, link checking and banned-phrase scans catch most issues without an LLM (Deterministic Evaluators).
Design rules
Define the artifact schema for every edge before writing any prompt. That schema is your test fixture: you can run Write against 50 stored Analyze outputs without ever running Research, which makes stage evals fast and cheap (Golden Datasets).
Keep back-edges bounded. A Review → Write loop is fine with a revision cap of 2; without a cap it is an agent loop in disguise. Persist the artifact after each stage so a failure in Write does not re-run Research's 40 web searches (Idempotency).
1type Research = { sources: { url: string; excerpt: string }[] }2type Analysis = { claims: { text: string; sourceIdx: number[] }[] }3type Draft = { markdown: string }4type Review = { approved: boolean; issues: string[] }5 6const stages = {7 research: (topic: string): Promise<Research> => runAgent(RESEARCH, topic, [search, readUrl]),8 analyze: (r: Research): Promise<Analysis> => callLlmJson(ANALYZE, r, AnalysisSchema),9 write: (a: Analysis, issues: string[] = []): Promise<Draft> => callLlmJson(WRITE, { a, issues }, DraftSchema),10 review: (d: Draft, a: Analysis): Review => lintDraft(d, a), // deterministic first11}Cost and latency profile
Latency is the sum of stage latencies — a 4-stage pipeline of 6 s stages is 24 s, always. That predictability is a feature for batch jobs and a problem for chat. If users are waiting, stream the Write stage and run Research in parallel shards.
Error propagation is the main risk: a wrong claim from Analyze becomes a confident paragraph from Write. Put validation between stages, not only at the end — checking that every claim cites an existing source index costs nothing and catches the most common hallucination path (hallucinated-citations).
When to use — and when not to
- The task is genuinely sequential with clear intermediate artifacts.
- You need per-stage metrics and the ability to replay stages offline.
- Batch or asynchronous workloads where predictability beats speed.
- The next step depends on runtime judgment — use a supervisor or a workflow graph with conditional edges.
- Interactive latency budgets under a few seconds.
- Only one stage really needs an LLM — then it is a script with one model call, not a pipeline of agents.
Failure modes
Reference · showHide
- Error compounding: early mistakes are amplified downstream.
- Unbounded review loops.
- Stage schemas drift as prompts change; downstream stages silently misread fields.
- Re-running the whole pipeline on a late failure because artifacts were not persisted.
Tradeoffs
Best debuggability of any multi-agent shape because every edge is an inspectable artifact.
Check yourself
Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.
What is the difference between an agent and a workflow, and why does the distinction matter in practice?
Show a strong answerHide the answer
In a workflow the code owns the control flow: the steps and their order are defined ahead of time, and LLM calls are nodes within that graph. In an agent the model owns the control flow: it chooses the next action based on the last result. Both can use tools, both can use retrieval, both can be multi-step; the difference is who decides what happens next. See Workflow State Graph and Single Agent.
It matters because everything downstream depends on it. A workflow is deterministic in shape, so you can unit test each node, cache intermediate results, reason about worst-case cost and latency, and explain a failure by pointing at the node that failed. An agent has a variable number of steps, so testing needs golden datasets and statistical thresholds, cost is a distribution, and a failure can be "it chose the wrong tool on step 7 of 12".
Most production systems are hybrids: a workflow graph where one or two nodes are small bounded agents. That keeps the unpredictable part small and observable.
Full interview question, with follow-ups and red flags →When does splitting a system into multiple agents improve it, and when does it make the system worse?
Show a strong answerHide the answer
A split helps when the parts have genuinely different responsibilities that would otherwise crowd one prompt, need independent context (a reviewer should not see the drafter's reasoning, or a worker needs 50k tokens of documents the coordinator does not), need different capabilities (different tools, permissions, or models, such as a cheap model for extraction and a strong one for judgement), or can run in parallel on independent sub-tasks. The boundary between agents must be a clear, typed contract. See Multi-Agent Systems Overview and When Not to Use Multi-Agent.
It makes the system worse when the agents share most of their context (you now pay to transmit it), when the task is sequential and one agent could do it with a longer prompt, when coordination requires many round trips (each is an LLM call plus latency), or when nobody can say what each agent is responsible for. Information is lost at every hand-off because agents summarise for each other, and errors compound across hops.
The precondition is always: can this be solved reliably with one agent or a deterministic workflow? If yes, the split is cost without benefit. If not, I introduce the smallest number of agents with the clearest boundaries and evaluate the whole system end-to-end, not each agent in isolation.
Full interview question, with follow-ups and red flags →A task has five steps but step three sometimes needs to be repeated until a check passes. Agent or workflow?
Show a strong answerHide the answer
Workflow with a bounded loop node; the retry is deterministic control flow, no model decision required.
Full interview question, with follow-ups and red flags →