Skip to content

fix(anthropic): skip tool calls with empty names#1715

Closed
darrenzeng2025 wants to merge 1 commit intosipeed:mainfrom
darrenzeng2025:fix/1658-skip-empty-tool-name
Closed

fix(anthropic): skip tool calls with empty names#1715
darrenzeng2025 wants to merge 1 commit intosipeed:mainfrom
darrenzeng2025:fix/1658-skip-empty-tool-name

Conversation

@darrenzeng2025
Copy link
Contributor

修复内容

修复 Issue #1658: 当使用Claude API时,如果tool_use.name为空字符串,会返回400错误

问题

Anthropic API要求tool_use.name必须至少包含1个字符。当传入空字符串时,API返回错误:

tool use.name string should contain at least 1 character

解决方案

在构建ToolUseBlock之前,添加空字符串检查。如果tc.Name为空字符串,则跳过该tool call。

修改的文件

  • pkg/providers/anthropic/provider.go: 在循环开始时添加空字符串检查
  • pkg/providers/anthropic/provider_test.go: 添加测试用例验证修复

测试

添加了TestBuildParams_ToolCallMessageWithEmptyName测试用例,验证:

  1. 包含空名称tool call的消息被正确处理
  2. 空名称的tool call被跳过
  3. 有效的tool call仍然被保留

参考修复: openclaw/openclaw@aa56045

@yinwm
Copy link
Collaborator

yinwm commented Mar 18, 2026

@darrenzeng2025 plz fix Linter and tests

@yinwm yinwm closed this Mar 18, 2026
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