Code and per-run logs for the paper:
When Is Emergent Consensus Real? A Measured Coupling Gain and a Validity Diagnostic for LLM Agent Societies Dongxu Yang (DeepLethe). Preprint, 2026. arXiv: to be added.
We replace demonstration with measurement. The central quantity is the
coupling gain gamma — a per-agent susceptibility measured directly from an
LLM by counterfactually perturbing a neighbour's stated opinion. From gamma
(plus a backfire coefficient beta and a modality-matched group coupling
p_ft) we organise the macro outcome of an agent society into consensus,
pluralism, and (induced) polarization, and we supply a (slope, bias) validity
diagnostic that separates a genuine social dynamic from a model-prior artifact.
Python 3.9+ and an OpenRouter API key.
pip install -r requirements.txt # only matplotlib, for the figures
cp .env.example .env # then put your real key in .env
# .env contents: OPENROUTER_API_KEY=sk-or-v1-...The model client (or_client.py) reads the key from .env; the key is never
hard-coded. Everything except figure rendering is standard-library only —
bootstrap CIs and permutation tests are hand-rolled (no scipy/numpy).
Running the live probes calls paid LLM APIs. If you only want to re-derive the numbers in the paper, the
results/*.logfiles are the raw per-run records and the analysis scripts below read straight from them — no API calls needed.
The committed results/*.log are the actual per-run logs the paper is built
from. Re-run an analysis (no API needed):
| Paper claim | Analysis script | Reads / writes |
|---|---|---|
gamma table + bootstrap 95% CIs (Fig. 1) |
bootstrap_ci.py |
results/gamma_reps.log |
Open-weight replication of gamma |
open_gamma.py, open_gamma_one.py |
results/open_gamma*.log |
| Social-neighbour vs numeric-anchor control | sycophancy_control.py |
results/sycophancy_control.log |
No spontaneous backfire (beta <= 0) |
backfire.py |
(live probe) |
| Induced polarization, t(4)=23.5 | induced_reps.py |
results/induced_reps.log |
| (slope, bias) authenticity diagnostic | prop_authenticity.py, authenticity_reps.py |
results/authenticity_reps.log |
| Boundary-censoring confound ruled out | censoring_control.py |
results/censoring_control.log |
| Interior-fact control (Table 2) | interior_measure_ci.py, interior_demo.py |
results/interior_*.log |
| Chuang et al. (2023) re-analysis | run_debunk.py |
(live probe) |
Independent prior-p calibration |
p_calibration.py |
results/p_calibration.log |
Free-text group pull p_ft |
transfer_group_ft.py |
results/transfer_group_ft.log |
| Society convergence (clean) | transfer_converge_clean.py |
results/transfer_converge_clean.log |
p_ft -> final spread, r=-0.70, perm p=0.008 (n=16) |
correlate.py |
results/transfer_* |
gamma <-> p_ft anti-correlation + leave-one-out (Prop. 4) |
correlate_gp.py |
results/gamma_reps.log, open_gamma*.log, transfer_group_ft.log |
| Per-(model, condition) separation | analyze_clean.py |
results/transfer_converge_clean.log |
| Figures 1-7 | make_figures.py |
results/* -> fig*.pdf |
Core engine: or_client.py (OpenRouter client), jot.py (durable append-only
logging used by every probe), society.py / network.py (multi-agent loop).
Example:
python correlate.py # p_ft <-> spread correlation, permutation test
python correlate_gp.py # gamma <-> p_ft, with leave-one-model-out
python bootstrap_ci.py # gamma bootstrap CIs
python make_figures.py # regenerate fig1..fig7An early version of the society loop had a silent-freeze bug: when an API
call returned no content, the agent's stance was silently kept, fabricating a
spurious "hold". We fixed it (retry + fallback-parse, and we discard runs
with any true failure rather than fabricate data — genuine holds are kept,
distinguished by fails == 0, not by a frozen trajectory), re-ran the affected
cells, and audited every convergence log. audit_frozen.py is that audit, and
both the contaminated and the clean logs are committed so the fix is verifiable
(results/transfer_converge.log vs results/transfer_converge_clean.log).
@misc{yang2026coupling,
title = {When Is Emergent Consensus Real? A Measured Coupling Gain and
a Validity Diagnostic for LLM Agent Societies},
author = {Yang, Dongxu},
year = {2026},
eprint = {XXXX.XXXXX},
archivePrefix = {arXiv},
primaryClass = {cs.CL}
}(Update eprint with the arXiv id once posted.)
MIT.