liveBook · Manning

Chapter 9: Assembling MAS with Subagents

What you will learn in chapter 9 of Build a Multi-Agent System (from Scratch)

This introduction explains how a main LLM agent can delegate tasks to subagents and how subagent dispatch works through a tool.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains how a main LLM agent can delegate tasks to subagents and how subagent dispatch works through a tool.

Key terms: main LLM agent, subagents, LLMAgent, LLMAgentBuilder, registry of subagents, descriptions, tool call, delegated task, tool call result

9.1 Using subagents for context management and specialization

9.1.1 Context management

This section explains how delegating subtasks to isolated subagents helps prevent context sprawl in an LLM agent.

Key terms: context sprawl, task history, context window, subagent, subtask, execution rollout

9.1.2 Specialization and repeatability

This section explains how specialized subagents support repeatable task execution, narrower permissions, and lower costs.

Key terms: subagent, tools, skills, prompt templates, consistency, repeatability, permissions, principle of least privilege, attack surface, read-only access

9.2 Supporting subagents in our framework

This section introduces the framework’s mental model for specifying subagents and dispatching them to subtasks.

Key terms: SubAgentSpec, UseSubAgentTool, backbone LLM, subtasks

9.2.1 SubAgentSpec: a core type for specifying a subagent

This section introduces SubAgentSpec as a configuration for constructing, running, and describing a subagent.

Key terms: SubAgentSpec, LLMAgentBuilder, dispatch time, max_steps, skills_scopes, explicit_only_skills, catalog(), XML-formatted string, template

9.2.2 Implementing UseSubAgentTool

This section implements and demonstrates an asynchronous tool that dispatches registered subagents and returns their results.

Key terms: UseSubAgentTool, AsyncBaseTool, _subagents_registry, system message, parameters_json_schema, enum, subagent name, task instruction, __call__, Task

9.2.3 Updating LLMAgent and TaskHandler

This section updates LLMAgent and TaskHandler to register, disclose, and dispatch subagents during task execution.

Key terms: subagents_registry, SubAgentSpec, Skills, TaskHandler, _use_subagent_tool, UseSubAgentTool, _subagents_catalog, run_step(), system message, Task

9.2.4 Defining default subagents

This section defines reusable general and explore subagent recipes and explains their tool permissions and dispatch depth.

Key terms: general subagent, explore subagent, permissions, subagent recipes, SubAgentSpec, LLMAgentBuilder, llm, name, max_steps, dispatch depth

9.3 Supporting tool-based HITL in MAS

This section makes tool-based human input safe for concurrent subagents by introducing a shared, asynchronous console lock.

Key terms: HumanInputTool, SharedConsoleHumanInputTool, shared lock, human operator, AsyncBaseTool, _console_lock, asyncio.Lock, _prompt_human(), worker thread, coroutines

9.4 MAS patterns using subagents

9.4.1 Router

This section explains the Router pattern for selecting a subagent and demonstrates it with a local Hailstone sequence lookup.

Key terms: Router pattern, subagent, coordinator LLM agent, subagent description, subagents catalog, system message, tool, explore subagent, logging, hailstone_known_sequences.json

9.4.2 Fan-out

This section explains how a coordinator uses the Fan-out pattern to delegate concurrent subtasks and combine their results.

Key terms: Fan-out, coordinator LLM agent, subagents, subtasks, concurrently, tool call, processing loop

9.4.3 Chaining

This section explains the Chaining pattern for sequential subagent tasks and demonstrates it with a Hailstone example.

Key terms: Chaining, LLMAgent, subagents, subtasks, task instruction, skill, dispatch order, Hailstone subagent, hailstone_known_sequences.json, coordinator

9.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 8: Human In the Loop Chapter 10: Assembling Interoperable MAS with A2A →

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.