From a8fc21d070cdf1529291820e4e2de400a3b69638 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 15 Feb 2026 21:30:52 +0800 Subject: [PATCH] Add initial ChunkToolCall handling in Anthropic provider - Implement functionality to send an initial ChunkToolCall with the event's ID and function name, aligning with OpenAI's format for tool name resolution. - Enhance message tracking by incrementing the chunk count after sending the tool call data, improving the overall message handling process in the streamWithRetry function. --- agent/llm/providers/anthropic/anthropic.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/agent/llm/providers/anthropic/anthropic.go b/agent/llm/providers/anthropic/anthropic.go index a1843d5c..2c9aec9c 100644 --- a/agent/llm/providers/anthropic/anthropic.go +++ b/agent/llm/providers/anthropic/anthropic.go @@ -362,6 +362,23 @@ func (p *Provider) streamWithRetry(ctx *context.Context, messages []context.Mess Index: event.Index, } 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, + }, + }, + }) + handler(message.ChunkToolCall, toolCallData) + incrementChunk(msgTracker) + } } }