Skip to main content

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. Each run() 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 not
int
default:"1"
Stored on the instance but not used. Each run() routes the task once
HistoryOutputType
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 calling

Methods

run()

Processes a single task through the swarm system. The router agent picks a swarm and rewrites the task as a task_description, then the selected swarm runs that description.
Parameters:
  • task (str): The task to process
Returns: The conversation history formatted according to 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
The conversation is created once in the constructor and never cleared. A second run() on the same instance returns the earlier tasks and outputs too. Create a new HybridHierarchicalClusterSwarm when each task needs a clean history.

batched_run()

Calls run() for every task concurrently in a thread pool of os.cpu_count() * 2 workers.
Parameters:
  • tasks (List[str]): List of task strings to process
Returns: List of results in task order, so 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.
Parameters:
  • swarm_name (str): Name of the swarm to find
Returns: The first swarm whose name matches, or None if there is none

route_task()

Routes a task to a specific swarm by name.
Parameters:
  • swarm_name (str): Name of the target swarm
  • task_description (str): The task to route
Runs the swarm and adds its output to the conversation under the swarm’s 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

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

  1. Task Input: A task is submitted to the HHCS
  2. Router Analysis: The router agent analyzes the task requirements
  3. Swarm Selection: The router calls select_swarm with a swarm name and a rewritten task description
  4. Task Routing: The task description is routed to the selected swarm for processing
  5. Swarm Execution: The selected swarm’s agents process the task (sequentially or concurrently depending on swarm type)
  6. Result Collection: The swarm’s output is added to the conversation history
  7. Final Output: The conversation history is returned in the output_type format

Source Code

View the source code on GitHub