What are the common agentic workflow patterns?

Learning path, stage 4 of 5: Agents, tools and MCP · question 10 of 10

Anthropic's "Building effective agents" names five patterns that sit between a single call and a fully autonomous agent: prompt chaining, routing, parallelisation (sectioning or voting), orchestrator–workers, and evaluator–optimizer. Most production systems are combinations of these with code-controlled flow, not open-ended agents.

The patterns

  • Prompt chaining: a fixed sequence of LLM calls, with checks between steps ("gates"). Example: outline → check → draft.
  • Routing: classify the input, then send it to a specialised prompt or model. Easy questions go to a cheap model, hard ones to a strong model.
  • Parallelisation:
    • Sectioning: independent sub-tasks run at the same time.
    • Voting: run the same task several times and aggregate.
  • Orchestrator–workers: an LLM decides the sub-tasks at run time and hands them out.
  • Evaluator–optimizer: a generate → evaluate → revise loop against criteria.

How to choose

  • The steps are known in advance → chain.
  • The inputs are clearly different kinds → route.
  • Sub-tasks are independent or you need confidence → parallelise.
  • The sub-tasks aren't known in advance → orchestrator.
  • There's a measurable quality bar → evaluator–optimizer.
  • Truly open-ended, with good feedback → agent.

Sources

Code example

tsx
1// Routing + chaining: classify, send to the right model, then a gated second step.
2import Anthropic from "@anthropic-ai/sdk";
3
4const client = new Anthropic();
5const ask = async (model: string, content: string) => {
6 const r = await client.messages.create({ model, max_tokens: 2048, messages: [{ role: "user", content }] });
7 return r.content.flatMap((b) => (b.type === "text" ? [b.text] : [])).join("").trim();
8};
9
10export async function handleTicket(ticket: string) {
11 // 1. route with a cheap model
12 const kind = await ask("claude-haiku-5-5", `Reply with one word, simple or complex:\n${ticket}`);
13 const model = kind.toLowerCase().startsWith("complex") ? "claude-opus-5-5" : "claude-haiku-5-5";
14
15 // 2. chain: draft, then gate, then polish
16 const draft = await ask(model, `Draft a helpful support reply:\n${ticket}`);
17 if (draft.length < 40) throw new Error("Gate failed: draft too short"); // programmatic check
18 return ask(model, `Make this reply friendly and concise. Keep every fact:\n${draft}`);
19}

To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod @modelcontextprotocol/sdk, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.

Open in study app