From 2607888a977aacaf79235823fe8633503b5b3a39 Mon Sep 17 00:00:00 2001 From: Ben Vargas Date: Sat, 16 May 2026 17:57:40 -0600 Subject: [PATCH] fix(xai): default missing function tool parameters --- internal/runtime/executor/xai_executor.go | 9 +++++++++ internal/runtime/executor/xai_executor_test.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/internal/runtime/executor/xai_executor.go b/internal/runtime/executor/xai_executor.go index 3060eaf58..b5b581390 100644 --- a/internal/runtime/executor/xai_executor.go +++ b/internal/runtime/executor/xai_executor.go @@ -726,6 +726,7 @@ func normalizeXAITool(tool gjson.Result) ([]byte, bool, bool) { return nil, false, false } raw = updatedTool + toolType = xaiFunctionToolType changed = true } if toolType == xaiWebSearchToolType && tool.Get("external_web_access").Exists() { @@ -736,6 +737,14 @@ func normalizeXAITool(tool gjson.Result) ([]byte, bool, bool) { raw = updatedTool changed = true } + if toolType == xaiFunctionToolType && !tool.Get("parameters").Exists() { + updatedTool, errSet := sjson.SetRawBytes(raw, "parameters", []byte(`{"type":"object","properties":{}}`)) + if errSet != nil { + return nil, false, false + } + raw = updatedTool + changed = true + } return raw, changed, true } diff --git a/internal/runtime/executor/xai_executor_test.go b/internal/runtime/executor/xai_executor_test.go index 59bdbe78e..b9064b2bd 100644 --- a/internal/runtime/executor/xai_executor_test.go +++ b/internal/runtime/executor/xai_executor_test.go @@ -114,6 +114,9 @@ func TestXAIExecutorExecuteShapesResponsesRequest(t *testing.T) { if toolType != "function" && toolType != "web_search" { t.Fatalf("tools.%d.type = %q, want function or web_search; body=%s", i, toolType, string(gotBody)) } + if toolType == "function" && !tool.Get("parameters").Exists() { + t.Fatalf("tools.%d.parameters missing for xAI function tool; body=%s", i, string(gotBody)) + } if got := tool.Get("name").String(); got == "apply_patch" { t.Fatalf("tools.%d.name = apply_patch, want removed; body=%s", i, string(gotBody)) } @@ -243,6 +246,9 @@ func TestXAIExecutorExecuteStreamFiltersToolSearchTool(t *testing.T) { if toolType != "function" && toolType != "web_search" { t.Fatalf("tools.%d.type = %q, want function or web_search; body=%s", i, toolType, string(gotBody)) } + if toolType == "function" && !tool.Get("parameters").Exists() { + t.Fatalf("tools.%d.parameters missing for xAI function tool; body=%s", i, string(gotBody)) + } if got := tool.Get("name").String(); got == "apply_patch" { t.Fatalf("tools.%d.name = apply_patch, want removed; body=%s", i, string(gotBody)) }