Skip to content

feat: add max_retries to the messages handler factories - #214

Open
aknight-ld wants to merge 1 commit into
mainfrom
AIC-3084-max-retries-passthrough
Open

aknight-ld wants to merge 1 commit into
mainfrom
AIC-3084-max-retries-passthrough

Conversation

@aknight-ld

@aknight-ld aknight-ld commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Add in a max retries passthrough argument to let handler factories natively retry.


Note

Overview
Adds an optional max_retries argument on the Claude, OpenAI, LangChain, and LiteLLM messages handler factories and convenience wrappers, so callers can raise provider-level retry counts (for example under shared rate limits during batched evals) without touching model.parameters.

Shared validation lives in validate_max_retries in launchdarkly-ai-server (exported in 1.1.0): non-negative int or None; invalid types fail at handler construction. Omitted values are not passed through, preserving each vendor’s default (including 0 when explicitly set). model.parameters cannot override handler-level retries.

Wiring differs by integration: Claude/OpenAI set max_retries on AsyncAnthropic / AsyncOpenAI; LangChain applies it only when the handler builds the default chat model ( ValueError if llm is supplied); LiteLLM picks max_retries vs num_retries per model route (OpenAI/Azure vs everything else). Provider packages now require launchdarkly-ai-server>=1.1.0.

Tests cover forwarding, defaults, validation, and (for LiteLLM) end-to-end retry behavior on a failing route.

Reviewed by Cursor Bugbot for commit 7040d29. Bugbot is set up for automated code reviews on this repo. Configure here.

@aknight-ld
aknight-ld force-pushed the AIC-3084-max-retries-passthrough branch from 3072cbf to 4bed864 Compare October 27, 2026 14:24
@aknight-ld
aknight-ld marked this pull request as ready for review October 27, 2026 15:17
@aknight-ld
aknight-ld requested a review from a team as a code owner October 27, 2026 15:17
@aknight-ld
aknight-ld force-pushed the AIC-3084-max-retries-passthrough branch from 4bed864 to 2c6228b Compare October 29, 2026 18:50

@jeffdupont jeffdupont left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This matches ai-sdks-monorepo#88 on every §1.1a rule. Keyword-only max_retries=None is validated at construction (bool refused), passed only when set, refused with llm or a model factory in LangChain, and forwarded by every wrapper, and model.parameters can't set it. The LiteLLM route rule is exactly what A.23 asks for: max_retries on openai/azure, num_retries elsewhere, an unresolvable model falling back to num_retries, plus the real-acompletion test that counts N + 1 requests on a non-OpenAI route.

Two small things:

  1. validate_max_retries should stay internal, since only handler packages call it. The suggestions below take it out of __all__ and the public-surface test. After applying them, run make api-report and commit the result: it removes the validate_max_retries line from packages/client/api-report/launchdarkly_ai_server.txt. The spec list should mark it "- # internal" too (asked on #88).
  2. Three places cite "TESTING.md A.22" (litellm handler.py:141, test_utils.py:441, litellm test_handler.py:750). #88 has to be renumbered again because main now has A.22 and A.23, so please update them to whatever number it lands on. There are no suggestions for these because the number isn't settled yet.

Approve once those are in. Not a 1.0 blocker: it's additive, so it can ship in 1.1.

@aknight-ld
aknight-ld force-pushed the AIC-3084-max-retries-passthrough branch from 2c6228b to a3f1d04 Compare November 2, 2026 21:24

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@aknight-ld
aknight-ld force-pushed the AIC-3084-max-retries-passthrough branch from a3f1d04 to 500addb Compare November 2, 2026 21:35

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 500addb. Configure here.

@aknight-ld
aknight-ld force-pushed the AIC-3084-max-retries-passthrough branch from 500addb to 7040d29 Compare November 2, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants