Loop Detection
Fuze uses a layered approach to loop detection. Layers 1 and 2 are fully implemented. Layers 3-5 are planned and accept configuration, but are not yet actively enforced by the guard.
Layer 1: Hard iteration cap
The simplest check. If a function has been called more than maxIterations times in a run, kill it.
[defaults]
max_iterations = 25Catches: 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
[defaults]
max_iterations = 25 # Layer 1
kill_on_loop = true # What to do when loop detected
[loop_detection]
window_size = 10 # Layer 2: sliding window size
repeat_threshold = 3 # Layer 2: max identical hashes before flagging
cost_velocity_window = 5 # Layer 3 (planned): steps to measure
progress_window = 4 # Layer 4 (planned): steps to compareRecovery 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',
})