Skip to content

Retry, self-correction and stopping budgets with independent checks

14 min reading

Derive retry and stopping limits, and distinguish a new observation from a repeated attempt.

Page details

GenAI · Lesson 24 of 45 · 3 / 3.2

Sources · 14 min reading · 27 min with practice

Published · Last edited:

More
20px

Progress is saved in this browser when storage is available.

View guided paths and progress

Know first: Scratchpads, episodic and semantic memory; provenance, correction and forgetting. Optional help: GenAI foundations.

Optional background references

Hypothetical scenario. Northwind’s assistant keeps revising a failed query. Dev points to a graph-step limit, but Maya is still waiting because each step can invoke several components and their retries. Priya asks what the limit actually counts.

Maya: “A finite run can still finish too late to help.”

Dev: “The graph guard counts transitions, not every nested attempt.”

Priya: “Give attempts, effects and elapsed time their own limits and a useful stopping outcome.”

You will derive nested retry work and stopping conditions with distinct accounting units. Evaluate what a new attempt can establish before spending the remaining deadline or treating another model response as progress.

Which allowance actually stops the run?

Northwind's assistant has a graph-step limit, so Dev considers it bounded. During an investigation, each step can call a model several times and retry a remote tool. The graph eventually stops, but Priya receives no useful recommendation before the task deadline. The configured limit controlled one unit of work while the application consumed several others.

Define the accounting units before choosing limits. A transition advances workflow control. An attempt invokes a component again. A tool action can create an external effect. A token allowance bounds a particular representation or generated output. Elapsed time includes waiting and queueing, not just measured component execution. One counter cannot describe all of these quantities.

Why local retry policies multiply

A worker, client library and downstream service can each retry independently. Every layer may believe it is making a small recovery effort while the combined path produces many attempts. An agent that branches can multiply that work again. Record the task-level allowance and propagate the remaining budget to the boundary that actually invokes a dependency.

Retries also need a reason. A transient connection failure before a read can justify a different action from a timeout after submitting a write. For uncertain effects, reconciliation precedes the decision to retry. A remaining attempt count grants capacity to make an allowed attempt; it does not establish that the attempt is safe.

Make every nested retry spend the same task ledger

Hypothetical scenario. A planner and tool wrapper each allow three attempts including the first. If both exhaust their limits, one intended tool step can create 3 × 3 = 9 target attempts. Local limits are not a shared task budget.

Make every nested retry spend the same task ledger
ArtifactConcrete evidenceDecision boundary
Task ledgerdeadline, tokens, attempt grantsShared owner
Attempt evidencelayer, cause, operation identityExplain extra work
Stop statecomplete, bounded failure, pending effectHonest disposition
Shared grants only: Task budget → Planner / wrapper.Shared grants only: Task budget → Planner / wrapper. Task budget to Planner / wrapper: shared grants only; Planner / wrapper to Target attempts: stable operation identity.Task budgetPlanner / wrapperTarget attemptsshared grants onlystable operation identity
Shared grants only: Task budget → Planner / wrapper. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

Track model calls, tool attempts, elapsed deadline, token allowance and authorized business effects separately. A retry consumes work even when the target suppresses duplicate effects. Correction loops need an independent acceptance check and a stop disposition when no valid improvement appears. Persist remaining allowances across resume; restarting a worker must not refill the task budget. Refund only resources whose actual consumption is known or conservatively accounted for.

What a graph recursion limit controls

LangGraph's GRAPH_RECURSION_LIMIT reference describes the error produced when execution reaches its configured step bound without a stopping condition. That guard is useful for detecting an unbounded or unexpectedly long control path. It is not a complete accounting of every nested API request, external side effect or token consumed inside a node.

Give the application its own task record with the limits it promises to enforce. A proposed design can track remaining transition allowance, dependency attempts, action permissions, elapsed deadline and context capacity. Updates to those budgets belong with the durable task state so a restart does not reset a task that has already spent most of its allowance.

