---
id: "action-use-ralph-loops"
type: "action-item"
source_timestamps: ["§ Long Horizon Autonomous Execution"]
tags: ["orchestration", "long-horizon"]
related: ["concept-ralph-loop", "claim-long-horizon-compounds", "concept-filesystem-primitive"]
action: "Intercept model exit attempts and reinject prompts in clean context windows to force task continuation."
outcome: "Overcomes early stopping and incoherence in long-horizon autonomous execution."
speakers: ["Vivek Trivedy"]
---
# Use Ralph Loops for Long-Horizon Tasks

## Action

**Intercept model exit attempts and reinject prompts in clean context windows to force task continuation.**

## How

For complex, long-running tasks, implement a [[concept-ralph-loop|Ralph Loop]]:

1. Install a hook that intercepts the model's exit attempt.
2. Clear the context window.
3. Reinject the original prompt.
4. Force the agent to read its prior state from the [[concept-filesystem-primitive|filesystem]].
5. Continue working toward the goal.

This works only if durable state is already in place — see [[action-implement-filesystem]].

## Expected Outcome

Overcomes **early stopping** and **incoherence across context windows** in long-horizon autonomous execution. Operationalizes [[claim-long-horizon-compounds]].

## Guardrails

Add:

- **Budget limits** (max iterations, wall-clock, tokens) to prevent runaway loops.
- **Stop criteria** based on task-completion signals (tests pass, plan complete).
- **Human approval gates** for high-stakes or production deployments.
