diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md index ae70ae456..c1a9f0240 100644 --- a/docs/subsystems/provider-plugins.md +++ b/docs/subsystems/provider-plugins.md @@ -96,7 +96,7 @@ A plugin can instead mark single models of its list with `searches: true` (on th A plugin says which service tiers its vendor serves a model at with `serviceTiers` on the model (#2514): ids such as `"priority"` and `"ultrafast"`, or objects with an `id`. The host keeps the ids (`tiersOf` in `host.js`, into `plugin.Model.ServiceTiers`), `pluginCatalog` puts them on the catalog model's `Tiers`, and [`CodexTiers`](../../internal/provider/codex_models.go) offers them to Codex, as `codexcat` names them (`priority` is Fast). In [`forwardTranslated`](../../internal/gateway/gateway.go) a request translated to the plugin's Chat or Responses keeps its `service_tier` (`Request.OwnTier`) only when it is among the model's tiers (`provider.PluginTiers`); a request relayed in its own protocol was sent as the client wrote it before, and still is. A model served at `priority` on its Chat or Responses API has fast mode ([`CanFast`](../../internal/provider/groupfast.go), via `pluginTierOn`), whichever plugin it is: it can be a group's fast member or an agent's fast pick, and it can be picked Ultrafast when it is served at `ultrafast` too (`UltraOn`). Fast mode in Claude's words (speed `"fast"`, or a fast pick from an agent on Claude's API) reaches the plugin as tier `priority`, or as `ultrafast` for an Ultrafast pick, when the model is served at that tier (Lovest on Discord). Cursor's `fast` flag and `-fast` siblings still give Cursor's plugin fast mode as before. -A request translated to the Grok plugin's Responses API that turned tools off with no tools declared (Chat's `tool_choice: "none"`, Anthropic's `{"type":"none"}`, Gemini's `functionCallingConfig.mode` `NONE`) reaches the plugin's `fetch` with `tool_choice: "none"` and no `tools` (#3110). Before, it went without a `tool_choice`, the same as a request with no preference, so a plugin that adds a server-side tool of its own (Grok's `x_search`, magpie-community/plugins#263) couldn't respect it. [`buildResponses`](../../internal/gateway/responses.go) keeps the `"none"`, and [`forwardTranslated`](../../internal/gateway/gateway.go) leaves a lone `tool_choice` out for every other upstream (`keepsLoneNone`): every vendor, xAI and Copilot (`refusesLoneToolChoice`, #378), and every other plugin, whose vendors haven't been tried with a lone `"none"`. So what a vendor is sent is unchanged. Grok's Responses backend doesn't take it either: the Grok plugin's bodies are shaped by `grokPluginBody`, which keeps the lone `"none"` that `grokBody` drops for the built-in, and the plugin leaves it out before its request goes to Grok (0.1.18, the mover's `min`). A request the plugin serves in its own Responses protocol goes to its `fetch` as the client wrote it, and the client's own `tool_choice` object of a type Grok's backend doesn't take (an `allowed_tools` naming the client's tools) was dropped the same way (`grokShaped`), so the plugin couldn't tell it from no choice and added `x_search` over it: a tool outside the client's allowed list went out. `grokPluginBody` keeps such an object for the plugin to read now, and the plugin leaves it out before Grok as it does the lone `"none"` (#3153); the built-in, which is Grok's last stop, still drops it. Chat, Anthropic and Gemini requests still carry no tool choice beside no tools, which OpenAI's Chat refuses ("'tool_choice' is only allowed when 'tools' are specified"). `TestToolsOffWithoutToolsReachesPlugin`, `TestToolsOffWithoutToolsNotSentToOtherPlugins`, `TestToolsOffWithoutToolsNotSentToVendor`, `TestToolsOffWithoutToolsLeftOutForXAI` and `TestToolsOffWithoutToolsPerBuilder` in [`tool_choice_none_test.go`](../../internal/gateway/tool_choice_none_test.go), `TestGrokPluginBodyKeepsLoneNone` and `TestGrokPluginBodyKeepsUnsupportedToolChoice`, cover it. +A request translated to the Grok plugin's Responses API that turned tools off with no tools declared (Chat's `tool_choice: "none"`, Anthropic's `{"type":"none"}`, Gemini's `functionCallingConfig.mode` `NONE`) reaches the plugin's `fetch` with `tool_choice: "none"` and no `tools` (#3110). Before, it went without a `tool_choice`, the same as a request with no preference, so a plugin that adds a server-side tool of its own (Grok's `x_search`, magpie-community/plugins#263) couldn't respect it. [`buildResponses`](../../internal/gateway/responses.go) keeps the `"none"`, and [`forwardTranslated`](../../internal/gateway/gateway.go) leaves a lone `tool_choice` out for every other upstream (`keepsLoneNone`): every vendor, xAI and Copilot (`refusesLoneToolChoice`, #378), and every other plugin, whose vendors haven't been tried with a lone `"none"`. So what a vendor is sent is unchanged. Grok's Responses backend doesn't take it either: the Grok plugin's bodies are shaped by `grokPluginBody`, which keeps the lone `"none"` that `grokBody` drops for the built-in, and the plugin leaves it out before its request goes to Grok (0.1.18, the mover's `min`). A request the plugin serves in its own Responses protocol goes to its `fetch` as the client wrote it, and the client's own `tool_choice` object of a type Grok's backend doesn't take (an `allowed_tools` naming the client's tools) was dropped the same way (`grokShaped`), so the plugin couldn't tell it from no choice and added `x_search` over it: a tool outside the client's allowed list went out. `grokPluginBody` keeps such an object for the plugin to read now, and the plugin leaves it out before Grok as it does the lone `"none"` (#3153); the built-in, which is Grok's last stop, still drops it. Chat, Anthropic and Gemini requests still carry no tool choice beside no tools, which OpenAI's Chat refuses ("'tool_choice' is only allowed when 'tools' are specified"). `TestToolsOffWithoutToolsReachesPlugin`, `TestToolsOffWithoutToolsNotSentToOtherPlugins`, `TestToolsOffWithoutToolsNotSentToVendor`, `TestToolsOffWithoutToolsLeftOutForXAI` and `TestToolsOffWithoutToolsPerBuilder` in [`tool_choice_none_test.go`](../../internal/gateway/tool_choice_none_test.go), `TestGrokPluginBodyKeepsLoneNone`, `TestGrokPluginBodyKeepsUnsupportedToolChoice` and the gateway-to-plugin `TestAllowedToolsReachesGrokPlugin`, cover it. ## A plugin model's sampling diff --git a/internal/gateway/tool_choice_none_test.go b/internal/gateway/tool_choice_none_test.go index 80ab1c027..0261dd132 100644 --- a/internal/gateway/tool_choice_none_test.go +++ b/internal/gateway/tool_choice_none_test.go @@ -190,3 +190,30 @@ func TestToolsOffWithoutToolsPerBuilder(t *testing.T) { } } } + +// #3153: the Grok plugin must see the client's allowed list before it +// decides whether to add its own server-side search tool. +func TestAllowedToolsReachesGrokPlugin(t *testing.T) { + var mu sync.Mutex + var sent []byte + pid := besideFake(t, "grok", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, _ := io.ReadAll(r.Body) + mu.Lock() + sent = b + mu.Unlock() + w.Header().Set("Content-Type", "text/event-stream") + io.WriteString(w, noneReply) + })) + const choice = `{"type":"allowed_tools","mode":"auto","tools":[{"type":"function","name":"read_file"}]}` + code, body := postTo(t, New(), "/v1/responses", `{"model":"`+pid+`/fake-resp","stream":true,"input":"hi","tools":[{"type":"function","name":"read_file","parameters":{"type":"object","properties":{}}}],"tool_choice":`+choice+`}`) + if code != 200 { + t.Fatalf("%d %s", code, body) + } + mu.Lock() + defer mu.Unlock() + var got map[string]json.RawMessage + if err := json.Unmarshal(sent, &got); err != nil { + t.Fatal(err) + } + sameJSON(t, got["tool_choice"], choice) +}