Overview

9 Orchestrating multi-agent systems

As an agent’s responsibilities grow, a single prompt and tool set can become too crowded for reliable performance. This chapter introduces multi-agent systems as a way to split complex work into specialized roles, each with a shorter, clearer prompt and a focused set of tools. The core idea is to treat collaboration like a team: one agent researches, another codes, another writes, and another reviews, allowing the overall system to handle harder tasks with better focus and reuse.

The chapter then lays out three main collaboration patterns. Workflow gives the developer control over execution order, making it ideal for predictable pipelines such as sequential, parallel, or iterative loops. Agent as Tool lets an orchestrator call specialist agents as isolated tools, so the main agent stays in charge while only the final result is returned. Transfer goes a step further by handing control to the most appropriate agent, with shared context so the new agent can continue the conversation directly. These patterns can also be combined to build flexible orchestration structures.

Finally, the chapter shows how these ideas extend beyond one process. It explains how workflows can be composed because they share the same run interface as regular agents, how transfer is implemented with an agent tree and a dynamically created transfer tool, and how A2A makes it possible to work with remote agents over HTTP. Together, these mechanisms let you build agent systems that are modular, scalable, and capable of collaborating both locally and across networks.

Book structure overview: Chapter 9 in focus.
Four specialist agents for technical blog writing: Each agent focuses on a single role with optimized prompts and dedicated tools.
Sequential Workflow: Same context passed through agents one at a time.
Parallel Workflow: Same input distributed to multiple agents with results merged.
Loop Workflow: Iterative execution with writer and reviewer until quality threshold is reached.
Orchestrator Agent: Regular tools and agent tools in the same tool list.
Sequential Workflow: All processes accumulate in a shared context.
Agent as Tool: Child agent runs in an isolated environment and returns only the final result.
Context handling comparison: Agent as Tool isolates the child agent and returns only the summarized result, while Transfer hands over control with shared context.
Transfer pattern flow: Router agent calls the transfer tool to hand over control to the Math Agent, which inherits the same context.
Agent tree structures: Supervisory pattern with single router, Hierarchical pattern with delegation levels, and Network pattern with peer-to-peer transfers.
A2A client-server model: Client queries Agent Card and sends task requests, Server provides agent information and executes tasks.

Summary

  • Single agents face limitations as responsibilities grow. Longer system prompts and more tools make it harder for the LLM to focus on what's relevant, leading to confusion and incorrect tool selection.
  • Multi-agent systems address this by assigning each agent a specialized role with focused prompts and dedicated tools. Benefits include separation of concerns, specialization, reusability, and scalability.
  • Three collaboration patterns exist, distinguished by two criteria: who decides the next agent (developer or LLM) and whether context is shared or isolated.
  • The Workflow pattern has the developer define execution order in code. By making workflows inherit from Agent, you can compose Sequential, Parallel, and Loop patterns freely. Sequential passes context from one agent to the next, Parallel runs agents concurrently, merges results, and Loop repeats until a stop condition is met.
  • The Agent as Tool pattern wraps agents with the BaseTool interface using AgentTool. The orchestrator calls specialists like functions, receiving only final results while intermediate processes remain hidden. This provides abstraction and context efficiency through isolation.
  • The Transfer pattern lets the LLM decide which agent should handle a request by calling a transfer_to_agent tool. Unlike Agent as Tool, control is fully handed over, and context is shared, so the transferred agent continues the conversation directly.
  • The agent tree structure defines transfer relationships through sub_agents and parent references. Each agent can transfer to children, parent, and optionally siblings, with name uniqueness enforced across the tree.
  • A2A (Agent-to-Agent) protocol enables agents to collaborate across network boundaries. Servers expose agents through Agent Cards and process task requests, while clients use RemoteAgent to call remote agents with the same interface as local ones.
  • These patterns are not mutually exclusive. Real systems often combine Workflow for overall structure, Agent as Tool for specialist consultation, and Transfer for domain-based routing, with A2A enabling cross-system integration.

FAQ

Why should you use a multi-agent system instead of one large agent?Using multiple specialized agents reduces prompt bloat, tool overload, and confusion in the LLM’s context window. Each agent can focus on one role, such as research, coding, writing, or review, which improves clarity, specialization, reusability, and scalability.
What are the three collaboration patterns introduced in this chapter?The chapter introduces Workflow, Agent as Tool, and Transfer. Workflow uses developer-defined ordering, Agent as Tool lets a main agent call specialists as tools, and Transfer hands control from one agent to another chosen by the LLM.
When is the Workflow pattern the best choice?Workflow is best when the execution order is known in advance, such as research → write → review. It is predictable, easy to debug, and useful for pipelines where each step naturally follows the previous one.
What is the difference between Sequential, Parallel, and Loop workflows?Sequential runs agents one after another and passes context along. Parallel runs multiple agents at the same time on the same input and merges their results. Loop repeats a set of agents until a stop condition is met or a maximum iteration count is reached.
Why do workflow classes inherit from Agent?They inherit from Agent so they can expose the same run() interface as normal agents. This makes workflows composable, meaning you can nest workflows inside other workflows or use them anywhere a regular agent is expected.
What problem does Agent as Tool solve?Agent as Tool solves dynamic delegation problems where the main agent needs to decide which specialist to call based on the user request. It allows the orchestrator to keep control while delegating subtasks to expert agents.
What is context isolation in Agent as Tool?Context isolation means the child agent runs in its own separate context and returns only its final result to the parent. The orchestrator does not see the child’s intermediate steps, which saves context space and hides internal reasoning.
How is Transfer different from Agent as Tool?In Agent as Tool, the parent agent remains in control and simply calls a specialist like a function. In Transfer, control is handed over to another agent, which then continues the conversation using the shared context.
How does the transfer_to_agent tool work?The transfer_to_agent tool is created from the available target agents and includes their names and descriptions. When the LLM calls it, the tool sets context.transfer_to to the chosen agent name, and the run() loop later detects this and performs the actual transfer.
What is A2A and why is it important for multi-agent systems?A2A, or Agent-to-Agent, is an open HTTP-based protocol for connecting agents across networks, even when they use different frameworks or languages. It lets agents expose an Agent Card for discovery and accept standardized task requests and responses, making cross-system collaboration possible.

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
  • Build an AI Agent (From Scratch) 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
  • Build an AI Agent (From Scratch) 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
  • Build an AI Agent (From Scratch) ebook for free