From 8a3dd148c763234368955e49a01851b26d6dbc51 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 15 Feb 2026 21:31:16 +0800 Subject: [PATCH] Refactor ChunkToolCall handling in Anthropic provider - Clean up the code for sending the initial ChunkToolCall, improving readability and maintaining alignment with OpenAI's format for tool name resolution. - Ensure that the chunk count is incremented after sending the tool call data, enhancing the message handling process in the streamWithRetry function. --- agent/llm/providers/anthropic/anthropic.go | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/agent/llm/providers/anthropic/anthropic.go b/agent/llm/providers/anthropic/anthropic.go index 2c9aec9c..decfb949 100644 --- a/agent/llm/providers/anthropic/anthropic.go +++ b/agent/llm/providers/anthropic/anthropic.go @@ -363,22 +363,22 @@ func (p *Provider) streamWithRetry(ctx *context.Context, messages []context.Mess } startToolCallMessage(msgTracker, toolCallInfo, handler) - // Send initial ChunkToolCall with id and function name - // to match OpenAI format so CUI can resolve tool name from stored chunks - if handler != nil { - toolCallData, _ := jsoniter.Marshal([]map[string]interface{}{ - { - "index": event.Index, - "id": event.ContentBlock.ID, - "type": "function", - "function": map[string]interface{}{ - "name": event.ContentBlock.Name, + // Send initial ChunkToolCall with id and function name + // to match OpenAI format so CUI can resolve tool name from stored chunks + if handler != nil { + toolCallData, _ := jsoniter.Marshal([]map[string]interface{}{ + { + "index": event.Index, + "id": event.ContentBlock.ID, + "type": "function", + "function": map[string]interface{}{ + "name": event.ContentBlock.Name, + }, }, - }, - }) - handler(message.ChunkToolCall, toolCallData) - incrementChunk(msgTracker) - } + }) + handler(message.ChunkToolCall, toolCallData) + incrementChunk(msgTracker) + } } }