diff --git a/internal/runtime/executor/xai_executor.go b/internal/runtime/executor/xai_executor.go index 95f71805f..37e1e2970 100644 --- a/internal/runtime/executor/xai_executor.go +++ b/internal/runtime/executor/xai_executor.go @@ -727,6 +727,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() { @@ -737,6 +738,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 8cc850709..a75f13474 100644 --- a/internal/runtime/executor/xai_executor_test.go +++ b/internal/runtime/executor/xai_executor_test.go @@ -123,6 +123,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)) } @@ -261,6 +264,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)) }