Skip to content

ModelRetryStrategy

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

Abstract base class for model-retry strategies.

A ModelRetryStrategy is a Plugin that retries failed model calls. Subclasses implement computeRetryDecision to answer whether to retry and how long to wait; the base class orchestrates the rest:

  1. Short-circuits if another hook already set event.retry (no stacked delay).
  2. Short-circuits on success events (event.error === undefined).
  3. Calls onFirstModelAttempt when a fresh retry budget starts (event.attemptCount === 1), letting stateful subclasses clear per-budget state.
  4. Invokes computeRetryDecision; on retry: true, sleeps for waitMs then sets event.retry = true.

Other retry kinds (e.g. tool retries) will land as sibling abstract classes, not as additional methods on this one — different retry kinds have different unit-of-work boundaries and don’t share a single state contract.

Single-agent attachment: instances typically carry per-budget state, so sharing one instance across agents would let their calls trample each other. The base class throws on attempts to attach to a different agent.

new ModelRetryStrategy(): ModelRetryStrategy;

ModelRetryStrategy

abstract readonly name: string;

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

A stable string identifier for this retry strategy.

Plugin.name

abstract protected computeRetryDecision(event):
| RetryDecision
| Promise<RetryDecision>;

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

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 | Promise<RetryDecision>


protected onFirstModelAttempt(): void;

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

Called when event.attemptCount === 1, at the start of a fresh retry budget. This occurs on a new turn and when model routing switches candidates. Subclasses with per-budget state override this to clear it; the default is a no-op.

void


initAgent(agent): void;

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

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

Plugin.initAgent