self-consistency

Sample multiple paths, select most consistent - +17.9% on GSM8K

170 stars

Best use case

self-consistency is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Sample multiple paths, select most consistent - +17.9% on GSM8K

Teams using self-consistency should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/self-consistency/SKILL.md --create-dirs "https://raw.githubusercontent.com/Miosa-osa/canopy/main/library/skills/ai-patterns/self-consistency/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/self-consistency/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How self-consistency Compares

Feature / Agentself-consistencyStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Sample multiple paths, select most consistent - +17.9% on GSM8K

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Self-Consistency (CoT-SC) Pattern

Sample multiple reasoning paths and select the most consistent answer. Achieved **+17.9% on GSM8K**, **+12.2% on AQuA**.

## Activation

Use for:
- Problems with fixed answer sets (math, multiple choice)
- When single-path reasoning is unreliable
- High-stakes decisions requiring confidence
- Factual queries where accuracy is critical

## Process

### 1. Sample Diverse Paths
Generate N (typically 5-10) reasoning paths with higher temperature.

### 2. Extract Final Answers
Parse the conclusive answer from each path.

### 3. Majority Vote
Select the most frequent answer across all paths.

## Implementation

```python
def self_consistency(prompt, question, num_samples=5):
    answers = []
    for _ in range(num_samples):
        response = reason_with_cot(prompt, question)
        answer = extract_final_answer(response)
        answers.append(answer)
    
    # Majority vote
    from collections import Counter
    return Counter(answers).most_common(1)[0][0]
```

## When NOT to Use

- Free-form generation (no fixed answers)
- Time-critical tasks (adds latency from multiple samples)
- Simple queries (overkill)
- Creative tasks (want diversity, not consensus)

## Universal Self-Consistency

For open-ended tasks without fixed answers:

```
"Here are several responses to the same question:
[Response 1]
[Response 2]
[Response 3]

Determine which elements are most consistent across these responses
and synthesize the most reliable answer."
```

## Integration

- Use with @test-automator for test case generation
- Combine with reflection for verified answers
- Log consistency scores to learning engine

---

*Based on Google Research - arXiv:2203.11171*