Hierarchical Structured Communication Framework¶
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.
Overview¶
This framework provides: - Structured Communication Protocol with Message (M_ij), Background (B_ij), and Intermediate Output (I_ij) - Hierarchical Evaluation System with supervisor coordination - Specialized Agent Classes for different roles - Main Swarm Orchestrator for workflow management
Key Components¶
Agent Classes¶
HierarchicalStructuredCommunicationGenerator
- Creates initial contentHierarchicalStructuredCommunicationEvaluator
- Evaluates content qualityHierarchicalStructuredCommunicationRefiner
- Improves content based on feedbackHierarchicalStructuredCommunicationSupervisor
- Coordinates workflow
Main Framework¶
HierarchicalStructuredCommunicationFramework
- Main orchestrator classHierarchicalStructuredCommunicationSwarm
- Convenience alias
Quick Start¶
from swarms.structs.hierarchical_structured_communication_framework import (
HierarchicalStructuredCommunicationFramework,
HierarchicalStructuredCommunicationGenerator,
HierarchicalStructuredCommunicationEvaluator,
HierarchicalStructuredCommunicationRefiner,
HierarchicalStructuredCommunicationSupervisor
)
# Create specialized agents
generator = HierarchicalStructuredCommunicationGenerator(
agent_name="ContentGenerator"
)
evaluator = HierarchicalStructuredCommunicationEvaluator(
agent_name="QualityEvaluator"
)
refiner = HierarchicalStructuredCommunicationRefiner(
agent_name="ContentRefiner"
)
supervisor = HierarchicalStructuredCommunicationSupervisor(
agent_name="WorkflowSupervisor"
)
# Create the framework
framework = HierarchicalStructuredCommunicationFramework(
name="MyFramework",
supervisor=supervisor,
generators=[generator],
evaluators=[evaluator],
refiners=[refiner],
max_loops=3
)
# Run the workflow
result = framework.run("Create a comprehensive analysis of AI trends in 2024")
Basic Usage¶
from swarms.structs.hierarchical_structured_communication_framework import (
HierarchicalStructuredCommunicationFramework,
HierarchicalStructuredCommunicationGenerator,
HierarchicalStructuredCommunicationEvaluator,
HierarchicalStructuredCommunicationRefiner
)
# Create agents with custom names
generator = HierarchicalStructuredCommunicationGenerator(agent_name="ContentGenerator")
evaluator = HierarchicalStructuredCommunicationEvaluator(agent_name="QualityEvaluator")
refiner = HierarchicalStructuredCommunicationRefiner(agent_name="ContentRefiner")
# Create framework with default supervisor
framework = HierarchicalStructuredCommunicationFramework(
generators=[generator],
evaluators=[evaluator],
refiners=[refiner],
max_loops=3,
verbose=True
)
# Execute task
result = framework.run("Write a detailed report on renewable energy technologies")
print(result["final_result"])
Advanced Configuration¶
from swarms.structs.hierarchical_structured_communication_framework import (
HierarchicalStructuredCommunicationFramework
)
# Create framework with custom configuration
framework = HierarchicalStructuredCommunicationFramework(
name="AdvancedFramework",
max_loops=5,
enable_structured_communication=True,
enable_hierarchical_evaluation=True,
shared_memory=True,
model_name="gpt-4o-mini",
verbose=True
)
# Run with custom parameters
result = framework.run(
"Analyze the impact of climate change on global agriculture",
max_loops=3
)
Integration with Other Swarms¶
from swarms.structs.hierarchical_structured_communication_framework import (
HierarchicalStructuredCommunicationFramework
)
from swarms.structs import AutoSwarmBuilder
# Use HierarchicalStructuredCommunicationFramework for content generation
framework = HierarchicalStructuredCommunicationFramework(
max_loops=2,
verbose=True
)
# Integrate with AutoSwarmBuilder
builder = AutoSwarmBuilder()
swarm = builder.create_swarm(
swarm_type="HierarchicalStructuredCommunicationFramework",
task="Generate a comprehensive business plan"
)
API Reference¶
HierarchicalStructuredCommunicationFramework¶
The main orchestrator class that implements the complete framework.
Parameters¶
name
(str): Name of the frameworksupervisor
: Main supervisor agentgenerators
(List): List of generator agentsevaluators
(List): List of evaluator agentsrefiners
(List): List of refiner agentsmax_loops
(int): Maximum refinement loopsenable_structured_communication
(bool): Enable structured protocolenable_hierarchical_evaluation
(bool): Enable hierarchical evaluationverbose
(bool): Enable verbose logging
Methods¶
run(task)
: Execute complete workflowstep(task)
: Execute single workflow stepsend_structured_message()
: Send structured communicationrun_hierarchical_evaluation()
: Run evaluation system
Contributing¶
Contributions to improve the Hierarchical Structured Communication Framework are welcome! Please:
- Follow the existing code style and patterns
- Add comprehensive tests for new features
- Update documentation for any API changes
- Ensure all imports use the correct module paths
License¶
This framework is part of the Swarms project and follows the same licensing terms.