SocialAlgorithms framework provides complete flexibility for defining custom communication patterns between agents. Upload any arbitrary social algorithm as a callable that defines exactly how agents interact and communicate.
When to Use
- Custom communication patterns: Unique agent interaction requirements
- Research implementations: Test novel multi-agent algorithms
- Specialized workflows: Domain-specific communication protocols
- Flexible orchestration: Full control over agent interactions
- Algorithm experimentation: Compare different social patterns
Key Features
- Accept any callable as social algorithm
- Communication history tracking (optional)
- Execution timeout management
- Multiple output formats
- Agent lifecycle management
- Async execution support
- Parallel execution options
- Detailed logging and monitoring
Basic Example
Custom Algorithm Patterns
Debate Algorithm
Hierarchical Review
Consensus Building
Key Parameters
str
default:"SocialAlgorithm"
Name for the algorithm instance
str
Description of the algorithm’s purpose
List[Agent]
required
List of agents that will participate
Callable
required
Function defining the communication pattern (agents, task, **kwargs) -> Any
float
default:"300.0"
Maximum execution time in seconds
OutputType
default:"dict"
Format for output (dict, list, str)
bool
default:"False"
Log all agent communications
bool
default:"False"
Enable parallel execution where possible
bool
default:"False"
Enable detailed logging
Methods
run()
Execute the social algorithm.run_async()
Asynchronous execution.add_agent() / remove_agent()
Dynamic agent management.get_communication_history()
Retrieve communication logs (if enabled).SocialAlgorithmResult
Detailed execution results:Use Cases
Multi-Stage Pipeline
Collaborative Writing
Expert Panel
Communication Logging
Track all agent interactions:Execution Timeout
Output Formatting
Algorithm Requirements
Your social algorithm must:- Accept agents and task:
def algorithm(agents, task, **kwargs) - Return results: Any structure (dict, list, str, object)
- Handle errors: Exceptions will be caught and logged
Best Practices
Algorithm Design: Keep algorithms focused on communication patterns, not complex logic
- Clear Signatures: Always accept (agents, task, **kwargs)
- Error Handling: Handle agent failures gracefully
- Timeout Awareness: Set appropriate max_execution_time
- Communication Logging: Enable for debugging and analysis
- Documentation: Document your algorithm’s communication pattern
Error Handling
Agent Management
Related Architectures
- Agent Rearrange - Predefined flow patterns
- Graph Workflow - DAG-based workflows
- Group Chat - Conversational patterns
- Hierarchical Swarm - Director-worker pattern