Skip to content

fix(llm): forward thinking on Anthropic requests and drop sampling wi… - #483

Open
renanalmd wants to merge 1 commit into
openJiuwen-ai:developfrom
renanalmd:fix/anthropic-forward-thinking
Open

fix(llm): forward thinking on Anthropic requests and drop sampling wi…#483
renanalmd wants to merge 1 commit into
openJiuwen-ai:developfrom
renanalmd:fix/anthropic-forward-thinking

Conversation

@renanalmd

@renanalmd renanalmd commented Aug 11, 2026

Copy link
Copy Markdown

Paired: GitHub #483GitCode !2297

What type of PR is this?

/kind bug

What does this PR do / why do we need it:

  • _build_anthropic_params rebuilds its payload from an explicit key set and dropped thinking.
  • Forward thinking, size max_tokens for the budget plus answer headroom, and omit sampling knobs when thinking is present.

Which issue(s) this PR fixes:

Fixes openJiuwen-ai/jiuwenswarm#2710

What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.)

  • Unit tests: 63 passed in tests/unit_tests/core/foundation/llm/test_anthropic_model_client.py
    • Forwards thinking with budget_tokens.
    • Raises max_tokens when the budget would leave less than 4096 answer tokens.
    • Drops sampling knobs when thinking is enabled.
    • Preserves sampling behavior when thinking is absent.

Self-checklist:(Please check carefully,and mark an x in the [] brackets. We will review your completion status.

    • Design: Has the solution corresponding to the PR been reviewed by the Maintainer, and have all review comments been replied to and revised
    • Test: Has the code in the PR been fully covered by UT/ST test cases, and have the newly added test cases been uploaded to the repository along with this PR or already uploaded.
    • Verification: Does the PR description contains a detailed description of the verification results regarding the achievement of the expected goals for the Feature, Refactor, and Bug Fix to this PR.
    • Interface: Does it involve changes to external interfaces? The corresponding changes have been approved by the interface review organization, and the annotation information for the API has been correctly refreshed.
    • Document: Does it involve modifications to the official website documentation? If so, please submit the materials to the Doc repository in a timely manner.

…th it

_build_anthropic_params rebuilds its payload from an explicit key set and
dropped thinking. Forward thinking, size max_tokens for the budget plus
answer headroom, and omit sampling knobs when thinking is present.
@openjiuwen-collaboration-bot

openjiuwen-collaboration-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

head_sha: 703e6efe40ef8015569e8edc3a8979309b21ee7d

变更摘要

此 PR 修复了 AnthropicModelClient._build_anthropic_params 中因显式键集合重建请求体而遗漏 thinking 参数的缺陷,使扩展思考(extended thinking)功能能够正确转发给 Anthropic API。同时,当传入 thinking 时自动提升 max_tokens 以确保预算外有至少 4096 个 token 的回答空间,并移除不兼容的采样参数(temperature/top_p),避免 API 返回 400 错误。

主要改动

  • 转发 thinking 参数:在 _build_anthropic_params 中新增对 openai_params["thinking"] 的提取与赋值,使调用方传入的思考配置能正确传递到 Anthropic 请求体,不再被静默丢弃。
  • max_tokens 自动扩容:当 thinking 包含 budget_tokens 且当前 max_tokens 减去预算后不足 _THINKING_MAX_TOKENS_HEADROOM(4096)时,自动将 max_tokens 提升为 budget + 4096,避免 API 拒绝请求或回答空间过小。
  • 思考模式下抑制采样参数:当 thinking 存在时,不再向请求体中写入 temperaturetop_p,因为扩展思考模式不允许非默认采样参数;仅在 thinkingNone 时沿用原有的 temperature 优先于 top_p 的转发逻辑。
  • 引入常量 _THINKING_MAX_TOKENS_HEADROOM:模块级常量定义回答头空间为 4096 token,用于 max_tokens 扩容判断,兼顾可读性和可维护性。
  • 新增单元测试 TestThinkingForward:在 test_anthropic_model_client.py 中新增 8 个测试用例,覆盖 thinking 转发、max_tokens 提升、预算不足时的兜底行为、异常 budget 值的健壮性,以及思考模式下采样参数的排除。

@openjiuwen-collaboration-bot

openjiuwen-collaboration-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

head_sha: 703e6efe40ef8015569e8edc3a8979309b21ee7d

代码审查

✅ 未发现问题

@openjiuwen-collaboration-bot

Copy link
Copy Markdown

head_sha: 703e6efe40ef8015569e8edc3a8979309b21ee7d

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ✅SUCCESS 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Provider-agnostic reasoning_level mapping

1 participant