Choose where a budget is reserved and where it is released. Reserving before starting work prevents two concurrent branches from both spending the same final unit. Releasing a reservation after a failed attempt may be appropriate for a concurrency slot, but not for a count of attempts already made. Capacity and cumulative consumption need different records.

Separate the ledgers before combining them

Follow the decision boundaries

Agent Budgets: Bounding Retries, Time and Context Across a TaskBars represent distinct allowances for transitions, attempts, and time with context. Illustrative widths are not measurements.TransitionsAttemptsTime and context

The diagram shows independent allowances rather than one universal remaining-work score. A request can have transitions left but no time to complete another dependency call. Another can have enough elapsed time but no authority to perform a write. The next transition must satisfy the relevant conditions together.

Derive the maximum attempts in a nested policy

Hypothetical scenario. Suppose an outer workflow permits three attempts at a node. Its client permits three attempts for each invocation, and the selected downstream wrapper permits two attempts per client attempt. These are chosen maxima, not default settings for any named product.

The upper bound is 3 × 3 × 2 = 18 downstream attempts for one logical node operation, assuming every layer exhausts its allowance and each attempt reaches the next layer. If the task creates two such independent branches, the upper bound becomes 2 × 18 = 36 downstream attempts. Actual work can be lower when an earlier attempt succeeds, but the admission policy must account for the work it permits.

Now impose a shared task allowance of six downstream attempts, reserved at the invocation boundary across both branches. The combined bound is six, not six per branch. A local retry that would exceed the task allowance must stop or return an explicit budget-exhausted outcome. That policy does not by itself decide how the six attempts should be allocated; prioritization remains an application choice.

A remaining count does not create remaining time

For a second toy calculation, choose a 30-second task deadline. Assume the task has already used 18 seconds, and final validation needs an allotted four seconds. The time available for further investigation is 30 − 18 − 4 = 8 seconds. A proposed serial dependency call with a nine-second timeout cannot fit that allocation.

A shorter timeout is not proof that the dependency will finish sooner. It changes when the caller stops waiting. The task can choose a genuinely cheaper path, return a partial result that satisfies a declared contract, or state that more evidence is needed. Repeating the expensive call after its timeout would consume a different interval and can leave the original attempt unresolved.

For a context-growth example, assume each retained round adds a chosen 500 tokens to an existing 2,000-token prompt. After six rounds, the represented context is 2,000 + 6 × 500 = 5,000 tokens. An application allowance of 4,500 tokens would be exceeded by 500. Pruning, summarizing or selecting fewer observations changes the information available to the next decision; evaluate that change instead of treating it as a free optimization.

Stopping should produce an understandable result

Distinguish “task completed,” “evidence insufficient,” “authority required,” “dependency unresolved” and “budget exhausted.” Those outcomes suggest different next actions. Returning the same generic error for all five forces Priya to infer whether a retry would help, be wasteful or repeat an already committed effect.

A stopped task can preserve a compact continuation record: accepted observations, unresolved actions, consumed allowances and the specific condition needed to proceed. Resuming should be a new authorized decision about that record, not an accidental counter reset. If a person grants more time, retain the fact that the earlier allowance was exhausted.

Apply the same accounting to fallback models or tools. A fallback can be a useful alternative, but it consumes time and may change output quality, data handling or permissions. A routing decision should explain which budget and task contract the fallback still satisfies.

In the wild: a limit signals a control problem

The official LangGraph error reference provides a concrete stopping guard for a graph that reaches its step bound. That is useful operational evidence: a task can end because control did not reach an intended termination condition. The reference does not imply that increasing the bound fixes the task's logic.

Northwind's nested policy is hypothetical. Use it to ask whether the configured guard accounts for the actual amplification inside each node. Inspect the application counters and the dependency attempt identities when diagnosing a real failure; a step-limit error alone cannot describe the complete cost or effect history.

Evaluate the policy against a useful stopping rule

Test a task that completes early, one that needs clarification, one with a permanently unavailable dependency and one whose write outcome is unknown. Verify that each stops for the appropriate reason and that no restart silently restores consumed allowance. Budget tests need more than a successful ordinary request.

