Overview
TheRoundRobinSwarm implements an AutoGen-style communication pattern where agents are shuffled randomly each loop for varied interaction patterns. Each agent receives the full conversation context and builds upon others’ responses collaboratively.
Installation
Attributes
str
default:"RoundRobinSwarm"
Name of the swarm
str
Description of the swarm’s purpose
List[Agent]
required
List of agents in the swarm
bool
default:"False"
Flag to enable verbose mode
int
default:"1"
Maximum number of loops to run
callable
default:"None"
Callback function to be called after each loop
int
default:"3"
Maximum number of retries for agent execution
OutputType
default:"final"
Type of output format (“final”, “list”, “dict”, etc.)
Methods
run()
Executes the given task on the agents in a randomized round-robin fashion.task(str): The task to be executed
run_batch()
Execute multiple tasks sequentially through the round-robin swarm.tasks(List[str]): A list of task strings to be executed
Usage Examples
Basic Round-Robin Execution
Multiple Loops with Callback
Batch Processing
Different Output Types
Custom Agent Configuration
How It Works
- Initial Task: User provides a task to the swarm
- Random Shuffling: Agents are randomly shuffled each loop for varied interactions
- Context Building: Each agent receives the full conversation history
- Collaborative Prompting: Agents are prompted to acknowledge and build upon previous responses
- Multiple Loops: Process repeats for
max_loopsiterations - Final Output: Returns formatted output based on
output_type
Collaborative Prompt Format
Each agent receives a prompt like:Features
- Randomized Order: Agents are shuffled each loop for dynamic interactions
- Full Context: Each agent sees the complete conversation history
- Collaborative: Agents are prompted to acknowledge and build on others’ work
- Retry Logic: Automatic retries with exponential backoff on failures
- Flexible Output: Multiple output format options
- Batch Processing: Process multiple tasks efficiently
- Callback Support: Execute custom logic after each loop
- Error Handling: Comprehensive error handling and logging
Best Practices
- Agent Diversity: Use agents with complementary skills and perspectives
- Clear Prompts: Give agents specific roles in their system prompts
- Loop Count: Start with 1-2 loops; increase if deeper collaboration needed
- Output Type: Use “final” for simple tasks, “dict” for analysis of full conversation
- Verbose Mode: Enable for debugging and understanding agent interactions