Skip to content

条件化 thinking block 剥离,仅跨供应商场景触发#182

Merged
ThreeFish-AI merged 1 commit into
feature/1.x.xfrom
vk/84f5-debug-anthropic
Apr 16, 2026
Merged

条件化 thinking block 剥离,仅跨供应商场景触发#182
ThreeFish-AI merged 1 commit into
feature/1.x.xfrom
vk/84f5-debug-anthropic

Conversation

@ThreeFish-AI

Copy link
Copy Markdown
Owner

概要

将 thinking block 剥离从 AnthropicVendor._prepare_request()(无条件执行)提升至 _RouteExecutor._prepare_body_for_tier()(条件执行),解决纯 Anthropic 会话中 thinking blocks 被不必要剥离的问题。

变更内容

  • 条件化剥离逻辑: 基于请求规范化信号(has_cross_vendor_signals)和会话历史信号(provider_state)判断是否需要剥离,纯 Anthropic 会话保留 thinking blocks 以维持上下文连续性
  • 安全回退: 当 compat_session_store 未配置(session_recordNone)时,回退到始终剥离,确保向后兼容
  • count_tokens 端点加固: 因无会话上下文,安全剥离防止跨供应商 signature 导致 400 错误
  • 纵深防御保留: _strip_misplaced_tool_results 仍在 AnthropicVendor._prepare_request() 中保持不变

测试验证

  • 全量 1213 个测试通过
  • 新增 7 个 _needs_thinking_strip 条件判断测试
  • 新增 5 个 _prepare_body_for_tier thinking 剥离行为测试
  • 新增 7 个 has_cross_vendor_signals 属性测试
  • 新增 7 个 strip_thinking_blocks 函数测试
  • 更新 7 个现有 vendor thinking 测试断言

🤖 Generated with Claude Code, CodeX, Gemini

将 thinking block 剥离从 AnthropicVendor._prepare_request()(无条件执行)
提升至 _RouteExecutor._prepare_body_for_tier()(条件执行),基于请求规范化
信号(has_cross_vendor_signals)和会话历史信号(provider_state)判断是否
需要剥离。纯 Anthropic 会话中 thinking blocks 保持原样以维持上下文连续性。

- 新增 NormalizationResult.has_cross_vendor_signals 属性
- 迁移 strip_thinking_blocks() 至 request_normalizer.py
- 新增 _RouteExecutor._needs_thinking_strip() 条件判断方法
- 补充 count_tokens 端点的安全剥离(无会话上下文时回退到始终剥离)

🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist)
Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
@ThreeFish-AI
ThreeFish-AI merged commit a674210 into feature/1.x.x Apr 16, 2026
4 of 6 checks passed
@ThreeFish-AI
ThreeFish-AI deleted the vk/84f5-debug-anthropic branch April 16, 2026 14:29
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