revert behaviour

This commit is contained in:
Kunal Karmakar 2026-03-27 16:53:56 +00:00
parent 3f9c31fd55
commit cdc588a152
2 changed files with 24 additions and 14 deletions

View file

@ -61,8 +61,8 @@ func TranslateMessages(messages []protocoltypes.Message) (input responses.Respon
})
}
for _, tc := range msg.ToolCalls {
name, args := ResolveToolCall(tc)
if name == "" {
name, args, ok := ResolveToolCall(tc)
if !ok {
continue
}
input = append(input, responses.ResponseInputItemUnionParam{
@ -152,28 +152,29 @@ func ParseDataAudioURL(mediaURL string) (format, data string, ok bool) {
}
// ResolveToolCall extracts the function name and JSON arguments string from a ToolCall.
func ResolveToolCall(tc protocoltypes.ToolCall) (name string, arguments string) {
// Returns ok=false if the tool call has no name or if arguments fail to marshal.
func ResolveToolCall(tc protocoltypes.ToolCall) (name string, arguments string, ok bool) {
name = tc.Name
if name == "" && tc.Function != nil {
name = tc.Function.Name
}
if name == "" {
return "", ""
return "", "", false
}
if len(tc.Arguments) > 0 {
argsJSON, err := json.Marshal(tc.Arguments)
if err != nil {
return name, "{}"
return "", "", false
}
return name, string(argsJSON)
return name, string(argsJSON), true
}
if tc.Function != nil && tc.Function.Arguments != "" {
return name, tc.Function.Arguments
return name, tc.Function.Arguments, true
}
return name, "{}"
return name, "{}", true
}
// TranslateTools converts internal ToolDefinition entries to the OpenAI Responses API

View file

@ -148,7 +148,10 @@ func TestResolveToolCall_FromNameAndArguments(t *testing.T) {
Name: "get_weather",
Arguments: map[string]any{"city": "SF"},
}
name, args := ResolveToolCall(tc)
name, args, ok := ResolveToolCall(tc)
if !ok {
t.Fatal("expected ok=true")
}
if name != "get_weather" {
t.Errorf("name = %q, want %q", name, "get_weather")
}
@ -165,7 +168,10 @@ func TestResolveToolCall_FromFunctionField(t *testing.T) {
Arguments: `{"path":"README.md"}`,
},
}
name, args := ResolveToolCall(tc)
name, args, ok := ResolveToolCall(tc)
if !ok {
t.Fatal("expected ok=true")
}
if name != "read_file" {
t.Errorf("name = %q, want %q", name, "read_file")
}
@ -176,15 +182,18 @@ func TestResolveToolCall_FromFunctionField(t *testing.T) {
func TestResolveToolCall_EmptyName(t *testing.T) {
tc := protocoltypes.ToolCall{}
name, _ := ResolveToolCall(tc)
if name != "" {
t.Errorf("name = %q, want empty", name)
_, _, ok := ResolveToolCall(tc)
if ok {
t.Error("expected ok=false for empty tool call")
}
}
func TestResolveToolCall_NoArgsFallsBackToEmptyObject(t *testing.T) {
tc := protocoltypes.ToolCall{Name: "do_something"}
name, args := ResolveToolCall(tc)
name, args, ok := ResolveToolCall(tc)
if !ok {
t.Fatal("expected ok=true")
}
if name != "do_something" {
t.Errorf("name = %q, want %q", name, "do_something")
}