Agent patterns

Prompt chaining

Also called: chaining

Prompt chaining breaks a task into a fixed sequence of steps, feeding each step’s output into the next. It is the simplest workflow pattern, and it beats one giant prompt whenever a task has natural stages.

James Phoenix
Understanding Data Updated July 3, 2026

Prompt chaining is the most basic way to build something bigger than a single call: split the task into steps and pipe each step's output into the next. Outline, then draft. Draft, then critique, then revise. The path is fixed and you designed it, which makes chaining a workflow, not an agent.

The pattern

Each step gets a focused prompt and a focused context, instead of asking one prompt to do everything at once:

TypeScript
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'

const model = openai('gpt-5-mini')

const outline = await generateText({
  model,
  prompt: 'Give a 3-bullet outline for a short note about RAG.',
})

const draft = await generateText({
  model,
  prompt: 'Write one tight paragraph from this outline: ' + outline.text,
})

The outline becomes part of the second prompt. Two small, well-scoped calls tend to beat one sprawling instruction.

Why break it up

  • Each step is easier to get right. A focused prompt with a focused context has less room to wander.
  • Each step is easier to debug. When the output is wrong you can see exactly which stage produced the problem.
  • You can mix models. Use a cheap model for the easy steps and an expensive one only where it earns its keep.

The cost is rigidity: a chain always runs the same steps in the same order. When the right sequence depends on the input, add a routing step, and when it genuinely cannot be known in advance, reach for an agent.

Tip
Most things people build with agents would be cheaper, faster, and more reliable as a two or three step chain. Try the chain first; only escalate when the numbers say you must.

Related terms

Engineering context for real systems?

Getting the right information into the window at the right time is most of the job. If you want that thinking applied to your product, that is what I do.

See how I can help