From 0908d8a5a051c4af3a2de3a0beaf19c2b7da8715 Mon Sep 17 00:00:00 2001 From: ruirui6946 <2733936092@qq.com> Date: Tue, 14 Jul 2026 21:03:52 +0800 Subject: [PATCH] fix(openai): default empty tool arguments to JSON object --- libs/acl/openai/chat_model.go | 6 +++++- libs/acl/openai/chat_model_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libs/acl/openai/chat_model.go b/libs/acl/openai/chat_model.go index 4b3f98f25..a213d28f4 100644 --- a/libs/acl/openai/chat_model.go +++ b/libs/acl/openai/chat_model.go @@ -375,13 +375,17 @@ func toOpenAIToolCalls(toolCalls []schema.ToolCall) []openai.ToolCall { ret := make([]openai.ToolCall, len(toolCalls)) for i := range toolCalls { toolCall := toolCalls[i] + arguments := toolCall.Function.Arguments + if arguments == "" { + arguments = "{}" + } ret[i] = openai.ToolCall{ Index: toolCall.Index, ID: toolCall.ID, Type: openai.ToolTypeFunction, Function: openai.FunctionCall{ Name: toolCall.Function.Name, - Arguments: toolCall.Function.Arguments, + Arguments: arguments, }, } } diff --git a/libs/acl/openai/chat_model_test.go b/libs/acl/openai/chat_model_test.go index 098956c49..cfd55898a 100644 --- a/libs/acl/openai/chat_model_test.go +++ b/libs/acl/openai/chat_model_test.go @@ -266,6 +266,18 @@ func TestToOpenAIToolCalls(t *testing.T) { assert.Equal(t, fakeToolCall1.ID, toolCalls[0].ID) assert.Equal(t, fakeToolCall1.Function.Name, toolCalls[0].Function.Name) }) + + t.Run("empty arguments", func(t *testing.T) { + fakeToolCall := schema.ToolCall{ + ID: randStr(), + Function: schema.FunctionCall{Name: randStr()}, + } + + toolCalls := toOpenAIToolCalls([]schema.ToolCall{fakeToolCall}) + + assert.Len(t, toolCalls, 1) + assert.Equal(t, "{}", toolCalls[0].Function.Arguments) + }) } func randStr() string {