Skip to content

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

Merged
aknight-ld merged 2 commits into
mainfrom
AIC-3084-max-retries-passthrough
Nov 3, 2026
Merged

aknight-ld merged 2 commits 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 handler factory argument across Claude, OpenAI, LangChain, and LiteLLM messages packages so callers can raise provider-level retry behavior (especially under shared rate limits) without putting retries in AI config model.parameters.

launchdarkly-ai-server now exposes shared validate_max_retries (non-negative int or None; rejects bools). Message packages bump their dependency to launchdarkly-ai-server>=1.1.0. Convenience wrappers pop max_retries from kwargs so it does not reach config().

Claude / OpenAI: when set, the value is passed into AsyncAnthropic / AsyncOpenAI at client construction; omitted leaves the SDK default. model.parameters.max_retries is not forwarded on individual API calls.

LangChain: applies only when the handler builds the default chat model; **max_retries with a custom llm or factory raises ValueError.

LiteLLM: per model route, sends max_retries for OpenAI/Azure client routes and num_retries elsewhere (never both); unresolvable models use num_retries.

Public API reports and broad tests cover validation, defaults, invoke/stream/tool loops, and wrapper forwarding.

Reviewed by Cursor Bugbot for commit b1a73f3. 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
@aknight-ld
aknight-ld requested a review from jeffdupont November 3, 2026 15:51

@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.

Thanks, this is ready.

  • validate_max_retries is out of __all__ but still importable from the package root for the handler packages, and the API report and public-surface test match.
  • Raising the handler packages' floor to launchdarkly-ai-server>=1.1.0 fixes the import Bugbot flagged: without it, upgrading only a handler package could pair it with a 1.0.0 server that has no validate_max_retries.

I applied the PR to its base and ran the client and messages handler tests (2614 passed), the API report check and uv lock --check. All pass.

One small, non-blocking change, and it replaces my earlier ask to update the section numbers: three comments cite sections of a doc that isn't in this repo, so readers here can't follow them. The suggestions below drop the references and keep the rule in plain words. Fine to apply now or in a follow-up.

Comment thread packages/client/tests/test_utils.py Resolved
@aknight-ld
aknight-ld merged commit c08aea8 into main Nov 3, 2026
12 checks passed
@aknight-ld
aknight-ld deleted the AIC-3084-max-retries-passthrough branch November 3, 2026 17:49
@github-actions github-actions Bot mentioned this pull request Nov 3, 2026
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