Multi-Agent Systems
A single agent can handle simple tasks. Complex, real-world problems — research, software development, data analysis — require teams of specialised agents working together. Multi-agent systems divide and conquer.
Why Multiple Agents?
Each agent has a focused role — Researcher, Writer, Critic — and does it better than one generalist.
Independent subtasks run simultaneously, cutting total time dramatically.
One agent's output is checked by another, catching mistakes before they propagate.
Split large tasks across agents, each with a smaller focused context window.
The Supervisor Pattern
The most common multi-agent architecture: a supervisor agent receives the goal, breaks it into subtasks, delegates to worker agents, and synthesises results.
Plans, delegates, synthesises
Web search, data gathering
Statistics, trend analysis
Drafts final report
Reviews and fact-checks
Interactive: Agent Network Visualizer
CrewAI — Role-Based Agents
CrewAI is the most popular framework for building collaborative agent teams with defined roles, goals, and backstories.
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# Define agents with roles and backstories
researcher = Agent(
role="Senior Research Analyst",
goal="Find accurate, up-to-date information on any topic",
backstory="You are an expert researcher with 10 years of experience...",
tools=[search_tool],
verbose=True
)
writer = Agent(
role="Content Writer",
goal="Write clear, engaging articles based on research",
backstory="You transform complex research into readable content...",
verbose=True
)
# Define tasks
research_task = Task(
description="Research the current state of electric vehicles in 2024",
expected_output="A detailed summary of EV market trends, key players, and statistics",
agent=researcher
)
write_task = Task(
description="Write a 500-word article using the research provided",
expected_output="A polished, SEO-friendly article with clear sections",
agent=writer,
context=[research_task] # Writer sees researcher's output
)
# Assemble and run the crew
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential
)
result = crew.kickoff()
print(result) AutoGen — Conversational Agents
Microsoft's AutoGen takes a different approach: agents communicate through conversation, with a human-proxy that can approve actions.
import autogen
config_list = [{"model": "gpt-4o", "api_key": "YOUR_KEY"}]
# Assistant that can write and execute code
assistant = autogen.AssistantAgent(
name="Assistant",
llm_config={"config_list": config_list},
system_message="You are a helpful AI. Write Python code to solve problems."
)
# Proxy for the human — can run code locally
user_proxy = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER", # Fully automatic
max_consecutive_auto_reply=5,
code_execution_config={"work_dir": "coding", "use_docker": False},
is_termination_msg=lambda x: "DONE" in x.get("content", "")
)
# Start the conversation
user_proxy.initiate_chat(
assistant,
message="Calculate the first 20 Fibonacci numbers and plot them."
) LangGraph — Graph-Based Agent Workflows
LangGraph models agent workflows as a directed graph — nodes are agents or functions, edges define flow. This gives precise control over complex pipelines.
from langgraph.graph import StateGraph, END
from typing import TypedDict, List
class AgentState(TypedDict):
messages: List[str]
next_agent: str
final_output: str
# Define agent nodes
def supervisor(state: AgentState) -> AgentState:
"""Decides which agent to call next"""
last_msg = state["messages"][-1]
if "search" in last_msg.lower():
return {**state, "next_agent": "researcher"}
elif "write" in last_msg.lower():
return {**state, "next_agent": "writer"}
else:
return {**state, "next_agent": END}
def researcher(state: AgentState) -> AgentState:
# ... call search API, return results
result = "Found: EV market grew 35% in 2024..."
return {**state, "messages": state["messages"] + [result], "next_agent": "supervisor"}
def writer(state: AgentState) -> AgentState:
# ... write based on research
article = "The EV revolution is accelerating..."
return {**state, "final_output": article, "next_agent": END}
# Build the graph
graph = StateGraph(AgentState)
graph.add_node("supervisor", supervisor)
graph.add_node("researcher", researcher)
graph.add_node("writer", writer)
graph.set_entry_point("supervisor")
graph.add_conditional_edges("supervisor", lambda s: s["next_agent"])
graph.add_edge("researcher", "supervisor")
graph.add_edge("writer", END)
app = graph.compile()
result = app.invoke({"messages": ["Write a report on EVs"], "next_agent": "supervisor", "final_output": ""}) Agent Communication Patterns
Agent A → Agent B → Agent C. Simple, easy to debug. Output of each feeds the next.
CrewAI defaultSupervisor delegates to workers, collects results. Good for tasks with independent subtasks.
Supervisor patternMultiple agents run simultaneously. Much faster — requires result merging logic.
CrewAI Process.parallelTwo agents argue opposing positions. A judge agent picks the winner. Reduces hallucinations.
Society of MindFrequently Asked Questions
When should I use multi-agent vs a single agent?
Use a single agent for tasks that fit in one context window and don't benefit from specialisation. Multi-agent shines for: tasks requiring multiple skills (research + coding + writing), tasks that can parallelise, peer review to reduce errors, or tasks too long for one context window. The overhead of orchestration is only worth it for genuinely complex workflows.
How do I prevent agents from going in circles?
Set a maximum iteration count (e.g., max_iterations=10). Use a termination condition — a special token like "DONE" or a final state in LangGraph. Have the supervisor track which tasks have been completed. LangGraph's graph structure naturally prevents infinite loops if you design edges carefully.
Frequently Asked Questions
What will I learn here?
This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.
How should I use this page?
Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.
What should I read next?
Use the navigation below to continue to the next lesson or explore related topics.