Skip to content

DefaultModelRetryStrategy

Defined in: src/retry/default-model-retry-strategy.ts:70

Retries failed model calls classified by the SDK as retryable.

Today, only ModelThrottledError is treated as retryable — subclass and override isRetryable to expand or narrow that set without reimplementing the rest of the retry policy.

State is per-turn: backoff timing state resets in onFirstModelAttempt, which the base class calls when event.attemptCount === 1. The attempt counter itself is owned by the agent loop and read off AfterModelCallEvent.attemptCount.

Hook precedence: AfterModelCallEvent fires hooks in reverse registration order, so user-registered hooks run before this strategy. If a user hook sets event.retry = true first, the base class returns early and does not stack additional backoff on top.

Sharing: a given instance tracks its own backoff state and must not be shared across multiple agents. Create a separate instance per agent.

const agent = new Agent({
model,
retryStrategy: new DefaultModelRetryStrategy({ maxAttempts: 4 }),
})
new DefaultModelRetryStrategy(opts?): DefaultModelRetryStrategy;

Defined in: src/retry/default-model-retry-strategy.ts:79

ParameterType
optsDefaultModelRetryStrategyOptions

DefaultModelRetryStrategy

ModelRetryStrategy.constructor

readonly name: string = 'strands:default-model-retry-strategy';

Defined in: src/retry/default-model-retry-strategy.ts:71

A stable string identifier for this retry strategy.

ModelRetryStrategy.name

protected isRetryable(error): boolean;

Defined in: src/retry/default-model-retry-strategy.ts:94

Whether error should be retried. Override to extend or narrow the retryable set (e.g. to also retry transient 5xx errors).

ParameterType
errorError

boolean


protected computeRetryDecision(event): RetryDecision;

Defined in: src/retry/default-model-retry-strategy.ts:98

Decide whether to retry the failed model call, and how long to wait first.

Called only for error events that have not already been marked for retry by another hook. The base class has already filtered out successes and short-circuited events where event.retry is true, so implementations only need to reason about event.error.

Return { retry: false } to let the error propagate. Return { retry: true, waitMs } to retry after sleeping for waitMs milliseconds.

ParameterType
eventAfterModelCallEvent

RetryDecision

ModelRetryStrategy.computeRetryDecision


protected onFirstModelAttempt(): void;

Defined in: src/retry/default-model-retry-strategy.ts:126

Called when event.attemptCount === 1, i.e. at the start of a fresh turn. Subclasses with per-turn state override this to clear it; the default is a no-op.

The agent loop guarantees attemptCount === 1 on every new turn, so this is a reliable turn-boundary signal.

void

ModelRetryStrategy.onFirstModelAttempt


initAgent(agent): void;

Defined in: src/retry/model-retry-strategy.ts:99

Initialize the retry strategy with the agent instance.

Enforces the single-agent attachment guard and registers the AfterModelCallEvent hook that drives retry orchestration.

Subclasses that override this method MUST call super.initAgent(agent) to preserve the attachment guard and hook registration. Additional hooks may be registered after the super call.

ParameterTypeDescription
agentLocalAgentThe agent to register hooks with

void

ModelRetryStrategy.initAgent