Orchestration Patterns — How to Compose Model Calls
When one call isn't enough, how do you chain multiple calls?
"Ask the LLM and get an answer" — fine for simple questions. But "fix this repo's bug" doesn't work in one shot. Read files, analyze the problem, create a patch, run tests, fix again if they fail. Designing this entire flow is orchestration.
Key Patterns
Chaining — serial structure where the first call's output becomes the second call's input. Simplest but effective. Example: code generation → code review → revision. Each step can use different prompts.
Routing — analyze input and send it to the appropriate processing path. "This question is code-related, send to coding agent." "This is docs-related, send to search agent." A classifier model acts as router.
Parallelization — run independent tasks simultaneously. Analyzing 10 files is faster in parallel than sequentially. Fan-out → process → fan-in structure.
Agent loop — keep iterating until the goal is achieved. "Modify code until tests pass" is the classic example. Calling the model repeatedly inside a while loop. See Agent Loop in the Agentic AI category.
Pipeline — extended chaining. Multiple stages execute in fixed order, each stage using different tools and models. Similar concept to CI/CD.
Pattern Selection Criteria
Simple Q&A → single call is enough.
Quality-critical generation → chaining (generate → validate → fix).
Diverse input types → routing.
Independent bulk processing → parallelization.
Uncertain results, iterative improvement → agent loop.
Complex multi-stage processing → pipeline.
In practice, these patterns are combined. Claude Code uses chaining and parallelization within an agent loop.
How It Works
Chaining — serial structure where A's output feeds B's input (generate → validate → fix)
Routing — classify input and branch to appropriate processing path
Parallelization — run independent tasks simultaneously (fan-out → process → fan-in)
Agent loop — iterate until goal achieved (while + model call + tool use)
Pipeline — multi-stage processing in fixed order, different tools/models per stage