liveBook · Manning

Subagent

As explained in Agent Design Patterns

An agent that operates under the coordination or supervision of another agent.

A single agent can struggle when a task depends on more information than fits effectively in its language-model context. A subagent is a specialist agent coordinated by another agent to handle part of a larger task. Instead of giving one agent every detail, the system delegates bounded work to specialists that can be refined and tested independently. section 2.4

Two coordination designs place subagents in different roles:

  • Supervisor team: a supervising agent splits a larger task into subtasks and calls specialist subagents as tools. A mortgage-advice workflow uses this design to combine analysts’ work into an aggregate analysis. section 2.4.2
  • Router: a selector chooses a registered specialist for an incoming task, forwards the input, and maintains a unified communication interface. Selection can account for constraints rather than relying on a fixed hierarchy. section 9.0
Listing 2.6 analyst_team.py: Bundling analysts under a single supervisor
from typing import Any
from .client import Client
from .react import ReActAgent
from .analysts import (
    RateFairnessAnalyst,
    IncomeSufficiencyAnalyst,
    PropertyValueAnalyst,
    IncomeTrendAnalyst,
    ...
)
 
 
class AnalystTeam:
    def __init__(self, client: Client):
        self.client = client
        self.team: dict[str, ReActAgent] = {
            "rate_fairness": RateFairnessAnalyst(client),
            "income_sufficiency": IncomeSufficiencyAnalyst(
                client
            ),
            "property_value": PropertyValueAnalyst(client),
            "income_trend": IncomeTrendAnalyst(client),
            ...
        }
        self.supervisor = ReActAgent(
            client,
            ADVISORY_TEAM_SUPERVISOR_SYSTEM_PROMPT,
            self.team,
            ADVISORY_TEAM_SUPERVISOR_USER_PROMPT_TEMPLATE,
        )
        self.advisory_output: dict[str, Any] = {}
 
    async def run(
        self, mortgate_details: dict[str, Any]
    ) -> str:
        response: str = await self.supervisor.run(
            mortgate_details=mortgate_details
        )
        self.advisory_output = {
            str(type(agent).__name__): agent.get_result()
            for agent in self.team
        }
        return response
 
    def get_result(self) -> dict[str, Any]:
        return self.advisory_output
 
 
ADVISORY_TEAM_SUPERVISOR_SYSTEM_PROMPT = """
...
"""
 
ADVISORY_TEAM_SUPERVISOR_USER_PROMPT_TEMPLATE = """
...
"""

The analyst-team listing registers specialist ReAct agents by name and supplies that registry to a supervising ReAct agent. The registry makes the available delegation targets explicit. section 2.4.2

Mortgage analysis

A mortgage-advice supervisor can call separate agents for rate fairness, income sufficiency, property value, and income trends. Each analyst owns a focused task; the supervisor coordinates their contributions to the larger analysis. section 2.4.2

Choose the coordination mechanism to match the job: a supervisor can assemble multiple specialist contributions, while a router can classify and dispatch a request to an appropriate specialist. Both avoid making one general-purpose agent carry every specialist’s responsibilities. section 2.4 section 9.0

How Agent Design Patterns covers it

How deep it goes
Shows supervised composition in a Python listing and outlines router components, but does not provide a router implementation.
Examples
Uses a mortgage-analyst team and support-line dispatch to illustrate supervision and specialist selection.
What it assumes
Assumes familiarity with agents and tools; starts team assembly from existing specialist ReAct agents rather than building those specialists here.
What you can do after
Build it from scratch by registering specialist ReAct agents under a supervisor, or evaluate routing as an alternative delegation design.
How it connects
Connects subagents to multi-agent systems, ReAct agents, tool use, supervisors, and routing.

Also explained in

Compare how 7 books explain subagent →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Agent Design Patterns. The section links point to the parts of the book it draws on.