cascade_engine
NCM Cascade Engine — Multi-turn neurochemical event sequences.
╔═══════════════════════════════════════════════════════════════════════════════╗ ║ 🌀 CASCADE ENGINE ║ ╠═══════════════════════════════════════════════════════════════════════════════╣ ║ Loads cascade definitions from ncm_cascades.yaml ║ ║ Checks triggers against current NCM vector + active emotions ║ ║ Advances active cascades one stage-tick per turn ║ ║ Handles interrupts (abort / pause / skip_to_stage / trigger_cascade) ║ ║ Applies synergy bonuses when cascades co-activate ║ ║ Persists state in Redis: ncm:cascades:{channel_id} ║ ╠═══════════════════════════════════════════════════════════════════════════════╣ ║ Called during exhale() after metabolic decay, stimulus delta ║ ║ stacking, and antagonist suppression. ║ ╚═══════════════════════════════════════════════════════════════════════════════╝
- class cascade_engine.CascadeState[source]
Bases:
objectPer-channel cascade bookkeeping, serializable to and from Redis.
Holds everything the engine needs to advance a channel’s cascades across turns: the currently
activecascades and their stage progress, per-cascadecooldowns, a rollinghistoryof trigger/abort/complete events, rolling windows of recent node values, delta counts and emotion sets used for sustained-condition checks, and the habituationfire_counts/last_fired_turnused for tolerance and recovery. Instances are loaded and persisted byCascadeEngine._load_state()andCascadeEngine._save_state()under thencm:cascades:{channel_id}Redis key, round-tripping throughto_dict()andfrom_dict().- __init__()[source]
Initialize an empty cascade state with no active cascades.
Sets up all tracking containers to their empty defaults so a fresh channel starts with nothing active, no cooldowns, and zeroed rolling windows. Touches no external state; called by
from_dict()and byCascadeEngine._load_state()when Redis holds no prior state.
- class cascade_engine.CascadeEngine(redis_client=None, variant_cache=None)[source]
Bases:
objectDrives multi-turn neurochemical cascades for the limbic system.
Owns the per-channel cascade lifecycle: each turn it loads
CascadeStatefrom Redis, checks interrupts on active cascades, advances their stages and accumulates stage deltas, applies synergy bonuses and the meta-systems (habituation/tolerance, sensitization, GABA polarity inversion), evaluates triggers for new cascades, and persists state back to Redis underncm:cascades:{channel_id}. Cascade definitions and meta configs are loaded once via_load_cascade_defs()and_load_meta_configs(); stage cue text is humanized through an optionalCueVariantCache, and the returned delta vector feeds back into the NCM state. Instantiated once bylimbic_system.coordinator.LimbicCoordinator(itscascade_engineattribute), which callstick()andget_active_cascades()fromexhale()each turn.- Parameters:
variant_cache (CueVariantCache | None)
- __init__(redis_client=None, variant_cache=None)[source]
Initialize the instance.
- Parameters:
redis_client – Redis connection client.
variant_cache (
CueVariantCache|None) – The variant cache value.
- async tick(channel_id, vector, active_emotions, delta_count=0)[source]
Execute one turn of cascade processing.
Called during exhale(). Returns combined delta vector from all active cascade stages this turn.
- Parameters:
- Returns:
Combined delta vector from cascade processing this turn.
- Return type:
- async get_active_cascades(channel_id)[source]
Summarize a channel’s in-flight cascades for prompt-context injection.
Loads the channel’s
CascadeState(read-only; it does not advance anything) and, for each active cascade, resolves the current stage name and a humanized cue line through_pick()(the variant cache), plus how many turns it has run and whether it is paused. The coordinator’sexhale()calls this right aftertick()and forwards the non-paused cues into the limbic context so active cascades can color the bot’s reply.