From 472889c3bd0a65ed6e18a1031228b5b8fdf32508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=AE=20=28Jade=20Lin=29?= Date: Fri, 22 Aug 2025 21:59:29 +0800 Subject: [PATCH] fix: return nil for empty tools slice to handle omitzero properly (#861) The `anthropic.MessageNewParams` uses omitzero tag, but an empty slice is not considered zero value. Return `nil` instead of empty slice when no tools are provided to ensure proper omitzero behavior. --- internal/llm/provider/anthropic.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go index 18767b56ec04f2615c57931660772cc628ddda20..d7f678a9b82932356d15e423fe362aab15d521a8 100644 --- a/internal/llm/provider/anthropic.go +++ b/internal/llm/provider/anthropic.go @@ -169,6 +169,9 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic } func (a *anthropicClient) convertTools(tools []tools.BaseTool) []anthropic.ToolUnionParam { + if len(tools) == 0 { + return nil + } anthropicTools := make([]anthropic.ToolUnionParam, len(tools)) for i, tool := range tools {