Agent Design Patterns and Multi-Agent Development in Practice
This article explains how to build production-grade AI agents using a stateful graph runtime instead of linear chains. It covers environment setup and engineering baselines, core concepts such as state, nodes, edges, and checkpointers, nine common agent design patterns, and three multi-agent topologies with guidance on when to use each. Practical scenarios and a pre-launch checklist help teams move from simply calling models to designing reliable agent systems.
1. Why Graphs Instead of Chains
Early agent implementations mostly relied on linear chained calls: prompt in, model out, result returned. This is sufficient for single-turn question answering, but it breaks down quickly once a task requires deciding which path to take, retrieving additional context midway, or stepping back after a failure. Branching gets buried in nested conditions, state is passed through global variables, and loops are written as manual recursion, eventually turning into unmaintainable spaghetti.
The core idea behind production-grade agent runtime frameworks is to model an agent as a stateful graph: nodes carry computation (model calls, tool calls, rule processing), edges carry control flow, and a state object is explicitly passed and merged across the entire graph. This brings three direct benefits:
- Controlled branching and looping: conditional edges make routing a first-class concern, and loops make “reflect and retry” a natural expression;
- Resumable execution: once state is persisted, long-running tasks can resume from the breakpoint, and human review can be inserted at any node;
- Observability: node boundaries are natural instrumentation boundaries, so token consumption, tool latency, and failure reasons can all be tracked at node granularity.
2. Environment Setup and Engineering Baseline
Many agent projects fail not because the model is not capable enough, but because the engineering baseline is missing. It is worth fixing four things from the start:
- Dependency and version pinning: pin versions of the runtime framework, model access layer, and serialization libraries to avoid “works locally, breaks in production.”
- Separate configuration from secrets: keep model endpoints, keys, and threshold parameters in environment variables or a configuration center, not in code.
- Observability essentials: structured logs, distributed tracing, and metrics with alerting. At minimum, record node latency, retry counts, and tool return codes for each run.
- Evaluation set and regression tests: prepare 20–50 test cases for typical intents, and run a regression pass after any prompt or graph structure change.
A minimal illustrative skeleton (pseudocode, structure only):
graph = StateGraph(State)graph.add_node("plan", planner)graph.add_node("act", actor)graph.add_node("reflect", reflector)graph.add_conditional_edges("act", route_by_result,{"ok": END, "retry": "reflect"})graph.add_edge("reflect", "plan")app = graph.compile(checkpointer=memory_saver)
3. Core Components and Multi-Condition Branching
Four concepts are enough to cover about 80% of runtime framework scenarios:
- State: the shared data structure that runs through the entire graph; you need to define which fields can be written concurrently and how they are merged;
- Node: a function-level computation unit that takes state as input and outputs a state delta;
- Edge: normal edges define ordering, conditional edges handle routing;
- Checkpointer: a state snapshot that supports recovery, replay, and human intervention.
The key to multi-condition branching is to decouple decisions from execution: let a lightweight node do only classification (intent recognition, risk assessment, result validation), output a structured label, and let conditional edges map that label to a target node. Adding a business branch then requires only a new label and a mapping, with no changes to execution nodes.
4. Nine Agent Design Patterns (Abstract View)
Frameworks use different names, but the design patterns converge heavily and can be grouped into nine categories:
- Basic reactive loop: repeated model–tool–observation iterations, suitable for open-ended tasks;
- Action-first (ReAct-style): reasoning and actions interleaved, emphasizing “think and act at the same time,” with a maximum iteration count and timeout;
- Memory systems: short-term memory in the context window, long-term memory externalized as vector retrieval or structured storage, with deduplication and decay on writes;
- Separation of planning and execution: produce a step plan first, then execute step by step, with support for replanning;
- Context engineering: trimming, ordering, and compressing prompts, retrieved snippets, and tool results to control noise and cost;
- Reflection and self-validation: an independent review node scores the output after generation, with fallback if it falls short;
- Routing and dispatch: route by intent to dedicated subgraphs to reduce single-graph complexity;
- Parallel fan-out and aggregation: run multiple retrievals or candidates in parallel, then merge results and resolve conflicts;
- Human in the loop: insert a confirmation node before high-risk actions, pausing and waiting for external input.
5. Multi-Agent Systems: Three Topologies and How to Choose
More agents is not always better; the topology determines cost and stability:
- Orchestrator–worker (lead agent driven): the lead agent handles task decomposition and aggregation, while sub-agents do only specialized work. This offers the best controllability and suits businesses with well-defined processes.
- Shared-space driven (blackboard model): agents read and write the same shared state and collaborate through fields. Coupling is loose and extension is easy, but write permissions and conflict resolution must be strictly defined.
- Peer negotiation (group chat/debate): multiple roles speak freely, suitable for creative divergence and solution review, but token costs are high, so a round limit and convergence condition are mandatory.
Selection experience: if a single graph with branching can solve it, do not use multiple agents; when multiple roles are truly required, prefer the orchestrator–worker model; consider shared space only when cross-domain knowledge needs to be aggregated.
6. Practical Scenario Walkthroughs
Scenario 1: Copy generation balancing long-term and short-term goals. Long-term goals (brand tone, compliance red lines) go into persistent memory and system constraints; short-term goals (this campaign’s channel, word count) go into the current state. After generation, a review node scores compliance, tone, and conversion; if it falls short, it falls back for a rewrite, up to two rounds.
Scenario 2: Shared-space-driven inspection. A data agent, an analysis agent, and a report agent share one state: the first writes metrics, the second writes conclusions, and the third writes the document. Field-level write permissions prevent overwriting each other, and if any step fails, the whole run is marked as pending retry.
Scenario 3: Orchestrator-driven ticket handling. The lead agent performs intent classification and task decomposition, dispatching to query, execution, and review subgraphs; execution actions are preceded by a confirmation node to implement human in the loop.
7. Pre-Launch Checklist
- Every loop has an iteration limit and timeout; every tool has a failure fallback;
- State fields have a schema and merge strategy to avoid concurrent overwrites;
- Sensitive actions require human confirmation; logs are redacted;
- There is a regression evaluation set and a gradual rollout switch to release traffic by percentage;
- Cost and latency have baseline data, with automatic degradation to a smaller model or cached results on anomalies.
With these patterns and topologies in hand, teams can upgrade from “knowing how to call a model” to “knowing how to design agent systems” and deliver reliably in real business settings.
