Skip to main content

LLM-driven agent-based information diffusion simulation

Project description

LLM Society Information Diffusion Simulation

A modular repo to simulate information diffusion using LLM-based agent conversations.

Features

  • Segment-based persona configuration (proportions, flexible trait specs)
  • Random network generation with tie strengths
  • LLM-driven conversations and belief updates, or simple/complex contagion modes
  • YAML/JSON config + CLI
  • Visualization utilities and notebook integration

Install

  1. Python 3.10+
  2. Install the package (from PyPI when published, or locally):
pip install llm-society
# or for local development
pip install -e .
  1. Set OpenAI API key via env var or add api-key.txt (single line):
# Preferred: environment variable
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
# Or: file (gitignored)
echo "<YOUR_OPENAI_API_KEY>" > api-key.txt

Run from CLI

# write an example config to a path
llm-society --write-example-config my-config.yaml

# run the simulation with your config
llm-society --config my-config.yaml

# override selected parameters via flags
llm-society --config my-config.yaml --depth 0.8 --rounds 20

# run fully via flags (no config file)
llm-society \
  --information "5G towers cause illness." \
  --n 20 --degree 4 --rounds 10 \
  --depth 0.6 --depth-max 6 --edge-frac 0.5 \
  --seeds 0,1 --seed-belief 0.98 --talk-prob 0.25 \
  --mode llm --complex-k 2 --rng 0 --model gpt-4.1

Use in Notebook Example snippet:

from llm_society import network

net = network(n=5, degree=2, rounds=10, depth=0.6, depth_max=6,
             edge_frac=0.5, seeds=[0,1], seed_belief=0.98,
             information="5G towers cause illness.", talk_prob=0.25,
             mode="llm", complex_k=2, rng=0)
net.simulate()   # prints conversations, belief updates, summaries
net.plot()       # coverage curve + final beliefs graph
net.nodes[1].plot()  # single-node belief trajectory

Config Schema See llm_society/data/example.yaml. Key fields:

  • n, degree, rounds, depth (0-1), max_convo_turns, edge_sample_frac
  • seed_nodes, seed_belief, information_text, talk_information_prob
  • contagion_mode: llm | simple | complex; complex_threshold_k
  • persona_segments: list of segments with proportion and traits.
    • Trait values can be fixed strings, weighted choices, or numeric distributions (dist: normal, or uniform: [a,b]).
    • Extra traits allowed and included in prompts.

Depth interpretation:

  • depth ∈ [0,1] controls conversation length tendency. Higher means longer conversations.
  • Internally mapped to a geometric distribution; depth=0 → very short; depth=1 → near the max_convo_turns cap often.

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.1.1.tar.gz (18.6 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.1.1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file llm_society-0.1.1.tar.gz.

File metadata

  • Download URL: llm_society-0.1.1.tar.gz
  • Upload date:
  • Size: 18.6 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.1.1.tar.gz
Algorithm Hash digest
SHA256 d6b359eabc2b302eb4385a3a727f1e0ef2c3607e9139a961c8412931df6ba429
MD5 607ddd160f096ffb3b569bce2bb426c8
BLAKE2b-256 0bd803cc19f71ad29a75af54d5416c685fa506f2dcc8a01867fe71d5bd12082e

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_society-0.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: llm_society-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.5 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6cac4bb8c85f8af3aa7d9ef0a5f89a1ac9d236877d6efc83bcb303e92f3cd5b3
MD5 177cc1be24a6b5495a616b7e359a5b22
BLAKE2b-256 6a1605e1de1a9c64b62b1b6cc928103592a5f4baa2303599d6a89311b1604c55

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_society-0.1.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