Example: State Hydration

Architecture desk with JSON sheets and state blocks

If you persist genesis state for entities, you can hydrate them later and replay events. This keeps your simulation deterministic while enabling save/load workflows.

Scenario

You store an NPC's initial state at creation time. Later, you load that state and replay stored events to reconstruct current behavior.

Step 1: Load Genesis State

// Load persisted genesis state (your serialization format)
let genesis: GenesisState = load_from_json("npc_001_genesis.json")?;

Step 2: Hydrate the Entity

use behavioral_pathways::entity::EntityBuilder;

let entity = EntityBuilder::new()
    .id(&genesis.id)
    .species(Species::Human)
    .birth_date(genesis.birth_date)
    .age(genesis.age)
    .hexaco(genesis.hexaco)
    .person_characteristics(genesis.person_characteristics)
    .mood(genesis.mood)
    .needs(genesis.needs)
    .mental_health(genesis.mental_health)
    .social_cognition(genesis.social_cognition)
    .disposition(genesis.disposition)
    .build()?;

Step 3: Replay Events

let mut sim = SimulationBuilder::new(genesis.anchor_timestamp).build()?;

sim.add_entity(entity, genesis.anchor_timestamp);
for event in stored_events {
    sim.add_event(event.event, event.timestamp);
}

let current_state = sim.entity(&genesis.id)?.state_at(Timestamp::now());

Why This Matters

  • Deterministic replay: The same genesis + events yields the same state.
  • Save/load ready: Store state once, replay deltas later.
  • Auditability: You can inspect or diff event logs over time.