@ -32,21 +32,20 @@ Multi-agent architectures leverage these communication patterns to ensure that a
| Graph Workflow | Agents collaborate in a directed acyclic graph (DAG) format to manage dependencies and parallel tasks. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/graph_workflow/) | AI-driven software development pipelines, complex project management |
| Group Chat | Agents engage in a chat-like interaction to reach decisions collaboratively. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/group_chat/) | Real-time collaborative decision-making, contract negotiations |
| Interactive Group Chat | Enhanced group chat with dynamic speaker selection and interaction patterns. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/interactive_groupchat/) | Advanced collaborative decision-making, dynamic team coordination |
| Agent Registry | A centralized registry where agents are stored, retrieved, and invoked dynamically. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/agent_registry/) | Dynamic agent management, evolving recommendation engines |
| SpreadSheet | Manages tasks at scale, tracking agent outputs in a structured format like CSV files. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/spreadsheet_swarm/) | Large-scale marketing analytics, financial audits |
| Router | Routes and chooses the architecture based on the task requirements and available agents. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/swarm_router/) | Dynamic task routing, adaptive architecture selection, optimized agent allocation |
| Heavy | High-performance architecture for handling intensive computational tasks with multiple agents. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/heavy_swarm/) | Large-scale data processing, intensive computational workflows |
| Deep Research | Specialized architecture for conducting in-depth research tasks across multiple domains. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/deep_research_swarm/) | Academic research, market analysis, comprehensive data investigation |
| De-Hallucination | Architecture designed to reduce and eliminate hallucinations in AI outputs through consensus. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/de_hallucination_swarm/) | Fact-checking, content verification, reliable information generation |
| Council as Judge | Multiple agents act as a council to evaluate and judge outputs or decisions. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/council_of_judges/) | Quality assessment, decision validation, peer review processes |
| MALT | Specialized architecture for complex language processing tasks across multiple agents. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/malt/) | Natural language processing, translation, content generation |
| Majority Voting | Agents vote on decisions with the majority determining the final outcome. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/majorityvoting/) | Democratic decision-making, consensus building, error reduction |
| Round Robin | Tasks are distributed cyclically among agents in a rotating order. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/round_robin_swarm/) | Load balancing, fair task distribution, resource optimization |
| Auto-Builder | Automatically constructs and configures multi-agent systems based on requirements. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/auto_swarm_builder/) | Dynamic system creation, adaptive architectures, rapid prototyping |
| Hybrid Hierarchical Cluster | Combines hierarchical and peer-to-peer communication patterns for complex workflows. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/hhcs/) | Complex enterprise workflows, multi-department coordination |
| Election | Agents participate in democratic voting processes to select leaders or make collective decisions. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/election_swarm/) | Democratic governance, consensus building, leadership selection |
| Tree | Hierarchical tree structure for organizing agents in parent-child relationships. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/tree_swarm/) | Organizational hierarchies, decision trees, taxonomic classification |
| Batched Grid Workflow | Executes tasks in a batched grid format, where each agent processes a different task simultaneously in parallel. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/batched_grid_workflow/) | Parallel task processing, batch operations, grid-based task distribution |
| LLM Council | Orchestrates multiple specialized LLM agents to collaboratively answer queries through structured peer review and synthesis. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/llm_council/) | Multi-model evaluation, peer review systems, collaborative AI decision-making |
| Debate with Judge | A debate architecture where two agents (Pro and Con) debate a topic, with a Judge agent evaluating arguments and providing refined synthesis over multiple rounds. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/debate_with_judge/) | Argument analysis, decision refinement, structured debates, iterative improvement |
| Self MoA Seq | Sequential self-mixture of agents that generates multiple candidate responses and synthesizes them sequentially using a sliding window approach. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/self_moa_seq/) | High-quality response generation, ensemble methods, sequential synthesis |
A dynamic architecture where agents rearrange themselves based on task requirements and environmental conditions. Agents can adapt their roles, positions, and relationships to optimize performance for different scenarios.
**Use Cases:**
- Adaptive manufacturing lines that reconfigure based on product requirements
- Dynamic sales territory realignment based on market conditions
@ -123,6 +123,7 @@ graph TD
Multiple agents operate independently and simultaneously on different tasks. Each agent works on its own task without dependencies on the others.
**Use Cases:**
- Tasks that can be processed independently, such as parallel data analysis
- Large-scale simulations where multiple scenarios are run simultaneously
@ -204,6 +205,7 @@ graph TD
Makes it easy to manage thousands of agents in one place: a CSV file. Initialize any number of agents and run loops of agents on tasks.
**Use Cases:**
- Multi-threaded execution: Execute agents on multiple threads
- Save agent outputs into CSV file
@ -242,12 +244,52 @@ graph TD
---
### Batched Grid Workflow
**Overview:**
Multi-agent orchestration pattern that executes tasks in a batched grid format, where each agent processes different tasks simultaneously. Provides structured parallel processing with conversation state management.
Combines multiple agents with different capabilities and expertise to solve complex problems that require diverse skill sets.
**Use Cases:**
- Financial forecasting requiring different analytical approaches
- Complex problem-solving needing diverse expertise
@ -282,6 +324,7 @@ graph TD
Organizes agents in a directed acyclic graph (DAG) format, enabling complex dependencies and parallel execution paths.
**Use Cases:**
- AI-driven software development pipelines
- Complex project management with dependencies
@ -311,6 +354,7 @@ graph TD
Enables agents to engage in chat-like interactions to reach decisions collaboratively through discussion and consensus building.
**Use Cases:**
- Real-time collaborative decision-making
- Contract negotiations
@ -345,6 +389,7 @@ graph TD
Enhanced version of Group Chat with dynamic speaker selection, priority-based communication, and advanced interaction patterns.
**Use Cases:**
- Advanced collaborative decision-making
- Dynamic team coordination
@ -378,49 +423,13 @@ graph TD
---
### Agent Registry
**Overview:**
A centralized registry system where agents are stored, retrieved, and invoked dynamically. The registry maintains metadata about agent capabilities, availability, and performance metrics, enabling intelligent agent selection and management.
**Use Cases:**
- Dynamic agent management in large-scale systems
- Evolving recommendation engines that adapt agent selection
Intelligently routes tasks to the most appropriate agents or architectures based on task requirements and agent capabilities.
**Use Cases:**
- Dynamic task routing
- Adaptive architecture selection
@ -458,6 +467,7 @@ graph TD
High-performance architecture designed for handling intensive computational tasks with multiple agents working on resource-heavy operations.
**Use Cases:**
- Large-scale data processing
- Intensive computational workflows
@ -493,6 +503,7 @@ graph TD
Specialized architecture for conducting comprehensive research tasks across multiple domains with iterative refinement and cross-validation.
**Use Cases:**
- Academic research projects
- Market analysis and intelligence
@ -528,6 +539,7 @@ graph TD
Architecture specifically designed to reduce and eliminate hallucinations in AI outputs through consensus mechanisms and fact-checking protocols.
**Use Cases:**
- Fact-checking and verification
- Content validation
@ -558,12 +570,52 @@ graph TD
---
### Self MoA Seq
**Overview:**
Ensemble method that generates multiple candidate responses from a single high-performing model and synthesizes them sequentially using a sliding window approach. Keeps context within bounds while leveraging diversity across samples.
Multiple agents act as a council to evaluate, judge, and validate outputs or decisions through collaborative assessment.
**Use Cases:**
- Quality assessment and validation
- Decision validation processes
@ -594,12 +646,91 @@ graph TD
---
### LLM Council
**Overview:**
Orchestrates multiple specialized LLM agents to collaboratively answer queries through structured peer review and synthesis. Different models evaluate and rank each other's work, often selecting responses from other models as superior.
Debate architecture with self-refinement through a judge agent, enabling Pro and Con agents to debate a topic with iterative refinement. The judge evaluates arguments and provides synthesis for progressive improvement.
Specialized architecture for complex language processing tasks that require coordination between multiple language-focused agents.
**Use Cases:**
- Natural language processing pipelines
- Translation and localization
@ -637,6 +768,7 @@ graph TD
Agents vote on decisions with the majority determining the final outcome, providing democratic decision-making and error reduction through consensus.
**Use Cases:**
- Democratic decision-making processes
- Consensus building
@ -675,6 +807,7 @@ graph TD
Automatically constructs and configures multi-agent systems based on requirements, enabling dynamic system creation and adaptation.
**Use Cases:**
- Dynamic system creation
- Adaptive architectures
@ -706,12 +839,55 @@ graph TD
---
### Swarm Rearrange
**Overview:**
Orchestrates multiple swarms in sequential or parallel flow patterns with thread-safe operations and flow validation. Provides comprehensive swarm management and coordination capabilities.
Combines hierarchical and peer-to-peer communication patterns for complex workflows that require both centralized coordination and distributed collaboration.
**Use Cases:**
- Complex enterprise workflows
- Multi-department coordination
@ -753,6 +929,7 @@ graph TD
Agents participate in democratic voting processes to select leaders or make collective decisions.
**Use Cases:**
- Democratic governance
- Consensus building
@ -794,6 +971,7 @@ graph TD
Adaptive conversation management with dynamic agent selection and interaction patterns.
**Use Cases:**
- Adaptive chatbots
- Dynamic customer service
@ -833,6 +1011,7 @@ graph TD
Hierarchical tree structure for organizing agents in parent-child relationships.
This will output a visual tree structure showing the Director and all worker agents, making it easy to understand the swarm's organizational structure before executing tasks.
## Key Takeaways
1. **Agent Specialization**: Create agents with specific, well-defined expertise areas
@ -222,5 +264,6 @@ print(result)
3. **Appropriate Loop Count**: Set `max_loops` based on task complexity (1-3 for most tasks)
4. **Verbose Logging**: Enable verbose mode during development for debugging
5. **Context Preservation**: The swarm maintains full conversation history automatically
6. **Hierarchy Visualization**: Use `display_hierarchy()` to visualize swarm structure before execution
For more detailed information about the `HierarchicalSwarm` API and advanced usage patterns, see the [main documentation](hierarchical_swarm.md).
| **Token-by-Token Updates** | Watch text formation in real-time as agents generate responses |
| **Hierarchy Visualization** | Visual tree representation of swarm structure with `display_hierarchy()` |
## Constructor
@ -70,6 +71,65 @@ Initializes a new HierarchicalSwarm instance.
## Core Methods
### `display_hierarchy()`
Displays a visual tree representation of the hierarchical swarm structure, showing the Director at the top level and all worker agents as children branches. This method uses Rich formatting to create an aesthetically pleasing console output that helps visualize the organizational structure of the swarm.
#### Returns
| Type | Description |
|------|-------------|
| `None` | Prints the hierarchy visualization to the console |
#### Example
```python
from swarms import Agent
from swarms.structs.hiearchical_swarm import HierarchicalSwarm
# Create specialized agents
research_agent = Agent(
agent_name="Research-Analyst",
agent_description="Specialized in comprehensive research and data gathering",
model_name="gpt-4o-mini",
)
analysis_agent = Agent(
agent_name="Data-Analyst",
agent_description="Expert in data analysis and pattern recognition",
model_name="gpt-4o-mini",
)
strategy_agent = Agent(
agent_name="Strategy-Consultant",
agent_description="Specialized in strategic planning and recommendations",
model_name="gpt-4o-mini",
)
# Create hierarchical swarm
swarm = HierarchicalSwarm(
name="Swarms Corporation Operations",
description="Enterprise-grade hierarchical swarm for complex task execution",
Executes the hierarchical swarm for a specified number of feedback loops, processing the task through multiple iterations for refinement and improvement.
- **[models/](models/)** - Various model integrations including Cerebras, GPT-5, GPT-OSS, Llama 4, Lumo, and Ollama implementations with concurrent processing examples and provider-specific configurations.
- **[models/](models/)** - Various model integrations including Cerebras, GPT-5, GPT-OSS, Llama 4, Lumo, O3, Ollama, and vLLM implementations with concurrent processing examples and provider-specific configurations.
- [README.md](models/README.md) - Model integration documentation
- [simple_example_ollama.py](models/simple_example_ollama.py) - Ollama integration example
- [cerebas_example.py](models/cerebas_example.py) - Cerebras model example
- [lumo_example.py](models/lumo_example.py) - Lumo model example
- [example_o3.py](models/example_o3.py) - O3 model example
- **[swarms_api_examples/](swarms_api_examples/)** - Swarms API usage examples including agent overview, batch processing, client integration, team examples, analysis, and rate limiting.
- [README.md](swarms_api_examples/README.md) - API examples documentation
- [client_example.py](swarms_api_examples/client_example.py) - API client example
- [batch_example.py](swarms_api_examples/batch_example.py) - Batch processing example
- **[swarms_api/](swarms_api/)** - Swarms API usage examples including agent overview, batch processing, client integration, team examples, analysis, and rate limiting.
- [README.md](swarms_api/README.md) - API examples documentation
- [client_example.py](swarms_api/client_example.py) - API client example
- [batch_example.py](swarms_api/batch_example.py) - Batch processing example
- [hospital_team.py](swarms_api/hospital_team.py) - Hospital management team simulation
- [legal_team.py](swarms_api/legal_team.py) - Legal team collaboration example
- [icd_ten_analysis.py](swarms_api/icd_ten_analysis.py) - ICD-10 medical code analysis
- [rate_limits.py](swarms_api/rate_limits.py) - Rate limiting and throttling examples
- **[mcp/](mcp/)** - Model Context Protocol (MCP) integration examples including agent implementations, multi-connection setups, server configurations, and utility functions.
- **[mcp/](mcp/)** - Model Context Protocol (MCP) integration examples including agent implementations, multi-connection setups, server configurations, utility functions, and multi-MCP guides.
@ -72,6 +102,11 @@ This directory contains comprehensive examples demonstrating various capabilitie
- **[utils/](utils/)** - Utility functions and helper implementations including agent loader, communication examples, concurrent wrappers, miscellaneous utilities, and telemetry.
- **[cli/](cli/)** - CLI command examples demonstrating all available Swarms CLI features including setup, agent management, multi-agent architectures, and utilities.
Each subdirectory contains its own README.md file with detailed descriptions and links to all available examples. Click on any folder above to explore its specific examples and use cases.
This directory contains shell script examples demonstrating all available Swarms CLI commands and features. Each script is simple, focused, and demonstrates a single CLI command.