Event System Reference
This reference documents the typed event system that enables the AI narrative layer to observe simulation state changes. For conceptual background, see Event System Architecture.
Overview
The simulation emits typed Pydantic events during each tick. Events are
captured by the EventBus, converted to typed models, and persisted
in WorldState.events. This enables:
AI narrative generation from structured data
Event-driven analysis and visualization
Replay and counterfactual scenarios
Key Components:
babylon.models.events- Pydantic event models (13 classes)babylon.models.enums- EventType enum (11 types)babylon.engine.event_bus- Pub/sub event busbabylon.engine.simulation_engine- Event conversion
EventType Enum
All events are categorized by type. The EventType enum defines 11
distinct event types:
EventType |
Category |
Description |
|---|---|---|
|
Economic |
Imperial rent extracted from worker |
|
Economic |
Subsidy paid to comprador state |
|
Economic |
Crisis event triggered |
|
Consciousness |
Ideology transmitted via solidarity edge |
|
Consciousness |
Class consciousness crosses threshold |
|
Consciousness |
Source enters active struggle |
|
Struggle |
Spark event (George Floyd Dynamic) |
|
Struggle |
Revolt triggered |
|
Struggle |
Solidarity infrastructure built |
|
Contradiction |
Tension reaches 1.0 |
|
Topology |
Percolation state changes |
Event Class Hierarchy
Events form a type hierarchy with shared base classes:
SimulationEvent (base - frozen)
|
+-- EconomicEvent (amount: Currency)
| +-- ExtractionEvent (SURPLUS_EXTRACTION)
| +-- SubsidyEvent (IMPERIAL_SUBSIDY)
| +-- CrisisEvent (ECONOMIC_CRISIS)
|
+-- ConsciousnessEvent (target_id: str)
| +-- TransmissionEvent (CONSCIOUSNESS_TRANSMISSION)
| +-- MassAwakeningEvent (MASS_AWAKENING)
|
+-- StruggleEvent (node_id: str)
| +-- SparkEvent (EXCESSIVE_FORCE)
| +-- UprisingEvent (UPRISING)
| +-- SolidaritySpikeEvent (SOLIDARITY_SPIKE)
|
+-- ContradictionEvent (edge: str)
| +-- RuptureEvent (RUPTURE)
|
+-- TopologyEvent (percolation_ratio, num_components)
+-- PhaseTransitionEvent (PHASE_TRANSITION)
Base Event Model
SimulationEvent
All events inherit from SimulationEvent:
Field |
Type |
Description |
|---|---|---|
|
|
Discriminator for event category |
|
|
Simulation tick when event occurred |
|
|
Optional wall-clock time |
Model Configuration:
frozen=True: Events are immutable after creationextra="forbid": No additional fields allowed
Economic Events
Events related to value extraction and imperial rent dynamics.
EconomicEvent (Base)
Field |
Type |
Description |
|---|---|---|
|
|
Value transferred in this event |
ExtractionEvent
Emitted when imperial rent is extracted via EXPLOITATION edge.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Worker node ID (extracted from) |
|
|
Owner node ID (extracted to) |
|
|
Amount of rent extracted |
|
|
Extraction mechanism (default: “imperial_rent”) |
Example:
from babylon.models.events import ExtractionEvent
from babylon.models.enums import EventType
event = ExtractionEvent(
tick=5,
source_id="C001",
target_id="C002",
amount=0.15,
mechanism="imperial_rent",
)
assert event.event_type == EventType.SURPLUS_EXTRACTION
SubsidyEvent
Emitted when imperial subsidy is paid via CLIENT_STATE edge.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Core bourgeoisie node ID |
|
|
Comprador state node ID |
|
|
Subsidy amount |
|
|
Increase to target’s repression capacity |
CrisisEvent
Emitted when economic crisis conditions are detected.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Current imperial rent pool ratio |
|
|
Total system tension |
|
|
Bourgeoisie response (e.g., “AUSTERITY”) |
|
|
Change in wage rates |
Consciousness Events
Events related to ideology drift and consciousness transmission.
ConsciousnessEvent (Base)
Field |
Type |
Description |
|---|---|---|
|
|
Node whose consciousness is affected |
TransmissionEvent
Emitted when consciousness is transmitted via SOLIDARITY edge.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Transmitting node ID |
|
|
Receiving node ID |
|
|
Consciousness change magnitude |
|
|
Edge strength facilitating transmission |
MassAwakeningEvent
Emitted when a node’s consciousness crosses the awakening threshold.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Awakened node ID |
|
|
Consciousness before awakening |
|
|
Consciousness after awakening |
|
|
Node that triggered awakening |
Struggle Events
Events related to the Agency Layer (George Floyd Dynamic).
StruggleEvent (Base)
Field |
Type |
Description |
|---|---|---|
|
|
Node where struggle occurs |
SparkEvent
Emitted when EXCESSIVE_FORCE event occurs (stochastic police brutality).
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Target of state violence |
|
|
Repression level at node |
|
|
Probability that triggered event |
UprisingEvent
Emitted when conditions trigger revolt.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Node where uprising occurs |
|
|
What triggered uprising (e.g., “spark”, “p_rev”) |
|
|
Agitation level at trigger |
|
|
Repression level at trigger |
SolidaritySpikeEvent
Emitted when solidarity infrastructure is built during uprising.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Node gaining solidarity |
|
|
Amount of solidarity added |
|
|
Number of edges strengthened |
|
|
Cause (e.g., “uprising”) |
Contradiction Events
Events related to tension accumulation and rupture.
ContradictionEvent (Base)
Field |
Type |
Description |
|---|---|---|
|
|
Edge identifier (format: “source->target”) |
RuptureEvent
Emitted when tension on an edge reaches 1.0.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Edge that ruptured |
Topology Events
Events related to network structure and phase transitions.
TopologyEvent (Base)
Field |
Type |
Description |
|---|---|---|
|
|
L_max / total_nodes |
|
|
Number of disconnected components |
PhaseTransitionEvent
Emitted when percolation ratio crosses a threshold boundary.
Field |
Type |
Description |
|---|---|---|
|
|
Always |
|
|
Previous phase (“gaseous”, “transitional”, “liquid”) |
|
|
New phase after transition |
|
|
Size of giant component (L_max) |
|
|
Resilience test result (if available) |
Phase State Thresholds:
State |
Threshold |
Meaning |
|---|---|---|
Gaseous |
|
Atomized, no coordination capacity |
Transitional |
|
Emerging structure, unstable |
Liquid |
|
Giant component, vanguard formation |
Event Lifecycle
Events flow through the system in this sequence:
Emission: Systems call
event_bus.publish(type, tick, payload)Collection:
EventBus.get_history()returns all events for tickConversion:
_convert_bus_event_to_pydantic()creates typed modelsPersistence: Events appended to
WorldState.eventsObservation: AI/narrative layer reads typed events
Observer Events (Sprint 3.3):
Observers like TopologyMonitor emit events after the tick completes.
These are collected via get_pending_events() and injected into the
next tick’s WorldState.events via persistent_context['_observer_events'].
Factory Methods
The DomainFactory provides factory methods for creating events in tests:
from tests.factories.domain import DomainFactory
factory = DomainFactory()
# Create events
extraction = factory.create_extraction_event(tick=1, amount=0.1)
subsidy = factory.create_subsidy_event(tick=1, amount=0.05)
transmission = factory.create_transmission_event(tick=1, delta=0.1)
spark = factory.create_spark_event(tick=1, repression=0.8)
uprising = factory.create_uprising_event(tick=1, agitation=0.7)
phase = factory.create_phase_transition_event(
tick=1,
previous_state="gaseous",
new_state="liquid",
)
Assertions
The BabylonAssert class provides semantic assertions for events:
from tests.assertions import Assert
from babylon.models.events import ExtractionEvent
# Assert event exists
Assert(world_state).has_event(ExtractionEvent)
# Assert event with specific fields
Assert(world_state).has_event(
ExtractionEvent,
source_id="C001",
target_id="C002",
)
# Assert event count
Assert(world_state).has_events_count(3)
# Assert amount condition
Assert(world_state).has_event(ExtractionEvent, amount_gt=0.0)
See Also
Event System Architecture - Conceptual explanation of event architecture
Topology System Reference - TopologyMonitor and phase transitions
Simulation Systems Reference - Systems that emit events
babylon.engine.event_bus- Event bus implementation