liveBook · Manning

Subagent

As explained in Build a Multi-Agent System (from Scratch)

A subagent is an agent dispatched by another agent to work on a subtask contributing to an overall task.

A subagent is an agent dispatched by another agent to perform a task or subtask. A coordinator can delegate distinct responsibilities to subagents, then combine their results into an overall response. In one implementation, both coordinator and subagents are LLMAgent instances built with the same processing-loop mechanics. section 1.6 section 4.4

Divide a food search

A coordinator searching for the best-value foods in New York City can delegate croissant and pizza searches to specialized subagents, then combine their completed results. section 1.6

Delegation helps manage context: the subagent maintains its own execution history and returns only its result, rather than filling the coordinator’s context window with intermediate tool calls. This also means the coordinator does not receive the subagent’s full rollout. section 9.1.1

A subagent’s configuration can be tailored to its responsibility:

  • Give it task-specific tools, skills, and prompt templates to support specialization and repeatability. section 9.1.2
  • Restrict access to the tools and data it needs; a sensitive-data subagent might have read-only access. section 9.1.2
  • Use a less expensive backbone model for simpler subtasks when appropriate. section 9.1.2

A tool-based implementation represents each available subagent with a SubAgentSpec containing a builder and task-related configuration. LLMAgent builds a registry from these specifications at construction time. TaskHandler includes a catalog in the system message and exposes UseSubAgentTool when the registry is nonempty. section 9.5 section 9.2.3

To delegate, the coordinator chooses a registered name and supplies a task instruction in a tool call. UseSubAgentTool validates the arguments, constructs a fresh agent, and invokes run() with a new Task. It packages the result or an error as a ToolCallResult for the coordinator. section 9.0 section 9.2.2

Listing 9.3 Implement UseSubAgentTool: parameters_json_schema
# llm_agents_from_scratch/subagents/tools.py
… #A
from typing import Any
 
class UseSubAgentTool(AsyncBaseTool):
   … #B
 
    @property
    def parameters_json_schema(self) -> dict[str, Any]:
        """JSON schema for tool parameters."""
        return {
            "type": "object",
            "properties": {
                "name": { #C
                    "type": "string",
                    "enum": sorted(self._subagents_registry),
                    "description": (
                        "Name of the subagent to dispatch the task to."
                    ),
                },
                "task": { #D
                    "type": "string",
                    "description": "The task instruction for the subagent.",
                },
            },
            "required": ["name", "task"],
        }

The dispatch tool’s JSON schema requires a task string and constrains the subagent name to the registry. section 9.2.2

Common coordination patterns include:

  • Router: select the subagent best suited to a task. section 9.5
  • Fan-out: dispatch independent subtasks concurrently and combine their results. section 9.4.2
  • Chaining: pass work through a predefined sequence, with each step waiting for the previous one. section 9.5

Fan out sequence calculations

A coordinator dispatches three concurrent calls: two compute Hailstone sequences for 4 and 8, while another looks up the sequence for 12. It then compares the returned step counts. section 9.4.2

In this implementation, subagents run locally in the coordinator’s process and event loop, with their logic available to the developer. Remote A2A agents instead run behind a server and are typically treated as black boxes. Hierarchy depth also matters: a depth of one permits only the main agent to dispatch subagents. section 10.1.1 section 9.5

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Implements registry-based dispatch, argument validation, agent construction, result handling, and coordinator integration.
Examples
Uses specialized food searches and concurrent Hailstone sequence tasks to illustrate delegation and aggregation.
What it assumes
Assumes familiarity with LLM agent processing loops, tool calls, builders, and task handling.
What you can do after
Build it from scratch using subagent specifications, a dispatch tool, and coordinator integration.
How it connects
Connects subagents to tool calling, context management, skills, multi-agent coordination, and the A2A protocol.

Also explained in

Compare how 7 books explain subagent →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Multi-Agent System (from Scratch). The section links point to the parts of the book it draws on.