Skip to main content

Overview

The RoundRobinSwarm 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.
Parameters:
  • task (str): The task to be executed
Returns: The result of the task execution in the specified output format

run_batch()

Execute multiple tasks sequentially through the round-robin swarm.
Parameters:
  • tasks (List[str]): A list of task strings to be executed
Returns: List of results, one for each task

Usage Examples

Basic Round-Robin Execution

Multiple Loops with Callback

Batch Processing

Different Output Types

Custom Agent Configuration

How It Works

  1. Initial Task: User provides a task to the swarm
  2. Random Shuffling: Agents are randomly shuffled each loop for varied interactions
  3. Context Building: Each agent receives the full conversation history
  4. Collaborative Prompting: Agents are prompted to acknowledge and build upon previous responses
  5. Multiple Loops: Process repeats for max_loops iterations
  6. 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

  1. Agent Diversity: Use agents with complementary skills and perspectives
  2. Clear Prompts: Give agents specific roles in their system prompts
  3. Loop Count: Start with 1-2 loops; increase if deeper collaboration needed
  4. Output Type: Use “final” for simple tasks, “dict” for analysis of full conversation
  5. Verbose Mode: Enable for debugging and understanding agent interactions