DAY 96

Multi-Agents 🤖🤝⚡

Learn how multi-agent systems work — one orchestrator breaks down a goal and assigns it to specialised agents, each handling only their domain, with structured outputs chaining between them to produce results better than any single agent alone.

⏱ 15 mins
⚡ +50 XP
Multi-Agents 🤖🤝⚡

Day 96: Multi-Agent Systems

Why Should I Care?

No single mind — human or artificial — solves the hardest problems alone. The greatest breakthroughs happen when specialised intelligence coordinates. One doctor cannot be a cardiologist, surgeon, pharmacist, and nurse at the same time. But a team of specialists — each focused on their domain, coordinated by one attending physician — produces better outcomes than any single brilliant doctor alone. Multi-agent systems are how AI starts to work the way the best teams do. Today you build that team.

Core Concept

A multi-agent system has three moving parts: an orchestrator that assigns, specialists that execute, and results that combine. The orchestrator is the attending physician — it receives the goal, breaks it down, and assigns each piece to the right specialist. Each specialist agent handles only its domain and returns a structured result. Results flow between agents until the final output is assembled. The outcome is better than any single agent alone — because each agent is focused, not overloaded.

How It Works

Goal comes in: "Explain RAG for beginners." The Orchestrator breaks it down and assigns tasks — same as a triage nurse assessing a patient and directing them to the right specialist. The Research Agent finds key facts and returns structured JSON — like the cardiologist running tests. The Writer Agent takes that research and writes a clear summary — like the surgeon performing the procedure. The Review Agent checks quality and marks it ready to publish — like the pharmacist verifying the prescription before it leaves. Each agent is a separate LLM call with its own specialisation. Results chain through the pipeline. Published output comes out at the end.

GOAL: "Explain RAG"
    |
ORCHESTRATOR    --> breaks it down, assigns tasks
    |
RESEARCH AGENT  --> finds key facts, returns JSON
    |
WRITER AGENT    --> writes summary using research
    |
REVIEW AGENT    --> checks quality, marks ready
    |
OUTPUT: Published

Each agent = one LLM call, one domain, one structured output.
Three specialists. One shared goal. Better than any solo agent.

Real World Connection

When you ask Perplexity a complex research question, one agent searches, another ranks sources, another summarises, another formats the answer. When a company uses an AI hiring tool, one agent screens resumes, another scores candidates, another drafts interview questions, another logs results. When RohithBuilds generates a new course lesson, one agent researches the topic, another writes the content, another reviews it for quality, another formats it for the platform. Tools like LangGraph, CrewAI, AutoGen, and LlamaIndex are all built on this exact same pattern — orchestrator, specialists, structured outputs. Now you build it yourself in pure Python.

Examples

goal  = "Explain how RAG works for beginners"
tasks = orchestrator(goal)

print("== Multi-Agent Pipeline Running ==\n")

for agent_name, task in tasks:
    result = agents[agent_name](task)
    print(f"  Agent  : {agent_name}")
    print(f"  Task   : {task[:40]}...")
    print(f"  Result : {result}\n")

print("== Pipeline Complete ==")
print(f"Agents used: {len(agents)} | Tasks done: {len(tasks)}")

# OUTPUT:
# Agent  : research_agent
# Result : Research complete: Found 5 key facts
#
# Agent  : writer_agent
# Result : Draft written: 3-paragraph summary
#
# Agent  : review_agent
# Result : Review passed. Ready to publish.
#
# == Pipeline Complete ==
# Agents used: 3 | Tasks done: 3

The orchestrator assigns all subtasks before the loop starts. Each agent handles only its own domain and returns a clean result. Results chain through the pipeline — each agent builds on what the previous one produced.

Common Mistakes

Mistake 1 — Building one massive agent that handles everything:

-- WRONG:
def one_big_agent(goal):
    research = llm_call(f"Research this: {goal}")
    written  = llm_call(f"Write about: {research}")
    reviewed = llm_call(f"Review this: {written}")
    return reviewed
# monolithic agents hit context limits
# lose focus, produce lower quality than a coordinated team

-- CORRECT:
research_agent = lambda task: llm_call(f"Research only: {task}")
writer_agent   = lambda task: llm_call(f"Write only: {task}")
review_agent   = lambda task: llm_call(f"Review only: {task}")
# one agent, one domain -- split complex goals into specialists
# one orchestrator to coordinate them all

Mistake 2 — Agents communicating with unstructured plain text:

-- WRONG:
research_result = "Here''s what I found about RAG..."
# unstructured -- writer agent confused
# one misunderstood output breaks the entire pipeline downstream

-- CORRECT:
research_result = {
    "summary": "RAG retrieves documents before generating",
    "facts":   ["fact 1", "fact 2", "fact 3"]
}
# structured JSON between every agent
# every agent output must be parseable by the next
# always define clear input/output formats between agents

Mini Challenge

Mini Challenge

Build a three-agent pipeline in Python for this goal: "Write a beginner tip about Python lists." Agent 1 is the Research Agent — it returns three key facts about Python lists as a JSON list. Agent 2 is the Writer Agent — it takes those facts and writes one beginner-friendly paragraph. Agent 3 is the Review Agent — it checks the paragraph and returns "Approved" or "Needs revision." Wire all three through an orchestrator function and run the full pipeline with one function call. See all three agents fire in sequence. See the structured output chain between them. That is your first multi-agent system. Ship it to GitHub.

Quick Quiz

Q: What is the role of the orchestrator in a multi-agent system?
A: The orchestrator receives the goal, breaks it into subtasks, assigns each subtask to the right specialist agent, and coordinates the results — like an attending physician directing a medical team.

Q: Why must agents communicate with structured JSON instead of plain text?
A: Because one misunderstood output breaks the entire pipeline downstream. Structured JSON ensures every agent output is parseable by the next agent — unstructured text causes confusion and silent failures.

Q: Why does splitting one big agent into specialists produce better results?
A: Monolithic agents hit context limits and lose focus trying to do everything. Specialist agents stay focused on one domain — the combined output of a coordinated team is better than any single overloaded agent.

Bonus Knowledge

LangGraph, CrewAI, AutoGen, and LlamaIndex are four popular frameworks built entirely on multi-agent coordination. LangGraph adds stateful pipelines — agents can loop back, make decisions, and retry steps based on results. CrewAI makes it easy to define agent roles, goals, and backstories so each agent behaves consistently in its domain. AutoGen from Microsoft allows agents to have conversations with each other — one agent critiques another''s output in a feedback loop. All of them are just structured versions of the pattern you built today: orchestrator assigns, specialists execute, results combine. You now understand the foundation every one of those frameworks is built on.

Key Takeaways

Key Takeaways

  • A multi-agent system has three parts: orchestrator assigns, specialists execute, results combine.
  • Each agent handles only its own domain — one agent, one job, one structured output.
  • The orchestrator is the coordinator — it breaks down the goal and directs the right specialist for each piece.
  • Always use structured JSON between agents — one misunderstood output breaks the entire pipeline downstream.
  • Never build one massive agent for everything — monolithic agents hit context limits and produce lower quality than a coordinated team.
  • LangGraph, CrewAI, AutoGen, and LlamaIndex are all built on this exact pattern — now you understand their foundation.
  • No single mind solves the hardest problems alone. Multi-agent systems are how AI starts to work the way the best teams do.

← Previous Lesson