Classify the workflow before choosing a pattern
I start with four questions:- How predictable is the path? A fixed sequence favors a chain. Branching based on a small set of known intents favors a router.
- How expensive is a wrong action? Read-only research tolerates more exploration than a workflow that changes records or contacts a customer.
- How much state is required? A single request may need no persistence. A long-running process may require checkpoints, resumability, and explicit state transitions.
- What must be auditable? If an operator must reconstruct a decision, tool inputs, evidence, policy checks, and approvals should be stored as structured events.
Match the architecture to the decision structure
Four patterns cover many enterprise use cases:Deterministic chain
Use a chain when the steps and their order are known: validate input, retrieve evidence, generate a response, check policy, then return or escalate. Each step has a typed contract, and the model operates only where interpretation is needed. This is usually the best starting point because testing and failure ownership remain clear.Router and specialized workers
Use a router when requests fall into distinct domains that need different prompts, sources, or tools. The router should make a narrow classification decision, not solve the task. Workers then receive only the context and permissions required for their domain. A safe default handles ambiguous routing rather than forcing a low-confidence choice.Planner and executor
Use planning when the sequence cannot be known before inspecting the problem. The planner proposes bounded steps, while an executor performs them under tool and budget limits. A verifier checks completion and evidence. Planning adds flexibility, but it also creates more states to evaluate, more opportunities for loops, and a larger prompt-injection surface.Stateful graph
Use a graph when business transitions, approvals, retries, or long-running state matter. Nodes represent explicit operations and edges represent allowed transitions. Checkpoints make recovery possible, while interrupts provide human review before sensitive actions. Graphs are particularly useful when the workflow mixes deterministic services with model-driven decisions. My RAG Equity Research Agent case study illustrates graph orchestration across retrieval, market data, and synthesis. It is a useful example of why each branch needs an observable contract rather than an opaque autonomous loop.Define state, memory, and tool boundaries
State should contain the minimum information required to continue the workflow. I separate:- request-scoped state, such as the active plan and retrieved evidence;
- durable workflow state, such as approvals and completed actions;
- user memory, which requires an explicit purpose, retention policy, and deletion path;
- analytics data, which should not silently become application memory.