AI Summary Hub

Multi-agent systems

Multiple agents collaborating or competing.

Definition

Multi-agent systems (MAS) involve multiple AI agents that interact to solve tasks: collaboration (divide work, share state), debate (argue and refine answers), or specialized roles (planner, executor, critic). Rather than a single monolithic agent trying to do everything, MAS assigns distinct responsibilities to different agents and composes their outputs.

They extend single agents when one model or one loop is insufficient: for example, one agent for RAG retrieval, another for generation, and another for critique and fact-checking. Each agent can use a different model, a different set of tools, and a different system prompt tuned for its role. This modularity makes individual agents simpler, more reliable, and easier to swap or upgrade.

Subagents are a hierarchical form where a root agent delegates to children; multi-agent systems can also be flat (peer-to-peer) or mesh-structured, where agents communicate with each other without a central orchestrator. The right topology — hierarchical, flat, or hybrid — depends on whether the workflow has a natural decomposition into independent or sequentially dependent sub-tasks.

How it works

Orchestrated (hierarchical) topology

Debate / review topology

The user sends a task to an orchestrator (which can be an LLM or a fixed workflow). The orchestrator assigns work to Agent 1, Agent 2, etc., each with its own role, tools, and optionally model. Agents may share a common state, pass messages, or be invoked in sequence or in parallel. Their outputs are aggregated (combined, voted, or summarized) and returned. MAS are useful when you want modularity, specialization, reusability, and structured control flow across complex multi-step tasks.

When to use / When NOT to use

ScenarioUse MASDon't use MAS
Task decomposes cleanly into distinct rolesYes — planner + executor + critic is a natural splitNo — if the task is single-role, one agent suffices
High-confidence needed via debate/reviewYes — debate pattern filters errors through disagreementNo — single-agent is fine for well-understood domains
Different subtasks need different tools/modelsYes — each agent uses only what it needsNo — one agent with all tools is simpler if roles overlap heavily
Rapid prototyping or simple pipelinesNo — MAS overhead adds complexityYes — start with a single agent and add complexity as needed
Strong real-time latency requirementsNo — parallel agents add coordination overheadYes — single-agent is faster for tight latency budgets

Comparisons

PatternStructureCommunicationAutonomyBest for
Single agentMonolithicNoneHigh per agentSimple or moderate tasks
Hierarchical MASTree (root → children)Root delegatesMedium per agentStructured workflows
Flat / peer-to-peer MASMesh or ringDirect messagingHighCollaborative reasoning
Debate / reviewParallel + mergeCritique-basedMediumHigh-confidence generation
Subagent (strict hierarchy)Tree (root owns goal)Controlled delegationLow per subagentComplex, long-horizon tasks

Pros and cons

ProsCons
Modular — each agent has a clear, testable responsibilityCoordination overhead (latency, tokens, state sync)
Specialized agents outperform generalist agents on their roleHarder to debug than a single agent trace
Reusable — same agent in different workflowsCommunication protocol design is non-trivial
Debate patterns can significantly improve accuracyRisk of cascading errors across agents

Code examples

from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage

llm = ChatOpenAI(model="gpt-4o-mini")

def planner_agent(task: str) -> str:
    """Break a task into a numbered plan."""
    response = llm.invoke([
        SystemMessage(content="You are a planning agent. Break the task into 3–5 clear steps."),
        HumanMessage(content=task),
    ])
    return response.content

def executor_agent(plan: str) -> str:
    """Execute the plan and produce a draft output."""
    response = llm.invoke([
        SystemMessage(content="You are an execution agent. Follow the plan and produce a detailed output."),
        HumanMessage(content=f"Plan:\n{plan}"),
    ])
    return response.content

def critic_agent(draft: str) -> str:
    """Review the draft and suggest improvements."""
    response = llm.invoke([
        SystemMessage(content="You are a critic agent. Identify flaws and suggest concrete improvements."),
        HumanMessage(content=f"Draft:\n{draft}"),
    ])
    return response.content

# Orchestrate
task = "Write a short guide on how to get started with RAG."
plan = planner_agent(task)
print("Plan:\n", plan)

draft = executor_agent(plan)
print("\nDraft:\n", draft)

critique = critic_agent(draft)
print("\nCritique:\n", critique)

Practical resources

Sources

See also