fix: honor temperature override for LiteLLMModel queries with n set by BlueX888 · Pull Request #1557 · SWE-agent/SWE-agent · GitHub
Skip to content

fix: honor temperature override for LiteLLMModel queries with n set - #1557

Open
BlueX888 wants to merge 1 commit into
SWE-agent:mainfrom
BlueX888:fix/prep-comparison-temperature-never-applied
Open

BlueX888 wants to merge 1 commit into
SWE-agent:mainfrom
BlueX888:fix/prep-comparison-temperature-never-applied

Conversation

@BlueX888

Copy link
Copy Markdown

Reference Issues/PRs

Fixes #1556

See also #1484 — it reports a different defect in the same _query method (n is not forwarded to the provider). That behaviour is unchanged by this PR.

What does this implement/fix? Explain your changes.

Summary. BinaryTrajectoryComparisonConfig.comparison_temperature is documented as an override of the model temperature, but it never reached the API: the pairwise-comparison query ran at the model's own temperature.

Why. BinaryTrajectoryComparison.get_action passes the override at sweagent/agent/action_sampler.py:288:

response = self._model.query(messages, temperature=self.config.comparison_temperature)["message"]

LiteLLMModel.query defaults n to 1 (sweagent/agent/models.py:793), so _query took its loop branch — and that branch forwarded only the message list:

for _ in range(n):
    outputs.extend(self._single_query(messages))   # temperature dropped

_single_query then fell back to temperature=self.config.temperature if temperature is None else temperature (sweagent/agent/models.py:725), i.e. the model temperature. The n is None branch directly above already forwarded the argument correctly (sweagent/agent/models.py:786-787), which is why only the sampler path was affected.

Changes.

  • sweagent/agent/models.py: one line in LiteLLMModel._query — forward temperature into _single_query inside the loop, so an explicitly passed override is honoured for every sampled call and not only when n is None.
  • tests/test_action_sampler.py: new regression test driving the real BinaryTrajectoryComparison with a real LiteLLMModel, patching only litellm.completion so no API key is needed. It asserts the two candidate-sample calls keep the model temperature (0.0) and the comparison call reaches litellm.completion with 0.9, the configured override.

All other callers of query (sweagent/agent/action_sampler.py:83,89,251,259, sweagent/agent/agents.py:1042, sweagent/agent/reviewer.py:284,360,429) pass no temperature, so for them temperature=None is forwarded and they keep the configured model temperature exactly as before.

Testing

Command Result
pytest tests/test_action_sampler.py -q (unpatched models.py) 1 failed — assert 0.0 == 0.9 at tests/test_action_sampler.py:62
pytest tests/test_action_sampler.py -q 1 passed
pytest tests/test_models.py tests/test_agent.py -q 15 passed, 2 xfailed
ruff check + ruff format --check on both files All checks passed! / 2 files already formatted
typos on both files no findings

The red run was produced by checking out the unpatched sweagent/agent/models.py at 3ea751c while keeping the new test: the comparison call reaches litellm.completion with 0.0 (the model temperature) instead of 0.9.

LiteLLMModel._query only forwarded the temperature override to
_single_query in its `n is None` branch. BinaryTrajectoryComparison.get_action
calls query(messages, temperature=comparison_temperature), but query defaults
n to 1, so it took the loop branch and every comparison query was sent to
litellm at the model's configured temperature instead of the documented
override.

Forward temperature inside the loop as well, which also makes it apply to
multi-sample queries.

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

Reviewed temperature forwarding through the n-sample loop and the action-sampler caller. The focused sampler/model suites pass (5 tests), including comparison_temperature=0.9.

No blocking issue found in the reviewed diff. Validation was limited to the focused checks described above; the full integration suite was not run.

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

Requesting changes as a reviewer-directed hold pending specific revision requirements. No additional technical defect is asserted in this follow-up; the findings and validation limits in my earlier review still apply.

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

Reviewed temperature forwarding and the action-sampler comparison caller. The sampler/model suites reported 5 passed, including the comparison-temperature regression.

No new blocking defect found in this review. These were focused local checks; the full integration suite was not run.

@BlueX888

Copy link
Copy Markdown
Author

sun04222 added a commit to sun04222/SWE-agent that referenced this pull request Oct 23, 2026

This branch has not been deployed

No deployments
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.

BinaryTrajectoryComparisonConfig.comparison_temperature is silently discarded: the comparison query runs at the model's own temperature

2 participants