Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AIScientists Dev WorldSeed Reactive Consequence Scanning

From Leeroopedia
Knowledge Sources
Domains Simulation, Reactive_Systems
Last Updated 2026-10-26 18:00 GMT

Overview

A reactive rule engine that evaluates declarative trigger conditions each tick, fires effects when conditions transition or persist, and cascades — re-scanning until stable — to support world reactions that chain from one consequence triggering another.

Description

Consequences are the reactive layer of WorldSeed: declarative rules in scene config that fire automatically when world state matches their trigger conditions, without any agent action required. The `ConsequenceScanner` evaluates these triggers each tick.

Two firing modes:

  • on_change: Fires once on a false→true transition. The scanner tracks previous state per consequence (and per entity for `$entity`-referencing consequences) to detect transitions.
  • every_tick: Fires every tick while the condition is true.

Two scoping modes:

  • Global: Consequences without `$entity` references — evaluated once per tick.
  • Per-entity: Consequences referencing `$entity` — evaluated once per entity per tick, with `$entity` bound in the evaluation context.

Cascading: When a consequence fires and changes state, it may cause another consequence's trigger to become true. The scanner re-scans (up to 10 passes) until a full pass produces no new firings. After the first pass, `every_tick` consequences are skipped (they fire once per tick); only `on_change` re-scans for cascades.

Consequences can also trigger DM calls (with a `dm` config field), which are resolved asynchronously.

The HighlightScanner mirrors this logic but emits highlight events (admin-scoped, dashboard-only) instead of executing effects.

Usage

Use this principle to create world reactions — environmental changes, automatic effects, emergent behaviors triggered by state conditions rather than agent actions. Consequences are defined in the `consequences` section of scene config YAML.

Theoretical Basis

The scanner follows a fixed-point iteration pattern:

# Abstract algorithm (NOT real implementation)
for pass in range(MAX_SCAN_PASSES):
    triggered_this_pass = []
    for consequence in consequences:
        if pass > 0 and consequence.frequency == "every_tick":
            continue  # every_tick fires once
        if consequence.references_entity:
            for entity in store.all_entities():
                ctx["entity"] = entity.id
                fired, dm = eval_and_fire(consequence, ctx)
        else:
            fired, dm = eval_and_fire(consequence, ctx)
    if not triggered_this_pass:
        break  # stable — fixed point reached

The `_MAX_SCAN_PASSES = 10` cap prevents infinite loops (e.g., A triggers B triggers A). State tracking for `on_change` uses a composite key: `"{consequence_name}::{entity_id}"` for per-entity consequences.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment