Skip to content

[integration][openai] Align default parameters for openai chat model between java and python#883

Open
rob-9 wants to merge 16 commits into
apache:mainfrom
rob-9:fix/464-align-connection-defaults
Open

[integration][openai] Align default parameters for openai chat model between java and python#883
rob-9 wants to merge 16 commits into
apache:mainfrom
rob-9:fix/464-align-connection-defaults

Conversation

@rob-9

@rob-9 rob-9 commented Jul 7, 2026

Copy link
Copy Markdown

purpose

the Java OpenAI chat model connections (OpenAICompletionsConnection, AzureOpenAIChatModelConnection, and OpenAIResponsesModelConnection) didn't set explicit defaults for timeout and max_retries, falling through to the openai-java SDK's internal values. the Python SDK explicitly defaults to timeout=60s and max_retries=3, meaning the same agent config behaves differently across languages.

this PR aligns Java to match Python:

  • adds shared DEFAULT_TIMEOUT_SECONDS = 60 / DEFAULT_MAX_RETRIES = 3 constants in OpenAIChatCompletionsUtils.
  • all three Java connections now resolve these via Optional.ofNullable(...).orElse(DEFAULT_*) so absent args get the explicit default.
  • invalid values (timeout < 0, retries < 0) throw IllegalArgumentException at construction time instead of being silently skipped.
  • javadoc and docs updated to document the new defaults and validation constraints.

testing

  • new OpenAICompletionsConnectionTest — asserts correct defaults, explicit overrides, negative rejection, zero acceptance, and api_key validation.
  • new OpenAIResponsesModelConnectionTest — same coverage for the Responses API connection.
  • extended AzureOpenAIChatModelConnectionTest with default-resolution, override, and boundary assertions.
  • new Python test pinning timeout == 60.0 and max_retries == 3.

breaking changes

  • max_retries default changed from 2 → 3 for OpenAICompletionsConnection and OpenAIResponsesModelConnection.
  • timeout=0 was previously silently ignored (SDK default applied); it is now passed through as Duration.ofSeconds(0).
  • negative values for either parameter now throw instead of being silently skipped.

docs

  • doc-not-needed

@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue. labels Jul 7, 2026
@wenjin272 wenjin272 changed the title [fix][java] align connection default parameters with python SDK [integration][opneai] Align default parameters for openai chat model between java and python Jul 9, 2026
@wenjin272 wenjin272 changed the title [integration][opneai] Align default parameters for openai chat model between java and python [integration][openai] Align default parameters for openai chat model between java and python Jul 9, 2026
@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs and removed doc-not-needed Your PR changes do not impact docs labels Jul 9, 2026

@wenjin272 wenjin272 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 for taking this on @rob-9. The code looks good to me, but I think we should also update the documentation.

The user-facing docs still describe the old Java defaults. After this PR, Java OpenAI/Azure connections explicitly default to timeout=60 and max_retries=3, but these tables still mention SDK fallback/None and max_retries=2. Please update the docs to match the new constructor behavior.

@rob-9

rob-9 commented Jul 9, 2026

Copy link
Copy Markdown
Author

@wenjin272 thx

@rob-9 rob-9 force-pushed the fix/464-align-connection-defaults branch from 98af5a7 to cf9be98 Compare July 10, 2026 20:57
@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs and removed doc-not-needed Your PR changes do not impact docs labels Jul 10, 2026

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

Hi, @rob-9. I left two new minor comments about details.

Integer maxRetries = descriptor.getArgument("max_retries");
if (maxRetries != null && maxRetries >= 0) {
builder.maxRetries(maxRetries);
builder.timeout(Duration.ofSeconds(this.timeoutSeconds));

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.

timeout=0 has opposite semantics in Java and Python. openai-java interprets Duration.ZERO as no timeout, while Python forwards 0.0 to HTTPX as a zero-second timeout. Please define one consistent zero-value contract across both languages and test the effective SDK timeout rather than only the stored field.

The same pattern is also present in AzureOpenAIChatModelConnection and OpenAIResponsesModelConnection.

builder.timeout(Duration.ofSeconds(timeoutSeconds));
this.timeoutSeconds =
Optional.ofNullable(descriptor.<Number>getArgument("timeout"))
.map(Number::intValue)

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.

Calling Number.intValue() before validation silently truncates or overflows the input. For example, -0.5 becomes 0 and bypasses the negative check, while fractional timeouts lose precision and fractional retry counts differ from Python validation. Please validate the original value first, preserve fractional timeout values, and require an exact bounded integer for max_retries.

The same pattern is also present in AzureOpenAIChatModelConnection and OpenAIResponsesModelConnection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants