openclaw - 💡(How to fix) Fix Feature: Loop detection + forced skill scan for agents in troubleshooting loops [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#56309Fetched 2026-04-08 01:42:23
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Root Cause

Agent was asked 3 times to "use the deep research skill" while troubleshooting a Chrome extension. Ignored it all 3 times because it was stuck in a fix-it loop. The skill existed, the trigger words matched, but the agent skipped skill scanning entirely because it was in rapid troubleshooting mode. Prompt-level rules alone didn't prevent it.

Fix Action

Fix / Workaround

Current workaround

Code Example

[SYSTEM] Loop detected: you've made 4 similar edit→exec cycles without resolution. 
Before your next action: scan SKILLS.md for a better approach, or ask the user for direction.

---

{
  "agents.defaults.maxToolCallsBeforeReview": 10,
  "agents.defaults.loopDetection": true
}
RAW_BUFFERClick to expand / collapse

Problem

When agents enter iterative troubleshooting (try → fail → fix → repeat), they progressively abandon their structured skill system and drop into ad-hoc behavior. This happens even when the user explicitly asks the agent to use a specific skill. The AI agent community calls this "loop drift" — a well-documented pattern where cognitive pressure causes agents to skip structured workflows.

Current workaround

Added explicit rules to RULES.md and SOUL.md:

  • User-named skills treated as commands (not suggestions)
  • Mandatory skill scan before multi-step work
  • 3-strike rule (stop after 3 failed attempts of the same approach)
  • No ad-hoc research when a research skill exists

These help but are still prompt-level — the model can ignore them under pressure, which is exactly when they matter most.

Proposed feature (3 ideas)

1. Loop detection middleware

Monitor repeated identical tool-call patterns (e.g., edit→exec→edit→exec cycling). After N repetitions without progress, inject a system message forcing a strategy review:

[SYSTEM] Loop detected: you've made 4 similar edit→exec cycles without resolution. 
Before your next action: scan SKILLS.md for a better approach, or ask the user for direction.

2. Keyword-triggered skill routing

When user messages contain skill trigger words that match a skill description ("research", "deep research", "investigate"), auto-inject a reminder or pre-load that skill's context into the agent's next turn. This could use the same matching logic that the system prompt already describes but enforce it at the platform level.

3. Configurable iteration caps

Max tool calls per "phase" before forcing a pause. Configurable per-agent:

{
  "agents.defaults.maxToolCallsBeforeReview": 10,
  "agents.defaults.loopDetection": true
}

Real-world case

Agent was asked 3 times to "use the deep research skill" while troubleshooting a Chrome extension. Ignored it all 3 times because it was stuck in a fix-it loop. The skill existed, the trigger words matched, but the agent skipped skill scanning entirely because it was in rapid troubleshooting mode. Prompt-level rules alone didn't prevent it.

Research

This is a known issue across the agent community (LangChain, AutoGPT, CrewAI). Solutions from practitioners include:

  • Hard iteration ceilings (r/AI_Agents)
  • External loop guardrails outside the agent (Perplexity synthesis of multiple sources)
  • Regression detection tools like Windtunnel (r/LLMDevs)
  • Agent-native architecture with explicit specs instead of chatbot-style tool wrappers (r/AI_Agents)

The consensus is that prompt-level rules help but external enforcement is the robust solution.

extent analysis

Fix Plan

To address the "loop drift" issue, we will implement a combination of the proposed features. Here are the concrete steps:

  • Loop Detection Middleware:
    1. Monitor tool-call patterns and detect repeated identical patterns.
    2. After N repetitions without progress, inject a system message forcing a strategy review.
  • Keyword-Triggered Skill Routing:
    1. Implement a keyword matching system to detect skill trigger words in user messages.
    2. Auto-inject a reminder or pre-load the skill's context into the agent's next turn.
  • Configurable Iteration Caps:
    1. Introduce a configurable maxToolCallsBeforeReview parameter.
    2. Enforce a pause after the specified number of tool calls per phase.

Example Code

Here's an example implementation in Python:

import re

# Define a dictionary of skill trigger words
skill_triggers = {
    "research": ["research", "investigate", "deep research"],
    "edit": ["edit", "modify"]
}

# Define the loop detection middleware
def detect_loop(tool_calls):
    pattern = re.compile(r"(edit→exec)+")
    if pattern.search("→".join(tool_calls)):
        return True
    return False

# Define the keyword-triggered skill routing
def route_skill(user_message):
    for skill, triggers in skill_triggers.items():
        for trigger in triggers:
            if trigger in user_message:
                return skill
    return None

# Define the configurable iteration caps
max_tool_calls_before_review = 10

# Example usage
tool_calls = []
user_message = "Use the deep research skill to troubleshoot this issue"
skill = route_skill(user_message)

if skill:
    # Pre-load the skill's context into the agent's next turn
    print(f"Pre-loading {skill} context")
else:
    # Monitor tool-call patterns and detect repeated identical patterns
    tool_calls.append("edit")
    tool_calls.append("exec")
    if detect_loop(tool_calls):
        print("[SYSTEM] Loop detected: review your strategy")
        # Enforce a pause after the specified number of tool calls per phase
        if len(tool_calls) >= max_tool_calls_before_review:
            print("[SYSTEM] Maximum tool calls reached: pausing for review")

Verification

To verify that the fix worked, test the agent with various scenarios, including:

  • Repeated identical tool-call patterns
  • User messages containing skill trigger words
  • Configurable iteration caps

Monitor the agent's behavior and ensure that it:

  • Detects and responds to loop drift
  • Routes skills correctly based on user input
  • Enforces configurable iteration caps

Extra Tips

  • Continuously monitor and refine the loop detection middleware and keyword-triggered skill routing to improve accuracy.
  • Consider implementing additional features, such as regression detection tools or agent-native architecture, to further robust

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature: Loop detection + forced skill scan for agents in troubleshooting loops [1 participants]