Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gateway: an upstream naming the type an unknown variant `custom` turns custom tools to functions (#3392, kongkongklng)

vincentb6303043220d
diff --git a/internal/gateway/custom_tool.go b/internal/gateway/custom_tool.go
index 715395018..f0ebad338 100644
--- a/internal/gateway/custom_tool.go
+++ b/internal/gateway/custom_tool.go
@@ -20,9 +20,10 @@ import (
// the start.
// customToolRefusal is an upstream turning a custom tool away: DeepSeek's
-// "Unsupported custom tool: 'exec'", or the type named unsupported. A
+// "Unsupported custom tool: 'exec'", or the type named unsupported — as
+// xAI names it, Rust's own wording, "unknown variant `custom`" (#3392). A
// refusal of anything else about a tool doesn't match.
-var customToolRefusal = regexp.MustCompile(`(?i)unsupported custom tool|custom tools? (?:is |are )?not (?:supported|allowed)|(?:unsupported|unknown|invalid) tool type[^\n{}]{0,20}?['"\x60]custom['"\x60]|tool type ['"\x60]custom['"\x60] (?:is )?(?:not supported|unsupported)`)
+var customToolRefusal = regexp.MustCompile(`(?i)unsupported custom tool|custom tools? (?:is |are )?not (?:supported|allowed)|(?:unsupported|unknown|invalid) tool type[^\n{}]{0,20}?['"\x60]custom['"\x60]|tool type ['"\x60]custom['"\x60] (?:is )?(?:not supported|unsupported)|unknown variant[^\n{}]{0,20}?['"\x60]custom['"\x60]`)
// customToolRefused is how unfit remembers model turning custom tools
// away.
diff --git a/internal/gateway/custom_tool_test.go b/internal/gateway/custom_tool_test.go
index c3ed67c7d..53704c089 100644
--- a/internal/gateway/custom_tool_test.go
+++ b/internal/gateway/custom_tool_test.go
@@ -197,13 +197,18 @@ func TestCustomToolRefusalInGroup(t *testing.T) {
// not taken for one. A group's next member is asked over it where it
// reaches the group untranslated.
func TestCustomToolRefusalWordings(t *testing.T) {
- for _, b := range []string{
+ known := []string{
deepSeekCustomRefusal,
`{"error":{"message":"Unsupported custom tool: 'exec'. Only 'apply_patch' is supported."}}`,
`{"error":{"message":"DeepSeek: Unsupported custom tool: 'exec'. Only 'apply_patch' is supported.","type":"invalid_request_error"}}`,
`{"error":{"message":"Invalid tool type: 'custom'"}}`,
`{"error":{"message":"custom tools are not supported"}}`,
- } {
+ // xAI 422s the type with Rust's own wording (#3392, kongkongklng),
+ // in an error body and bare, as magpie reads it off a reply's words
+ `{"error":{"message":"xAI: Failed to deserialize the JSON body into the target type: tools[6].type: unknown variant ` + "`custom`" + `, expected one of ` + "`function`" + `, ` + "`web_search`" + `","type":"invalid_request_error"}}`,
+ `Failed to deserialize the JSON body into the target type: tools[6].type: unknown variant ` + "`custom`" + `, expected one of ` + "`function`" + `, ` + "`shell`" + `, ` + "`tool_search`" + ``,
+ }
+ for _, b := range known {
if !customToolRefusal.Match(wordsOf([]byte(b))) {
t.Errorf("not known: %s", b)
}
@@ -215,6 +220,8 @@ func TestCustomToolRefusalWordings(t *testing.T) {
`{"error":{"message":"Invalid schema for function 'exec': 'input' is required"}}`,
`{"error":{"message":"tools[0].function.strict is not supported"}}`,
`{"error":{"message":"Insufficient Balance"}}`,
+ // a variant other than the type itself says nothing of custom tools
+ `{"error":{"message":"tools[2].type: unknown variant ` + "`web_search_2025`" + `"}}`,
} {
if customToolRefusal.Match([]byte(b)) {
t.Errorf("taken for one: %s", b)