Skip to content

fix(anthropic): stop sending temperature in non-thinking requests - #55

Open
Lucifus613 wants to merge 1 commit into
ApodexAI:mainfrom
Lucifus613:upstream/anthropic-omit-sampling
Open

Lucifus613 wants to merge 1 commit into
ApodexAI:mainfrom
Lucifus613:upstream/anthropic-omit-sampling

Conversation

@Lucifus613

Copy link
Copy Markdown

Summary

AnthropicClient._build_kwargs still sends temperature in non-thinking mode. Two problems follow:

  • The SDK no longer accepts it. In the Anthropic Python SDK v1, AsyncMessages.create no longer has temperature, top_p or top_k parameters, so passing temperature= raises TypeError. This was checked with inspect.signature on anthropic 1.0.0 and 1.3.0.
  • Newer models reject it. Anthropic's Opus 5.5 migration guide says that a non-default temperature, top_p or top_k on Claude Opus 4.7 and later models returns a 400, and recommends omitting these parameters entirely. Sending them through extra_body gets the same 400.

This PR stops writing temperature into the request. The constructor, chat and stream still accept a temperature argument, so callers do not break. Thinking and effort handling are unchanged.

Changes

  • agent_core/providers/anthropic.py: removed the non-thinking temperature branch and updated the comments to match.
  • tests/test_provider_native_clients.py: three new tests.
    • The built kwargs contain no sampling parameters.
    • Every top-level key is a parameter of the installed SDK's AsyncMessages.create.
    • A request sent through a real AsyncAnthropic client over a mock transport has no sampling parameters in its body.
  • tests/test_provider_protocol_reasoning.py: the old "keeps temperature when thinking is off" test now asserts that temperature is dropped.
  • changes/a4-anthropic-omit-sampling.fix.md: changelog fragment.

Test plan

Run on this branch, which is main plus this commit:

  • python -m pytest tests -q: 1622 passed (anthropic 1.3.0, openai 3.7.0).
  • ruff check agent_core tests: clean.
  • The two changed test files copied onto unmodified main give 6 failed and 91 passed; with this commit all pass.
  • Live Anthropic API call: not run (paid).

pyright agent_core reports 6 errors, all in agent_core/runtime/loop/agent_loop.py. Unmodified main reports the same 6, and this PR does not touch that file.

🤖 Generated with Claude Code

Anthropic Python SDK v1 removed temperature/top_p/top_k from
messages.create (passing one raises TypeError), and Claude Opus 4.7+
rejects non-default sampling values with HTTP 400. The constructor,
chat and stream keep accepting temperature for compatibility but no
longer send it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

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.

1 participant