yuexian7 on Discord: models.dev lists their model as reasoning, and the
vendor answers any reasoning parameter with 422 while the same request
without it works. In a routing group they couldn't set an effort per
model, and the model editor refused to untick the last level ("Keep at
least one level"). The learned refusals (bed306ae, #1062) don't cover
this: they learn a refusal of reasoning *off* and of Gemini levels, and
optionalFields holds thinking/enable_thinking, not reasoning_effort.
- settings.ModelReasonless, set by provider.SetModelReasonless (the
provider editor's Names & levels with every level unticked, saved as
modelPrefs {reasonless: true}; `magpie model efforts <ref> off`).
Ticking levels again or Restore default clears it (setModelEfforts);
setting it drops the model's kept levels.
- entryFor and Efforts/Thinks/Levelless: the model offers no levels and
is Quiet, so agents are given none for it.
- Gateway: the candidate loop strips the body with withoutAnyReasoning
in the agent's protocol (Chat/Responses reasoning_effort, reasoning,
thinking, enable_thinking, include's reasoning.encrypted_content;
Anthropic thinking of any type and output_config.effort; Gemini
thinkingConfig). The Anthropic relay doesn't add
thinking:{type:disabled} for it, and forwardTranslated clears Effort,
ThinkOff and Thinking for its other callers (continuation, search).
- A routing group with it as a member keeps the other members' levels
(it `continue`s like a member whose levels are unknown, #597), and the
member that reasons is still sent the effort asked.
- GUI: none ticked shows "No reasoning field sent" beside the levels, in
zh, zh-TW, ja and de too; a model with one known level now shows its
picker so it can be unticked. A model whose levels aren't known
(m.given) keeps none ticked meaning no levels known.
Run (worktree on origin/main 82f3befd2, sandbox HOME, private GOCACHE):
gofmt -l clean; with set -o pipefail go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./... all clean; node --check
app.js. go test -count=1 ./internal/provider ./internal/gateway
./internal/settings ./internal/cli: ok. ./internal/gui: ok except
TestMainWindowCorners/macOS_15_SDK killed at its 40s deadline under
load (AppKit window measurement, untouched here; #1936, noted there).
The run caught TestSettingsSaveKeepsWhatItDoesNotSend (ModelReasonless
added to it) and the CLI usage alignment tests (fixed).
New tests and what breaking the change does: TestReasonlessModelSentNoReasoning
(Chat, Chat+enable_thinking, Responses with include, Anthropic->Chat
translated; by name and through group/mix) and TestReasonlessAnthropicRelay
fail with gateway.go/quiet.go reverted; TestGroupReasonlessMemberKeepsLevels
fails with group.go's reasonless branch disabled; TestModelReasonless
needs the new API. model-reasonless.test.cjs in chromium and webkit, at
1100 and 420, in en, zh, zh-TW, ja, de: 20/20; on the old assets all
fail. Related GUI tests 418/418 (one model-copy-id failure on a first
run under load, passed alone; #2066).
Not tried against the reporter's real vendor: the 422 is taken from
their report.
145 lines
5.2 KiB
Go
145 lines
5.2 KiB
Go
package gateway
|
|
|
|
// A routing group reasons when any member does (provider.groupEntries), so
|
|
// an agent asks a group for reasoning that a member of it may not think
|
|
// at all: the group's own model is a member's, and its levels are the ones
|
|
// the members share. Asking such a member anyway is what #950 is about:
|
|
// some vendors turn a reasoning ask away with a 400 on a model that can't
|
|
// think, where magpie knows from the model's own list that it can't.
|
|
//
|
|
// The gateway sends such a member no reasoning ask: the effort is for the
|
|
// members that take it, and a member known not to think is sent the
|
|
// request as one that asked for none. Which member goes first is not
|
|
// changed: the group routes as it did, and only the body changes. A model
|
|
// nothing speaks for isn't touched — it is sent the effort the agent asked
|
|
// for, as #597 leaves it — and neither is a request to a model of its own,
|
|
// outside a group. Nor is a member the user fixed at an effort (candidate
|
|
// effort, #189): that is the user saying this model does think, over a
|
|
// catalog that may be wrong about it — the Trae plugin's own model, whose
|
|
// plugin gave no capabilities, is what #950 was reported about — so the
|
|
// user's word goes as it is, and magpie's default doesn't override it.
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// quietTo is whether pid/model is known not to think: magpie has a word on
|
|
// it, and that word says no reasoning. Like blindTo, it asks the served
|
|
// entry, so a provider kept unlisted still answers.
|
|
func quietTo(pid, model string) bool {
|
|
e, ok := provider.ServedEntryOf(pid + "/" + model)
|
|
return ok && e.Quiet()
|
|
}
|
|
|
|
// withoutReasoningAsk removes the fields that ask a model to think, in the
|
|
// agent's own protocol, keeping every other field: what a member known not
|
|
// to think is sent (#950). Chat's reasoning_effort and reasoning,
|
|
// Responses' reasoning (with reasoning_effort, which some relays take),
|
|
// Anthropic's thinking when it asks to think — thinking disabled is no
|
|
// ask and stays — and output_config's effort alone, the rest of
|
|
// output_config kept, and Gemini's generationConfig.thinkingConfig when it
|
|
// asks to think. The body goes as it is when it asked for nothing.
|
|
func withoutReasoningAsk(proto provider.Protocol, body []byte) []byte {
|
|
return withoutReasoningFields(proto, body, false)
|
|
}
|
|
|
|
// withoutAnyReasoning removes every field about reasoning, in the agent's own
|
|
// protocol: withoutReasoningAsk's, and those turning it off as well —
|
|
// Anthropic's thinking of any type, Gemini's thinkingConfig whatever it
|
|
// says, and Chat's thinking switches (Kimi's thinking, Qwen's
|
|
// enable_thinking), and the sealed reasoning Responses' include asks
|
|
// for, which OpenAI refuses of a model that doesn't reason. It is what a
|
|
// model the user said takes no reasoning ask is sent
|
|
// (provider.SetModelReasonless; yuexian7 on Discord: the vendor answers
|
|
// reasoning_effort with 422, and the request without it works).
|
|
func withoutAnyReasoning(proto provider.Protocol, body []byte) []byte {
|
|
return withoutReasoningFields(proto, body, true)
|
|
}
|
|
|
|
func withoutReasoningFields(proto provider.Protocol, body []byte, all bool) []byte {
|
|
dec := json.NewDecoder(bytes.NewReader(body))
|
|
dec.UseNumber()
|
|
var m map[string]any
|
|
if dec.Decode(&m) != nil {
|
|
return body
|
|
}
|
|
changed := false
|
|
drop := func(k string) {
|
|
if _, ok := m[k]; ok {
|
|
delete(m, k)
|
|
changed = true
|
|
}
|
|
}
|
|
switch proto {
|
|
case provider.Chat, provider.Responses:
|
|
drop("reasoning_effort")
|
|
drop("reasoning")
|
|
if all {
|
|
drop("thinking")
|
|
drop("enable_thinking")
|
|
if inc, ok := m["include"].([]any); ok {
|
|
kept := inc[:0:0]
|
|
for _, v := range inc {
|
|
if v != "reasoning.encrypted_content" {
|
|
kept = append(kept, v)
|
|
}
|
|
}
|
|
if len(kept) < len(inc) {
|
|
m["include"], changed = kept, true
|
|
}
|
|
}
|
|
}
|
|
case provider.Anthropic:
|
|
if t, ok := m["thinking"].(map[string]any); ok {
|
|
if s, _ := t["type"].(string); all || s == "enabled" || s == "adaptive" {
|
|
drop("thinking")
|
|
}
|
|
} else if all {
|
|
drop("thinking")
|
|
}
|
|
if oc, ok := m["output_config"].(map[string]any); ok {
|
|
if _, ok := oc["effort"]; ok {
|
|
delete(oc, "effort")
|
|
changed = true
|
|
if len(oc) == 0 {
|
|
drop("output_config")
|
|
}
|
|
}
|
|
}
|
|
case provider.Gemini:
|
|
// generationConfig's thinkingConfig when it asks to think (as
|
|
// parseGemini reads it), the rest of generationConfig kept; a
|
|
// budget of 0 is no ask and stays. The body was spelled in
|
|
// camelCase on its way in (geminiCamel).
|
|
if gc, ok := m["generationConfig"].(map[string]any); ok {
|
|
if raw, err := json.Marshal(gc["thinkingConfig"]); err == nil {
|
|
var tc gThinking
|
|
if _, has := gc["thinkingConfig"]; has && all || json.Unmarshal(raw, &tc) == nil && tc.effort() != "" {
|
|
delete(gc, "thinkingConfig")
|
|
changed = true
|
|
if len(gc) == 0 {
|
|
drop("generationConfig")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
return body
|
|
}
|
|
if !changed {
|
|
return body
|
|
}
|
|
// the fields the agent sent, as it wrote them: <, > and & are not
|
|
// escaped (withFields)
|
|
var out bytes.Buffer
|
|
enc := json.NewEncoder(&out)
|
|
enc.SetEscapeHTML(false)
|
|
if enc.Encode(m) != nil {
|
|
return body
|
|
}
|
|
return bytes.TrimSuffix(out.Bytes(), []byte("\n"))
|
|
}
|