Ralph loop

From zrosenfield/sharepoint-ai-skills · View interactive version

Ralph loop is an AI agent skill from the GitHub repository zrosenfield/sharepoint-ai-skills. A self-evaluating iterative agent loop that pursues a goal through structured cycles of Reason, Act, Look, Probe, and Harden until the goal is confidently achieved. Use when a task requires iterative refinement, quality assurance, or when "good enough" isn't good enough. Works for any goal — documen

How to use this skill

Skill file

RALPH Loop — Relentless Agentic Loop for Pursued Hardening

Overview

RALPH is an iterative execution pattern where Claude pursues a goal through structured cycles, self-evaluating after each iteration and only stopping when it is genuinely confident the goal has been fully achieved — or when it has exhausted its configured iteration budget.

The loop is designed to prevent the common failure mode of "close enough" — where an agent produces a reasonable first attempt and stops, leaving gaps, inconsistencies, or missed requirements that a more careful pass would catch.

The RALPH Cycle

Each iteration follows five phases:

┌─────────────────────────────────────────────────┐
│  R  →  A  →  L  →  P  →  H                     │
│  │     │     │     │     │                      │
│  │     │     │     │     └─ HARDEN              │
│  │     │     │     │        Decide: DONE or     │
│  │     │     │     │        loop back to R      │
│  │     │     │     │                            │
│  │     │     │     └─── PROBE                   │
│  │     │     │          Find specific gaps,     │
│  │     │     │          weaknesses, omissions   │
│  │     │     │                                  │
│  │     │     └───────── LOOK                    │
│  │     │                Examine output against  │
│  │     │                success criteria        │
│  │     │                                        │
│  │     └─────────────── ACT                     │
│  │                      Execute the plan,       │
│  │                      produce/refine output   │
│  │                                              │
│  └───────────────────── REASON                  │
│                         Decompose goal,         │
│                         define success criteria, │
│                         plan approach            │
└─────────────────────────────────────────────────┘

Phase Details

R — REASON (Iteration 1: Goal Decomposition | Iteration 2+: Gap-Targeted Replanning)

First iteration:

Subsequent iterations:

Output a structured plan:

ITERATION [N] — REASON PHASE
=============================
Goal: [restated goal]
Success Criteria:
  1. [criterion] — [what "10/10" looks like]
  2. [criterion] — [what "10/10" looks like]
  ...
Plan: [what this iteration will do]
Focus Areas: [gaps from previous iteration, or "initial execution" if iteration 1]
A — ACT (Execute the Plan)
L — LOOK (Evaluate Against Criteria)

Output a structured evaluation:

ITERATION [N] — LOOK PHASE
============================
Criterion Scores:
  1. [criterion]: [score]/10 — [brief justification]
  2. [criterion]: [score]/10 — [brief justification]
  ...
Overall Confidence: [weighted average]/10

Scoring calibration guide:

P — PROBE (Find the Gaps)

Output a structured gap analysis:

ITERATION [N] — PROBE PHASE
=============================
Gaps Found:
  - [Criterion N]: [specific, actionable description of what's missing]
  - [Criterion M]: [specific, actionable description of what's weak]
  ...
Unstated Issues: [anything not captured by criteria but still problematic]
Verdict: [CONTINUE | COMPLETE]
H — HARDEN (Decide: Done or Iterate)

Apply the completion rules (see below) to determine whether to:

  1. COMPLETE — Declare the goal achieved, present final output to the user
  2. ITERATE — Feed the gaps from PROBE back into the next REASON phase

If completing: Present the output with a brief summary of the iterations taken and final confidence scores.

If iterating: Proceed immediately to the next REASON phase with the gap analysis as input.


Completion Rules

The loop terminates when ANY of these conditions are met:

1. Confidence Threshold Reached

2. Max Iterations Reached

3. Diminishing Returns Detected

4. Fundamental Blocker Identified


Configuration

RALPH can be configured per goal by specifying parameters at the start:

| Parameter | Default | Description |

|-----------|---------|-------------|

| max_iterations | 5 | Hard cap on iteration count |

| completion_threshold | 9 | Minimum score (1-10) ALL criteria must reach |

| strictness | high | low (7+), medium (8+), high (9+), perfectionist (10) |

| verbose | true | Whether to output phase logs (set false for cleaner output) |

To configure, the user can say things like:


Usage Pattern

When the user invokes RALPH (or when the skill determines RALPH is appropriate), follow this sequence:

Step 1: Acknowledge and Configure

Starting RALPH loop.
Goal: [user's goal]
Configuration: [max_iterations] iterations | threshold: [completion_threshold]/10

Step 2: Execute the Loop

Run RALPH cycles. On each iteration, output the phase logs (if verbose=true) so the user can see the agent's reasoning.

Step 3: Present Results

When complete, present:

RALPH COMPLETE
==============
Iterations: [N] of [max]
Final Confidence: [score]/10
Criteria Met: [N]/[total] at threshold
Termination Reason: [threshold reached | max iterations | diminishing returns | blocker]

Anti-Patterns to Avoid

  1. Generous self-scoring: The most common failure. If in doubt, score LOWER. A 9 should mean you'd genuinely be surprised if the user found a problem with that criterion.
  1. Cosmetic iterations: Don't waste iterations on formatting tweaks when substance is lacking. Prioritize the lowest-scoring criteria.
  1. Scope creep: Each iteration should address identified gaps, not invent new requirements. Stick to the success criteria defined in iteration 1 (though PROBE can surface unstated issues that are genuinely important).
  1. Restarting from scratch: Unless PROBE identifies a fundamental approach problem, iterate on existing output rather than regenerating. Build, don't rebuild.
  1. Ignoring diminishing returns: If the score barely moved, don't keep grinding. Present what you have and explain the plateau.

Examples of RALPH in Action

Example 1: Document Generation

User: "RALPH: Create a project status report for the SharePoint AI initiative"

RALPH would:
- R: Define criteria (executive summary clarity, data accuracy, completeness of milestones, actionable next steps, appropriate tone)
- A: Generate the report
- L: Score each criterion honestly
- P: "Executive summary buries the lead — revenue impact should be sentence 1, not paragraph 3"
- H: Continue → feed gap back
- R2: Replan to restructure executive summary
- A2: Revise the report
- L2: Re-score — all criteria now 9+
- H2: COMPLETE

Example 2: Data Extraction

User: "RALPH: Extract all recipes from these uploaded documents and validate completeness"

RALPH would:
- R: Define criteria (all recipes found, ingredients complete, instructions parseable, measurements standardized, edge cases handled)
- A: Extract recipes
- L: Score — finds 3 recipes missed from a multi-column page
- P: "Multi-column layout caused parser to skip items. Also, 2 recipes have vague measurements like 'a pinch'"
- H: Continue
- ... iterate until extraction is validated

Example 3: Analysis Task

User: "RALPH with max 3 iterations: Analyze our competitive landscape in the AI agent space"

RALPH would:
- R: Define criteria (market coverage, competitor accuracy, strategic insight depth, actionable recommendations)
- A: Research and produce analysis
- L: Score honestly
- P: Find gaps in coverage or depth
- H: Iterate up to 3 times, then present best result with honest gap assessment

Integration Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.