Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
routing: a group's member may offer several reasoning levels for the agent to pick among
yetonedf9376592d87
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.mdindex a2f149245..481a6a496 100644--- a/docs/subsystems/gateway-routing.md+++ b/docs/subsystems/gateway-routing.md@@ -257,6 +257,7 @@ recorded as a prediction failure (`noPrediction`).- An image's `detail` (`Part.Detail`, read from a Responses `input_image` and a Chat `image_url`, in a message or a tool's output) is carried on a translation to Chat and Responses (`chatImage`, `chatDetail`, `responsesDetail` in [`chat.go`](../../internal/gateway/chat.go)). Chat takes `low`, `high` and `auto` as they came, and Responses' `original`, which Chat lacks, as `high`; an image without one goes without. Responses takes the four as they came, and anything else, none included, as `auto` (#1474). Messages and Gemini have no such field, so it isn't sent there (mysterious_dove on Discord, Codex: `high` and `original` were dropped on the way to Chat; `TestResponsesImageDetailReachesChat`, `TestChatImageDetailReachesResponses`).- Group members are `provider/model[:effort]`. A member with a fixed effort is asked for that effort, bounded by the group's levels (#671).- A member the user unchecked in its provider's model list is skipped (`unpicked` in [`group.go`](../../internal/provider/group.go), in `membersOff`; #3911, timonwong): the provider has picks and its served models lack it, as the Routing page strikes it, and the Routing card says it is not ready (`provider.ResolveRoute`). A provider with no picks still routes a model its list lacks (#2642), a decision model is still a decision group's, and a request naming the model itself still reaches it (`resolveIn` takes any `provider/model` of a provider that is on). `group_model_pick_test.go`.+- A member's suffix may join several levels with `+` (`provider/model:low+xhigh`, Garydesu on X): the agent picks among them. `provider.MemberLevels` splits it into `Member.Levels` and leaves `Effort` empty, so it isn't fixed; one level is still a fixed effort. The suffix is kept lowest first, each level once, and the whole stays the member's id, so its rules, fast, off and weight are keyed by it as for any member. The gateway fits the agent's ask to the member's own levels (`groupLevels` returns the candidate's `levels` first), and the group lists those for it to agents (`buildGroupEntries`), intersected with the other members' as usual. In the GUI the member's reasoning menu has "Several levels…". Tests: `TestMemberSeveralLevels` (provider), `TestMemberSeveralLevelsFollowAgent` (gateway), `group-member-levels.test.cjs`.- A group offers agents the reasoning levels its members have in common (`groupEntries` in [`group.go`](../../internal/provider/group.go)), or the ones it names (`Group.Levels`, #295). A member that doesn't follow the agent's effort is left out of that: one fixed at an effort, one whose levels nothing knows (#597), one that thinks with no levels, one the user made reasonless, and one known not to think (`Entry.Quiet`), which the gateway sends no reasoning ask (`withoutReasoningAsk`, [`quiet.go`](../../internal/gateway/quiet.go)). A quiet member used to empty the group's levels, so Codex got its entry with no `supported_reasoning_levels`, showed no effort control and ran at its own medium (#2127, `TestGroupQuietMemberKeepsCodexEffortControl`).- An agent whose config can't carry an effort has one picked in magpie (`provider.AgentEffort`, settings' `agentEfforts`; Cursor Private Inference's row, #1003). It is asked for on that agent's requests to a model that reasons (`Provider.Thinks`), in place of the level the request sent, fitted to the model's levels and bounded by the group's. Order: a member's fixed effort, then the effort the rule that put the member first sets (`Rule.UseEffort`), then a model's `:effort` suffix, then the turn's pick (a routing rule's), then the agent's pick, then the request's own. A model that doesn't reason is sent as asked; the default (none picked) leaves every request as it came. The pick beats the request's own because Cursor sends its own default as often as a real choice. Picking Default hands the choice back to Cursor.- In models.dev, entries from `deepseek`, `kimi-code-plan-cn` and `kimi-code-plan-global` gain `none` only when they have both a `toggle` and effort levels; the DeepSeek and Kimi APIs accepted that value in [#1098](https://github.com/yetone/magpie/issues/1098). Other providers keep their listed levels because their APIs may reject `none`; toggle-only entries remain level-less ([`mdModel.efforts`](../../internal/catalog/catalog.go)).diff --git a/internal/cli/groups_cli.go b/internal/cli/groups_cli.goindex 3503c04ad..c078db32d 100644--- a/internal/cli/groups_cli.go+++ b/internal/cli/groups_cli.go@@ -72,6 +72,8 @@ const groupUsage = `usage:or max — sent whatever the agent asks or effort=auto picks, at the level the model has nearest;without one it reasons as the group's effort says. The same model at two efforts is two members(a rule can send to either). A model whose own id ends so (a :free, :7b or :0) stays as it is+ provider/model:low+high gives it several levels for the agent to choose from, each sent at the+ level the model has nearest, and the group offers agents those for itprovider/model[:effort]:fast sends the member in its vendor's fast mode: priority processing on aChatGPT account (Codex's Fast) or an OpenAI key, Cursor's -fast model, Claude's fast mode on anAnthropic key for Opus 4.8 and 5; a model without one is refused (codex/gpt-6.1-sol:high:fast)@@ -918,7 +920,9 @@ func memberLabel(id string, names map[string]provider.Entry) (string, bool) {if n == "" {n = e.Model}- if effort != "" {+ if _, levels := provider.MemberLevels(effort); len(levels) > 0 {+ n += " · " + strings.Join(levels, "/") + " reasoning, as the agent picks"+ } else if effort != "" {n += " · " + effort + " reasoning, whatever the agent asks"}return e.Provider.Name + " · " + n, truediff --git a/internal/gateway/decide.go b/internal/gateway/decide.goindex cd6814358..04395f167 100644--- a/internal/gateway/decide.go+++ b/internal/gateway/decide.go@@ -769,15 +769,22 @@ func withFixedEffort(proto provider.Protocol, body []byte, effort string) []byte// groupLevels are the reasoning levels the group offers for the member a// candidate is of, where the user named them (Group.Levels, #295): the// group's own, else those of the outermost group in it that names some.-// nil when none is named. They bound what the candidate is asked for+// nil when none is named. A member given several levels of its own+// ("provider/model:low+high") is bounded by those instead. They bound what the candidate is asked for// (withinLevels): the agent, a model's suffix or the turn's pick asking// for a level the group doesn't offer is sent the nearest it does (#671).func groupLevels(g provider.Group, ms []provider.Member, c candidate) []string {+ if len(c.levels) > 0 {+ // the member's own (Member.Levels): the agent picked among the+ // group's, and this member is sent the nearest of those it was+ // given+ return c.levels+ }if len(g.Levels) > 0 {return g.Levels}for _, m := range ms {- if m.Provider.ID != c.p.ID || m.Model != c.model || m.Effort != c.effort {+ if m.Provider.ID != c.p.ID || m.Model != c.model || m.Effort != c.effort || !slices.Equal(m.Levels, c.levels) {continue}if i := slices.IndexFunc(m.Via, func(v provider.Group) bool { return len(v.Levels) > 0 }); i >= 0 {diff --git a/internal/gateway/fallback.go b/internal/gateway/fallback.goindex ae3720903..7b05fdff6 100644--- a/internal/gateway/fallback.go+++ b/internal/gateway/fallback.go@@ -43,6 +43,10 @@ type candidate struct {// effort is the reasoning the group's member it is of is fixed at// ("provider/model:low"); "" for one that follows the agent or the groupeffort string+ // levels are the reasoning levels the member follows the agent among+ // (Member.Levels, "provider/model:low+high"): what the agent asks is+ // sent at the nearest of them. nil for one fixed or following the group.+ levels []string// fast is set on a member the group sends in its vendor's fast mode// (Group.Fast); ultra on an agent's fast pick sent Ultrafast (#1954)fast, ultra bool@@ -112,7 +116,7 @@ func (c candidate) restKey() string {// seat is the candidate as one of a group's members has it: its key or// account, the model, and the effort the member is fixed at.func (c candidate) seat() string {- return provider.WithMemberEffort(c.rest+"/"+c.model, c.effort)+ return provider.WithMemberEffort(c.rest+"/"+c.model, cmp.Or(c.effort, strings.Join(c.levels, "+")))}func (c candidate) isOpenRouterFree() bool {@@ -502,7 +506,7 @@ func planLevel(g provider.Group, ms []provider.Member, depth int, from provider.// the same model at another effort is another member'sfor _, l := range [][]candidate{cs, aside, left, barred} {for i := range l {- l[i].effort, l[i].fast = m.Effort, m.Fast+ l[i].effort, l[i].levels, l[i].fast = m.Effort, m.Levels, m.Fastl[i].firstToken = innerFirstToken(m)l[i].patience = innerPatience(m)}diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.goindex 353c16ec7..377a46180 100644--- a/internal/gateway/gateway.go+++ b/internal/gateway/gateway.go@@ -1357,6 +1357,9 @@ func unprefixed(id string) string {func askedAt(id string) (string, string) {bare, marked := strings.CutSuffix(id, "[1m]")m, e := provider.MemberEffort(bare)+ if strings.Contains(e, "+") {+ return id, "" // a group's member at several levels, not one asked+ }if i := strings.LastIndex(bare, ":"); e == "" && i > 0 && strings.EqualFold(bare[i+1:], "off") {m, e = provider.MemberEffort(bare[:i] + ":none")}@@ -2813,7 +2816,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro// One the user fixed at an effort is left as it is: that is the// user saying this model does think, over a catalog that may be// wrong about it (the Trae plugin's own model, #950)- quiet := isGroup && c.effort == "" && quietTo(c.p.ID, c.model)+ quiet := isGroup && c.effort == "" && len(c.levels) == 0 && quietTo(c.p.ID, c.model)if provider.Reasonless(c.p.ID, c.model) {// a model the user said takes no reasoning ask is sent none,// in a group or not, at a fixed effort or not: not evendiff --git a/internal/gateway/groupeffort_test.go b/internal/gateway/groupeffort_test.goindex 46e454d28..d4005cfac 100644--- a/internal/gateway/groupeffort_test.go+++ b/internal/gateway/groupeffort_test.go@@ -300,3 +300,69 @@ func TestGroupUltra(t *testing.T) {t.Fatalf("group levels without an ultra %v", got)}}++// A member given several levels ("a/small:low+high", Garydesu on X)+// follows the agent among them: the agent's level when the member has it,+// else the nearest of them; no reasoning when the agent asks for none.+// The vendor is asked for the model's own id, and the group lists the+// member's levels as its own.+func TestMemberSeveralLevelsFollowAgent(t *testing.T) {+ s, a, _ := ruled(t)+ if err := provider.SetModelEfforts("a/small", []string{"low", "medium", "high", "xhigh"}); err != nil {+ t.Fatal(err)+ }+ setMembers(t, []string{"a/small:low+xhigh", "b/big"})+ for _, c := range []struct{ asked, want string }{+ {"low", "low"},+ {"xhigh", "xhigh"},+ {"high", "xhigh"}, // the nearest of the member's+ {"minimal", "low"},+ {"", ""}, // asked for no reasoning: none given+ } {+ extra := ""+ if c.asked != "" {+ extra = `,"reasoning_effort":"` + c.asked + `"`+ }+ out, r := postOK(t, s, "", chat("hi", nil, 0, extra))+ sent := sentBody(t, a)+ got, _ := sent["reasoning_effort"].(string)+ if !strings.Contains(out, "from ka") || sent["model"] != "small" || got != c.want {+ t.Fatalf("asked %q: sent %v (%s)", c.asked, sent, out)+ }+ if len(r.Tries) != 1 || r.Tries[0].Fixed != "" || r.Tries[0].Effort != c.want {+ t.Fatalf("asked %q: traced %+v", c.asked, r.Tries)+ }+ if r.Group == nil || r.Group.Members[0] != "a/small:low+xhigh" {+ t.Fatalf("group %+v", r.Group)+ }+ }+ // what agents are offered: the member's own levels, within those+ // b/big has in common with them+ if err := provider.SetModelEfforts("b/big", []string{"low", "medium", "high", "xhigh"}); err != nil {+ t.Fatal(err)+ }+ rec := httptest.NewRecorder()+ s.Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/v1/models", nil))+ var list struct {+ Data []struct {+ ID string `json:"id"`+ Levels []struct {+ Effort string `json:"effort"`+ } `json:"supported_reasoning_levels"`+ } `json:"data"`+ }+ if err := json.Unmarshal(rec.Body.Bytes(), &list); err != nil {+ t.Fatalf("%v: %s", err, rec.Body)+ }+ var got []string+ for _, m := range list.Data {+ if m.ID == "group/r" {+ for _, l := range m.Levels {+ got = append(got, l.Effort)+ }+ }+ }+ if !slices.Equal(got, []string{"low", "xhigh"}) {+ t.Fatalf("group offers %v, want low and xhigh", got)+ }+}diff --git a/internal/gateway/rules.go b/internal/gateway/rules.goindex 2352958a6..f91f05845 100644--- a/internal/gateway/rules.go+++ b/internal/gateway/rules.go@@ -819,7 +819,7 @@ func applyRule(hit *RuleHit, ms []provider.Member, cs []candidate, pl planned) (// effort.func ofMember(c candidate, m provider.Member) bool {id := m.Provider.ID- return c.model == m.Model && c.effort == m.Effort && (c.rest == id || strings.HasPrefix(c.rest, id+"#") || strings.HasPrefix(c.rest, id+"@"))+ return c.model == m.Model && c.effort == m.Effort && slices.Equal(c.levels, m.Levels) && (c.rest == id || strings.HasPrefix(c.rest, id+"#") || strings.HasPrefix(c.rest, id+"@"))}// membersImageInput is whether a group request may carry images: when adiff --git a/internal/gateway/trace.go b/internal/gateway/trace.goindex 92e339ea0..ae11d9aa7 100644--- a/internal/gateway/trace.go+++ b/internal/gateway/trace.go@@ -216,7 +216,7 @@ func groupRef(g provider.Group, ms []provider.Member) *GroupRef {ref := &GroupRef{ID: g.ID, Ref: g.Ref(), Name: g.Name, Routing: g.Routing, Affinity: g.Affinity, Auto: g.Auto, Sink: sinks(g.Sink, g.Routing)}seen := map[string]bool{}for _, m := range ms {- ref.Members = append(ref.Members, provider.WithMemberEffort(m.Provider.ID+"/"+m.Model, m.Effort))+ ref.Members = append(ref.Members, m.Spelled())if m.Fast {ref.Fast = append(ref.Fast, ref.Members[len(ref.Members)-1])}diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.jsindex 0ac46d30d..ee184cb40 100644--- a/internal/gui/assets/plugins/routing/client.js+++ b/internal/gui/assets/plugins/routing/client.js@@ -4777,13 +4777,17 @@ function routingPage(part) {}// a member may be a model at an effort of its own, "provider/model:low" —// unless the whole is a model's own id (a :free, a :7b); see- // provider.MemberEffort+ // provider.MemberEffort. Several levels joined by "+" ("…:low+high",+ // Garydesu on X) are those the agent picks among (provider.MemberLevels),+ // kept each once, lowest firstconst LEVELS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"]; // provider.MemberEffortsfunction splitMember(id) {id = id || "";if (id.startsWith("group/") || groups?.models.some((m) => m.id === id)) return [id, ""];- const m = /^(.+):(none|minimal|low|medium|high|xhigh|max)$/i.exec(id);- return m ? [m[1], m[2].toLowerCase()] : [id, ""];+ const m = /^(.+):((?:none|minimal|low|medium|high|xhigh|max)(?:\+(?:none|minimal|low|medium|high|xhigh|max))*)$/i.exec(id);+ if (!m) return [id, ""];+ const parts = m[2].toLowerCase().split("+");+ return [m[1], LEVELS.filter((v) => parts.includes(v)).join("+")];}// a decision model (Jev) is a member of a group of decision models only,// asked at /v1/systemone (provider/decide_group.go): it is in@@ -4831,7 +4835,7 @@ function routingPage(part) {// patterns matched when it was read — they are found again each timeconst namedOf = (g) => (g.members || []).filter((x) => !(g.matched || []).includes(x));const fixedOf = (id) => subOf(id) ? "" : splitMember(id)[1];- const fixedWords = (level) => t("{level} reasoning", { level });+ const fixedWords = (level) => t("{level} reasoning", { level: level.split("+").join(" / ") });// a routing group among a group's members: group/<id>const subOf = (id) => id?.startsWith("group/") ? groups?.groups.find((x) => "group/" + x.id === id && !x.hidden) : null;// a group's editor, its draft being the group as it is now. The group's own@@ -5822,25 +5826,48 @@ function routingPage(part) {// a decision model reasons at no level of the group's or its ownif (!s && !deciderOf(id)) {const [base, fixed] = splitMember(id);+ const several = fixed.includes("+");const fx = el("button", "rt-cond rt-fixed" + (fixed ? " on" : ""), fixed ? fixedWords(fixed) : t("Group's reasoning"));- fx.title = fixed ? t("Sent at {level} reasoning whatever the agent asks, at the model's nearest level", { level: fixed }) : t("Reasons as the group's effort says");+ fx.title = several ? t("The agent picks among {levels} reasoning, each sent at the model's nearest level", { levels: fixed.split("+").join(" / ") })+ : fixed ? t("Sent at {level} reasoning whatever the agent asks, at the model's nearest level", { level: fixed }) : t("Reasons as the group's effort says");const levels = m?.efforts?.length ? m.efforts.filter((v) => LEVELS.includes(v)) : LEVELS.filter((v) => v !== "none" && v !== "minimal");+ // the member under another id: its rules, fast, off, weight and+ // pick go with it+ const moveTo = (to) => {+ const from = d.members[i];+ if (to === from) return true;+ if (d.members.includes(to)) { status(t("{name} at that reasoning is in the group already", { name: memberName(from) }), "err"); return false; }+ d.members[i] = to;+ d.matched = d.matched.filter((x) => x !== from); // named now, at its own reasoning+ for (const r of d.rules) setUses(r, rUses(r).map((x) => x === from ? to : x));+ d.fast = d.fast.map((x) => x === from ? to : x);+ d.off = d.off.map((x) => x === from ? to : x);+ if (d.weights[from]) { d.weights[to] = d.weights[from]; delete d.weights[from]; }+ if (d.pick === from) d.pick = to;+ return true;+ };+ // several levels the agent picks among (provider.MemberLevels): a+ // menu that stays open, each level ticked or not; one left is a+ // fixed effort again, none follows the group+ const pickSeveral = (ev) => {+ let have = fixed ? fixed.split("+") : [];+ openPicker({ id: "", name: "", fields: [] }, { key: "rule", label: "reasoning", value: "", menu: true, multi: true,+ options: levels.map((v) => ({ value: v, label: v })), picked: (v) => have.includes(v), onPick: (v) => {+ const next = have.includes(v) ? have.filter((x) => x !== v) : LEVELS.filter((x) => x === v || have.includes(x));+ const at = next.join("+");+ if (!moveTo(at ? `${base}:${at}` : base)) return;+ have = next;+ draw(); drawRules();+ } }, fx, ev);+ };fx.onclick = (ev) => pickFrom("reasoning", fx, ev, [{ value: "", label: t("Follow the group"), note: t("as the group's effort says") },...levels.map((v) => ({ value: v, label: fixedWords(v), note: t("whatever the agent asks") })),+ ...(levels.length > 1 ? [{ value: "+", label: t("Several levels…"), note: t("the agent picks among them") }] : []),], (v) => {- const to = v ? `${base}:${v}` : base;- if (to === id) return;- if (d.members.includes(to)) { status(t("{name} at that reasoning is in the group already", { name: memberName(id) }), "err"); return; }- d.members[i] = to;- d.matched = d.matched.filter((x) => x !== id); // named now, at its own reasoning- for (const r of d.rules) setUses(r, rUses(r).map((x) => x === id ? to : x));- d.fast = d.fast.map((x) => x === id ? to : x);- d.off = d.off.map((x) => x === id ? to : x);- if (d.weights[id]) { d.weights[to] = d.weights[id]; delete d.weights[id]; }- if (d.pick === id) d.pick = to;- draw(); drawRules();- }, fixed);+ if (v === "+") { pickSeveral(ev); return; }+ if (moveTo(v ? `${base}:${v}` : base)) { draw(); drawRules(); }+ }, several ? "+" : fixed);row.append(fx);// its vendor's fast mode, where the model has one: priority// processing, Claude's fast mode (provider.CanFast)diff --git a/internal/gui/assets/plugins/routing/i18n.js b/internal/gui/assets/plugins/routing/i18n.jsindex e2acbb4cd..75011d0b8 100644--- a/internal/gui/assets/plugins/routing/i18n.js+++ b/internal/gui/assets/plugins/routing/i18n.js@@ -274,6 +274,9 @@ magpie.strings({"Sent at {level} reasoning whatever the agent asks, at the model's nearest level": "无论 Agent 要求什么,都以 {level} 推理强度发送(取模型最接近的档位)","Reasons as the group's effort says": "推理强度按分组的设置","Follow the group": "跟随分组",+ "Several levels…": "多个强度…",+ "the agent picks among them": "由 Agent 从中选择",+ "The agent picks among {levels} reasoning, each sent at the model's nearest level": "由 Agent 在 {levels} 推理强度中选择,各取模型最接近的档位","{name} at that reasoning is in the group already": "{name} 以这个推理强度已经在分组里了","Standard speed": "标准速度","Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "无论 Agent 要求什么,都以服务商的快速模式发送:更快,价格更高",@@ -848,6 +851,9 @@ magpie.strings({"Sent at {level} reasoning whatever the agent asks, at the model's nearest level": "無論 Agent 要求什麼,都以 {level} 推理強度傳送(取模型最接近的檔位)","Reasons as the group's effort says": "推理強度按分組的設定","Follow the group": "跟隨分組",+ "Several levels…": "多個強度…",+ "the agent picks among them": "由 Agent 從中選擇",+ "The agent picks among {levels} reasoning, each sent at the model's nearest level": "由 Agent 在 {levels} 推理強度中選擇,各取模型最接近的檔位","{name} at that reasoning is in the group already": "{name} 以這個推理強度已經在分組裡了","Standard speed": "標準速度","Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "無論 Agent 要求什麼,都以服務商的快速模式傳送:更快,價格更高",@@ -1420,6 +1426,9 @@ magpie.strings({"Sent at {level} reasoning whatever the agent asks, at the model's nearest level": "エージェントの指定にかかわらず {level} の推論で送ります(モデルの最も近いレベル)","Reasons as the group's effort says": "グループの推論レベルに従います","Follow the group": "グループに従う",+ "Several levels…": "複数のレベル…",+ "the agent picks among them": "エージェントがその中から選びます",+ "The agent picks among {levels} reasoning, each sent at the model's nearest level": "エージェントが {levels} の推論から選び、それぞれモデルの最も近いレベルで送ります","{name} at that reasoning is in the group already": "この推論レベルの {name} はすでにグループにあります","Standard speed": "標準速度","Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "エージェントの指定にかかわらず、ベンダーの高速モードで送ります。速くなりますが、料金は高くなります",@@ -1994,6 +2003,9 @@ magpie.strings({"Sent at {level} reasoning whatever the agent asks, at the model's nearest level": "Mit {level} Reasoning gesendet, egal was der Agent verlangt, auf der nächstgelegenen Stufe des Modells","Reasons as the group's effort says": "Reasoning gemäß Effort der Gruppe","Follow the group": "Der Gruppe folgen",+ "Several levels…": "Mehrere Stufen…",+ "the agent picks among them": "der Agent wählt daraus",+ "The agent picks among {levels} reasoning, each sent at the model's nearest level": "Der Agent wählt unter {levels} Reasoning, jeweils auf der nächstgelegenen Stufe des Modells gesendet","{name} at that reasoning is in the group already": "{name} mit diesem Reasoning ist bereits in der Gruppe","Standard speed": "Standardgeschwindigkeit","Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "Im Schnellmodus des Anbieters gesendet, egal was der Agent verlangt: schneller, zu höherem Preis",diff --git a/internal/gui/tests/group-member-levels.test.cjs b/internal/gui/tests/group-member-levels.test.cjsnew file mode 100644index 000000000..60c85c706--- /dev/null+++ b/internal/gui/tests/group-member-levels.test.cjs@@ -0,0 +1,191 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// A group's member may offer several reasoning levels for the agent to+// pick among (Garydesu on X: "能不能让路由组里的模型设置多个可选推理强度"),+// not only one fixed level or the group's. In the group editor the member's+// reasoning menu has "Several levels…", which opens a menu of the model's+// levels that stays open, each ticked or not. Ticking a second level beside+// a fixed one makes "provider/model:low+high"; the chip says the levels and+// its title that the agent picks; the member's fast setting follows its new+// id; one level left is a fixed effort again, none follows the group. A+// fixed level picked from the first menu still replaces the old one, as+// before. Nothing on the page moves. In every language, Chromium and+// WebKit, at a wide and a narrow window.+const assert = require("node:assert/strict");+const fs = require("node:fs/promises");+const path = require("node:path");+const { test } = require("node:test");+const { chromium, webkit } = require("playwright");++const assets = path.resolve(__dirname, "../assets");+const models = [+ { id: "oa/gpt-6.1-sol", name: "gpt-6.1-sol", providerName: "OpenAI", icon: "generic", efforts: ["low", "medium", "high", "xhigh"], canFast: true },+ { id: "rl/glm-5", name: "glm-5", providerName: "Relay", icon: "generic", efforts: ["low", "high"] },+];+const groups = (members) => ({+ models, pools: [],+ groups: [{ id: "sol", name: "Sol", members, fast: ["oa/gpt-6.1-sol:high"], routing: "order", ready: true,+ memberInfo: members.map((id) => ({ id, ready: true, fast: id === "oa/gpt-6.1-sol:high", canFast: id.startsWith("oa/") })) }],+});++const words = {+ en: { edit: "Edit", save: "Save", several: "Several levels…", follow: "Follow the group", one: "high reasoning", two: "low / high reasoning", three: "low / high / xhigh reasoning", ends: "low / xhigh reasoning", fixed: "medium reasoning",+ title: "The agent picks among low / high reasoning, each sent at the model's nearest level" },+ zh: { edit: "编辑", save: "保存", several: "多个强度…", follow: "跟随分组" },+ "zh-TW": { edit: "編輯", save: "儲存", several: "多個強度…", follow: "跟隨分組" },+ ja: { edit: "編集", save: "保存", several: "複数のレベル…", follow: "グループに従う" },+ de: { edit: "Bearbeiten", save: "Speichern", several: "Mehrere Stufen…", follow: "Der Gruppe folgen" },+};++function serve(lang, posts, members) {+ const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } };+ return async (r) => {+ const url = new URL(r.request().url());+ const json = (data) => r.fulfill({ json: data });+ if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });+ if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return json(state);+ if (url.pathname === "/api/plugins") return json({ plugins: [] });+ if (url.pathname === "/api/gateway/trace") {+ if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes+ return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });+ }+ if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });+ if (url.pathname === "/api/groups") return json(groups(members));+ if (url.pathname.startsWith("/api/groups/")) {+ posts.push({ path: url.pathname, body: JSON.parse(r.request().postData() || "{}") });+ return json(groups(members));+ }+ if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });+ if (url.pathname.startsWith("/api/")) return json({});+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];+ await r.fulfill({ body: await fs.readFile(file), contentType });+ };+}++async function open(engine, lang, width, members, t) {+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));+ const page = await (await browser.newContext({ viewport: { width, height: 1600 }, reducedMotion: "reduce" })).newPage();+ t.after(async () => {+ if (process.env.ARTIFACT_DIR) {+ await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });+ await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-group-member-levels.png`) });+ }+ await browser.close();+ });+ page.setDefaultTimeout(5000);+ const errors = [], posts = [];+ page.on("pageerror", (e) => errors.push(e.message));+ await page.route("**/*", serve(lang, posts, members));+ await page.goto("http://magpie.test/?view=routing");+ const card = page.locator(".rt-group", { hasText: "Sol" });+ await card.waitFor();+ return { page, card, errors, posts };+}++const keys = ["Several levels…", "the agent picks among them", "The agent picks among {levels} reasoning, each sent at the model's nearest level"];+const option = (page, text) => page.locator("#pop:not([hidden]) #list li:not(.group)", { has: page.locator(".v", { hasText: new RegExp("^" + text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "$") }) });++async function save(page, w) {+ const b = page.locator(".rt-gedit button.primary", { hasText: w.save });+ await b.scrollIntoViewIfNeeded();+ await b.click();+ await page.waitForFunction(() => !document.querySelector(".rt-gedit"));+}++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ for (const lang of Object.keys(words)) {+ for (const width of [1100, 420]) {+ const w = words[lang];+ test(`${engine} ${lang} ${width}px: a group's member offers several levels`, async (t) => {+ const { page, card, errors, posts } = await open(engine, lang, width, ["oa/gpt-6.1-sol:high", "rl/glm-5"], t);+ await card.locator("button", { hasText: w.edit }).click();+ const ed = page.locator(".rt-gedit");+ const row = (name) => ed.locator(".fbrow", { has: page.locator(".n", { hasText: name }) });+ const chip = () => row("gpt-6.1-sol").locator("button.rt-fixed:not(.rt-fast)");+ await chip().waitFor();+ const said = async () => (await chip().textContent()).trim();+ const one = await said();+ assert(one.includes("high"), `the chip says the fixed level: ${one}`);++ await chip().evaluate((x) => x.scrollIntoView({ block: "center" })); // by the test, as the reader would+ await page.waitForTimeout(200);+ const at = () => page.evaluate(() => [...document.querySelectorAll("*")].filter((e) => e.scrollTop && !e.closest("#pop")).map((e) => [e.id || e.className, e.scrollTop]).join(";") + "|" + Math.round(document.querySelector(".rt-gedit").getBoundingClientRect().top));+ const before = await at();++ // the first menu: follow the group, each level, and several+ await chip().click();+ await option(page, w.several).waitFor();+ assert.equal(await option(page, w.follow).count(), 1);+ await option(page, w.several).click();+ // the levels, the fixed one ticked; the menu stays open as each is picked+ await option(page, "low").waitFor();+ assert.deepEqual(await page.locator("#pop #list li:not(.group) .v").allTextContents(), ["low", "medium", "high", "xhigh"]);+ assert.match(await option(page, "high").getAttribute("class"), /\bcur\b/);+ assert.doesNotMatch(await option(page, "low").getAttribute("class"), /\bcur\b/);+ await option(page, "low").click();+ await page.waitForFunction(() => !document.querySelector("#pop").hidden);+ assert.match(await option(page, "low").getAttribute("class"), /\bcur\b/);+ assert.match(await option(page, "high").getAttribute("class"), /\bcur\b/);+ if (lang === "en") assert.equal(await said(), w.two);+ assert((await said()).includes("low / high"), `the chip says both levels: ${await said()}`);+ if (lang === "en") assert.equal(await chip().getAttribute("title"), w.title);+ await option(page, "xhigh").click();+ if (lang === "en") assert.equal(await said(), w.three);+ await option(page, "high").click();+ if (lang === "en") assert.equal(await said(), w.ends);+ assert((await said()).includes("low / xhigh"), `the chip says both levels: ${await said()}`);+ await page.keyboard.press("Escape");+ await page.waitForFunction(() => document.querySelector("#pop").hidden);+ assert.equal(await at(), before, "the picks moved nothing");++ // the first menu again has "several" as what it is now+ await chip().click();+ await option(page, w.several).waitFor();+ assert.match(await option(page, w.several).getAttribute("class"), /\bcur\b/);+ await page.keyboard.press("Escape");+ await page.waitForFunction(() => document.querySelector("#pop").hidden);++ // the chip fits the row at a narrow window, the page doesn't scroll sideways+ const fits = await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth);+ assert(fits, "no sideways scroll");++ const missing = await page.evaluate((keys) => keys.filter((k) => !I18N.zh[k] || !I18N["zh-TW"][k] || !I18N.ja[k] || !I18N.de[k]), keys);+ assert.deepEqual(missing, [], "every string has each language");++ await save(page, w);+ const sent = posts.find((p) => p.path === "/api/groups/save");+ assert.deepEqual(sent.body.members, ["oa/gpt-6.1-sol:low+xhigh", "rl/glm-5"]);+ assert.deepEqual(sent.body.fast, ["oa/gpt-6.1-sol:low+xhigh"], "fast follows the member");+ assert.deepEqual(errors, []);+ });+ }++ test(`${engine} ${lang}: several levels back to one, and one picked as before`, async (t) => {+ const w = words[lang];+ const { page, card, errors, posts } = await open(engine, lang, 1100, ["oa/gpt-6.1-sol:low+high", "rl/glm-5:high"], t);+ // the card says both levels+ assert((await card.locator(".mem").first().textContent()).includes("low / high"));+ await card.locator("button", { hasText: w.edit }).click();+ const ed = page.locator(".rt-gedit");+ const row = (name) => ed.locator(".fbrow", { has: page.locator(".n", { hasText: name }) });+ const chip = (name) => row(name).locator("button.rt-fixed:not(.rt-fast)");+ await chip("gpt-6.1-sol").waitFor();+ // one left is a fixed effort again+ await chip("gpt-6.1-sol").click();+ await option(page, w.several).click();+ await option(page, "low").click();+ await page.keyboard.press("Escape");+ assert((await chip("gpt-6.1-sol").textContent()).includes("high"));+ assert(!(await chip("gpt-6.1-sol").textContent()).includes("low"));+ // a fixed level picked from the first menu replaces the old one+ await chip("glm-5").click();+ await option(page, w.several).waitFor();+ await page.locator("#pop:not([hidden]) #list li:not(.group)").nth(1).click(); // low, the model's first+ await save(page, w);+ const sent = posts.find((p) => p.path === "/api/groups/save");+ assert.deepEqual(sent.body.members, ["oa/gpt-6.1-sol:high", "rl/glm-5:low"]);+ assert.deepEqual(errors, []);+ });+ }+}diff --git a/internal/provider/group.go b/internal/provider/group.goindex fd65c42e6..0fa2abae8 100644--- a/internal/provider/group.go+++ b/internal/provider/group.go@@ -287,6 +287,11 @@ type Member struct {// asked of the model whatever the agent or the group's classifier// asked; "" follows the group.Effort string+ // Levels are the reasoning levels the member follows the agent among+ // ("provider/model:low+high"), lowest first: the agent's effort is+ // sent at the nearest of them. nil for a member fixed at one (Effort)+ // or following the group.+ Levels []string// Fast is set on a member the group sends in its vendor's fast mode// (Group.Fast), where its model has one.Fast bool@@ -356,7 +361,7 @@ func (m Member) Groups() []string {// Below is the member as the group at depth (0 the group itself, 1 the// group in it Path[0] names, …) has it.func (m Member) Below(depth int) Member {- out := Member{ID: m.Path[depth], Path: m.Path[depth:], Via: m.Via[depth:], Provider: m.Provider, Model: m.Model, Effort: m.Effort, Fast: m.Fast, At: m.At}+ out := Member{ID: m.Path[depth], Path: m.Path[depth:], Via: m.Via[depth:], Provider: m.Provider, Model: m.Model, Effort: m.Effort, Levels: m.Levels, Fast: m.Fast, At: m.At}// its other places in the same group at depthfor _, o := range m.Also {if len(o.Path) > depth && slices.Equal(o.Path[:depth], m.Path[:depth]) {@@ -910,7 +915,8 @@ func membersOff(entries []Entry, all []Group, g Group, off func(pid, model strinif !ok || unpicked(find, p, m) {continue // none serves it, or the user unchecked it (#3911)}- mem := Member{ID: here[0], Path: here, Via: via, Provider: p, Model: m, Effort: effort, Fast: g.IsFast(id), At: at}+ fixed, levels := MemberLevels(effort)+ mem := Member{ID: here[0], Path: here, Via: via, Provider: p, Model: m, Effort: fixed, Levels: levels, Fast: g.IsFast(id), At: at}at++if i, ok := seen[key]; ok {// asked once, where it was met first; a rule naming this@@ -1084,9 +1090,13 @@ func buildGroupEntries(entries []Entry) []Entry {} else {e.ImageInput = anyImageInput(e.ImageInput, imageInput)}+ // a member the user gave several levels of its own offers them+ // (Garydesu on X: one model at a few efforts, the agent picking);// a group in the group that names its own levels offers them for// its models (the outermost that does)- if i := slices.IndexFunc(m.Via, func(v Group) bool { return len(v.Levels) > 0 }); i >= 0 {+ if len(m.Levels) > 0 && !reasonless {+ efforts = m.Levels+ } else if i := slices.IndexFunc(m.Via, func(v Group) bool { return len(v.Levels) > 0 }); i >= 0 {efforts = m.Via[i].Levels} else if reasonless {// the user said it takes no reasoning ask: the gateway sendsdiff --git a/internal/provider/groupeffort.go b/internal/provider/groupeffort.goindex 1ef8c2286..ac8fb21e7 100644--- a/internal/provider/groupeffort.go+++ b/internal/provider/groupeffort.go@@ -13,6 +13,13 @@ package provider// a group saved before reads the same, and a backup or a sync carries it// as any other member.//+// A member may instead carry several levels, joined by "+"+// ("provider/model:low+high", Garydesu on X): it follows the agent's+// effort, as a member without one does, but only among those levels — the+// group offers agents them for it (groupEntries), and a request asking+// for another is sent the nearest of them (Member.Levels). One level is a+// fixed effort as before, so a member saved before reads the same.+//// A model's own id may have a colon in it — OpenRouter's// "deepseek/deepseek-r1:free", Ollama's "qwen:7b", Bedrock's// "anthropic.claude-…-v1:0" — so only a last part that is a level's name@@ -20,6 +27,7 @@ package provider// provider has.import (+ "cmp""fmt""slices""strings"@@ -41,14 +49,15 @@ func MemberEffort(id string) (model, effort string) {}// memberEffortIn is MemberEffort with the catalog's entries read already-// (nil to read the providers' models as needed).+// (nil to read the providers' models as needed). Several levels come+// back as MemberLevels reads them: each once, lowest first, joined by "+".func memberEffortIn(entries []Entry, id string) (string, string) {i := strings.LastIndex(id, ":")if i <= 0 {return id, ""}- level := strings.ToLower(id[i+1:])- if !slices.Contains(MemberEfforts, level) {+ level := memberLevelsSpelled(id[i+1:])+ if level == "" {return id, "" // ":free", ":7b", ":0" — the model's own}if !strings.HasPrefix(id, GroupPrefix) && isModel(entries, id) {@@ -57,6 +66,35 @@ func memberEffortIn(entries []Entry, id string) (string, string) {return id[:i], level}+// memberLevelsSpelled is a member's effort suffix as it is kept: one+// level, or several joined by "+" each once, lowest first, lowercase; ""+// when a part isn't a level (the suffix is the model's own).+func memberLevelsSpelled(suffix string) string {+ parts := strings.Split(strings.ToLower(suffix), "+")+ for _, p := range parts {+ if !slices.Contains(MemberEfforts, p) {+ return ""+ }+ }+ return strings.Join(fixedLevels(parts), "+")+}++// MemberLevels splits the effort MemberEffort gives into the one a member+// is fixed at and the several the agent picks among (nil for one or none):+// "high" is fixed at high, "low+high" follows the agent among low and high.+func MemberLevels(effort string) (fixed string, levels []string) {+ if !strings.Contains(effort, "+") {+ return effort, nil+ }+ return "", strings.Split(effort, "+")+}++// Spelled is the member's model as the group names it: with the effort it+// is fixed at, or the levels it follows the agent among.+func (m Member) Spelled() string {+ return WithMemberEffort(m.Provider.ID+"/"+m.Model, cmp.Or(m.Effort, strings.Join(m.Levels, "+")))+}+// isModel reports whether id is a model a provider has as it is spelled,// colon and all: a catalog id, a model the user picked for its provider,// or one its provider lists.diff --git a/internal/provider/groupeffort_test.go b/internal/provider/groupeffort_test.goindex 7dc1a5d9e..cebdc8df7 100644--- a/internal/provider/groupeffort_test.go+++ b/internal/provider/groupeffort_test.go@@ -178,3 +178,67 @@ func TestMemberEffortLooksOncePerHold(t *testing.T) {t.Fatalf("not held: looked %d times, want 3", got)}}++// A member may carry several levels, joined by "+" (Garydesu on X: one+// model in a group at a few efforts, the agent picking): kept each once,+// lowest first, lowercase; read back as levels the member follows the+// agent among, not one it is fixed at; offered to agents as the group's+// levels for it; and one level alone is still a fixed effort, as a group+// saved before has it.+func TestMemberSeveralLevels(t *testing.T) {+ effortHome(t)+ for in, want := range map[string][2]string{+ "a/m:high+low": {"a/m", "low+high"},+ "a/m:HIGH+low+low": {"a/m", "low+high"},+ "a/m:low+low": {"a/m", "low"},+ "a/m:low+turbo": {"a/m:low+turbo", ""},+ "or/odd:high+max": {"or/odd", "high+max"},+ } {+ if m, e := MemberEffort(in); m != want[0] || e != want[1] {+ t.Errorf("MemberEffort(%q) = %q %q, want %q %q", in, m, e, want[0], want[1])+ }+ }+ if f, l := MemberLevels("low+high"); f != "" || !slices.Equal(l, []string{"low", "high"}) {+ t.Errorf("MemberLevels(low+high) = %q %v", f, l)+ }+ if f, l := MemberLevels("high"); f != "high" || l != nil {+ t.Errorf("MemberLevels(high) = %q %v", f, l)+ }+ if err := SetModelEfforts("a/m", []string{"low", "medium", "high", "xhigh"}); err != nil {+ t.Fatal(err)+ }+ if err := SaveGroup(Group{Name: "Pick", Members: []string{"a/m:XHIGH+low", "a/n:medium"}, Rules: []Rule{{Use: "a/m:low+xhigh", Tokens: 10}}}); err != nil {+ t.Fatal(err)+ }+ g, ms, ok := FindGroup("group/pick")+ if !ok {+ t.Fatal("no group")+ }+ if want := []string{"a/m:low+xhigh", "a/n:medium"}; !slices.Equal(g.Members, want) {+ t.Fatalf("members %v, want %v", g.Members, want)+ }+ if ms[0].Effort != "" || !slices.Equal(ms[0].Levels, []string{"low", "xhigh"}) || ms[0].Spelled() != "a/m:low+xhigh" {+ t.Fatalf("member %+v", ms[0])+ }+ if ms[1].Effort != "medium" || ms[1].Levels != nil || ms[1].Spelled() != "a/n:medium" {+ t.Fatalf("fixed member %+v", ms[1])+ }+ i := slices.IndexFunc(Catalog(), func(e Entry) bool { return e.ID == "group/pick" })+ if i < 0 {+ t.Fatal("not listed")+ }+ if got := Catalog()[i].Efforts; !slices.Equal(got, []string{"low", "xhigh"}) {+ t.Fatalf("offered %v, want the member's own low and xhigh", got)+ }+ // beside a member that follows the agent, the group offers what both have+ if err := SetModelEfforts("a/n", []string{"low", "medium", "high"}); err != nil {+ t.Fatal(err)+ }+ if err := SaveGroup(Group{Name: "Shared", Members: []string{"a/m:low+xhigh", "a/n"}}); err != nil {+ t.Fatal(err)+ }+ i = slices.IndexFunc(Catalog(), func(e Entry) bool { return e.ID == "group/shared" })+ if got := Catalog()[i].Efforts; !slices.Equal(got, []string{"low"}) {+ t.Fatalf("shared %v, want low", got)+ }+}diff --git a/internal/provider/grouprule.go b/internal/provider/grouprule.goindex 406f51a88..6660e8173 100644--- a/internal/provider/grouprule.go+++ b/internal/provider/grouprule.go@@ -755,7 +755,7 @@ func PausedOut(g Group, ms []Member, agent, folder string, at time.Time) (kept [}for i, r := range by.Rules {if d < len(m.Path) && pathNames(m.Path[d:], r.Use) && r.Pauses(agent, folder, at) {- hit = &Paused{Member: WithMemberEffort(m.Provider.ID+"/"+m.Model, m.Effort), Group: in, Rule: i + 1, Use: r.Use, When: r.Conditions(), ByFolder: r.ByFolder()}+ hit = &Paused{Member: m.Spelled(), Group: in, Rule: i + 1, Use: r.Use, When: r.Conditions(), ByFolder: r.ByFolder()}if r.ByFolder() {hit.Folder = folder}