Skip to content

feat: #855 add opt-in model retry policies#1083

Merged
seratch merged 5 commits intomainfrom
feat/model-retry-policy
Mar 12, 2026
Merged

feat: #855 add opt-in model retry policies#1083
seratch merged 5 commits intomainfrom
feat/model-retry-policy

Conversation

@seratch
Copy link
Copy Markdown
Member

@seratch seratch commented Mar 11, 2026

This pull request adds opt-in model retry policies across @openai/agents-core, @openai/agents-openai, and @openai/agents-extensions. The core change introduces modelSettings.retry, public retryPolicies helpers, deep merging for nested retry settings, and a shared runner-owned retry path in packages/agents-core/src/model.ts, packages/agents-core/src/runner/modelRetry.ts, packages/agents-core/src/run.ts, packages/agents-core/src/runner/modelSettings.ts, and packages/agents-core/src/agentToolRunConfig.ts.

It also updates provider integrations so OpenAI and AI SDK models expose retry advice instead of making the final retry decision themselves. The OpenAI client calls now force maxRetries: 0 so SDK-level retries cannot bypass the runner policy, while safety vetoes still block retries for aborted requests, streams that already emitted visible output, and websocket requests that may already have been accepted.

This is still opt-in, but if a developers writes some code, this solution could resolve #855. We won't enable such by default, so when we release this enhancement, we'll add guides in documentation.

import { Agent, Runner, retryPolicies, type ModelRetrySettings } from '@openai/agents';

function isTerminatedError(error: unknown): boolean {
  return error instanceof Error && error.message.toLowerCase() === 'terminated';
}

const retry: ModelRetrySettings = {
  maxRetries: 3,
  backoff: {
    initialDelayMs: 250,
    maxDelayMs: 2_000,
    multiplier: 2,
    jitter: true,
  },
  policy: async (context) => {
    if (isTerminatedError(context.error)) {
      return {
        retry: true,
        reason: 'retry on intermittent terminated transport error',
      };
    }

    return retryPolicies.any(
      retryPolicies.providerSuggested(),
      retryPolicies.retryAfter(),
      retryPolicies.networkError(),
      retryPolicies.httpStatus([429, 500, 502, 503, 504]),
    )(context);
  },
};

const runner = new Runner({ modelSettings: { retry } });

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: dc07675

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-core Minor
@openai/agents-openai Minor
@openai/agents-extensions Minor
@openai/agents-realtime Minor
@openai/agents Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9dd72ddaa9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch changed the title feat: add opt-in model retry policies feat: #855. add opt-in model retry policies Mar 11, 2026
@seratch seratch changed the title feat: #855. add opt-in model retry policies feat: #855 add opt-in model retry policies Mar 11, 2026
@github-actions github-actions bot added this to the 0.6.x milestone Mar 11, 2026
@seratch seratch modified the milestones: 0.6.x, 0.7.x Mar 11, 2026
@github-actions github-actions bot modified the milestones: 0.7.x, 0.6.x Mar 11, 2026
@seratch seratch modified the milestones: 0.6.x, 0.7.x Mar 11, 2026
@seratch seratch merged commit 9bcc3f3 into main Mar 12, 2026
6 checks passed
@seratch seratch deleted the feat/model-retry-policy branch March 12, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: terminated

1 participant