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:
- Short-circuits if another hook already set
event.retry(no stacked delay). - Short-circuits on success events (
event.error === undefined). - Calls onFirstModelAttempt on turn boundaries (
event.attemptCount === 1), letting stateful subclasses clear per-turn state. - Invokes computeRetryDecision; on
retry: true, sleeps forwaitMsthen setsevent.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-turn 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.
Extended by
Section titled “Extended by”Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ModelRetryStrategy(): ModelRetryStrategy;Returns
Section titled “Returns”ModelRetryStrategy
Properties
Section titled “Properties”abstract readonly name: string;Defined in: src/retry/model-retry-strategy.ts:37
A stable string identifier for this retry strategy.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”computeRetryDecision()
Section titled “computeRetryDecision()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event | AfterModelCallEvent |
Returns
Section titled “Returns”| RetryDecision
| Promise<RetryDecision>
onFirstModelAttempt()
Section titled “onFirstModelAttempt()”protected onFirstModelAttempt(): void;Defined in: src/retry/model-retry-strategy.ts:63
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.
Returns
Section titled “Returns”void
initAgent()
Section titled “initAgent()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
agent | LocalAgent | The agent to register hooks with |
Returns
Section titled “Returns”void