New Tool Radar

AI Agents & Automation

How to Limit Agent Retries So They Do Not Become an Infinite Loop

Cap agent retries at a small fixed number so a failing step stops and reports, instead of retrying forever.

Schematic with three steps: Find every retry setting in the run; Set one cap per step and write; Run a permanently failing step and count.

Retries are a recovery tool, not a plan: a step that fails three times for the same reason will fail a fourth time too, only later and dearer. CrewAI’s guardrails retry a failed task up to a configured maximum, three by default, and then return the last output; its agent executor also stops a task on the fifth identical tool call. Set your own caps the same way, per step, and make the cap visible in the log: when the retries are spent, the run should stop and say which step failed and why, not quietly loop or quietly give up.

What you need

  • An agent step that retries today, with its current cap known or unknown
  • A cap to enforce, for example three retries per step
  • Access to the run log to see how many retries a run used

Step 1: Find every retry setting in the run

List the retry caps on the agent, the task, the guardrail, and the tool nodes. A run with four uncapped retries in four places has no real cap.

Step 2: Set one cap per step and write it down

Set each retry to the same small number, such as three, and record it next to the step. A cap that lives only in someone’s head will be raised under pressure.

Step 3: Run a permanently failing step and count the retries

Force a step to fail for a permanent reason and count its retries in the log. The run should stop at the cap and report the failure, not keep retrying.

Worked example: synthetic retry cap

The table below is a synthetic example. It shows the expected result of the retry cap; no agent was run.

Check Expected Result
Retries used on permanent failure 3 Pass
Run stops after the cap Yes Pass
Failure is reported with the reason Yes Pass
No infinite loop 0 loops Pass

Expected result (UNTESTED). the failing step retries three times, stops, and reports the reason, with no infinite loop. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • A cap stops the retries, it does not fix the failure that caused them.
  • Identical tool calls are a loop signal: CrewAI stops a task on the fifth identical call.
  • A cap that is too low kills a step that would have succeeded on one more try.
  • Retries on different layers add up, so count the total, not each layer alone.

Sources

See all