This chapter moves from single-agent assistants to practical multi-agent systems, emphasizing how real applications benefit from specialized agents coordinated to solve end-to-end tasks. It begins by connecting tools to concrete data sources so agents can act, not just retrieve information: a local SQLite hotel database exposed via a SQL toolkit and a mocked B&B REST API provide live-like accommodation data, while an existing travel information agent handles destinations and weather. Throughout, the chapter stresses good engineering hygiene—debugging, testing, and tracing—so you can observe reasoning steps, verify tool calls, and iteratively refine behavior.
With the tools in place, the chapter composes agents using two orchestration patterns. First, a router-based approach classifies each user query and dispatches it to the most suitable specialist—either the travel information agent or the accommodation booking agent—via a graph workflow. The router uses a concise system prompt and structured outputs to make clean, deterministic decisions, yielding “one-way ticket” interactions where a single agent handles the question and the workflow ends. This hybrid architecture combines predictable, top-level control flow with flexible, tool-using agents beneath it.
To handle multi-part requests that span domains, the chapter introduces the Supervisor pattern—an “agent of agents” that can invoke multiple specialists, possibly multiple times, in a single session. Treating agents like callable sub-tools, the Supervisor supports “return ticket” interactions, coordinating intermediate results (for example, picking a seaside town with good current weather, then checking hotel availability and price) to produce a coherent final answer. The chapter encourages inspecting traces to understand the collaboration, compare models for the Supervisor, and evolve the system toward richer, open-ended multi-agent workflows.
Router-based multi-agent Travel assistant: the router agent dispatches user queries to either the travel information agent or the accommodation booking agent, each equipped with their own specialized tools
LangSmith execution trace of a travel information question
Supervisor-based multi-agent Travel assistant: the router agent dispatches user queries to either the travel information agent or the accommodation booking agent, each equipped with their own specialized tools
LangSmith execution trace of a combine travel information and booking question
Summary
By integrating external tools—such as SQL databases and REST APIs—agents can retrieve real-time data and perform actions beyond simple information retrieval.
Router-based agent design enable modularity by directing each user query to the most appropriate specialist agent, simplifying single-task scenarios.
The supervisor pattern goes further, orchestrating collaboration among agents, so multiple agents can be used together to answer complex, multi-part questions.
Tracing and debugging with LangSmith provides valuable visibility into agent decisions and tool usage, making it easier to optimize and extend your system.
FAQ
What is the main goal of Chapter 12 on multi-agent systems?To evolve a single travel information agent into a multi-agent travel assistant that can both answer travel questions and book accommodations by coordinating specialized agents using router and supervisor patterns, with robust debugging and tracing.How does the accommodation booking agent connect to data sources?It uses two tools: a LangChain SQL Database Toolkit over a local SQLite database (cornwall_hotels.db) for hotel offers/availability, and a B&B availability tool that calls a (mocked) REST-style BnBBookingService to fetch B&B options.How do I set up and verify the hotel SQLite database?Create a hotel_db folder, place cornwall_hotels_schema.sql inside, then run: sqlite3 cornwall_hotels.db < cornwall_hotels_schema.sql from a plain Command Prompt (cmd). Open the shell with sqlite3 cornwall_hotels.db and verify with .tables and SELECT queries on hotels and hotel_room_offers. Prefer Command Prompt over PowerShell to avoid shell-related errors.How do I expose the SQLite hotel database as agent tools?Instantiate the DB with SQLDatabase.from_uri("sqlite:///hotel_db/cornwall_hotels.db"), create a toolkit via SQLDatabaseToolkit(db=hotel_db, llm=llm_model), then call hotel_db_toolkit.get_tools() to obtain tool objects the agent can invoke (e.g., sql_db_query).How is the B&B availability tool implemented?A mock BnBBookingService.get_offers_near_town(town, num_rooms) returns matching offers from mock data. The check_bnb_availability(destination, num_rooms) @tool wrapper calls that service and returns a list of offers or an error dict if none are available.How is the ReAct accommodation booking agent constructed?Combine hotel_db_toolkit_tools with check_bnb_availability into BOOKING_TOOLS and pass them to create_react_agent along with a prompt instructing the agent to check both hotels and B&Bs when the user doesn’t specify a preference. Invoke it in the chat loop with accommodation_booking_agent.invoke(state).How does the router-based multi-agent assistant work?A router agent classifies each user message into travel_info_agent or accommodation_booking_agent using an LLM with structured output (AgentTypeOutput). In LangGraph, the router node returns a Command with goto set to the chosen agent, and the graph has nodes for the router and both specialists, with terminal edges from the specialist nodes to END.When should I use the router pattern vs. the supervisor pattern?Use the router for single-purpose questions that clearly map to one specialist (“one-way ticket” flow). Use the supervisor when a request spans multiple domains or needs iterative coordination (“return tickets”), allowing the system to invoke multiple agents, possibly multiple times, to combine intermediate results.How do I implement the supervisor-based assistant?Name your leaf agents (e.g., travel_info_agent and accommodation_booking_agent) created with create_react_agent. Then create_supervisor(agents=[...], model=..., prompt=...) and compile it. The supervisor orchestrates agents as tools, deciding which to call and in what order; use a stronger LLM (e.g., gpt-5) for better task decomposition.How do I debug, test, and trace multi-agent interactions?Run scripts (e.g., main_04_01.py, main_05_01.py, main_06_01.py) in debug mode with LangSmith tracing enabled. Inspect traces to see message flows, tool calls, router decisions (structured outputs), Command-based transitions, and supervisor-coordinated sequences to validate reasoning and fix issues.
pro $24.99 per month
access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!