Pick the right structure for several specialised agents working together — supervisor, peer-to-peer, or hierarchical.
Three org structures: a manager decides who speaks next (supervisor); peers chat freely (peer-to-peer); a CEO escalates to a board (hierarchical). Each fits a different problem.
supervisor peer-to-peer hierarchical
| ---- C E O
orchestrator agents specialists
| bounce /
planner, executor between departments
Three common patterns: (a) Supervisor — a manager agent decides which worker speaks next based on intermediate outputs; (b) Peer-to-peer — workers chat freely with a termination condition; (c) Hierarchical — top-level agent delegates to sub-graphs. Supervisor is best for sequential heavy work (research then write); peer-to-peer suits debate/critique; hierarchical suits enterprise workflows with structured decomposition.
# supervisor: control flow that picks next agent
def route(state):
if 'plan' not in state: return 'planner'
if 'draft' not in state: return 'writer'
if 'qa_pass' not in state: return 'reviewer'
return END
graph.add_conditional_edges('orchestrator', route,
{'planner':'planner','writer':'writer','reviewer':'reviewer',END:END})
Supervisor routing makes control flow explicit via state keys — easy to test and reason about.
# peer-to-peer: all agents chat in a shared room
from autogen import GroupChat, GroupChatManager
chat = GroupChat(agents=[coder, tester, critic], max_round=8)
manager = GroupChatManager(groupchat=chat, llm_config=llm_cfg)
coder.initiate_chat(manager, message='Build a function to validate email.')
GroupChatManager is the canonical peer-to-peer pattern in AutoGen — natural-language loops.
# hierarchical: top-level agent delegates to sub-graphs
supervisor = Agent(name='supervisor', allow_delegation=True,
tools=[delegate_to_research_team, delegate_to_writing_team])
Hierarchical supervises sub-graphs; useful when each team is itself non-trivial.
Defaulting to peer-to-peer for sequential work. Without a routing agent, agents repeat and waste tokens.
Supervisor for sequential pipelines; peer for debate and critique; hierarchical for enterprise decomposition. Pick the smallest structure that works.