Peer-to-peer agent networks suffer from infinite conversational loops. The Hierarchical Supervisor Pattern introduces an executive router:
python
class RouterDecision(BaseModel):
next_worker: Literal["coder", "researcher", "tester", "FINISH"]
worker_instructions: str
# The supervisor inspects overall task status and delegates to one worker at a time
supervisor_prompt = """
Inspect the current work log. Choose the next specialized agent to execute:
- coder: Write or refactor code files.
- researcher: Search documentation or web data.
- tester: Execute unit tests and verify behavior.
- FINISH: All acceptance criteria met.
"""Centralized supervision guarantees linear forward progress and deterministic completion criteria.