Skip to main content
The 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

  1. Generates Multiple Independent Responses: Creates several reasoning paths for the same problem
  2. Analyzes Consistency: Examines agreement among different reasoning approaches
  3. Aggregates Results: Uses majority voting or consensus building
  4. Produces Reliable Output: Delivers a final answer reflecting the most reliable consensus
The agent uses 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

  1. Sample Size: Use 3-7 samples for most tasks; increase for critical decisions
  2. Model Selection: Choose models with strong reasoning capabilities
  3. Evaluation Mode: Enable for tasks with known correct answers
  4. Custom Prompts: Tailor majority voting prompts for specific domains
  5. Batch Processing: Use batched_run for multiple related tasks