From c4c5a4a01e05a8d18e0bf14ac92c43e60e517ea7 Mon Sep 17 00:00:00 2001 From: Parth Sareen Date: Tue, 14 Oct 2025 19:35:15 -0700 Subject: [PATCH] types: send index for tool calls (#12625) --- api/types.go | 2 +- api/types_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/types.go b/api/types.go index 85a4887764..1483c844fc 100644 --- a/api/types.go +++ b/api/types.go @@ -204,7 +204,7 @@ type ToolCall struct { } type ToolCallFunction struct { - Index int `json:"index,omitempty"` + Index int `json:"index"` Name string `json:"name"` Arguments ToolCallFunctionArguments `json:"arguments"` } diff --git a/api/types_test.go b/api/types_test.go index 5393b46230..5053c16210 100644 --- a/api/types_test.go +++ b/api/types_test.go @@ -298,6 +298,30 @@ func TestToolFunction_UnmarshalJSON(t *testing.T) { } } +func TestToolCallFunction_IndexAlwaysMarshals(t *testing.T) { + fn := ToolCallFunction{ + Name: "echo", + Arguments: ToolCallFunctionArguments{"message": "hi"}, + } + + data, err := json.Marshal(fn) + require.NoError(t, err) + + raw := map[string]any{} + require.NoError(t, json.Unmarshal(data, &raw)) + require.Contains(t, raw, "index") + assert.Equal(t, float64(0), raw["index"]) + + fn.Index = 3 + data, err = json.Marshal(fn) + require.NoError(t, err) + + raw = map[string]any{} + require.NoError(t, json.Unmarshal(data, &raw)) + require.Contains(t, raw, "index") + assert.Equal(t, float64(3), raw["index"]) +} + func TestPropertyType_UnmarshalJSON(t *testing.T) { tests := []struct { name string