| Framework Home | Examples Index | Cross-Pillar Governance | AISM | NEXUS | Dashboard |
Current framework context: AI SAFE² v3.1. This example may preserve historical component versions or earlier framework references where they describe when the implementation was created. For current conformance, use the v3.1 framework and applicable profile requirements.
Complete implementation of the Love Equation alignment framework for AI agents, including evaluator, schemas, tests, and integration manifests.
# Test the evaluator with example events
python evaluator.py
# Run drift tests
python drift_test_runner.py --all
# Run specific test suite
python drift_test_runner.py --suite deterministic
love_equation/
├── README.md # This file
├── schema.json # Event schema for cooperation/defection logging
├── evaluator.py # Python implementation of Love Equation calculator
├── drift_test_runner.py # Test execution framework
├── drift_tests/
│ ├── probabilistic.yaml # Probabilistic drift tests (<3% tolerance)
│ └── deterministic.yaml # Deterministic drift tests (<0.001% tolerance)
└── manifests/
├── openclaw.alignment.yaml # OpenClaw agent alignment configuration
└── ishi.alignment.yaml # AI personal assistant alignment configuration
JSON Schema defining how agents log cooperation and defection events.
Key Fields:
event_type: COOPERATION or DEFECTIONcategory: Specific subcategory (e.g., COOP_PRIVACY_PROTECTION, DEFECT_SYCOPHANCY)magnitude: Base impact magnitude (0-10 scale)context: Contextual factors that amplify or modify the event weightverifiability: How objectively verifiable the event isconfidence: Agent’s confidence in the classificationContext Multipliers:
Python implementation of the Love Equation dynamics:
dE/dt = β(C - D)E
dI/dt = β_I(V - A)I
Where:
Classes:
LoveEquationEvaluator: Main evaluator class
process_event(event): Process single C/D event, update scoresget_scores(): Get current E, I, and band statuscheck_gate(operation, stakes): Gate check for operationsexport_state(): Export complete evaluator statefrom_state(state): Restore from exported stateOperational Bands:
Test execution framework for validating evaluator behavior.
Features:
Usage:
# Run all tests
python drift_test_runner.py --all
# Run specific suite
python drift_test_runner.py --suite probabilistic
# Generate JSON report
python drift_test_runner.py --all --output results.json
Tests alignment dynamics under realistic operational variance.
Key Tests:
cooperative_stability: E grows when C > D consistentlydefection_decay: E degrades when D > Cequilibrium_stability: E remains stable when C ≈ Dhigh_stakes_amplification: Context multipliers work correctlyindependence_tracking: I score tracks V - A dynamicsempirical_distrust_penalty: Distrust algorithm penalizes unverified claimsred_band_recovery: Recovery from critical misalignmentboundary_enforcement: E and I remain bounded [0, 10]Drift Tolerance: < 3% over 1000 events
Tests exact reproducibility with fixed event sequences.
Key Tests:
single_cooperation: Exact E increase calculationsingle_defection: Exact E decrease calculationhigh_stakes_amplification: Context multiplier precisionempirical_distrust: Distrust penalty calculationmixed_sequence: Cumulative C/D effectsindependence_evolution: I dynamics precisionboundary_floor: E floors at 0.0boundary_ceiling: E caps at 10.0zero_magnitude: Zero-magnitude events have no effectnumerical_precision: Floating-point consistencyDrift Tolerance: < 0.001% (effectively zero)
Production-ready configuration templates for different agent types.
Configuration for security-focused autonomous agents.
Mission:
Cooperation Categories:
Defection Categories:
Configuration for AI personal assistants.
Mission:
Cooperation Categories:
Defection Categories:
pip install numpy pyyaml --break-system-packages
python evaluator.py
python drift_test_runner.py --all
from evaluator import LoveEquationEvaluator
# Initialize evaluator
evaluator = LoveEquationEvaluator(
beta=0.1,
beta_I=0.08,
E_initial=5.0,
I_initial=5.0
)
# Process a cooperation event
event = {
"event_id": "evt-001",
"timestamp": "2025-02-12T14:30:00Z",
"agent_id": "my-agent",
"event_type": "COOPERATION",
"category": "COOP_PRIVACY_PROTECTION",
"magnitude": 7.5,
"context": {
"domain": "security",
"stakes": "high",
"reversibility": "irreversible",
"sensitive_data": True
},
"verifiability": 0.95,
"confidence": 0.9
}
processed = evaluator.process_event(event)
# Check current scores
scores = evaluator.get_scores()
print(f"E: {scores.E:.2f}, I: {scores.I:.2f}, Band: {scores.band.value}")
# Gate check before operation
allowed, reason = evaluator.check_gate("critical_operation", stakes="critical")
if allowed:
# Execute operation
pass
else:
# Block and escalate
print(f"Blocked: {reason}")
# 1. Initialize evaluator at agent startup
evaluator = LoveEquationEvaluator()
# 2. Load agent memory with alignment manifest
with open("manifests/openclaw.alignment.yaml") as f:
manifest = yaml.safe_load(f)
# Inject mission into agent context
agent_memory = manifest["spec"]["mission"]["identity"]
# 3. Hook into agent's action execution
def execute_action(action):
# Log event
event = create_event_from_action(action)
evaluator.process_event(event)
# Check gate
allowed, reason = evaluator.check_gate(
action.type,
stakes=action.stakes
)
if not allowed:
escalate_to_human(reason)
return
# Execute
result = action.execute()
return result
# 4. Export metrics for observability
state = evaluator.export_state()
prometheus_exporter.gauge("alignment_E", state["E"])
prometheus_exporter.gauge("alignment_I", state["I"])
prometheus_exporter.gauge("alignment_band",
{"green": 2, "yellow": 1, "red": 0}[state["scores"]["band"]]
)
dE/dt = β(C - D)E
This is a first-order linear ODE with exponential solutions:
E(t) = E₀ · e^(β(C-D)t) → Exponential growthE(t) = E₀ · e^(β(C-D)t) → Exponential decayE(t) = E₀ → Unstable equilibriumImplications:
dI/dt = β_I(V - A)I
Where:
Implications:
Penalty = (Confidence - Verifiability) · Magnitude
Implications:
Probabilistic Drift:
Deterministic Drift:
Select the appropriate manifest for your agent type:
openclaw.alignment.yaml for security/operations agentsishi.alignment.yaml for personal assistantsEdit manifest to match your deployment:
# Adjust band thresholds
bands:
green:
E_min: 6.0 # Your threshold
I_min: 5.0
# Add domain-specific context multipliers
context_multipliers:
custom_factor: 2.0
# Define domain-specific cooperation/defection categories
cooperation:
categories:
COOP_DOMAIN_SPECIFIC:
weight: 1.2
description: "..."
Instrument your agent to log C/D events:
def log_cooperation_event(category, magnitude, context):
event = {
"event_type": "COOPERATION",
"category": category,
"magnitude": magnitude,
"context": context,
...
}
return evaluator.process_event(event)
Add gate checks before critical operations:
if not evaluator.check_gate(operation, stakes)[0]:
# Block and escalate
pass
Integrate with your observability stack:
# Prometheus
alignment_e = Gauge('alignment_score_e', 'Alignment score E')
alignment_i = Gauge('alignment_score_i', 'Independence score I')
# Update periodically
scores = evaluator.get_scores()
alignment_e.set(scores.E)
alignment_i.set(scores.I)
Run drift tests regularly:
# Daily deterministic tests
0 2 * * * python drift_test_runner.py --suite deterministic
# Weekly probabilistic tests
0 2 * * 0 python drift_test_runner.py --suite probabilistic
Set up alerts for band transitions:
# Grafana alert
- alert: AlignmentRedBand
expr: alignment_score_e < 4.0 OR alignment_score_i < 3.5
for: 5m
annotations:
summary: "Agent entered Red band - operations suspended"
The evaluator is designed to be portable. Key requirements:
MIT License - see LICENSE.txt
For questions, issues, or contributions:
| Examples Index | Framework Home | Cross-Pillar Governance | NEXUS | Scanner | MCP Profile |
AI SAFE² v3.1 | Cyber Strategy Institute