* provider: a routing group reasons when any member does, not only when all of them do groupEntries started a group at Reasoning: true and intersected it with each member's (e.Reasoning = e.Reasoning && thinks), so one member that doesn't think made the whole group 不支持推理. Pi reads that off /v1/models and turns /thinking off for the model: a routing group of deepseek-v4-flash-0731-max (a Trae plugin model magpie read as one that doesn't reason) with a DeepSeek that does lost reasoning for both. The group now reasons when any member does. Images already worked this way (#756: a text-only member doesn't turn every image away), and the gateway fits a request's effort to the member that gets it (fitFor), failing over when a member refuses the level (failEffort). What the group offers as levels is not changed: a member known to take none still leaves the group none (#597), so such a group is Levelless — a shape magpie serves — rather than one that doesn't reason. group_reasoning_test.go (6 tests) fails without the change: TestGroupReasoningFromAMemberThatThinks, TestGroupReasoningLevels and TestGroupReasoningQuietMemberKeepsTheRest report reasoning off. TestModelsListReasoning, the /v1/models contract test, fails the same way and is updated to the new semantics. go vet, go build, GOOS=linux GOARCH=amd64 go build -tags nogui and GOOS=windows go build pass; go test -tags nogui ./internal/provider ./internal/plugin pass under a temp HOME. internal/gateway passes except TestPluginStreamStalledClientKeepsOther RequestsMoving, which fails on this machine with and without the change. * gateway, provider: a group's member that can't think is sent no reasoning, rather than a 400 A routing group reasons when any member does (#950, 533887c2), so an agent asks a group for reasoning that a member of it may not think at all. The effort reached every member, and some vendors turn a reasoning ask away with a 400 on a model that can't think — the review's second point: the comment said the gateway routes a reasoning request to the members that take it, and nothing did. The gateway now sends such a member no reasoning ask, in the agent's own protocol: 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 kept. Everything else goes as the agent sent it, the Responses effort-update history is skipped for it, and the trace's Effort is "" (nothing was sent) with Fixed kept, so the user's own pin is still read. Which member goes first is unchanged: the group routes as it did, and only the body changes. provider.Entry.Quiet is the judgment: magpie has a word on the model — its vendor's or its maker's list, or its provider's own account list — and that word says no reasoning. A model nothing speaks for isn't quiet: it is sent the effort the agent asked for, as #597 leaves it. Nor is one that takes levels, which includes a model the user gave levels of their own: those take the effort the gateway fits to them. Direct requests outside a group are untouched, as TestPluginThinkingOff pins. TestModelsReasoningWithoutLevels (thinks_test.go) still expected group/mixed false; the review's first point. It is updated with a comment saying why the #402 expectation changes, and a group of two quiet members keeps the "none of them thinks" case. TestGroupNonThinkingMemberNoEffort (group_reasoning_test.go) fails without the change: with the withoutReasoningAsk call disabled it reports "B: the quiet member was sent map[... reasoning_effort:high]". TestEntryQuiet (provider) pins the judgment, and TestWithoutReasoningAsk the field set per protocol. go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./... and GOOS=windows go build ./... pass. go test ./internal/provider, ./internal/catalog and ./internal/plugin pass whole; internal/gateway passes in three chunks covering every test (TestGroup|TestFixed|TestFast| TestModels|TestPluginThink|TestWithout|TestMember, TestEffort|TestResponse| TestReasoning|TestQuiet|TestTrace|TestRoute|TestRules|TestRule, and the rest), 43s + 36s + 790s. The whole suite in one process times out on this machine in an unrelated test (TestRuleDecidesAtTurnStartAndHolds here, TestRequestBodyProgressRenewsIdleDeadline on another run) — the base commit 533887c2 times out the same way, at 800s — so the chunks are what was run. The GUI is untouched, so no Playwright run. * gateway, provider: a member the user fixed at an effort keeps it, quiet or not The review's remaining point: Quiet() rests on magpie's catalog or an account's own model list, and what this PR is about is that word being wrong — the Trae plugin gave no capabilities, and magpie read a thinking model as one that doesn't. A member the user fixed at an effort ("provider/model:high", #189) is the user saying this model does think, so magpie's word doesn't override theirs: the gateway sends the fixed member its effort and strips the reasoning ask from the others as before. quiet := isGroup && c.effort == "" && quietTo(c.p.ID, c.model). c.effort is only ever the member's own fixed effort (Member.Effort, planLevel), never the agent's, a group's Group.Levels, the turn's pick or the Settings' — so those are stripped as they were. TestGroupNonThinkingMemberNoEffort's E is now the other way: the fixed quiet member is sent reasoning_effort "high", and the trace's Effort is "high" with Fixed "high". Dropping the c.effort == "" guard makes it fail with "E: the fixed member was sent map[... model:plain]". quiet.go and Entry.Quiet say why. gofmt, go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./... and GOOS=windows go build ./... pass. The review's own set passes — go test -count=1 -run 'TestGroup|TestWithoutReasoningAsk|TestEntryQuiet| TestModelsReasoning|TestModelsListReasoning|Thinks|TestPluginThinking' ./internal/provider ./internal/gateway — and so does internal/provider whole (208s). internal/gateway passes in chunks (Test[A-D] 340s, Test[S-Z] 216s, Test[^A-DS-Z] split over TestEffort|TestResponse|TestReasoning|TestQuiet| TestTrace|TestRoute|TestRules|TestRule|TestFixed|TestFast 38s and the rest earlier): the whole suite in one process still hangs here on an unrelated test (TestCodexBodyReadsPastOldLimit this time, TestRuleDecidesAtTurnStart AndHolds and TestRequestBodyProgressRenewsIdleDeadline before), which the base commit does too and which passes alone in 0.9s.
192 lines
6.7 KiB
Go
192 lines
6.7 KiB
Go
package provider
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// A group reasons when a member does: a member that doesn't think is no
|
|
// reason to tell the agent the group can't, as a text-only member is no
|
|
// reason to say it can't see (#756's rule for images, applied to
|
|
// reasoning).
|
|
//
|
|
// Before this, one member that didn't think made the whole group
|
|
// 不支持推理, and the agent turned thinking off for it: a routing group of
|
|
// deepseek-v4-flash-0731-max (a Trae plugin model magpie read as one that
|
|
// doesn't reason) with a DeepSeek that does lost reasoning for both.
|
|
//
|
|
// What the group offers as levels is not changed here: a member known to
|
|
// take none still leaves the group none (#597), and the group is then
|
|
// Levelless — magpie's shape for a model that thinks with no level to
|
|
// pick from — rather than 不支持推理.
|
|
func TestGroupReasoningFromAMemberThatThinks(t *testing.T) {
|
|
groupReasoningHome(t)
|
|
for name, in := range map[string][]Entry{
|
|
// the one that doesn't think is the group's own model (its first
|
|
// member's), so the group's own entry says nothing of reasoning
|
|
"quiet first": {quietMember(), thinksMember()},
|
|
"quiet last": {thinksMember(), quietMember()},
|
|
} {
|
|
g := groupEntries(in)
|
|
if len(g) != 1 {
|
|
t.Fatalf("%s: groups %+v", name, g)
|
|
}
|
|
if !g[0].Reasoning {
|
|
t.Errorf("%s: a member thinks, but the group says it doesn't", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A group of members that don't think reasons for none of them.
|
|
func TestGroupReasoningFromNoMember(t *testing.T) {
|
|
groupReasoningHome(t)
|
|
g := groupEntries([]Entry{quiet("q"), quiet("r")})
|
|
if len(g) != 1 {
|
|
t.Fatalf("groups: %+v", g)
|
|
}
|
|
if g[0].Reasoning || len(g[0].Efforts) != 0 {
|
|
t.Fatalf("no member thinks: reasoning %v, levels %v", g[0].Reasoning, g[0].Efforts)
|
|
}
|
|
}
|
|
|
|
// A group that thinks offers the levels its members have in common, as
|
|
// before: a member that thinks with none of its own doesn't take the
|
|
// others' away (the #597 rule for a model whose levels nothing knows), and
|
|
// two that think share theirs.
|
|
func TestGroupReasoningLevels(t *testing.T) {
|
|
groupReasoningHome(t)
|
|
for name, c := range map[string]struct {
|
|
in []Entry
|
|
want []string
|
|
}{
|
|
"one thinks": {[]Entry{thinksMember(), quietMember()}, nil},
|
|
"quiet first": {[]Entry{quietMember(), thinksMember()}, nil},
|
|
"two think": {[]Entry{thinksMember(), thinks("b", []string{"low", "high", "medium"})}, []string{"low", "high"}},
|
|
"thinks no levels": {[]Entry{thinks("a", nil), thinks("b", []string{"low", "high"})}, []string{"low", "high"}},
|
|
} {
|
|
g := groupEntries(c.in)
|
|
if len(g) != 1 {
|
|
t.Fatalf("%s: groups %+v", name, g)
|
|
}
|
|
if !slices.Equal(g[0].Efforts, c.want) {
|
|
t.Errorf("%s: levels %v, want %v", name, g[0].Efforts, c.want)
|
|
}
|
|
if !g[0].Reasoning {
|
|
t.Errorf("%s: reasoning off", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A group that names its own levels offers those, member that doesn't
|
|
// think or not (Group.Levels, #295); one that doesn't think itself is
|
|
// still told to reason, its levels named.
|
|
func TestGroupReasoningNamedLevels(t *testing.T) {
|
|
groupReasoningHome(t)
|
|
if err := SaveGroup(Group{Name: "named", Members: []string{"a/m", "a/n"}, Levels: []string{"low", "high"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, g := range groupEntries(append([]Entry{quietMember()}, Catalog()...)) {
|
|
if g.ID != GroupPrefix+"named" {
|
|
continue
|
|
}
|
|
if !g.Reasoning || !slices.Equal(g.Efforts, []string{"low", "high"}) {
|
|
t.Fatalf("named levels: reasoning %v, levels %v", g.Reasoning, g.Efforts)
|
|
}
|
|
return
|
|
}
|
|
t.Fatal("no group named")
|
|
}
|
|
|
|
// A member that doesn't think doesn't take the other members' images,
|
|
// window or reply limit either: those aggregate as they did (#756, #700).
|
|
func TestGroupReasoningQuietMemberKeepsTheRest(t *testing.T) {
|
|
groupReasoningHome(t)
|
|
yes := true
|
|
quiet := quietMember()
|
|
quiet.Context, quiet.Output = 200000, 8000
|
|
other := thinksMember()
|
|
other.Images, other.ImageInput, other.Context, other.Output = true, &yes, 1000000, 64000
|
|
g := groupEntries([]Entry{quiet, other})
|
|
if len(g) != 1 {
|
|
t.Fatalf("groups: %+v", g)
|
|
}
|
|
e := g[0]
|
|
if !e.Images || e.ImageInput == nil || !*e.ImageInput || e.Context != 1000000 || e.Output != 64000 {
|
|
t.Fatalf("a quiet member took the rest: %+v", e)
|
|
}
|
|
if !e.Reasoning {
|
|
t.Fatalf("reasoning off: %+v", e)
|
|
}
|
|
}
|
|
|
|
// The group a Trae plugin model was reported in: its provider is signed in
|
|
// (so its levels are known to be none, not unknown — it is the plugin's own
|
|
// list that says nothing of reasoning), it has no levels, and the DeepSeek
|
|
// beside it has some. The group is told to reason, whatever it offers as
|
|
// levels.
|
|
func TestGroupReasoningOfAPluginModelThatDoesNotThink(t *testing.T) {
|
|
groupReasoningHome(t)
|
|
trae := Provider{ID: "trae", Name: "Trae", Key: "k", Chat: "http://127.0.0.1:1/v1",
|
|
Models: []string{"deepseek-v4-flash-0731-max"},
|
|
Account: &Account{Agent: "plugin", models: func() []catalog.Model { return nil }}}
|
|
if err := Save(trae); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := SaveGroup(Group{Name: "mix", Members: []string{"trae/deepseek-v4-flash-0731-max", "a/m"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
found := false
|
|
for _, e := range Catalog() {
|
|
if e.ID != GroupPrefix+"mix" {
|
|
continue
|
|
}
|
|
found = true
|
|
if !e.Reasoning {
|
|
t.Errorf("the group is 不支持推理, though a member thinks")
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("no group mix")
|
|
}
|
|
}
|
|
|
|
// levels are the levels of the member that thinks in these tests.
|
|
var levels = []string{"low", "high", "max"}
|
|
|
|
// thinksMember is a member that thinks, with levels.
|
|
func thinksMember() Entry { return thinks("a", levels) }
|
|
|
|
// thinks is a model that does: its own levels as given. Same model id as
|
|
// quietMember's, so the two are members of one group.
|
|
func thinks(p string, efforts []string) Entry {
|
|
return Entry{ID: p + "/m", Model: "m", Name: "m", Provider: Provider{ID: p}, Efforts: efforts, Reasoning: true}
|
|
}
|
|
|
|
// quietMember is a member that doesn't think, and has no levels of its own:
|
|
// the shape a plugin's model had before its plugin listed capabilities. Its
|
|
// provider's account gives a model list (so its levels are known to be none,
|
|
// not unknown: the gateway asks it the effort as it is, no more than high).
|
|
func quietMember() Entry {
|
|
e := quiet("q")
|
|
e.Provider.Account = &Account{Agent: "plugin", models: func() []catalog.Model { return nil }}
|
|
return e
|
|
}
|
|
|
|
// quiet is a model that doesn't think: its provider gives no levels for it,
|
|
// and nothing says it reasons.
|
|
func quiet(p string) Entry {
|
|
return Entry{ID: p + "/m", Model: "m", Name: "m", Provider: Provider{ID: p}}
|
|
}
|
|
|
|
// groupReasoningHome is a machine of its own with a provider whose model
|
|
// has levels the user set.
|
|
func groupReasoningHome(t *testing.T) {
|
|
t.Helper()
|
|
effortHome(t)
|
|
if err := SetModelEfforts("a/m", levels); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|