SelfConsistencyAgent generates multiple independent responses to a given task and aggregates them into a single, consistent final answer. It leverages concurrent processing and employs a majority voting mechanism to ensure reliability.
Based on the research paper: Self-Consistency Improves Chain of Thought Reasoning in Language Models (Wang et al., 2022).
Class: SelfConsistencyAgent
Parameters
Methods
Examples
Basic Usage
Evaluation Mode
Random Models for Diversity
Batch Processing
How It Works
- Generates Multiple Independent Responses: Creates several reasoning paths for the same problem
- Analyzes Consistency: Examines agreement among different reasoning approaches
- Aggregates Results: Uses majority voting or consensus building
- Produces Reliable Output: Delivers a final answer reflecting the most reliable consensus
ThreadPoolExecutor to generate multiple responses concurrently, improving performance while maintaining independence between reasoning paths.
Output Formats
"dict": Dictionary format with conversation history"str": Simple string output"list": List format"json": JSON formatted output
Best Practices
- Sample Size: Use 3-7 samples for most tasks; increase for critical decisions
- Model Selection: Choose models with strong reasoning capabilities
- Evaluation Mode: Enable for tasks with known correct answers
- Custom Prompts: Tailor majority voting prompts for specific domains
- Batch Processing: Use
batched_runfor multiple related tasks