There is a real trade-off between strict bounds and task completion. A tighter allowance can reject a task that would have succeeded with more investigation. A looser allowance can increase waiting, cost and exposure to unnecessary actions. Choose the policy from measured task outcomes and explicit constraints rather than maximizing either completion rate or low cost in isolation.

Include fairness when several tasks share a dependency. A single persistent investigation can consume many attempts while short requests wait. Per-task caps, concurrency limits and class-based queues address different aspects of that problem. Explain which unit each policy bounds and which work can still be delayed.

Three misleading interpretations of bounded execution

Every counter can reset on restart. That turns a bounded process into an effectively unbounded sequence of restarts.

A timeout cancels the remote action. It may end the caller's wait without establishing the remote outcome. Preserve the action identity and reconcile it.

A larger graph limit improves reasoning. It permits more execution. Whether that improves the task requires a comparison with an appropriate outcome measure.

Preserve useful progress when the allowance ends

Budget exhaustion should not destroy the evidence already accepted. Store a compact terminal or paused result that identifies the completed observations, unresolved questions and the condition under which work could continue. A person can then decide whether more investigation is worthwhile without replaying the entire task.

For Northwind, a stopped policy investigation can return the relevant document revisions and the specific missing supplier response. It should not turn that missing response into an invented conclusion. If a later message supplies the response, validate its identity and applicability before deciding whether to reopen the task under a new allowance.

A deadline also needs an owner. A caller can impose an end-to-end deadline while a dependency has a shorter local timeout. Propagate the remaining useful interval rather than granting every layer a fresh full timeout. Reserve any required final validation and response work when deciding whether another attempt can start.

These rules make operational metrics more informative. Separate tasks that completed within the selected allowance, tasks that stopped appropriately and tasks that crossed the bound unexpectedly. Otherwise a low completion rate can encourage increasing limits indiscriminately, while an apparently high success rate can conceal work that arrived too late to be useful.

What the arithmetic assumes

The attempt bound assumes nested policies exhaust their maxima and reach downstream invocations; the timing example assumes serial allocation and selected durations. Real implementations can batch, cancel, queue or perform uneven work. Framework guards need application accounting for their actual scope. Neither a budget nor a fallback policy grants permission to repeat an uncertain external effect, and token reduction can remove evidence the task still requires.

Test the task ledger boundary

The tool deduplicates effects. Are nine attempts equivalent in cost to one?

Reveal the design reasoning

No. Authorization, lookup, network and processing can still consume resources. Budget attempts independently from useful effects and retain uncertainty after timeout.

Decision: Assign one end-to-end work policy and persist its remaining grants.

Find the allowance that actually binds

Why can two branches produce 36 attempts under the toy local policies?

Each branch permits three outer, three client and two downstream attempts, giving 18. Two branches can exhaust that independently. A shared six-attempt reservation at the real invocation boundary changes the combined bound to six; assigning six independently to each branch would not.

The task has three attempts left but only eight seconds for investigation. Can it start a nine-second call?

Not under the selected serial time contract. Counts and elapsed allowance are independent constraints. Choose a path that fits, report a supported partial result or stop with its missing requirement instead of assuming an attempt count creates time.

Should an exhausted task resume from zero attempts after a worker restart?

No. Preserve cumulative consumption in durable task state. A new allowance can be granted explicitly under the application's policy, while retaining the earlier expenditure and unresolved effects. Otherwise repeated restarts defeat the bound.

Northwind decision log

  1. Reserve dependency work against a shared durable task allowance.
  2. Keep elapsed time, cumulative attempts and context capacity separate.
  3. Stop with accepted evidence and unresolved effects instead of resetting counters.

Go deeper: supporting mechanisms

Related: Agentic systems · Retries and tool outcomes.

Carry the decision forward

Northwind now has explicit stopping ledgers. Page 25 combines permitted tools, query correction and result interpretation in a bounded SQL analyst exercise.