liveBook · Manning

Chapter 9: Orchestrating multi-agent systems

What you will learn in chapter 9 of Build an AI Agent (From Scratch)

The introduction explains why growing task complexity motivates specialist agents and shows that the multi-agent system builds on the book’s existing Agent foundation.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why growing task complexity motivates specialist agents and shows that the multi-agent system builds on the book’s existing Agent foundation.

Key terms: single agent, system prompts, tools, multi-agent system, specialized role, Agent class, tool system, ExecutionContext, system prompt, run() method

9.1 Why multi-agent?

This section explains why dividing a complex task among specialist agents can be more effective than giving one agent every role, instruction, and tool.

Key terms: system prompt, tools, context window, multi-agent systems, Researcher, Coder, Writer, Reviewer, specialization, reusability

9.2 Three collaboration patterns

This section distinguishes three multi-agent collaboration patterns by who chooses the next agent, how context and control are handled, and when each pattern fits.

Key terms: execution order, context, sharing, isolation, Workflow, Agent as Tool, Transfer, orchestrator, execution flow, parallel execution

9.3 Agent workflow: Defining order in code

This section defines developer-controlled agent workflows, distinguishes three ways to order agents, and explains why workflows are a predictable starting point for multi-agent collaboration.

Key terms: Workflow pattern, execution order, LLM-driven routing, Sequential, Parallel, Loop, context

9.3.1 Workflow design principles

This section explains how giving workflows the same interface as agents makes multi-agent workflows composable.

Key terms: Agent, run(), ParallelWorkflow, SequentialWorkflow, composable

9.3.2 Sequential: Step-by-step execution

This section explains how a sequential workflow runs agents in order while carrying context from one agent to the next.

Key terms: Sequential workflow, user_input, context, result.context, final_result, current_step, termination state

9.3.3 Parallel: Concurrent execution

This section explains when to run independent agents in parallel and how to merge their events and results into one context and output.

Key terms: Parallel workflow, independent, concurrently, asyncio.gather(), existing_event_count, seen_user_event, event.author, [agent_name]

9.3.4 Loop: Iterative execution

Explains when to use a Loop workflow and how it repeatedly runs agents, carries context forward, and stops.

Key terms: Loop workflow, iterative refinement, user_input, context, iteration, is_first_agent, stop_condition, max_iterations, quality_reached

9.3.5 Composing workflows

This section explains how agent workflows can be nested into one pipeline while retaining a common interface, shared context, and a developer-defined execution flow.

Key terms: SequentialWorkflow, ParallelWorkflow, LoopWorkflow, Agent, run(), composability, Context, pipeline, stage, execution flow

9.4 Agent as Tool: Calling agents as tools

This section contrasts fixed workflows with request-dependent specialist selection and introduces calling specialist agents as tools.

Key terms: Workflow pattern, dynamic routing, specialists, agents as tools, LLM, specialist

9.4.1 Making agents into tools

This section explains that an agent can be presented to an LLM through the same interface as any other tool.

Key terms: Agent as Tool, tool, name, description, parameters, result

9.4.2 Implementing AgentTool

This section explains how AgentTool wraps a specialist agent as a tool, handles its input, and keeps its execution context separate from the parent agent’s.

Key terms: AgentTool, BaseTool, parent agent, orchestrator, child agent, request, input_schema, Pydantic, JSON schema, tool parameters

9.4.3 Context isolation

This section contrasts shared workflow context with isolated Agent as Tool context and explains the benefits and tradeoffs of that isolation.

Key terms: Sequential Workflow, Agent as Tool, context, orchestrator, child agents, Abstraction, Context efficiency, Independence, parent context, context window

9.4.4 Practical example: Researcher and coder collaboration

A researcher-and-coder example shows an orchestrator using specialist agents as tools to answer a request that needs both research and code.

Key terms: orchestrator, researcher, coder, AgentTool, web search, code-execution capability

9.5 Agent Transfer pattern

Introduces agent transfer by contrasting its handoff of control with the Agent as Tool pattern.

Key terms: Agent as Tool, Transfer pattern, orchestrator, control

9.5.1 Differences between Agent as Tool and Transfer

This section contrasts Agent as Tool and Transfer in control, context sharing, and who continues the conversation.

Key terms: Agent as Tool, Transfer, control, context sharing, conversation continuity

9.5.2 Transfer is also a tool

This section presents agent transfer as a tool call that reuses the existing tool system to hand control to a specialist agent.

Key terms: Transfer pattern, transfer_to_agent, tool system

9.5.3 Agent tree

This section explains how an agent tree represents transfer relationships, determines allowed targets, and lets a transfer tool find an agent by name.

Key terms: router agent, transfer_to_agent, ExecutionContext, transfer_to, transfer_tools, sub_agents, parent, description, _validate_and_set_sub_agents, agent tree

9.5.4 Implementing the transfer tool

This section explains how the transfer tool limits agent choices and records a requested transfer for the agent’s run method to handle.

Key terms: create_transfer_tool, transfer_to_agent, agent_name, enum constraint, context.transfer_to, run() method

9.5.5 Implementing agent transfer

This section connects the transfer tool to the Agent’s execution flow so an LLM-selected transfer hands work to another agent and returns its result.

Key terms: transfer_to_agent, context.transfer_tools, _prepare_llm_request(), act(), tools_dict, context.transfer_to, run(), step(), context.final_result

9.6 A2A: Collaborating across networks

This section explains why agents in separate codebases need A2A to collaborate over a network.

Key terms: A2A (Agent-to-Agent) protocol, Workflows, AgentTool, Transfer, HTTP-based communication

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

This section explains how A2A clients discover remote agents through agent cards and communicate with them through standardized task requests and responses.

Key terms: agent card, name, description, url, capabilities, A2A, client, server, task request/response, HTTP

9.6.2 Server: Exposing an agent to the network

Explains how to expose an agent as an A2A server by publishing an agent card and handling task requests through an AgentExecutor.

Key terms: A2A server, agent card, agent_card, agent_executor, AgentExecutor, execute, RequestContext, run(), A2A format

9.6.3 Client: Calling remote agents

This section shows how a client uses RemoteAgent to call a networked agent through the familiar agent interface and identifies security concerns for inter-agent communication.

Key terms: RemoteAgent, agent card, run(), _load_agent_info(), sub_agents, AgentTool, Transfer, A2A, authentication, communication encryption

9.7 Summary

The chapter summary explains why specialized agents help as tasks grow, compares three collaboration patterns, and shows how they can be combined across network boundaries.

Concepts explained in this chapter

← Chapter 8: Empowering agents with code execution Chapter 10: Evaluating agents →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.