Detects and prevents repetitive execution cycles that waste resources without progress.
text
SYMPTOMS:
├── Agent repeats the same actions indefinitely
├── Resource waste (CPU, RAM, GPU)
├── No progress toward goal
└── STC spikes (emotional tension)
python
class AntiInfiniteLoop:
max_retries = 3 # Max retry attempts
max_steps = 10 # Max steps per task
max_time_seconds = 300 # Time limit (5 min)
progress_threshold = 0.1 # Min improvement to continue
python
action_history = [] # Previous actions
def track_action(action):
if action in action_history[-5:]: # Repetition detected
log_warning("ACTION REPEATED - STOPPING")
return False # Stop
action_history.append(action)
return True
python
def check_progress(before, after):
improvement = calculate_improvement(before, after)
if improvement < progress_threshold:
return False # No progress → STOP
return True
python
def time_exceeded():
elapsed = time.time() - start_time
if elapsed > max_time_seconds:
return True
return False
WatchdogRoleThresholdSTCEmotional tension>0.700 = STOPSYNAction repetition>5 repeats = STOP
python
from anti_infinite_loop import AntiInfiniteLoop
loop_guard = AntiInfiniteLoop()
for step in range(loop_guard.max_steps):
action = decide_next_action()
if not loop_guard.track_action(action):
break # Repeated action → STOP
result = execute(action)
if not loop_guard.check_progress(before, result):
break # No progress → STOP
if loop_guard.time_exceeded():
break # Time exceeded → STOP
MetricValueDetection latency<10msMemory overhead<5MBCPU overhead<1%False positive rate<0.1%
text
anti-infinite-loop/
├── SKILL.md
├── scripts/
│ ├── anti_infinite_loop.py
│ ├── main.py
│ └── utils.py
├── data/
├── models/
└── tests/