Skip to content

Refine temperature/top_p handling for reasoning models - #2277

Merged
enyst merged 6 commits into
OpenHands:mainfrom
mayeco:patch-3
Mar 16, 2026
Merged

enyst merged 6 commits into
OpenHands:mainfrom
mayeco:patch-3

Conversation

@mayeco

@mayeco mayeco commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Update handling of temperature and top_p for OpenAI models.

This fix issue #2278

Checklist

  • If the PR is changing/adding functionality, are there tests to reflect this?
  • If there is an example, have you run the example to make sure that it works?
  • If there are instructions on how to run the code, have you followed the instructions and made sure that it works?
  • If the feature is significant enough to require documentation, is there a PR open on the OpenHands/docs repository with the same branch name?
  • Is the github CI passing?

Update handling of temperature and top_p for OpenAI models.
Copilot AI review requested due to automatic review settings March 3, 2026 13:33

Copilot AI 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.

Pull request overview

Updates chat-completion option normalization to avoid stripping sampling params (temperature, top_p) for non-OpenAI “reasoning effort” models (notably Gemini), while still handling OpenAI reasoning-model quirks.

Changes:

  • Only remove temperature/top_p for OpenAI reasoning models (o1*, o3*) instead of all models that support reasoning_effort.
  • Add model-name normalization logic in select_chat_options to gate this behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

openhands-sdk/openhands/sdk/llm/options/chat_options.py:59

  • The Gemini 2.5-pro substring check is case-sensitive and bypasses the model_lower normalization introduced above. For consistency with other model checks in this function (and with model_features.model_matches, which is case-insensitive), use model_lower (or another normalized form) so variants like provider-prefixed or differently-cased model IDs don’t skip this defaulting behavior.
        # Gemini 2.5-pro default to low if not set
        if "gemini-2.5-pro" in llm.model:
            if llm.reasoning_effort in {None, "none"}:
                out["reasoning_effort"] = "low"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mayeco
mayeco requested a review from Copilot March 3, 2026 13:52
@enyst
enyst requested review from enyst and removed request for Copilot March 3, 2026 13:59
@mayeco mayeco mentioned this pull request Mar 5, 2026
5 tasks done

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the contribution! This bit of code might be unnecessary now, since we just merged #1989

@mayeco

mayeco commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor Author

yes I understand @enyst but #1989 but still not fix my issue.

If I have a reasoning model like gemini, then set the temperature to 0.0. then will be 1 (the default)

https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-sdk/openhands/sdk/llm/options/chat_options.py#L43

{
  "generationConfig": {
    "maxOutputTokens": 65536,
    "temperature": 1,  // ← Incorrect: should be 0.0
    "thinkingConfig": {
      "includeThoughts": true,
      "thinkingLevel": "HIGH"
    }
  }
}

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, I agree. I just don't fully understand, why keep the code for o1 and o3?

@mayeco

mayeco commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

yes. maybe is not only o1 / o3 we need to make a list of models that the reasoning fail when temperature is set.
that is better @enyst ?

@enyst

enyst commented Mar 8, 2026

Copy link
Copy Markdown
Member

Sounds good!

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @mayeco, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@mayeco

mayeco commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

@enyst This approach is currently specific to the Gemini model. If we find that other models support reasoning_effort+temperature+top_p, we can add them to the exception list later.

For now, we are 100% sure that Gemini supports it.

https://docs.cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/adjust-parameter-values

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@enyst
enyst merged commit 772fb8d into OpenHands:main Mar 16, 2026
28 of 30 checks passed
@mayeco
mayeco deleted the patch-3 branch March 17, 2026 13:17
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

4 participants