Overview
The Hierarchical Structured Communication Framework implements the “Talk Structurally, Act Hierarchically” approach for LLM multi-agent systems, based on the research paper arXiv:2502.11098. It provides structured communication protocols with specialized agent classes for content generation, evaluation, refinement, and supervision.These classes are not exported from the top-level
swarms package. Import them from swarms.structs.hierarchical_structured_communication_framework.Installation
Key Components
Agent Classes
Each class subclassesAgent, fills in a role-specific default system prompt when system_prompt is None, and forwards other keyword arguments to Agent.
All four default to
model_name="gpt-5.4" and verbose=False. The framework itself calls each agent’s plain run() method, not these extra methods.
Main Framework
HierarchicalStructuredCommunicationFramework- Main orchestrator class
Attributes
str
default:"HierarchicalStructuredCommunicationFramework"
Name of the framework instance
str
default:"Talk Structurally, Act Hierarchically Framework"
Description of the framework instance
Optional[Union[Agent, Callable, Any]]
default:"None"
Main supervisor agent. If not provided, a default
Agent supervisor is created automatically. The workflow does not currently call the supervisor; its name (supervisor_name) is used as the sender of structured messages.Optional[List[Union[Agent, Callable, Any]]]
default:"None"
List of generator agents. If not provided, a single default generator agent is created automatically. Only the first generator is used.
Optional[List[Union[Agent, Callable, Any]]]
default:"None"
List of evaluator agents. If not provided (and
enable_hierarchical_evaluation=True), a single default evaluator agent is created automatically. Every evaluator runs, one after another, each on one criterion.Optional[List[Union[Agent, Callable, Any]]]
default:"None"
List of refiner agents. If not provided, a single default refiner agent is created automatically. Only the first refiner is used.
Optional[Union[Agent, Callable, Any]]
default:"None"
Supervisor that summarizes the evaluators’ results. Created automatically if not provided and
enable_hierarchical_evaluation=True. Its summary is logged but not passed to the refiner.int
default:"3"
Maximum number of generate-evaluate-refine loops
OutputType
default:"dict-all-except-first"
Stored on the instance but not used.
run() always returns a dictionary.str
default:"Supervisor"
Name of the default supervisor agent, and the sender name on messages to generators and refiners.
str
default:"EvaluationSupervisor"
Name of the default evaluation supervisor agent, and the sender name on messages to evaluators.
bool
default:"True"
Stored on the instance but not read. Structured messages are always recorded.
bool
default:"True"
When
False, no evaluators or evaluation supervisor are created by default and run_hierarchical_evaluation() returns [], so the refiner is skipped and each loop returns the generator’s output.Stored on the instance but not read.
str
default:"gpt-5.4"
LLM model name used for the default agents the framework creates
bool
default:"False"
Enable verbose logging
bool
default:"False"
Route the default agents’ calls through a local Ollama server instead of a hosted provider. Agents you pass in are not changed.
str
default:"http://localhost:11434/v1"
Base URL for the Ollama server when
use_ollama=True.str
default:"ollama"
API key sent to the Ollama server when
use_ollama=True.Methods
run()
Execute the complete workflow for a given task, looping up tomax_loops times (set at construction).
task(str): The task to executeimg(str, optional): Accepted but not passed to any agent
Each loop calls
step() on the original task, so it generates fresh content rather than refining the previous loop’s result. The loop stops early when the average evaluation score of a loop is 8.0 or higher (checked on every loop but the last), or when step() returns an error.
run() does not accept a max_loops override — the number of refinement loops is fixed by the max_loops value passed to the constructor.step()
Execute a single workflow step (generate, evaluate, refine).task(str): The task to execute for one stepimg(str, optional): Accepted but not passed to any agent
generator_result, evaluation_results, refined_result, and conversation_history (or an error key on failure). refined_result falls back to the generator’s output when there are no evaluations or the refiner fails
send_structured_message()
Send a structured communication message between agents, following the Message (M_ij) / Background (B_ij) / Intermediate Output (I_ij) protocol.sender(str): Name of the sending agentrecipient(str): Name of the receiving agentmessage(str): Specific task message (M_ij)background(str, optional): Background context (B_ij)intermediate_output(str, optional): Intermediate output (I_ij)
StructuredMessage that was appended to conversation_history
run_hierarchical_evaluation()
Run the hierarchical evaluation system with supervisor coordination.content(str): Content to evaluateevaluation_criteria(List[str], optional): Criteria to evaluate against. Defaults to["accuracy", "completeness", "clarity", "relevance"]. Evaluatorigets criterioni % len(evaluation_criteria).
EvaluationResult objects, one per evaluator that answered. An evaluator that raises is skipped. Returns [] when enable_hierarchical_evaluation=False
Each evaluator is asked for a score from 0 to 10 and a confidence from 0 to 1. The framework parses both from the reply: score is the last number after the word “score” that falls in 0-10 (default 7.5), and confidence is the last number after “confidence” that falls in 0-1 (default 0.8). Range hints such as (0-10) are ignored. The full reply is stored as feedback. If an evaluation supervisor exists, it summarizes the results and the summary is logged.
Usage Examples
Quick Start
Basic Usage with Default Supervisor
Advanced Configuration
How It Works
The framework operates through a structured multi-phase workflow:- Generation Phase: The first generator creates content for the task
- Evaluation Phase: Each evaluator scores the content on one criterion, and the evaluation supervisor summarizes the results
- Refinement Phase: The first refiner improves the content using every evaluator’s feedback and score
- Stopping rule: If the loop’s average evaluation score is 8.0 or higher, the workflow stops
- Iteration: Otherwise steps 1-3 repeat on the original task, up to
max_loopstimes
Structured Communication Protocol
The framework uses a formal communication protocol with three components:- Message (M_ij): Direct communication between agents
- Background (B_ij): Contextual information shared between agents
- Intermediate Output (I_ij): Partial results passed between workflow stages
Features
- Structured Communication: Formal protocol for inter-agent messaging
- Hierarchical Evaluation: Several evaluators, each on its own criterion, summarized by an evaluation supervisor
- Score-based Early Stop: Stops looping once the average parsed evaluation score reaches 8.0
- Specialized Agents: Purpose-built agent classes for each workflow role
- Local Models: Route the default agents through Ollama with
use_ollama=True