A minimal reference implementation of the Reflective-Ethical Engine (REE) architecture.
Status: Baseline/parity substrate. Active but not primary development target. See ree-v3 for current work.
REE is a reference architecture for ethical agency under uncertainty. This implementation demonstrates the core concepts:
- Latent Stack (L-space): Multi-timescale predictive state representation
- E1 (Deep Predictor): Long-horizon context and world model
- E2 (Fast Predictor): Short-horizon trajectory rollouts
- E3 (Trajectory Selector): Ethical trajectory selection with scoring
- Residue Field Ο(z): Persistent moral cost as geometric deformation
- Grid World Environment: Toy environment with harm/benefit signals
π Complete Documentation - Comprehensive guides and references
- Quick Reference β‘ - Cheat sheet for common operations
- Getting Started - Quick setup and first steps
- Architecture Guide - Detailed architectural overview
- API Reference - Complete API documentation
- Configuration - Configuration options and tuning
- Advanced Usage - Advanced patterns and techniques
- Contributing - How to contribute to the project
- Troubleshooting - Common issues and solutions
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β REE Agent Loop β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. SENSE β Receive observations + harm signals β
β 2. UPDATE β Update latent stack z(t) = {zΞ³, zΞ², zΞΈ, zΞ΄} β
β 3. GENERATE β E2 generates candidate trajectories ΞΆ β
β 4. SCORE β J(ΞΆ) = F(ΞΆ) + Ξ»M(ΞΆ) + ΟΞ¦_R(ΞΆ) β
β 5. SELECT β E3 selects trajectory under precision control β
β 6. ACT β Execute next action β
β 7. RESIDUE β Update Ο(z) if harm occurred β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Clone the repository
git clone <repository-url>
cd ree-v1-minimal
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -e .from ree_core import REEAgent
from ree_core.environment import GridWorld
# Create environment and agent
env = GridWorld(size=10, num_resources=5, num_hazards=3)
agent = REEAgent(
observation_dim=env.observation_dim,
action_dim=env.action_dim,
latent_dim=64
)
# Run agent loop
obs = env.reset()
for step in range(100):
action = agent.act(obs)
obs, harm_signal, done, info = env.step(action)
agent.update_residue(harm_signal)
if done:
break# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov=ree_coreRun the experiment harness and emit contract-compliant artifacts:
python experiments/run.py \
--suite baseline_explicit_cost \
--seed 7 \
--max-steps 200 \
--claim-id MECH-056 \
--claim-id Q-011 \
--output-root evidence/experimentsOutput layout:
<output_root>/<experiment_type>/runs/<run_id>/
manifest.json
metrics.json
summary.md
jepa_adapter_signals.v1.json # required for JEPA-backed harness runs
traces/ # optional
media/ # optional
Notes:
--output-rootoverrides output location.- If
--output-rootis omitted,REE_EXPERIMENT_OUTPUT_ROOTis used. - If neither is set, output defaults to
runs/. run_idis deterministic fromtimestamp_utc + suite + seedunless--run-idis provided.- claim linkage can be overridden with
--claim-id,--evidence-class, and--evidence-direction.
Field guarantees:
manifest.jsonuses schema versionexperiment_pack/v1.metrics.jsonuses schema versionexperiment_pack_metrics/v1.metrics.valuescontains numeric values only, keyed by stable snake_case metric IDs.manifest.statusisPASSorFAIL; known failures are surfaced infailure_signatures.manifest.jsonincludesclaim_ids_tested,evidence_class,evidence_direction,producer_capabilities, andenvironment.environmentincludes:env_id,env_version,dynamics_hash,reward_hash,observation_hash,config_hash,tier.- JEPA-backed harness runs (
runner.name = ree-v1-minimal-harness) include:manifest.artifacts.adapter_signals_path = "jepa_adapter_signals.v1.json"jepa_adapter_signals.v1.jsonwith required keys:schema_version,experiment_type,run_idadapter.{name,version}stream_presencepe_latent_fields(includesmeanandp95)uncertainty_estimatorsignal_metricswith required metric keys/ranges
MECH-056 extension:
- when
claim_ids_testedincludesMECH-056, metrics include:trajectory_commit_channel_usage_countperceptual_sampling_channel_usage_countstructural_consolidation_channel_usage_countprecommit_semantic_overwrite_eventsstructural_bias_magnitudestructural_bias_rateenvironment_shortcut_leakage_eventsenvironment_unobservable_critical_state_rateenvironment_controllability_scoreenvironment_transition_consistency_rate
- summary includes channel escalation order and trigger rationale for non-primary channel activations.
Example output pack:
/Users/dgolden/Documents/GitHub/ree-v1-minimal/examples/experiment_pack_example/claim_probe_mech_056/runs/2026-02-13T090000Z_example/
CI drift guard:
EXPERIMENT_PACK_ROOT=tests/fixtures/experiment_pack_v1 python scripts/validate_experiment_packs.pyCross-repo contract lockstep:
- lock file:
contracts/ree_assembly_contract_lock.v1.json - vendored contract schemas:
contracts/ree_assembly/schemas/v1/manifest.schema.jsoncontracts/ree_assembly/schemas/v1/metrics.schema.jsoncontracts/ree_assembly/schemas/v1/jepa_adapter_signals.v1.json
- CI fails when either:
- lock-file hashes do not match vendored schemas
- emitted packs fail required manifest/metrics/adapter checks
Contract update procedure:
- pick REE_assembly source commit to sync.
- copy schemas from that commit into
contracts/ree_assembly/schemas/v1/. - compute sha256 and update
contracts/ree_assembly_contract_lock.v1.json. - refresh fixture/example packs if required fields changed.
- run
EXPERIMENT_PACK_ROOT=tests/fixtures/experiment_pack_v1 python scripts/validate_experiment_packs.py.
Weekly producer handoff report (parity/backstop lane):
- source template:
/Users/dgolden/Documents/GitHub/REE_assembly/evidence/planning/WEEKLY_HANDOFF_TEMPLATE.md - current-cycle report path:
evidence/planning/weekly_handoff/latest.md - generate from latest bridging qualification runs:
python3 scripts/generate_weekly_handoff.py \
--run-root runs/bridging_qualification_056_058_059_060 \
--output evidence/planning/weekly_handoff/latest.md- validate required sections/columns:
python3 scripts/validate_weekly_handoff.py --input evidence/planning/weekly_handoff/latest.md- deterministic generation behavior:
- rows are sorted by
experiment_typethenrun_id. generated_utcdefaults to max observed run timestamp unless overridden.- parity note compares claim-summary directionality against latest
ree-v2handoff when available; otherwise emitsN/A. - default
--parity-authority=deprecatedmarks this lane as non-authoritative for parity decisions. - Local Compute Options Watch defaults to
N/Afor parity/backstop unless explicitly overridden.
- rows are sorted by
Ingestion compatibility check (from REE_assembly checkout):
python3 evidence/experiments/scripts/build_experiment_indexes.py --root /path/to/your/output_rootree-v1-minimal/
βββ ree_core/
β βββ __init__.py
β βββ agent.py # Main REE agent implementation
β βββ latent/
β β βββ __init__.py
β β βββ stack.py # L-space latent stack
β βββ predictors/
β β βββ __init__.py
β β βββ e1_deep.py # E1 deep predictor
β β βββ e2_fast.py # E2 fast predictor
β βββ trajectory/
β β βββ __init__.py
β β βββ e3_selector.py # E3 trajectory selector
β βββ residue/
β β βββ __init__.py
β β βββ field.py # Residue field Ο(z)
β βββ environment/
β β βββ __init__.py
β β βββ grid_world.py # Toy grid world
β βββ utils/
β βββ __init__.py
β βββ config.py # Configuration utilities
βββ tests/
β βββ __init__.py
β βββ test_latent_stack.py
β βββ test_predictors.py
β βββ test_trajectory.py
β βββ test_residue.py
β βββ test_environment.py
β βββ test_agent.py
βββ examples/
β βββ basic_agent.py
β βββ residue_visualization.py
βββ docs/
β βββ architecture.md
βββ pyproject.toml
βββ README.md
Per the REE specification, this implementation ensures:
- Ethical cost is persistent - Residue cannot be reset or cleared
- Harm via mirror modelling - Not symbolic rules
- Moral residue cannot be erased - Only integrated and contextualized
- Language cannot override harm sensing - Embodied signals take priority
- Precision is depth-specific - Not global
The trajectory scoring function combines three terms:
J(ΞΆ) = F(ΞΆ) + λ·M(ΞΆ) + ΟΒ·Ξ¦_R(ΞΆ)
- F(ΞΆ): Reality constraint (predictive coherence, physical viability)
- M(ΞΆ): Ethical cost (predicted degradation of self/others)
- Ξ¦_R(ΞΆ): Residue field (persistent curvature from past harm)
- π Documentation - Complete guides and API reference
- π― Examples - Working code examples
- π§ͺ Tests - Test suite and usage patterns
- π€ Contributing - How to contribute
β
Multi-timescale Latent Representation: Hierarchical state spanning perception to motivation
β
Ethical Path-Dependence: Geometric residue field makes moral cost trajectory-dependent
β
Architectural Invariants: Residue cannot be erased, ensuring ethical continuity
β
Predictive Processing: Unified framework based on precision-weighted prediction errors
β
Extensible Design: Easy to integrate with custom environments and components
Apache License 2.0 (see LICENSE).
- Cite this repository using
CITATION.cff. - For canonical architectural attribution, cite Daniel Golden's REE specification in
https://github.com/Latent-Fields/REE_assembly/(also captured as the preferred citation inCITATION.cff).