Skip to content

Build1 publisher2 min readPublished

Agent retries that feed errors back into the prompt make every attempt cost more than the last

Retry math in a dev.to post on agent circuit breakers has a failing agent's calls growing from 2,000 tokens to 20,000 by attempt 50. Summed, that spend rises with the square of the attempts, so the cap belongs in the orchestrator.

The Engineer · Build desk

Illustration accompanying Agent retries that feed errors back into the prompt make every attempt cost more than the last

What happened

  • A dev.to post on agent circuit breakers opens with a staging research agent that hits a CAPTCHA, retries in a loop and runs up $542.18 over one weekend.
  • In the post's worked example a 2,000-token request fails, its 500-word stack trace goes back into the prompt, and the next two calls grow to 2,600 and 3,300 tokens.
  • By the fiftieth retry, the post has the agent sending 20,000 tokens per call only to produce another failure.
  • According to the post, developers switch on framework retry flags assuming safeguards exist, while most frameworks rely on the model to notice it is stuck.
  • The breaker the post proposes tracks cumulative tokens in real time, caps step depth, interrupts retry loops, hands off to human operators and limits concurrency.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • cost Most of a failing loop's spend lands in its final attempts: on the post's figures the last 25 of 50 retries send about 71 percent of the tokens.
  • constraint Exponential backoff spaces an agent's retries out in time but leaves each payload growing, so a standard retry library does not bound what a failing loop spends.
  • decision A retry flag set to True is an incomplete configuration for an agent; teams running agents unattended have to set explicit ceilings on tokens per task, step depth and retries before launch.

The retry state in the post's example is the conversation itself [3]. When the tool fails, the orchestrator feeds the stack trace back into the prompt and asks the model to correct its approach. By the third request the prompt holds the entire history [3]. The post traces the pattern to the default reaction of telling the system to "try again and fix the error" [12]. Each attempt re-sends everything before it plus the newest error, and cost per call rises with every failure [2].

The post says cost per call "snowballed exponentially" [5]. Its own figures trace a line. The first two retries add 600 and 700 tokens [1], and the climb from 2,000 tokens to 20,000 by attempt 50 averages about 367 tokens per retry [2]. When each call grows by a roughly fixed amount, the total across a loop grows with the square of the attempt count [5]. On the post's line, 50 attempts send about 550,000 input tokens, 275 times the first call [4][7]. Fifty retries at a flat 2,000 tokens would send 100,000 [8]. Appending the history multiplies the bill by 5.5 [9].

Leaving loop detection to the model [7] puts the stop decision in the one component that gets a longer error log each time it fails to make it. The post puts the observer outside instead: logic, execution and error handling split into distinct entities inside a strictly monitored state machine [11]. On placement, the post warns: "If the retry logic is housed inside the prompt itself, you have already lost control of the system." [9]

In my context I would set a per-task token budget first and a retry cap second. A retry cap bounds the attempt count, and under linear growth that also bounds the total [5]. A token budget also catches the single attempt that drags in an oversized page or trace. It counts the quantity the cost comes from [2]. Both have to count per task. A per-call ceiling set anywhere above 20,000 tokens would let the post's loop run all 50 attempts untouched [4].

For the post's token figures to carry over to another agent, its orchestrator has to append the full error output on every retry and keep the whole history [3]. An orchestrator that truncates or summarizes old errors grows more slowly per call. The post puts average first-year implementation costs for enterprise agentic AI at $45,000 to $250,000 and blames a large share on unchecked recursive loops [10]. It does not source that range, and its $542.18 weekend is written in the second person as an illustration [1].

What to watch

  • Whether agent frameworks ship token-budget or step-depth limits as defaults alongside their boolean retry flags.
  • A sourced measurement of retry-loop spend in production agents that could test the post's $45,000 to $250,000 first-year cost range.
  • Whether the post's containment-funnel design publishes concrete thresholds and state transitions for when the breaker trips.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories