Skip to content

feat(core): expose Gemini retry options - #1413

Open
014-code wants to merge 1 commit into
google:mainfrom
014-code:feature/llm-retry-policy
Open

014-code wants to merge 1 commit into
google:mainfrom
014-code:feature/llm-retry-policy

Conversation

@014-code

@014-code 014-code commented Aug 8, 2026 •

Copy link
Copy Markdown

Summary

Expose optional Google Gen AI HttpRetryOptions through Gemini.Builder.retryOptions(...), allowing callers to configure retry attempts, backoff, jitter, and retryable HTTP status codes at the Gemini provider level.

All three existing public constructors and Builder.build() now use one private constructor taking the builder. Existing constructor signatures and null-argument checks are preserved; no new public constructor overloads are introduced. Retry options are forwarded for API-key, Vertex-credentials, and default-client construction. An explicitly supplied Client keeps its own configuration, and omitting retry options preserves the SDK defaults.

Tests

  • Added 10 GeminiBuilderTest cases covering retry-option propagation, the original constructors, client/credential precedence, default options, and argument validation.
  • Retained the two GeminiTest cases covering HTTP retry-option configuration.
  • Full core module clean test after rebasing onto main (84bae34a): BUILD SUCCESS; standard test execution reported 2901 tests, 0 failures, 0 errors, and 30 skipped. Additional environment-specific executions, including the tracking-header and Apigee variants, completed without failures.
  • Google Java Format and git diff --check passed.

Fixes #1397

@google-cla

google-cla Bot commented Aug 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@014-code
014-code force-pushed the feature/llm-retry-policy branch from bb7af9d to 38e2ef4 Compare August 8, 2026 13:23
@hemasekhar-p hemasekhar-p self-assigned this Aug 12, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @014-code, thank you for your contribution! We truly appreciate your work on this PR. I have noticed that your branch is currently out of sync with main and there are some issues with the Maven build with your changes. Could you please rebase your branch and resolve the build issues so we can proceed with the review process?

@hemasekhar-p hemasekhar-p added the waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. label Aug 12, 2026
@014-code
014-code force-pushed the feature/llm-retry-policy branch from 38e2ef4 to b4a1a05 Compare August 12, 2026 13:42
@014-code

Copy link
Copy Markdown
Author

Hi @014-code, thank you for your contribution! We truly appreciate your work on this PR. I have noticed that your branch is currently out of sync with main and there are some issues with the Maven build with your changes. Could you please rebase your branch and resolve the build issues so we can proceed with the review process?

Hi @hemasekhar-p, thanks for the feedback.

I rebased the branch onto the latest main (d7355a71) and fixed the Maven build issue caused by using an unsupported RxJava Flowable.flatMapPublisher(...) operator.

I also updated the asynchronous retry tests to wait for retry completion before asserting the terminal error.

Validation performed:

  • Core test-compile: passed
  • RunConfigTest and BaseLlmFlowTest: 46 tests passed, 0 failures
  • Google Java Format: passed
  • git diff --check: passed
  • Full core suite: 1777 tests executed; 1752 passed, 24 skipped, and 1 existing Windows-specific LocalSkillSourceTest failure caused by / vs \ path separators

The branch has been force-pushed as a single commit (b4a1a05e).

This PR fixes #1397.

@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @014-code, thank you for the update. Our team is currently reviewing your PR and we will let you know if any further information is required. Thank you!

@hemasekhar-p hemasekhar-p added needs review and removed waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. labels Aug 13, 2026
@damianmomotgoogle

Copy link
Copy Markdown
Contributor

Based on current checks this is not a standard approach in ADK.

Would exposing retry options on Gemini work instead, similar how ADK Python models it ?

https://github.com/google/adk-python/blob/156f007ce1899bf0116eb990ce448be8ac1b3308/src/google/adk/models/google_llm.py#L190-L197

