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.
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:
- Computes a fingerprint from
tool name + SHA-256(raw arguments). - Tracks call timestamps per
agent:<agent>:user:<userID>:tool:<tool>inside a slidingwindow_secondsinterval. - 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: 10Pairing 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
pagecounter ortimestampon each retry, the SHA-256 hash changes every call. Pairloop_protectionwith Rate Limiting (OrderRateLimit = 10) to cap total request volume regardless of payload variation. - Legitimate polling tools: Add status-checking tools to
exclude_toolsor raise per-tool thresholds withoverrides.
Next Steps
- Tune
ttl_seconds,max_keys, and per-agent overrides in the Loop Protection Reference. - Inspect overall filter ordering (
OrderPrefillthroughOrderHITL) in the Security Filter Pipeline Overview.
Protect your agent workflows today
Test this vulnerability against FaradAiWire locally with our CLI or apply for FaradAiLab Enterprise Edition private beta.