fix(claude): resolve empty tool name in Claude API requests
The ToolCall struct stores the tool name in Function.Name (OpenAI format) but the Claude provider was reading tc.Name (top-level), which is always empty. This caused 400 Bad Request errors on any conversation involving tool calls. Also handles the case where Arguments are stored as a JSON string in Function.Arguments rather than the top-level map. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
811e4f8728
commit
f5c5034c62
1 changed files with 9 additions and 1 deletions
|
|
@ -81,7 +81,15 @@ func buildClaudeParams(messages []Message, tools []ToolDefinition, model string,
|
|||
blocks = append(blocks, anthropic.NewTextBlock(msg.Content))
|
||||
}
|
||||
for _, tc := range msg.ToolCalls {
|
||||
blocks = append(blocks, anthropic.NewToolUseBlock(tc.ID, tc.Arguments, tc.Name))
|
||||
name := tc.Name
|
||||
if name == "" && tc.Function != nil {
|
||||
name = tc.Function.Name
|
||||
}
|
||||
args := tc.Arguments
|
||||
if args == nil && tc.Function != nil && tc.Function.Arguments != "" {
|
||||
json.Unmarshal([]byte(tc.Function.Arguments), &args)
|
||||
}
|
||||
blocks = append(blocks, anthropic.NewToolUseBlock(tc.ID, args, name))
|
||||
}
|
||||
anthropicMessages = append(anthropicMessages, anthropic.NewAssistantMessage(blocks...))
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue