Level 4 — Multi-Agent Pattern: A Manager Coordinates Sub-Agents

~12 min read

A manager agent coordinates multiple sub-agents, deciding the next step iteratively. The human lays out the hierarchy and roles up front; the LLM now controls the actual execution flow across multiple agents, not just a single tool call.

Level 4, the Multi-Agent pattern, extends single-agent tool calling into coordination across several distinct agents. A manager agent coordinates multiple sub-agents and decides the next steps iteratively — rather than one LLM call reasoning about one action, you now have a manager-level LLM deciding which sub-agent should handle the next piece of work, in what order, and how their outputs should feed into each other.

A human still lays out the hierarchy between agents up front — how many sub-agents exist, what each one's role and available tools are, and roughly how they relate to the manager — but within that structure, the LLM (specifically, the manager agent) now controls the actual execution flow: it decides what to do next at each step, which sub-agent to delegate to, and when the overall task is actually complete. This is a genuine step beyond Level 3's single-agent tool calling, where one LLM decides on one action at a time within its own single context — here, an entire multi-step, multi-agent process is being orchestrated by the model itself.

A concrete example: a research-report task might have a manager agent coordinating a research sub-agent (gathers information), an analysis sub-agent (synthesizes findings), and a writing sub-agent (drafts the final report) — the manager decides the order these run in, whether the research phase needs another pass before analysis can proceed, and when the writing sub-agent has produced a satisfactory final draft. None of this sequencing is hardcoded by a human; the manager agent makes these calls based on the actual state of the task as it unfolds.

This level introduces real new complexity beyond tool calling: sub-agents can fail or produce weak output, coordination overhead grows with the number of agents involved, and debugging a multi-agent failure means tracing through several LLM-driven decisions rather than one. It's worth the complexity specifically for tasks that genuinely decompose into distinct specialized roles — the same reasoning that motivates the 7 multi-agent orchestration patterns covered elsewhere in this curriculum.

💻 Code example

from openai import OpenAI

client = OpenAI()

def research_agent(topic: str) -> str:
    return f"[Research findings on {topic}: ...]"

def analysis_agent(research: str) -> str:
    return f"[Analysis of: {research}]"

def writing_agent(analysis: str) -> str:
    return f"[Final report based on: {analysis}]"

SUB_AGENTS = {"research": research_agent, "analysis": analysis_agent, "writing": writing_agent}

def manager_agent(task: str, max_steps: int = 5) -> str:
    """Level 4: the manager LLM decides the NEXT sub-agent to invoke at
    each step, and when the overall task is complete — a human defined
    the sub-agents and hierarchy, but not the execution sequence."""
    state = f"Task: {task}\nProgress so far: (nothing yet)"

    for _ in range(max_steps):
        decision = client.chat.completions.create(model="gpt-4.1", messages=[
            {"role": "user", "content":
                f"{state}\n\nWhich sub-agent should run next: research, analysis, "
                f"writing, or DONE if the task is complete? Answer with one word."}
        ]).choices[0].message.content.strip().lower()

        if decision == "done":
            return state

        result = SUB_AGENTS[decision](state)
        state += f"\n[{decision}] -> {result}"

    return state

💬 Deep Dive with AI

Key points

  • A manager agent coordinates multiple sub-agents, deciding the next step iteratively rather than a human hardcoding the sequence
  • A human defines the hierarchy, roles, and available tools per sub-agent up front — the LLM controls the actual execution flow within that structure
  • This is a real step beyond single-agent tool calling — an entire multi-step, multi-agent process is orchestrated by the model itself
  • New complexity at this level: sub-agent failures, growing coordination overhead, and harder debugging across multiple LLM-driven decisions
  • Worth the complexity for tasks that genuinely decompose into distinct specialized roles, not as a default over simpler levels