Skip to main content

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

  1. Python 3.10+
  2. Install
pip install -r requirements.txt
  1. 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"])
  • 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=G and omit segments, personas are built from node attributes (gender, race, age, religion, political; others go to extra).

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 legacy seed_belief)
  • Info/LLM: information_text, talk_information_prob, model, metric_name, metric_prompt
  • Modes: contagion_mode in {llm, simple, complex}, complex_threshold_k
  • Personas: persona_segments (with proportion, traits, optional name)

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

llm_society-0.2.1.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_society-0.2.1-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

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

Hashes for llm_society-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b087481c28f674ada27682ada6ad11a92b04f741102357c7520247bf2f6f8351
MD5 29ac9646fd6854ab600d7782446ec982
BLAKE2b-256 72417dc357690b0188e43aba14a2701559ddc3b396cb5e693eeeba14ee5b690f

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_society-0.2.1.tar.gz:

Publisher: publish.yml on TianzhuQin/LLM-ABM-Information-Network

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for llm_society-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dfe06f1f8075ff53acb1bdc6c3f9dc15b4aeac1380df0a818de0be02dbc965f
MD5 3e6a177610000c82cd5f6f5f17621546
BLAKE2b-256 6d56b2c5c474ed6fa38899924104df7ca547cb5aa34e8f820d600e0b26566e1b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page