@damianmomotgoogle damianmomotgoogle added waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. adk wide A new concept to ADK ecosystem - requires ADK wide alignment and removed needs review labels Oct 15, 2026
@014-code
014-code force-pushed the feature/llm-retry-policy branch from b4a1a05 to 411bfb7 Compare October 17, 2026 12:37
@014-code

Copy link
Copy Markdown
Author

Hi @damianmomotgoogle, thanks for the suggestion.

I updated PR #1413 to follow ADK Python's provider-level retry configuration:

  • Removed the generic BaseLlmFlow retry approach from this PR.
  • Added optional HttpRetryOptions to Gemini constructors and Gemini.Builder.retryOptions(...).
  • When Gemini creates a Google Gen AI client, it passes the options through HttpOptions.retryOptions(...). Retry execution stays in the Gen AI SDK, including configurable attempts, exponential backoff, jitter, and retryable HTTP status codes.
  • When no options are supplied, retries remain disabled. An explicitly supplied Client keeps its own HTTP options.

I rebased onto the latest main (97f22a28) and kept the PR as one commit (411bfb7).

Validation:

  • GeminiTest: 67 passed, 0 failed, including the new enabled and disabled retry-option propagation tests.
  • The Maven core test invocation completed with BUILD SUCCESS; the configured related profile tests also passed, with one pre-existing skipped test.
  • git diff --check: passed.

This keeps retry policy provider-specific and addresses #1397 through Gemini model configuration.

@hemasekhar-p hemasekhar-p added needs review and removed waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. labels Oct 19, 2026
@damianmomotgoogle damianmomotgoogle removed the adk wide A new concept to ADK ecosystem - requires ADK wide alignment label Oct 19, 2026
* @param apiKey The Google Gemini API key.
* @param retryOptions Options for retrying transient HTTP failures.
*/
public Gemini(String modelName, String apiKey, @Nullable HttpRetryOptions retryOptions) {

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.

Could you try introducing a Builder instead of another constructor ?

i.e. introduce a Builder, redirect existing constructors to builder one for backward compatibility but for more configurability we'll keep extending builder ?

@014-code 014-code Oct 24, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the guidance. I've refactored this to use the existing Gemini.Builder as the configuration entry point.

The two retry-enabled public constructor overloads have been removed. All three original public constructors now delegate to a single private Gemini(Builder) constructor, and Builder.build() uses that same constructor. Client selection and creation are centralized there, so future configuration can be added to the builder without expanding the public constructor API.

Retry options are configured through Gemini.builder().retryOptions(...) and passed to the Gen AI SDK for the API-key, Vertex-credentials, and default-client paths. An explicitly supplied Client retains precedence and its existing configuration. The original constructors retain their null-argument checks, and omitting retry options leaves the SDK defaults unchanged.

I added 10 tests in GeminiBuilderTest covering retry-option propagation through the public builder, all three original constructor paths, client/credential precedence, default options, and argument validation. The existing Gemini generation, continuation, and caching tests also pass.

I also rebased onto the latest main (84bae34a) and resolved the overlap with the recent tracking-header refactor. The shared ADK client builder and the internal Apigee constructor path retain their tracking-header behavior.

Validation on the rebased code: the full core module clean test completed with BUILD SUCCESS (the standard test execution reported 2901 tests, 0 failures, 0 errors, and 30 skipped). The additional environment-specific test executions, including the tracking-header and Apigee variants, also completed without failures. Google Java Format and git diff --check passed.

I've kept the PR as a single amended commit and updated its description to match the builder-based implementation.

@damianmomotgoogle damianmomotgoogle added waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. and removed needs review labels Oct 19, 2026
@014-code
014-code force-pushed the feature/llm-retry-policy branch from 411bfb7 to cfaf88f Compare October 24, 2026 14:30
@014-code 014-code changed the title feat(core): add opt-in retries for transient LLM failures feat(core): expose Gemini retry options Oct 24, 2026
@014-code
014-code force-pushed the feature/llm-retry-policy branch from cfaf88f to 4c13333 Compare October 24, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add opt-in retry policy for transient LLM failures

3 participants