Skip to content

fix(anthropic): tolerate models that reject an explicit temperature#84

Merged
mattprintz merged 2 commits into
mainfrom
fix/anthropic-temperature-deprecation
Jul 1, 2026
Merged

fix(anthropic): tolerate models that reject an explicit temperature#84
mattprintz merged 2 commits into
mainfrom
fix/anthropic-temperature-deprecation

Conversation

@brandomr

@brandomr brandomr commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Agent.execute() always passes temperature=, but the newest Claude models (e.g. Sonnet 5) reject it with "temperature is deprecated for this model". OpenAIModel already strips temperature for its reasoning models by name, but Claude's naming gives no reliable signal (a "5" appears in models that both do and don't accept it). So AnthropicModel learns from the first rejection: it retries once without temperature and remembers, skipping it on subsequent calls. Unrelated BadRequestErrors are re-raised untouched.

brandomr and others added 2 commits June 30, 2026 17:26
Agent.execute() always passes temperature=, but the newest Claude models
(e.g. Sonnet 5) reject it with "temperature is deprecated for this model".
OpenAIModel already strips temperature for its reasoning models by name, but
Claude's naming gives no reliable signal (a "5" appears in models that both do
and don't accept it). So AnthropicModel learns from the first rejection: it
retries once without temperature and remembers, skipping it on subsequent
calls. Unrelated BadRequestErrors are re-raised untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ting

Base `ainvoke` printed every caught error to stdout before delegating to
handle_invoke_error, so an error a subclass expects and recovers from -- e.g.
AnthropicModel retrying without a rejected `temperature` -- still dumped a scary
400 to the console and looked like a failure. Demote it to a debug log;
genuinely unhandled errors still surface upstream with a traceback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@mattprintz mattprintz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Slick solution. Looks good to me.

@mattprintz
mattprintz merged commit c1a1483 into main Jul 1, 2026
1 check passed
@mattprintz
mattprintz deleted the fix/anthropic-temperature-deprecation branch July 1, 2026 18:03
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.

2 participants