/** * Default concrete retry strategy for model invocations. * * Implements {@link ModelRetryStrategy.computeRetryDecision} to retry failed model * calls classified by {@link isRetryable}, bounded by `maxAttempts`, with * delays computed by the configured {@link BackoffStrategy}. * * The attempt counter lives on {@link AfterModelCallEvent.attemptCount}, * maintained by the agent loop. This strategy only keeps per-turn backoff * state (first-failure timestamp, last delay), which is cleared in * {@link onFirstModelAttempt}. */ import type { AfterModelCallEvent } from '../hooks/events.js'; import type { BackoffStrategy } from './backoff-strategy.js'; import { ModelRetryStrategy } from './model-retry-strategy.js'; import type { RetryDecision } from './retry-strategy.js'; /** * Options for {@link DefaultModelRetryStrategy}. */ export interface DefaultModelRetryStrategyOptions { /** * Total model attempts before giving up and re-raising the error. * Must be \>= 1. Default {@link DEFAULT_MAX_ATTEMPTS}. */ maxAttempts?: number; /** * Backoff used to compute the delay between retries. * Default: `new ExponentialBackoff({ baseMs: DEFAULT_BACKOFF_BASE_MS, maxMs: DEFAULT_BACKOFF_MAX_MS })`. */ backoff?: BackoffStrategy; } /** * Retries failed model calls classified by the SDK as retryable. * * Today, only {@link ModelThrottledError} is treated as retryable — subclass * and override {@link isRetryable} to expand or narrow that set without * reimplementing the rest of the retry policy. * * State is per-turn: backoff timing state resets in {@link onFirstModelAttempt}, * which the base class calls when `event.attemptCount === 1`. The attempt * counter itself is owned by the agent loop and read off * {@link AfterModelCallEvent.attemptCount}. * * Hook precedence: {@link 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. * * @example * ```ts * const agent = new Agent({ * model, * retryStrategy: new DefaultModelRetryStrategy({ maxAttempts: 4 }), * }) * ``` */ export declare class DefaultModelRetryStrategy extends ModelRetryStrategy { readonly name: string; private readonly _maxAttempts; private readonly _backoff; private _lastDelayMs; private _firstFailureAt; constructor(opts?: DefaultModelRetryStrategyOptions); /** * Whether `error` should be retried. Override to extend or narrow the * retryable set (e.g. to also retry transient 5xx errors). */ protected isRetryable(error: Error): boolean; protected computeRetryDecision(event: AfterModelCallEvent): RetryDecision; protected onFirstModelAttempt(): void; private _buildContext; } //# sourceMappingURL=default-model-retry-strategy.d.ts.map