KappaBench is a premium, zero-dependency consensus evaluation framework designed to measure, benchmark, and analyze inter-agent reliability in multi-agent classification tasks. It provides standalone Python implementations of standard consensus metrics and incorporates robust perturbation testing (e.g., noise injection, model dropout) to quantify the reliability and resilience of LLM-based agent networks.
-
Standardized Inter-Rater Reliability Metrics:
-
Cohen's Kappa (
$\kappa$ ): Pairwise agreement between two classifiers. -
Fleiss' Kappa (
$\kappa_F$ ): Generalized multi-rater agreement for fixed raters. -
Krippendorff's Alpha (
$\alpha$ ): Premium consensus coefficient supporting missing ratings and multiple measurement scales (Nominal, Ordinal, Interval, Ratio).
-
Cohen's Kappa (
- Robustness Perturbation Engine: Test consensus resilience by simulating agent/model dropouts or injecting classification noise.
- Unified CLI Interface: Run benchmarks directly on JSON/CSV datasets and output report summaries.
-
Developer Friendly: Fully type-hinted, packaged with standard packaging config (
pyproject.toml), and easy to integrate.
Cohen's Kappa measures the agreement between two raters who each classify
where:
-
$p_o$ is the relative observed agreement among raters (equivalent to accuracy). -
$p_e$ is the hypothetical probability of chance agreement.
Fleiss' Kappa extends Scott's
The mean of the subjects' agreement
The expected chance agreement
Krippendorff's Alpha is a general coefficient that measures the agreement among any number of observers, with any level of measurement (nominal, ordinal, interval, ratio) and handling missing values natively:
where:
-
$D_o$ is the observed disagreement:$$D_o = \frac{1}{n} \sum_{i} \frac{1}{m_i - 1} \sum_{c} \sum_{c'} n_{ic} n_{ic'} \delta^2(c, c')$$ -
$D_e$ is the expected disagreement:$$D_e = \frac{1}{n(n-1)} \sum_{c} \sum_{c'} n_{\cdot c} n_{\cdot c'} \delta^2(c, c')$$ -
$\delta^2(c, c')$ is the metric difference function depending on the level of measurement (e.g., Nominal, Ordinal, Interval).
The system consists of three main decoupled modules:
graph TD
CLI[cli.py: argparse interface] -->|Invokes| Benchmark[benchmark.py: ConsensusBenchmark]
Benchmark -->|Invokes| Metrics[metrics.py: Math Computations]
subgraph metrics.py
CK[cohen_kappa]
FK[fleiss_kappa]
KA[krippendorff_alpha]
end
subgraph benchmark.py
LD[load_dataset]
CC[compute_consensus]
PT[run_perturbation_tests]
end
To install KappaBench in editable development mode:
git clone https://github.com/Rituparno-Majumdar/kappabench.git
cd kappabench
make installfrom kappabench.metrics import cohen_kappa, fleiss_kappa, krippendorff_alpha
from kappabench.benchmark import ConsensusBenchmark
# 1. Direct Metric Calculations
rater1 = [1, 2, 1, 2, 1]
rater2 = [1, 2, 2, 2, 1]
ck = cohen_kappa(rater1, rater2)
print(f"Cohen's Kappa: {ck:.4f}")
# 2. Benchmarking Multi-Agent Data
benchmark = ConsensusBenchmark()
benchmark.load_dataset("tests/mock_data.csv")
# Compute baseline metrics
summary = benchmark.compute_consensus(level_of_measurement='nominal')
print("Fleiss' Kappa:", summary['fleiss_kappa'])
print("Krippendorff's Alpha:", summary['krippendorff_alpha'])KappaBench provides a CLI to run consensus analyses and perturbation tests:
# Run baseline evaluation
kappabench run --dataset my_agents_output.csv
# Run evaluation and noise/dropout robustness perturbation test suite
kappabench run --dataset my_agents_output.json --level nominal --perturb --output results.jsonWhen running kappabench run, you'll receive a professional summary:
==================================================
KAPPABENCH EVALUATION REPORT
==================================================
Dataset: my_agents_output.csv
Total Items: 100
Total Models: 3
Models: agent_a, agent_b, agent_c
Categories: class_1, class_2
Metric Level: nominal
--------------------------------------------------
Fleiss' Kappa: 0.7812
Krippendorff's Alpha: 0.7820
Mean Cohen's Kappa: 0.7818 (std: 0.0125)
==================================================
All code is linted and verified via unit tests. Run the test suite:
make testThis project is licensed under the MIT License - see the LICENSE file for details.