Hierarchical Swarm Example
HierarchicalSwarm implements a director-worker pattern where a central director agent creates comprehensive plans and distributes specific tasks to specialized worker agents. The director evaluates results and can issue new orders in feedback loops, making it ideal for complex project management and team coordination scenarios.
How Hierarchical Swarm Works
The hierarchical pattern follows a command-and-control structure:- Planning Phase: Director analyzes the task and creates a comprehensive plan
- Task Distribution: Director assigns specific subtasks to appropriate worker agents
- Worker Execution: Specialized workers complete their assigned tasks independently
- Evaluation Phase: Director reviews all worker outputs
- Feedback Loop: Director can issue refinements or new tasks based on results
Key Characteristics
- Centralized Coordination: Single director ensures cohesive strategy
- Specialized Workers: Each agent focuses on their area of expertise
- Adaptive Planning: Director adjusts based on worker outputs
- Quality Control: Director validates and refines results
- Scalable Structure: Easy to add new specialized workers
Basic Example: Marketing Team
This example demonstrates a marketing team coordinated by a director:How This Example Works
- Task Reception: Director receives the complex marketing challenge
- Strategic Planning: Director analyzes requirements and creates a master plan:
- Content strategy needs
- Creative campaign requirements
- SEO optimization goals
- Brand positioning objectives
- Task Assignment: Director assigns specific tasks to each specialist:
- Content Strategist: “Develop 3-month content calendar for product launch”
- Creative Director: “Create campaign concepts for SMB audience”
- SEO Specialist: “Research keywords for project management tools”
- Brand Strategist: “Define positioning against Asana and Monday.com”
- Execution: All workers complete their tasks in parallel
- Review & Coordination: Director reviews outputs and ensures alignment
- Refinement Loop (max_loops=2): Director may ask for adjustments:
- “Align content calendar with campaign launch dates”
- “Incorporate top SEO keywords into brand messaging”
- Final Synthesis: Director combines all work into cohesive strategy
The Director-Worker Pattern
The hierarchical pattern excels at:Centralized Vision
The director ensures all workers contribute to a unified goal, preventing fragmented or conflicting outputs.Efficient Delegation
Director identifies what needs to be done and assigns to the most qualified worker.Quality Assurance
Director reviews outputs and can request improvements or corrections.Adaptive Coordination
Based on initial results, director can adjust the plan and issue new directives.Real-World Examples
Software Development Team
Coordinate developers, designers, and testers:Research Team
Coordinate researchers across different specialties:Event Planning Team
Coordinate event specialists:Customer Service Team
Coordinate support specialists:Feedback Loop Examples
Themax_loops parameter enables iterative refinement:
Single Loop (max_loops=1)
Multiple Loops (max_loops=2+)
Real Feedback Example
Benefits of Hierarchical Swarm
- Complex Project Management: Handles multi-faceted projects requiring coordination
- Team Coordination: Ensures all agents work toward unified goals
- Quality Control: Director provides oversight and validation
- Adaptive Planning: Can adjust strategy based on initial results
- Scalable Teams: Easy to add new specialists without restructuring
- Clear Accountability: Director responsible for overall success
Best Practices
1. Define Clear Worker Specializations
2. Use Appropriate Loop Counts
- max_loops=1: Simple tasks, quick execution
- max_loops=2: Standard quality control and refinement
- max_loops=3+: Complex projects needing multiple iterations
3. Provide Comprehensive Context
4. Balance Team Size
- Too few workers (1-2): Underutilizes hierarchical pattern
- Optimal (3-6): Good balance of specialization and coordination
- Too many (8+): Director becomes overwhelmed coordinating
When to Use Hierarchical Swarm
Ideal for:- Complex Projects: Multi-faceted initiatives requiring coordination
- Team Coordination: When specialized workers need unified direction
- Quality-Critical Work: When oversight and validation are important
- Iterative Refinement: When feedback loops improve results
- Scalable Operations: When team may grow with new specialists
When NOT to Use Hierarchical Swarm
- Simple Tasks: Overhead not justified for straightforward work
- Independent Analyses: When diverse perspectives don’t need coordination (use MoA)
- Speed Critical: Additional director layer adds latency
- Linear Pipelines: When sequential processing suffices (use SequentialWorkflow)
Related Architectures
- MixtureOfAgents: Parallel experts with aggregation, no hierarchical control
- SequentialWorkflow: Linear pipeline without director
- GroupChat: Collaborative discussion without hierarchy