LLM Society — LLM-driven Information Diffusion
A Python package to simulate information diffusion with LLM-based agent conversations. It supports metric scoring in [0,1], segments-based personas, interventions, polished visualizations, and a simple CLI.
Links
- Tutorial (LLM network, segments, interventions, custom graphs, export):
docs/TUTORIAL.ipynb
Features
- Segment-based persona configuration (proportions, flexible trait specs; optional segment names)
- Random network generation with tie strengths, or use your own NetworkX graph
- LLM-driven conversations and numeric scoring in [0,1] (metric-based), or simple/complex contagion modes
- Tie strengths influence edge sampling, talk probability, conversation depth, and can grow/decay over time (even for non-adjacent pairs via all-pairs mode)
- Optional agent memory to keep recent utterances in-context for longer-term continuity
- Multi-metric scoring per topic (e.g., credibility, emotion, action intent) with user-defined prompts and joint JSON outputs
- Interactive dashboards (Plotly/Bokeh) for rapid, shareable analysis
- Group plots (by traits or by segment), intervention effect plots, centrality plots, animations
- YAML/JSON config + CLI; exporting history/scores/conversations
Installation
- Python 3.10+
- Install
pip install -r requirements.txt
- Provide OpenAI key (LLM mode)
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
# or use a file (first line)
echo "<YOUR_OPENAI_API_KEY>" > api-key.txt
Quickstart (Notebook)
from llm_society.api import network
from llm_society.viz import set_theme
set_theme()
net = network(
information="5G towers cause illness.",
n=20, degree=4, rounds=10,
talk_prob=0.25, mode="llm", complex_k=2, rng=0
)
net.simulate() # conversations, score updates, summaries
net.plot(type="final")
net.plot(type="centrality", metric="degree", show_exposure=False)
Plotting
- final: final node scores heatmap on the graph
- coverage: coverage (exposed & score>0) over time
- group: mean score by group (by="traits" with attr in segments' traits; or by="segment")
- centrality: centrality vs final score; optionally add exposure panel via show_exposure=True
- intervention: mean score over time with intervention marker; optionally group by traits
- animation: animated score evolution
Advanced Capabilities
- Grouping
- Traits:
net.plot(type="group", by="traits", attr="political") - Segment:
net.plot(type="group", by="segment", groups=["High-Dem", "High-Rep"])
- Traits:
- Interventions
net = network(..., intervention_round=6, intervention_nodes=[0,1,2], intervention_content="Be skeptical...") net.simulate() net.plot(type="intervention", attr="political", groups=["Democrat","Republican"])
- Custom Graph Personas
- If you pass
graph=Gand omitsegments, personas are built from node attributes (gender,race,age,religion,political; others go toextra).
- If you pass
- All-pairs conversations (LLM mode)
- Set
conversation_scope="all_pairs"(or CLI--conversation-scope all_pairs) to allow any node pair to chat. - Pairs without edges start at weight 0 but still get a small selection chance; repeated conversations strengthen their tie and add the edge into the network.
- Set
- Multi-metric scoring
- Define
metrics(list of{id,label,prompt}) so each conversation returns structured JSON with coordinated scores for both speakers. - The first metric acts as the "primary" score used by legacy APIs/plots; additional metrics are stored in
history[*].scores_multiand can be visualized vianet.plot(..., metric="emotion").
- Define
- Intervention-only runs
- Leave
information=""and configureintervention_round,intervention_nodes, andintervention_content. - Agents chat casually until the intervention round starts, after which conversations probabilistically focus on the treatment content.
- Leave
- Agent memory
- Set
memory_turns_per_agent > 0(e.g., 4–8) to inject that many recent utterances (self + partners) into each agent’s system prompt so they can recall past exchanges.
- Set
Exporting
net.export(
history_csv="history.csv",
scores_csv="scores_by_round.csv",
conversations_jsonl="conversations.jsonl",
)
# interactive dashboard inside notebooks
fig = net.dashboard(engine="plotly", attr="political", metric="credibility")
fig
# or save to HTML manually
html = net.dashboard(engine="plotly", attr="political", metric="credibility", to_html=True)
Path("dashboard.html").write_text(html, encoding="utf-8")
CLI
# write an example config
llm-society --write-example-config my-config.yaml
# run with a config
llm-society --config my-config.yaml
# or run fully via flags
llm-society \
--information "Claim text" --n 20 --degree 4 --rounds 10 \
--depth 0.6 --depth-max 6 --edge-frac 0.5 --conversation-scope all \
--seeds 0,1 --talk-prob 0.25 --mode llm --complex-k 2 --rng 0
Configuration (overview)
- Core:
n,degree,rounds,depth(0–1),max_convo_turns,edge_sample_frac - Seeds:
seed_nodes,seed_score - Info/LLM:
information(may be blank if an intervention is configured),talk_information_prob,model,metric_name,metric_prompt - Metrics: optional
metrics=[{id,label,prompt}, ...]to request multi-dimensional scoring (first metric remains the default for legacy APIs) - Modes:
contagion_modein {llm, simple, complex},complex_threshold_k - Conversation scope:
conversation_scopein {edges, all},pair_weight_epsilon(minimum sampling weight boost for zero-tie pairs) - Memory:
memory_turns_per_agent(0 disables memory) - Personas:
persona_segments(withproportion,traits, optionalname)
License
MIT
Metadata
Release files for llm-society 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm_society-0.3.3.tar.gz | 40.9 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_society-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 83.3 kB
Release files / llm_society-0.3.3.tar.gz
| Download URL | llm_society-0.3.3.tar.gz |
|---|---|
| Size | 40.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
addc0d6e809aa43967035bdcc8d270be5ecee96e7b9e37642e587e471ed9d07f
|
|
BLAKE2b-256 checksum How to use checksums |
fc76263949182b9d8a969daf6267ad72c89b3b91a5d2259825bd5ebd46d530c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2025.
Transparency logRelease files / llm_society-0.3.3-py3-none-any.whl
| Download URL | llm_society-0.3.3-py3-none-any.whl |
|---|---|
| Size | 42.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
98a8be1bc8759433f72dca2e4d7c1d45c51b98742f01da03ae70d1ad0ebfbefc
|
|
BLAKE2b-256 checksum How to use checksums |
0e1be40ecf51e9cf504cf84da3408fdffa1af4bd10f1a1ef9076e97cf49e302d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2025.
Transparency logSecurity for llm-society 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for llm_society-0.3.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.