Aulafy
Courses/Agents and automation/Infinite Loops and Cost Control

Infinite Loops and Cost Control

An agent that repeats the same call a hundred times doesn't seem dangerous until the bill arrives or it blocks an external service.

  • Detect loops by repetition of intent, tool, and arguments.
  • Apply budgets per task, user, model, and time window.
  • Design circuit breakers that stop the system before disaster strikes.
TerminalCode
guardrails:
  max_steps_per_task: 12
  max_tool_calls_per_tool: 4
  max_cost_usd_per_task: 0.80
  max_repeated_fingerprint: 3
  max_runtime_seconds: 300

fingerprint:
  campos:
    - normalized_goal
    - tool_name
    - sorted_args_hash
  si_repite_3_veces:
    parar
    guardar_traza
    pedir_revision_humana

Loop Signals

  • The same tool receives nearly identical arguments.
  • The agent says "I'm going to check" many times without new evidence.
  • Cost increases but the task state doesn't change.
  • Errors are recoverable, but the strategy doesn't change.