chapter nine

9 Orchestrating multi-agent systems

 

This chapter covers

  • Using 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 such as web search, calculation, and code execution. A single agent could solve many problems in the General AI Assistants (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. No matter how capable that person is, performance suffers when roles multiply. We’ll address this challenge by implementing a multi-agent system in which multiple agents collaborate. We’ll assign each agent a specialized role and dedicated tools and then orchestrate the agents 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

Summary