Overview
The Hybrid Hierarchical-Cluster Swarm (HHCS) is an advanced AI orchestration architecture that combines hierarchical decision-making with parallel processing capabilities. HHCS enables complex task solving by dynamically routing tasks to specialized agent swarms based on their expertise and capabilities.Installation
Purpose
HHCS addresses the challenge of efficiently solving diverse and complex tasks by:- Intelligently routing each task to the most appropriate specialized swarm
- Letting the selected swarm run its agents sequentially or in parallel, depending on its
swarm_type - Maintaining a clear hierarchy for effective decision-making
- Processing many independent tasks concurrently with
batched_run()
Architecture Diagram
The HHCS architecture follows a hierarchical structure with the router agent at the top level, specialized swarms at the middle level, and individual agents at the bottom level. Eachrun() sends the task to exactly one swarm.
Attributes
str
default:"Hybrid Hierarchical-Cluster Swarm"
The name of the swarm instance
str
Brief description of the swarm’s functionality
List[Union[SwarmRouter, Callable]]
default:"[]"
Swarms the HHCS can route tasks to. Each one needs
name, description, agents and swarm_type attributes, which the constructor reads to describe the swarms in the router’s system prompt, and a run(task) method. SwarmRouter instances meet this; a bare function does notint
default:"1"
Stored on the instance but not used. Each
run() routes the task onceHistoryOutputType
default:"list"
Format of the conversation history returned by
run() (e.g., “list”, “dict”, “str”, “final”, “json”)str
default:"gpt-5.4"
LLM model used by the router agent. The router is given a
select_swarm function schema with reasoning, swarm_name and task_description, and its reply is parsed into a dict, so pick a model that supports function callingMethods
run()
Processes a single task through the swarm system. The router agent picks a swarm and rewrites the task as atask_description, then the selected swarm runs that description.
task(str): The task to process
output_type (a list by default). It holds the user’s task followed by the selected swarm’s output, stored under the swarm’s name. The router’s reasoning is not recorded
Raises: ValueError if task is empty, if the router’s reply is not a string or lacks swarm_name or task_description, or if no swarm has the selected name
batched_run()
Callsrun() for every task concurrently in a thread pool of os.cpu_count() * 2 workers.
tasks(List[str]): List of task strings to process
results[i] belongs to tasks[i]. A task that raises yields the string "Error processing task: <error>" in its slot instead of stopping the batch
Raises: ValueError if tasks is empty
All tasks in a batch write to the same conversation, so each result can include turns from the other tasks in the batch.
find_swarm_by_name()
Retrieves a swarm by its name from the available swarms.swarm_name(str): Name of the swarm to find
name matches, or None if there is none
route_task()
Routes a task to a specific swarm by name.swarm_name(str): Name of the target swarmtask_description(str): The task to route
name.
Raises: ValueError if no swarm has that name
get_swarms_info() is not a method on HybridHierarchicalClusterSwarm. It is a standalone helper (from swarms import get_swarms_info) that the constructor calls internally to build the router agent’s system prompt from the swarms list.Usage Examples
Full Legal Practice Example
Features
- Router-based task distribution: Central router agent analyzes incoming tasks and directs each one to a single specialized swarm
- Hybrid architecture: Combines hierarchical control with clustered specialization
- Batch concurrency:
batched_run()processes many tasks in parallel, each routed independently - Flexible swarm types: Supports both sequential and concurrent workflows within swarms
- Conversation history: Records each task and the selected swarm’s output
How It Works
- Task Input: A task is submitted to the HHCS
- Router Analysis: The router agent analyzes the task requirements
- Swarm Selection: The router calls
select_swarmwith a swarm name and a rewritten task description - Task Routing: The task description is routed to the selected swarm for processing
- Swarm Execution: The selected swarm’s agents process the task (sequentially or concurrently depending on swarm type)
- Result Collection: The swarm’s output is added to the conversation history
- Final Output: The conversation history is returned in the
output_typeformat