Skip to content
FaradAiLab Logo FaradAiLab
• FaradAiLab Security Research

Stopping Runaway AI Agent Tool Loops at the MCP Gateway Layer

How FaradAiWire loop_protection fingerprints identical JSON-RPC tool calls with SHA-256 and pairs with rate_limiting to cap runaway agent retries.

#Loop Protection #Rate Limiting #Agent Reliability #MCP

Autonomous agents fail silently in expensive ways. When an upstream MCP tool returns an unexpected error or ambiguous output, an LLM planning loop can invoke the exact same tool with identical parameters dozens of times in seconds—burning token budgets and hammering downstream APIs.

How loop_protection Breaks the Cycle

Running at OrderLoopProtection = 15 (immediately after rate_limiting), FaradAiWire inspects every inbound tools/call frame:

  1. Computes a fingerprint from tool name + SHA-256(raw arguments).
  2. Tracks call timestamps per agent:<agent>:user:<userID>:tool:<tool> inside a sliding window_seconds interval.
  3. Once identical calls within the window exceed max_repeat, FaradAiWire fails closed with JSON-RPC error -32008 (ErrLoopDetected), forcing the model to change strategy.
filters:
loop_protection:
enabled: true
max_repeat: 3
window_seconds: 10
exclude_tools:
- "poll_status"
overrides:
- tool: "search_docs"
max_repeat: 10

Pairing Loop Protection with Rate Limiting

Because loop_protection hashes the exact raw JSON bytes of arguments, two practical caveats matter in production:

  • Varying arguments bypass exact-hash detection: If a hallucinating agent increments a page counter or timestamp on each retry, the SHA-256 hash changes every call. Pair loop_protection with Rate Limiting (OrderRateLimit = 10) to cap total request volume regardless of payload variation.
  • Legitimate polling tools: Add status-checking tools to exclude_tools or raise per-tool thresholds with overrides.

Next Steps

Protect your agent workflows today

Test this vulnerability against FaradAiWire locally with our CLI or apply for FaradAiLab Enterprise Edition private beta.