chapter nine

9 Orchestrating multi-agent systems

 

This chapter covers

  • Three collaboration patterns: Workflow, Agent as Tool, and Transfer
  • Implementing composable workflows with Sequential, Parallel, and Loop
  • Wrapping agents as tools with context isolation
  • Transferring control between agents using a dynamically created transfer tool
  • Connecting agents across networks with the A2A protocol

Throughout this book, we've explored how a single agent can perform diverse tasks. By assigning roles through system prompts and providing tools, we enabled capabilities like web search, calculation, and code execution. A single agent alone could solve many problems in the GAIA benchmark. But real-world problems are more complex. As an agent's responsibilities grow, system prompts become longer, and the number of required tools increases. It's like expecting one person to be a developer, product manager, designer, and operations specialist all at once. No matter how capable someone is, performance suffers when roles multiply. We’ll address this challenge by implementing a multi-agent system where multiple agents collaborate. We'll assign each agent a specialized role and dedicated tools, then orchestrate them to work together.

9.1 Why multi-agent?

9.2 Three collaboration patterns

9.3 Agent workflow: Defining order in code

9.3.1 Workflow design principles

9.3.2 Sequential: Step-by-step execution

9.3.3 Parallel: Concurrent execution

9.3.4 Loop: Iterative execution

9.3.5 Composing workflows

9.4 Agent as Tool: Calling agents as tools

9.4.1 Making agents into tools

9.4.2 Implementing AgentTool

9.4.3 Context isolation

9.4.4 Practical example: Researcher and coder collaboration

9.5 Agent transfer pattern

9.5.1 Differences between agent as tool and transfer

9.5.2 Transfer is also a tool

9.5.3 Agent tree

9.5.4 Implementing the transfer tool

9.5.5 Implementing agent transfer

9.6 A2A: Collaborating across networks

9.6.1 The core of A2A: Agent card and task request/response

9.6.2 Server: Exposing an agent to the network

9.6.3 Client: Calling remote agents

9.7 Summary