Overview

4 Architecting and building multi-agent systems

```html

The chapter introduces multi-agent systems as a practical response to the limits of a lone agent. As tasks become broader, more tool-heavy, or more difficult to reason through in one pass, developers split work across multiple agents to improve specialization and manageability. The text emphasizes that multi-agent designs can be powerful, but they also add cost, latency, and unpredictability, so they should be adopted deliberately rather than by default.

It then lays out the main architectural and coordination patterns used in agent systems: sequential flows, orchestration, collaboration, parallel delegation, hierarchical coordination, debate and refinement, voting, role-playing, conditional routing, and peer-to-peer networks. Across these patterns, three core concerns recur: who makes decisions, who controls execution, and how agents communicate. The chapter argues that simpler flows are usually easier to build, debug, and evaluate, while more centralized or decentralized structures offer greater flexibility only when the problem truly needs them.

Finally, the chapter focuses on making agent flows safer and more reliable through handoffs and guardrails. It shows how to pass work between agents either through explicit code or built-in handoff mechanisms, how to visualize and monitor those transitions, and how to validate inputs and outputs with guardrails or retry loops. The overall message is to keep agent architectures as simple and typed as possible, add structure only where needed, and use guardrails to preserve predictable behavior as workflows grow more complex.

```
The three well-established patterns for building multiple agent systems, from the agent flow (assembly line), orchestrator (hub-and-spoke), to the collaboration (peer to peer).
Decision-making (command) and control demonstrated for more specialized multi-agent architectures, the flow, orchestration and manager architectures.
Comparing different agent communication patterns represented in a flow.
Various ways agents may coordinate execution sequentially or in parallel.
A single agent is transformed into a multi-agent flow of agents. The agent role is broken down into three well-defined and distinct roles/agents that each encapsulate a well-defined set of tools, appropriate to each of those roles. The single agent becomes a flow of Research Tools agent, Planning agent and Filesystem agent.
shows an agent-to-agent flow with a deterministic (coded) decision point added. Taking the decision away from the agents and making it deterministic keeps the agent flow more deterministic and consistent.
three agent flow communication patterns demonstrating how agents can pass messages from one another and in turn pass command and control from agent to agent.
There are two ways to visualize the agent flow using draw_graph and the Traces page that can be found on the OpenAI Dashboard under logs.
Guardrails can be used to validate and control input and output from an agent, or agent flow.
Traces page after executing the Orchestration agent shows X and Y.

Summary

  • Single-agent designs often hit scalability walls; converting a monolithic agent into an agentic flow (a chain of specialised agents) restores clarity, extensibility, and performance.
  • Agent-to-agent flows work like prompt-chaining with superpowers: each node can invoke tools and reason independently yet pass concise, typed outputs downstream to keep the context lean.
  • Insert deterministic decision points (code or schema checks) wherever the flow must repeat reliably; don’t rely on stochastic LLM judgment for pass/fail branches.
  • The OpenAI Agents SDK supports two hand-off styles: conversational (shared thread) and pass-off (explicit code routing). Choose conversational for speed and pass-off for fine-grained control.
  • Use the handoffs field of the agent plus clear instructional prompts to enable internal hand-offs that require zero extra orchestration code.
  • Visualise complex flows early using draw_graph(), and the Dashboard Traces view reveals hidden loops, tool chains, and latency hotspots.
  • Wrap risky transfers in guardrails—input/output validators that reject, retry, or correct data before it corrupts the flow; tripwires surface as explicit exceptions you can loop on.
  • Guardrails themselves can be LLM-powered agents, giving you natural-language policies without brittle regex or length checks—remember they, too, need schemas and tests.
  • Tool limits still matter in multi-agent worlds: every registered tool inflates every call; keep each agent’s tool list tight (< 10) and scoped to its role to avoid token bloat.
  • Flow, orchestration, and manager-worker are the three canonical decision patterns. Start with plain flows and graduate to orchestrators only when centralised delegation is truly required.
  • Choose one communication layer (shared memory, message passing, MCP, or emerging A2A protocol) per project; mixing channels multiplies debugging pain.
  • A production-ready agentic flow blends typed I/O, deterministic checkpoints, visual traces, scoped tool sets, and guardrails—yielding pipelines that can scale, recover, and evolve without surprise.
  • Agents may be coordinated using multiple different strategies: Sequential Flow, Parallel Delegation, Hierarchical Coordination, Iterative Debate and Refinement, Voting / Best-of-N (Ensemble), Role-Playing Collaboration, Conditional Routing (Branching), and Peer-to-Peer Network

FAQ

What are the main multi-agent architecture patterns introduced in this chapter?The chapter focuses on three foundational patterns for multi-agent systems: flow (assembly line / agent-to-agent pipeline), orchestrator (hub-and-spoke), and collaboration (peer-to-peer). These patterns can be mixed and adapted depending on the use case, but the chapter recommends starting with the simplest pattern that works.
When should I move from a single agent to a multi-agent system?Move from a single agent when the agent becomes overloaded with too many tools, long prompts, or complex responsibilities. Multi-agent flows are also useful when you need specialization, lower cost, lower latency, or more predictable behavior than a monolithic agent can provide.
What is the difference between decision-making, control, and communication in agent systems?Decision-making is choosing what should happen next, control is executing the work, and communication is how agents pass context or messages to each other. The chapter treats these as core design dimensions for organizing agent behavior.
Why is the flow pattern often recommended as the first multi-agent architecture to use?The flow pattern is simple, easy to evaluate, and easy to debug. It works well when a large task can be broken into ordered stages, and it avoids the complexity of centralized orchestration or fully decentralized collaboration.
What are the main pros and cons of the orchestrator pattern?The orchestrator pattern handles complex decision-making well and can execute some or all agents as needed, making it useful for direct user interaction and robust recovery from worker failures. Its downsides are that it is more complex to build, harder to debug and evaluate, and often requires strong guardrails and feedback mechanisms.
How do communication strategies differ between message passing, shared memory, and MCP tool exchange?Message passing is simple and filters noise, but each message depends on the previous agent’s output. Shared message threads give all agents the same context, which improves robustness but increases token usage and confusion risk. MCP tool exchange keeps communication structured and minimal, but adds overhead for each tool call.
What are the most common coordination strategies in multi-agent flows?The chapter highlights sequential flow, parallel flow, hierarchical coordination, and iterative debate/refinement. It also discusses voting/best-of-N, role-playing collaboration, conditional routing, and peer-to-peer networks as useful additional patterns.
Why would you decompose a single agent into a flow of specialized agents?You usually decompose an agent when it is overloaded, when specialization would improve performance, or when you want to reduce cost and latency. Specialized agents can focus on a smaller tool set and a narrower responsibility, which makes the overall system more manageable.
What is an agent handoff, and how is it different from manually chaining agents in code?An handoff transfers control from one agent to another internally, reducing the amount of orchestration code you need to write. Manual chaining keeps control in code and is more explicit, while handoffs are simpler but make dependencies more implicit in the agent instructions.
How do guardrails help validate agent flows?Guardrails validate inputs, outputs, and agent-to-agent transfers to reduce unexpected or unsafe behavior. They can be used to block bad data, enforce typed output, trigger retries, or route the flow to a fallback path when a condition fails.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • AI Agents in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • AI Agents in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • AI Agents in Action, Second Edition ebook for free