LLM-driven agent-based information diffusion simulation
Project description
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
- Quickstart (tiny LLM network, n=8):
docs/QUICKSTART_TINY.ipynb - Advanced tutorial (segments, interventions, custom graphs, export):
docs/ADVANCED_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
- 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_scores")
net.plot(type="centrality", metric="degree", show_exposure=False)
Plotting
- final_scores: 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_effect: 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_effect", 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
Exporting
net.export(
history_csv="history.csv",
beliefs_csv="scores_by_round.csv", # backward-compatible argument name
conversations_jsonl="conversations.jsonl",
)
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 \
--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(or legacyseed_belief) - Info/LLM:
information_text,talk_information_prob,model,metric_name,metric_prompt - Modes:
contagion_modein {llm, simple, complex},complex_threshold_k - Personas:
persona_segments(withproportion,traits, optionalname)
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_society-0.2.1.tar.gz.
File metadata
- Download URL: llm_society-0.2.1.tar.gz
- Upload date:
- Size: 30.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b087481c28f674ada27682ada6ad11a92b04f741102357c7520247bf2f6f8351
|
|
| MD5 |
29ac9646fd6854ab600d7782446ec982
|
|
| BLAKE2b-256 |
72417dc357690b0188e43aba14a2701559ddc3b396cb5e693eeeba14ee5b690f
|
Provenance
The following attestation bundles were made for llm_society-0.2.1.tar.gz:
Publisher:
publish.yml on TianzhuQin/LLM-ABM-Information-Network
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_society-0.2.1.tar.gz -
Subject digest:
b087481c28f674ada27682ada6ad11a92b04f741102357c7520247bf2f6f8351 - Sigstore transparency entry: 700326509
- Sigstore integration time:
-
Permalink:
TianzhuQin/LLM-ABM-Information-Network@d0f215d4a1cf3e20b83e0b10739bdbdfeb3b9fa5 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/TianzhuQin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0f215d4a1cf3e20b83e0b10739bdbdfeb3b9fa5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file llm_society-0.2.1-py3-none-any.whl.
File metadata
- Download URL: llm_society-0.2.1-py3-none-any.whl
- Upload date:
- Size: 32.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dfe06f1f8075ff53acb1bdc6c3f9dc15b4aeac1380df0a818de0be02dbc965f
|
|
| MD5 |
3e6a177610000c82cd5f6f5f17621546
|
|
| BLAKE2b-256 |
6d56b2c5c474ed6fa38899924104df7ca547cb5aa34e8f820d600e0b26566e1b
|
Provenance
The following attestation bundles were made for llm_society-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on TianzhuQin/LLM-ABM-Information-Network
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_society-0.2.1-py3-none-any.whl -
Subject digest:
4dfe06f1f8075ff53acb1bdc6c3f9dc15b4aeac1380df0a818de0be02dbc965f - Sigstore transparency entry: 700326512
- Sigstore integration time:
-
Permalink:
TianzhuQin/LLM-ABM-Information-Network@d0f215d4a1cf3e20b83e0b10739bdbdfeb3b9fa5 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/TianzhuQin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0f215d4a1cf3e20b83e0b10739bdbdfeb3b9fa5 -
Trigger Event:
push
-
Statement type: