MESHFLOW_MOCK=1 python3 hands_on/05_multi_agent_team.pyThis lesson teaches how to design multi-agent systems in a starter-friendly way. A multi-agent system uses more than one agent to solve a task. Each agent should have a clear role, limited tools, clear inputs, and explicit outputs.
The main lesson:
Multiple agents can improve work only when their responsibilities are clear.
Without structure, they create more confusion, cost, and risk.
A multi-agent system is an AI application where two or more agents collaborate, debate, divide work, review each other, or hand off tasks.
Example:
researcher_agent -> writer_agent -> reviewer_agent -> approval_gate
Each agent uses an LLM, but each has a different responsibility.
Use multiple agents when different responsibilities benefit from separation.
Good reasons:
Weak reasons:
Beginner rule: add a second agent only when you can explain what it does that the first agent should not do.
| Role | Responsibility | Typical Tools |
|---|---|---|
| Planner | Breaks goal into steps | None or read-only project context |
| Researcher | Finds and summarizes evidence | Search, retrieval, file read |
| Analyst | Compares options and tradeoffs | Calculator, data query |
| Writer | Drafts final content | Usually no external tools |
| Reviewer | Checks quality and policy | Rubric, validator |
| Safety guard | Looks for risk | Policy checker |
| Executor | Performs approved actions | Restricted action tools |
Keep risky tools away from exploratory agents.
One agent produces an artifact for the next.
researcher -> writer -> reviewer
Best for beginner workflows because it is easy to inspect.
Several agents work independently, then a merge step combines results.
technical_researcher
market_researcher
risk_researcher
-> synthesizer
Best when subtopics are independent.
Agents argue different positions before a judge decides.
pro_agent -> con_agent -> judge_agent
Useful for decisions, but needs a strict stopping rule.
A manager agent delegates tasks to worker agents.
manager -> researcher
manager -> writer
manager -> reviewer
Powerful, but harder to debug. Use after you understand sequential handoff.
A critic reviews a draft, then a writer revises.
writer -> critic -> writer -> approval
Always set a maximum number of revisions.
Not every agent needs the same context.
Researcher context:
Writer context:
Reviewer context:
This separation reduces confusion and limits unnecessary exposure to data.
Multi-agent memory needs clear rules.
Decide:
Simple design:
shared project memory: approved facts and decisions
agent scratchpad: temporary, not stored
final memory write: only after approval
Do not store every agent message as long-term memory. Store useful approved summaries.
Tools should match roles.
Example:
| Agent | Allowed Tools | Blocked Tools |
|---|---|---|
| Researcher | search, read docs | send email, publish |
| Writer | style guide lookup | database write |
| Reviewer | rubric scorer, policy checker | publish |
| Executor | publish action | search everything |
This is least-privilege design for agents.
Agents should communicate through artifacts, not only hidden chat.
Examples:
research_brieftechnical_notesrisk_notesdraft_answerreview_findingsrevision_planapproval_recordArtifacts make collaboration inspectable.
Multi-agent systems need strong stopping rules because conversations can drift.
Examples:
No stop rule means no production-ready agent system.
Add governance wherever agents can:
Useful controls:
Run:
python3 -m src.mini_meshflow run examples/07_multi_agent_debate.json
Then inspect:
Design a multi-agent lesson-builder:
planner_agent
-> researcher_agent
-> writer_agent
-> reviewer_agent
-> approval_gate
-> final_lesson
For each agent, define:
Mistake 1: Too many agents.
Correction: Start with two or three roles.
Mistake 2: Every agent sees everything.
Correction: Give each agent only the context it needs.
Mistake 3: Every agent has every tool.
Correction: Match tools to roles.
Mistake 4: Agents talk but do not produce artifacts.
Correction: Require named outputs.
Mistake 5: No final authority.
Correction: Add a judge, reviewer, gate, or workflow rule.
Mistake 6: No stopping rule.
Correction: Add turn limits, artifact requirements, and budget limits.
Before building, answer:
Multi-agent systems are powerful when they divide responsibility clearly. The safe beginner pattern is:
specialized roles + limited tools + explicit artifacts + gates + traces
Do not measure sophistication by the number of agents. Measure it by clarity, control, and quality.
python3 -m src.mini_meshflow run examples/07_multi_agent_debate.json
Write down each agent-like step and the artifact it produces.
Design three agents for a training-course builder:
For each, list allowed tools and blocked tools.
Write the exact context each agent should receive. Keep each context package short and role-specific.
Choose one action that should require approval. Explain what artifact the gate checks and what happens if approval is denied.