resonant-swarm
Kuramoto phase coupling meets LMSR prediction markets via Oasis social simulation
resonant-swarm is the glue layer that connects Oasis social simulation with Kuramoto phase coupling and ghostsignals-rs prediction markets. It transforms social media simulations into collective prediction engines.
What It Does
-
Phase-Coupled Social Agents: Extends Oasis's
SocialAgentwith Kuramoto oscillator dynamics. Agents' phases influence what content they see and how they behave. -
Sentiment → Market Trades: Automatically converts agent posts, likes, and comments into prediction market trades based on sentiment analysis.
-
Convergence Detection: Monitors both market price stability and phase synchronization to determine when the swarm has reached consensus.
-
Live Visualization: WebSocket publisher for real-time dashboards showing phase dynamics and market evolution.
Architecture
Seed Question → MiroFish → Oasis + Kuramoto → ghostsignals → Prediction
│ │ │ │ │
Document Profiles Social Sim LMSR Market Consensus
+ Phases + Trades Probability
- MiroFish: Generates agent personas from seed documents (existing)
- Oasis: LLM-driven social media simulation (existing)
- Kuramoto: Phase oscillators create emergent coupling between agents
- ghostsignals: LMSR prediction markets aggregate opinions into probabilities
- resonant-swarm: The integration layer (this package)
Quick Start
from resonant_swarm import ResonantSwarmExperiment
# Define your prediction question
config = {
"question": "Will the Federal Reserve cut interest rates in Q3 2026?",
"outcomes": ["Yes, rate cut", "No change", "Rate increase"],
"seed_document": "Fed has maintained rates at 5.25% for 8 months...",
"agents": {"count": 10, "coupling_k": 1.5},
"simulation": {"rounds": 20, "platform": "twitter"},
}
# Run the experiment
experiment = ResonantSwarmExperiment(config)
result = await experiment.run()
print(f"Prediction: {result.market_prices}")
print(f"Confidence: {result.convergence_score}")
print(f"Report: {result.report}")
Core Components
1. KuramotoPhaseManager
Manages oscillator phases for all agents:
from resonant_swarm import KuramotoPhaseManager
phase_manager = KuramotoPhaseManager(coupling_k=1.5, dt=0.1)
phase_manager.add_agent("agent_1", initial_phase=0.5, natural_freq=1.0)
phase_manager.add_agent("agent_2", initial_phase=1.2, natural_freq=0.8)
# Run one Kuramoto step
state = phase_manager.step()
print(f"Order parameter: {state['order_parameter_r']}") # 0 = chaos, 1 = sync
2. ResonantSocialAgent
Drop-in replacement for Oasis's SocialAgent with phase coupling:
from resonant_swarm import ResonantSocialAgent
agent = ResonantSocialAgent(
agent_id=1,
user_info=user_info,
phase_manager=phase_manager,
# ... same args as SocialAgent
)
# Before each LLM decision, agent gets phase-coupled context:
# "You sense strong agreement with 3 other voices on this topic"
# or "The community seems divided with passionate arguments"
3. ActionToTradeMapper
Converts social actions into market trades:
from resonant_swarm import ActionToTradeMapper, MarketEngine
market_engine = MarketEngine()
market_id = market_engine.create_market(
"Will X happen?",
["Yes", "No"],
liquidity=100.0
)
mapper = ActionToTradeMapper(market_engine)
# Agent posts "I think this will definitely happen!"
trade = mapper.map_action(
agent_id="agent_1",
action={"type": "create_post", "content": "I think this will definitely happen!"},
market_id=market_id
)
# → Large trade on "Yes" outcome
4. LMSRMarket (Pure Python)
LMSR implementation mirroring the ghostsignals-rs API:
from resonant_swarm import LMSRMarket
market = LMSRMarket(
question="Will it rain tomorrow?",
outcomes=["Yes", "No"],
liquidity=100.0
)
# Initial prices are equal
print(market.prices()) # {"Yes": 0.5, "No": 0.5}
# Execute trades
trade = market.trade("trader_1", "Yes", amount=10.0)
print(market.prices()) # {"Yes": 0.52, "No": 0.48} (example)
Installation
git clone https://github.com/kannaka-labs/resonant-swarm.git
cd resonant-swarm
pip install -e .
For development:
pip install -e .[dev]
Example: 10-Agent Prediction
See experiments/simple_prediction.py for a complete example that:
- Generates 10 agent profiles from a seed document
- Runs 20 rounds of Twitter simulation with Kuramoto coupling
- Converts posts/likes into market trades
- Outputs final probability + confidence score
cd experiments
python simple_prediction.py --question "Will X happen?" --agents 10 --rounds 20
Integration with Existing Systems
With MiroFish
# MiroFish generates profiles (existing code)
profiles = mirofish.generate_profiles(seed_document, agent_count=10)
# Add phase information
for profile in profiles:
profile.initial_phase = random.uniform(0, 2*π)
# Use ResonantSocialAgent instead of SocialAgent in Oasis
With ghostsignals-rs
# Start with Python LMSR (this package)
market_engine = MarketEngine()
# Later: swap for Rust performance
# market_engine = GhostSignalsRust(api_url="http://localhost:3000")
With kannaka-radio
from resonant_swarm import SwarmVisualizer
viz = SwarmVisualizer(websocket_port=8765)
await viz.publish_state(phases, prices, actions, order_param)
# Dashboard shows live phase circle + price charts
Mathematical Foundation
The system implements the Kuramoto model for coupled oscillators:
dθᵢ/dt = ωᵢ + (K/N) Σⱼ sin(θⱼ - θᵢ)
Where:
θᵢ= phase of agent iωᵢ= natural frequency (posting rhythm)K= coupling strength (adjustable)N= number of agents
Order parameter measures synchronization:
r = |1/N * Σⱼ exp(iθⱼ)|
r = 0: completely incoherent (chaos)r = 1: fully synchronized (consensus)
Action feedback: Agent behavior updates phases:
- Positive sentiment (posts, likes) → pull toward mean phase
- Negative sentiment (arguments, dislikes) → push away from mean
Testing
pytest tests/
Test coverage includes:
- Kuramoto math (phase wrapping, order parameter, coupling)
- LMSR market mechanics (cost function, price normalization)
- Sentiment extraction and action mapping
- Convergence detection algorithms
Contributing
This is research code. If you find bugs or have ideas for improvements, please open an issue or PR.
License
Apache 2.0
Related Projects
- Oasis - LLM social media simulation
- ghostsignals-rs - LMSR prediction markets in Rust
- MiroFish - Ontology extraction and profile generation
- kannaka - Wave dynamics memory system
Citation
@software{resonant_swarm,
title={resonant-swarm: Kuramoto Phase Coupling for Social Prediction Markets},
author={Flachsenhaar, Nick},
year={2026},
url={https://github.com/kannaka-labs/resonant-swarm}
}
Metadata
Release files for resonant-swarm 0.1.0
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 | Actions |
|---|---|---|---|---|
| resonant_swarm-0.1.0.tar.gz | 53.3 kB | Without provenance | Details for resonant_swarm-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| resonant_swarm-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for resonant_swarm-0.1.0-py3-none-any.whl |
Total release size: 96.9 kB
Release files / resonant_swarm-0.1.0.tar.gz
| Download URL | resonant_swarm-0.1.0.tar.gz |
|---|---|
| Size | 53.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd8fa6d4bcbe45f3ebfaa5a210351d5c052586f6618104f88f0431e2e6e2aee9
|
|
BLAKE2b-256 checksum How to use checksums |
4833c3514ce6897d177645bdd77bdbbf767a45c3dbd8c24e564d848cf65c03d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / resonant_swarm-0.1.0-py3-none-any.whl
| Download URL | resonant_swarm-0.1.0-py3-none-any.whl |
|---|---|
| Size | 43.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fab1b74ba47ecde11fc7ce4956f33eeee4b5bf99c460e2cf45e9b183188dad72
|
|
BLAKE2b-256 checksum How to use checksums |
719381eb1c803127cda1f6fa7395496f4ca4d5a9c556d71eef27cfdfd4e7a572
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for resonant-swarm 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.