Loop Detection
Fuze layers five detection strategies to catch stuck agents. Layers 1 and 2 are enforced today; Layers 3-5 accept configuration but are not yet active.
Layer 1: Hard iteration cap
The simplest check. If a function has been called more than maxIterations times in a run, kill it.
Catches: simple infinite loops, unbounded recursion.
Layer 2: Tool+args hash dedup
Fuze hashes the function name and arguments for each call. If the same hash appears more than repeat_threshold times within a sliding window of size window_size, it's a loop.
Catches: identical repeated calls (e.g., searching for the same query over and over).
Layer 3: Cost velocity anomaly (Planned)
Coming soon, this layer accepts configuration but is not yet enforced by the guard.
Tracks cost accumulation rate. If cost is increasing faster than the configured threshold with no meaningful output, flag it.
Catches: agents that are "working" but burning money without producing useful results.
Layer 4: Progress check (Planned)
Coming soon, this layer accepts configuration but is not yet enforced by the guard.
Compares the output of consecutive calls. If the last N calls produced no new tokens or identical results, the agent is stuck.
Catches: agents that get slightly different inputs but produce the same output.
Layer 5: Semantic similarity (Planned)
Coming soon, this layer accepts configuration but is not yet enforced by the guard.
Optional. Uses embedding similarity to detect when an agent is rephrasing the same question or getting semantically identical responses.
Catches: ping-pong patterns where two agents bounce variations of the same request back and forth.
Configuration
Recovery actions
When a loop is detected, Fuze can:
- kill, terminate the run immediately (default)
- warn, log a warning but allow the call to proceed
- skip, skip the current step and move on
Configure per-function:
const search = guard(searchFn, { onLoop: 'warn' })