Skip to content

withRetry

withRetry<In>(stage, options): Stage<In, PlannerCandidate>

Defined in: packages/engine/src/lib/planner/with-retry.ts:42

Re-runs stage while the Engine’s validation recommends a retry, up to options.max retries (max + 1 attempts in total).

Each candidate is checked with ctx.validate. A retry happens only when the validation report sets retryHint.recommend; the retry receives the original input plus RetryFeedback about the attempt just rejected (never earlier ones). Every Err, from the stage or from validation, is returned at once without using the budget. When the budget runs out, the last candidate ships as-is: healing keeps it renderable.

The signal is not checked between attempts; each attempt is responsible for observing it.

Logs Retrying after recommended retry, Retry succeeded and Retries exhausted (the last only when max > 0), at a level derived from the retry severity.

In

Stage<Retryable<In>, PlannerCandidate>

WithRetryOptions

Stage<In, PlannerCandidate>

If options.max is not a non-negative integer.

// `modelPlanner` is any `Planner`, for example one that calls a model.
const planner = withRetry(modelPlanner, { max: 1 });