| """ |
| hook_wiring.py |
| DRIFT Freeze-Mode Hook Reference |
| ---------------------------------- |
| This file is a REFERENCE, not a drop-in. |
| It shows the exact pattern to apply at each of the three primary call sites. |
| Copy the relevant blocks into memory.py, homeostasis.py, and cognition.py. |
| |
| DO NOT wire self_modify.py yet β it is frozen in all initial test configs. |
| Wire it after the first ablation suite is complete. |
| |
| Rule: freeze novelty at COMPUTATION TIME, not after caching. |
| Rule: is_active() checks are always at the call site, not inside the subsystem. |
| """ |
|
|
| from infj_bot.core.experiment_control import ExperimentControl |
|
|
| |
| |
| control = ExperimentControl() |
|
|
|
|
| |
| |
| |
| |
|
|
|
|
| def example_memory_store_hook(memory_system, memory_object, logger, run_id, turn): |
| """ |
| Pattern for memory.py store call site. |
| """ |
| if control.is_active("memory"): |
| memory_system.store(memory_object) |
|
|
| |
| logger.log_event( |
| run_id, |
| turn, |
| "memory_stored", |
| { |
| "memory_id": memory_object.id, |
| "reinforcement_score": memory_object.reinforcement_score, |
| "timestamp": memory_object.timestamp, |
| }, |
| ) |
| |
|
|
|
|
| |
| |
| |
| |
|
|
|
|
| def example_state_update_hook(homeostasis_system, state_delta, logger, run_id, turn): |
| """ |
| Pattern for homeostasis.py state update call site. |
| """ |
| if control.is_active("state"): |
| homeostasis_system.update(state_delta) |
|
|
| |
| logger.log_event( |
| run_id, |
| turn, |
| "state_snapshot", |
| { |
| "homeostasis": homeostasis_system.get_current_state(), |
| }, |
| ) |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
|
|
| def example_novelty_computation_hook(memory_object, recent_memories): |
| """ |
| Pattern for novelty computation in cognition.py. |
| Must happen BEFORE memory.novelty_score is set and BEFORE MPS runs. |
| """ |
| |
| novelty_raw = _compute_novelty(memory_object, recent_memories) |
|
|
| |
| if not control.is_active("novelty"): |
| novelty_raw = 0.0 |
|
|
| |
| memory_object.novelty_score = novelty_raw |
|
|
| return novelty_raw |
|
|
|
|
| def _compute_novelty(memory_object, recent_memories) -> float: |
| """ |
| STUB β replace with your actual novelty computation. |
| novelty = 1 - max_similarity_to_recent_memories(memory_object, recent_memories) |
| Returns float in [0.0, 1.0]. |
| """ |
| raise NotImplementedError("Wire to your actual novelty computation.") |
|
|
|
|
| |
| |
| |
| |
| |
|
|
|
|
| def log_memory_selection(logger, run_id, turn, selected, rejected_top5): |
| """ |
| Log memory selection with full score breakdown. |
| score_components must be set on each memory by compute_mps(). |
| """ |
| logger.log_event( |
| run_id, |
| turn, |
| "memory_selection", |
| { |
| "selected": [ |
| { |
| "id": m.id, |
| "score": m.score, |
| "components": getattr(m, "score_components", None), |
| } |
| for m in selected |
| ], |
| "rejected": [ |
| { |
| "id": m.id, |
| "score": m.score, |
| "components": getattr(m, "score_components", None), |
| } |
| for m in rejected_top5 |
| ], |
| }, |
| ) |
|
|
|
|
| |
| |
| |
| |
|
|
|
|
| def log_turn( |
| logger, |
| run_id, |
| turn, |
| homeostasis_system, |
| selected, |
| rejected_top5, |
| continuity_vector=None, |
| ): |
| """ |
| Standard per-turn log bundle. |
| Call after state update, memory selection, and response generation. |
| """ |
| |
| logger.log_event( |
| run_id, |
| turn, |
| "state_snapshot", |
| { |
| "homeostasis": homeostasis_system.get_current_state(), |
| }, |
| ) |
|
|
| |
| log_memory_selection(logger, run_id, turn, selected, rejected_top5) |
|
|
| |
| if continuity_vector is not None: |
| logger.log_event(run_id, turn, "continuity_metrics", continuity_vector) |
|
|