Prompt chaining
Prompt chaining links agents in a line, so each one's output becomes the next one's input. This guide covers when that sequence fits, how to order the handoffs, and how to carry the result into an execution framework.
Read the orchestration guidesChoosing a chain over another pattern
A chain works in a straight line. One agent produces an output, the next agent takes that output as its input, and the step after that works on what it receives in turn. Nothing runs at the same time as anything else, and nothing branches. The order is fixed before the run starts.
When a chain fits
Chaining fits a task you can already describe as a fixed sequence of steps, where each step genuinely needs what the one before it produced. Research a topic, then draft from the research, then edit the draft, is a chain because the editor cannot do anything useful without a draft to work on. If you can write the steps down in order and each one depends on the last, you are looking at a chain.
When a different pattern serves better
Not every multi-agent task is a straight line, and forcing one into a chain usually shows up as agents waiting on work they did not need to wait for, or a single agent carrying decisions that belong to a separate step.
- If two or more steps can start from the same input and run without waiting on each other, that is a case for parallelisation.
- If the next step depends on a decision about which agent should handle the input at all, that is routing.
- If you don't know ahead of time how many subagents a task will need, because the work itself determines how it splits up, that calls for the orchestrator-workers pattern.
- If a step's output needs checking and revising against criteria before it moves on, that is an evaluator-optimiser loop.
Anthropic's post Building effective agents, published on 19 December 2024, sets out prompt chaining alongside these other patterns as separate shapes for separate problems. The guides here follow the same split, one pattern to a guide.
A research-to-summary pipeline: tracing one brief end to end
This example is invented to show the pattern.
The objective given to the pipeline: produce a 300-word brief on "API-based LLM pricing, Q2 2024" from three sources, with any contradictions between those sources flagged. Three agents handle it in sequence — Researcher, Analyst, Writer — each handing its output to the next.
| Role | Tool list | Trigger condition | Handoff target |
|---|---|---|---|
| Researcher | Web search, document fetch | Receives the topic and the 300-word limit | Analyst |
| Analyst | None | Receives the Researcher's raw findings | Writer |
| Writer | None | Receives the Analyst's comparison notes | None (chain ends) |
- The Researcher runs web search and document fetch against "API-based LLM pricing, Q2 2024" and returns three sources: OpenAI's published per-token rates, Anthropic's published per-token rates, and a third-party market report citing enterprise discounts of 15-30%. No synthesis attempted — that isn't this role's job.
- The Analyst reads only these three documents; it has no tools of its own. It finds the two vendor pages agree on usage-based billing — price scales with tokens. It finds the vendor pages and the market report disagree: neither vendor page mentions volume discounts, while the market report states a 15-30% enterprise discount is standard. That disagreement is the contradiction.
- The Writer reads the Analyst's comparison notes and drafts the 300-word brief. It states the usage-based billing point as established fact, then states the discount claim as contested: "the market report's enterprise discount figure is not corroborated by either vendor's own pricing page."
Result: a brief that commits to one claim — usage-based billing — and flags a second claim as unverified. A reader checking the brief against the Analyst's notes can see exactly why the discount line was hedged: the Researcher never found a vendor source for it.
The role split here is a starting point. For a shorter brief where research and comparison collapse into one judgment call, merging Researcher and Analyst into a single role may fit the job better than running three agents for it. That decision belongs to the person building the pipeline.
Turning a chain into subagent files and a framework export
A sequential chain only becomes something you can build once each role in it is written down on its own: a name, a description, the tools that role can call, the condition that starts it, and the agent it hands off to next. The order those files sit in follows the handoff order set in the chain.
One file per role
Each agent in the chain gets its own subagent file. A research agent's file lists its search tool and the condition that starts it; the agent it hands off to only needs that agent's name and the input it expects. Keeping roles separate is what lets you change one agent's tool list without reading through every other role to find it.
Carrying the structure across
LangGraph, CrewAI, n8n and AutoGen each expect that structure in a different shape: LangGraph as nodes and edges, CrewAI as agents and tasks, n8n as workflow nodes, AutoGen as agent definitions with a conversation pattern. The role, the tool list, the trigger condition and the handoff target carry across to any of them, but the shape they are written in does not stay the same. When you write the chain in your chosen framework, the handoff order from the plan becomes the order the framework runs it in.
Read the chain through before running it. A trigger condition or a tool that looks right in the plan can still misfit once the chain runs against your actual data.