# crisis A proof-of-concept and educational artifact for Mirco Richter's [_Crisis_ paper](Crisis.mirco-richter-2019.pdf) โ€” a DAG-based BFT consensus protocol that achieves total order on messages in fully open, unstructured peer-to-peer networks through **virtual voting**: votes are never sent explicitly but are deduced from the causal relationships encoded in Lamport graphs. This repository contains: - a **Python implementation** of the protocol (`src/crisis/`, `tests/`), - an **event recorder** that exports a deterministic simulation run to JSON, - **CrisisViz** โ€” a native macOS / SwiftUI curriculum visualizer that walks the protocol end-to-end across ten chapters, - **crisis_agents** โ€” a coordination layer that lifts the protocol from "consensus between machines" to "consensus between AI agents," with a decentralized async event-driven engine and quorum-ratified byzantine alarms. Everything in the visualizer is in extreme slow motion and serialized for didactic clarity. A signed speed slider scrubs each chapter forward and backward at any rate from $-16\times$ to $+16\times$; narration is bound to whichever beat the playhead is on. --- ## Architecture at a glance ```mermaid flowchart TD Paper["๐Ÿ“„ Paper โ€” the spec
Crisis.mirco-richter-2019.pdf"] Paper --> Algos subgraph Algos["๐Ÿงฎ Pure protocol algorithms โ€” src/crisis/"] direction LR Crypto["crypto.py"] Msg["message.py"] Graph["graph.py"] Weight["weight.py"] Rounds["rounds.py"] Voting["voting.py"] Order["order.py"] end Algos --> RealRT Algos --> SimRT Algos --> AgentLayer subgraph RealRT["๐ŸŒ Real runtime โ€” node.py + gossip.py
scalable, deployable"] Node["CrisisNode
asyncio ยท TCP push/pull gossip
3 concurrent loops
CLI: crisis-node"] end subgraph SimRT["๐Ÿงช In-process toy runtime โ€” demo.py
deterministic, recordable"] SimNode["SimulatedNode
direct in-memory message passing
NetworkParams: delays / drops / silences"] SimCtl["Simulation controller
spins up N honest + K byzantine
CLI: crisis-demo"] SimNode --- SimCtl end subgraph AgentLayer["๐Ÿค– Crisis-Agents โ€” src/crisis_agents/
decentralized, asynchronous"] Agent["CrisisAgent ร—N
owns own LamportGraph
emit ยท receive ยท gossip ยท detect"] Mom["Mothership
bootstrap + event-loop driver
no clock ยท no privileged state
CLI: crisis-agents"] Agent --- Mom end SimRT --> Rec Rec["๐Ÿ“ผ Recorder โ€” recorder.py
instruments every algorithm call
captures events + per-step snapshots"] Rec --> Export Export["๐Ÿ“ฆ JSON exporter โ€” export_json.py
writes crisis_data.json"] Export --> Viz AgentLayer --> ProofJSON["๐Ÿงพ proof_*.json
multi-signer byzantine proof
schema_version=2"] subgraph Viz["๐ŸŽฌ CrisisViz โ€” native macOS / SwiftUI"] Player["Keynote-style player
10 chapters ยท ~18 min @ 1ร—
scrubbable โˆ’16ร— to +16ร—"] Testbed["Testbed harness
invariants ยท source audit
PNG sweep ยท 36 MP4 clips"] end classDef paper fill:#fdf6e3,stroke:#586e75,color:#073642 classDef pure fill:#eee8d5,stroke:#586e75,color:#073642 classDef real fill:#fce5cd,stroke:#cc4125,color:#660000 classDef sim fill:#d9ead3,stroke:#38761d,color:#0b3d0b classDef agents fill:#fff2cc,stroke:#bf9000,color:#3d2e00 classDef rec fill:#cfe2f3,stroke:#2c5f8f,color:#062b4d classDef viz fill:#ead1dc,stroke:#741b47,color:#3d0a26 classDef proof fill:#fce5e8,stroke:#a64d59,color:#3d0014 class Paper paper class Algos pure class RealRT real class SimRT sim class AgentLayer agents class Rec,Export rec class Viz viz class ProofJSON proof ``` **Three independent consumers of the protocol.** `src/crisis/` provides the pure algorithms (Lamport graphs, virtual voting, total order, mutation detection). Three sibling layers sit on top: - **`CrisisNode`** โ€” a deployable distributed runtime (TCP gossip, three concurrent asyncio loops). Has no consumers in this repo; meant as a reference for how a real network deployment would look. - **`SimulatedNode`** โ€” an in-process deterministic simulator whose recording becomes `crisis_data.json`, the file CrisisViz visualizes. - **`crisis_agents`** โ€” agent-coordination layer. Each AI agent participates as a Crisis node; the network catches byzantine equivocation through decentralized detection + quorum voting. The engine is asynchronous and event-driven โ€” no global clock, no privileged observer. The three are **siblings, not layers**: refactoring one doesn't break the others. CrisisViz and crisis_agents don't know each other exists. --- ## Repository layout ``` crisis/ โ† git root โ”œโ”€โ”€ Crisis.mirco-richter-2019.pdf the paper โ”œโ”€โ”€ README.md this file โ”œโ”€โ”€ INSTALL.md fresh-macOS install guide โ”œโ”€โ”€ LICENSE MIT (code only; paper is CC-BY-4.0) โ”œโ”€โ”€ pyproject.toml Python โ‰ฅ3.11, networkx, pytest โ”œโ”€โ”€ crisis_data.json simulation export (source of truth) โ”‚ โ”œโ”€โ”€ src/crisis/ โ”€โ”€ PROTOCOL PoC (Python) โ”€โ”€ โ”‚ โ”œโ”€โ”€ crypto.py, message.py random-oracle hash + Message/Vertex โ”‚ โ”œโ”€โ”€ graph.py, weight.py, rounds.py Lamport DAG + PoW weight + round derivation โ”‚ โ”œโ”€โ”€ voting.py, order.py BBA virtual voting + total order โ”‚ โ”œโ”€โ”€ gossip.py, node.py real TCP runtime (CrisisNode) โ”‚ โ”œโ”€โ”€ demo.py in-process simulation harness โ”‚ โ”œโ”€โ”€ recorder.py event instrumentation โ”‚ โ””โ”€โ”€ export_json.py JSON exporter for CrisisViz โ”‚ โ”œโ”€โ”€ src/crisis_agents/ โ”€โ”€ AGENT COORDINATION (Python) โ”€โ”€ โ”‚ โ”œโ”€โ”€ README.md architecture & walkthrough โ”‚ โ”œโ”€โ”€ agent.py CrisisAgent + MockAgent + MockByzantineAgent โ”‚ โ”œโ”€โ”€ live_agent.py LiveClaudeAgent (Anthropic SDK) โ”‚ โ”œโ”€โ”€ boundary.py trust-set + open() trigger โ”‚ โ”œโ”€โ”€ mothership.py bootstrap + async event-loop driver โ”‚ โ”œโ”€โ”€ claim.py ClaimMessage payload โ”‚ โ”œโ”€โ”€ alarm.py decentralized detection โ”‚ โ”œโ”€โ”€ vote.py AlarmClaim + quorum tally โ”‚ โ”œโ”€โ”€ proof.py multi-signer ProofDocument โ”‚ โ”œโ”€โ”€ cli.py crisis-agents CLI entry point โ”‚ โ””โ”€โ”€ scenarios/fact_check.py the canonical demo โ”‚ โ”œโ”€โ”€ tests/ pytest suite (170 tests, ~0.8s) โ”‚ โ””โ”€โ”€ CrisisViz/ โ”€โ”€ VISUALIZER (Swift / macOS 26) โ”€โ”€ โ”œโ”€โ”€ Package.swift, bundle.sh, package-dmg.sh โ”œโ”€โ”€ Sources/CrisisViz/ App, Engine, Model, Chapters, Views, Glass, Testbed, Canvas โ”œโ”€โ”€ README.md Swift-side human guide โ””โ”€โ”€ HANDOFF.md agent-to-agent engineering log ``` --- ## Quick start Four audiences. Pick the one that matches what you want to do. ### ๐Ÿงฎ Verify the protocol โ€” pytest ```sh cd crisis source .venv/bin/activate # set up per INSTALL.md if first time pytest -q ``` Runs all 170 tests across the protocol algorithms and the crisis_agents layer. Should be green in under a second. ### ๐Ÿงช Run a deterministic protocol simulation โ€” Python CLI ```sh python -m crisis.demo --nodes 4 --byzantine 1 --rounds 10 ``` Spins up four honest + one byzantine `SimulatedNode`, runs ten consensus rounds in-process with a deterministic seed, prints the resulting total order. To export a fresh `crisis_data.json` for CrisisViz: ```sh python -m crisis.export_json --steps 80 -o crisis_data.json cp crisis_data.json CrisisViz/Sources/CrisisViz/crisis_data.json ``` ### ๐Ÿค– Run the AI-agent coordination demo โ€” Python CLI ```sh crisis-agents demo ``` Walks a six-phase scenario: a closed honest team, a byzantine joiner who equivocates on a fact-check statement, an asynchronous gossip + detection event loop, and a quorum-ratified proof. Output ends with a `proof_*.json` document that any third party can self-verify. See **[src/crisis_agents/README.md](src/crisis_agents/README.md)** for the architecture. For real Claude sub-agents instead of scripted mocks: ```sh pip install -e ".[live]" # adds anthropic SDK export ANTHROPIC_API_KEY=... crisis-agents demo --live ``` ### ๐ŸŽฌ Watch the protocol visualizer โ€” Swift / macOS ```sh cd CrisisViz ./bundle.sh # builds CrisisViz.app and opens it # or: ./package-dmg.sh # builds CrisisViz.dmg for distribution ``` Then arrow keys โ†/โ†’ to navigate, **Space** to play/pause, the bottom slider to scrub at any signed speed from $-16\times$ to $+16\times$. --- ## Where to read next - **[INSTALL.md](INSTALL.md)** โ€” clone-to-running on a fresh macOS box. Prerequisites, Python venv setup, Swift toolchain, regenerating sim data, running the agents demo, troubleshooting. - **[src/crisis_agents/README.md](src/crisis_agents/README.md)** โ€” the AI-agent coordination layer: architecture, six-phase walkthrough, decentralization principles, async event loop, quorum formula, live Claude mode, proof JSON shape. - **[CrisisViz/README.md](CrisisViz/README.md)** โ€” Swift-side guide: serial-timeline pattern, testbed outputs, controls, cast convention. - **[CrisisViz/HANDOFF.md](CrisisViz/HANDOFF.md)** โ€” engineering log for the next coding agent. --- ## License - **Code** (`src/`, `tests/`, `CrisisViz/`) is licensed under the [MIT License](LICENSE). - **Paper** (`Crisis.mirco-richter-2019.pdf`) by Mirco Richter is a separately licensed artifact under CC-BY-4.0.