fix(anthropic): enforce thinking sampling and forced tool_choice constraints
PC
9h ago+236+236+012345678901234567890123456789-24-24-01234567890123456789
Description
Anthropic answers 400 to two kinds of request that the Messages translation still sends, while the Bedrock Converse adapter (#1657) already adapts them:
top_pbelow 0.95 with thinking. Onlytemperature != 1was dropped; extended thinking also requirestop_p >= 0.95, so e.g.reasoning_effort: "low"withtop_p: 0.9onclaude-sonnet-4-6failed.- Thinking with a forced
tool_choice. Thinking now runs after the tool translation (including the relaxation toauto); whentool_choicestill forces a tool (any/tool),thinkingandoutput_configare left out, as on Bedrock.thinking: disabledandautoare kept.
Tests: TestConvertToAnthropicRequest_ThinkingSamplingConstraints and TestConvertToAnthropicRequest_ThinkingWithForcedToolChoice in internal/providers/anthropic.
AI Generated (optional)
Prepared with AI assistance; the provider test suite was run locally.
Summary by CodeRabbit
- Bug Fixes
- Anthropic requests now handle reasoning settings more consistently: incompatible temperature and sampling values are omitted when thinking is enabled, and the token limit is adjusted when needed.
- Thinking is omitted for forced tool choices, while remaining available for automatic tool selection. Disabled thinking and compatible sampling settings are preserved.