Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
effort: a vendor's light and extra_high are low and xhigh, in dsh, Pi and the gateway
yetonef6ed2c99bc1a
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.mdindex af9d383b3..9779787d9 100644--- a/docs/subsystems/gateway-routing.md+++ b/docs/subsystems/gateway-routing.md@@ -155,6 +155,7 @@ recorded as a prediction failure (`noPrediction`).- Desktop's subagent effort (`settings.DesktopSubagentEffort`, `desktopSubagentEffort` in [`desktop_subagent.go`](../../internal/gateway/desktop_subagent.go)) applies to the same subagent tool turns, independently of model replacement. Empty leaves requests unchanged. Set, it takes the place of a request model's effort suffix before the existing attempt-level effort fitting: a member fixed at an effort wins, then this pick fitted within group/model levels, then the turn's or request's effort. `withFixedEffort` can enable reasoning when it was disabled, or disable it with `none` on a model that supports that level; a reasonless model is still sent no reasoning fields. `countTokens` applies the pick after restoring any unmasked body. `Route.Effort` keeps the incoming effort, `Route.SubagentEffort` the configured pick, and each try and usage record the level actually sent; the Routing story explains the configured pick even when no model was replaced. A nonempty model pick already classifies the turn, so the effort check reuses it; empty effort costs only a held-settings read. The next request takes a changed or cleared effort without a Desktop restart.- Every Claude Code subagent's turn, Desktop's or a terminal's, moved or not, keeps its `x-claude-code-agent-id` in `Route.SubagentID` (`subagentTurnOf` in [`desktop_subagent.go`](../../internal/gateway/desktop_subagent.go)): a request with the id that offers tools and names no kind, the turn the two settings above take. Claude Code 2.1.295 sends the id from any agent context but the main one; its `x-claude-code-request-class` and `x-claude-code-agent-type` hints go only to a first-party base URL or with `CLAUDE_CODE_GATEWAY_HINT_HEADERS`, so magpie doesn't get them. A Desktop pick or effort that found the turn is trusted, so the body isn't decoded again, and a request without the id isn't decoded at all. The Routing page tags it as Codex's subagents are (`tagKind` in [`routing.js`](../../internal/gui/assets/routing.js)): in the request list, the story, the replay and the tray panel, with the reason `kindWhy` gives Codex's. `Kind` stays empty, so its purpose stays unmarked in the Purpose filter, as in the ledger and on the Usage page. The ledger's `Subagent` keeps the same id, and also marks a subagent's tool-less helper calls, which aren't tagged. A route recorded before this has no id and no tag.- A Chat or Responses client's effort spelled `off` (`reasoning_effort`, or `reasoning.effort`, any case) is read at the top of `serve` as magpie's own off level, `none` (`offAsNone`, plugins#334), and a model asked `<model>:off` as `<model>:none` (`askedAt`): every check and route below reads `none`, a model with an off level is sent its own spelling of it, and one without goes at its least level as `none` asked does (`fitEffort`). `off` itself is never sent on. `saysOff` looks for it without parsing the body, which only a body naming it pays for.+ - A level a vendor names in words of its own (`catalog.EffortAliases`: Trae's `light` and `extra_high`, which Our Free Model's plugin lists) is the level it is (`EffortLevel`): `effortOf` reads it as `low` or `xhigh`, and `NearestEffort` places a model's own words by it, so `low` asked of a model listing `light` is sent as `light`, and its `light` as it is (nianshou5 on Discord; `TestNearestEffortTakesVendorWords`, `TestPluginThinkingOff`). dsh and Pi offer such a model's levels as theirs, sent in its words (`modelEffort` in [`agents.go`](../../internal/agent/agents.go); `TestDshOffersTraeNamedLevels`).- Rules and image inputs are handled here too.- A rule is decided as a user's turn begins and held for the rest of it (`ruleFor`, [`rules.go`](../../internal/gateway/rules.go)). What counts as the user's own words is one helper, `userWords`/`userSaid` in [`prompt.go`](../../internal/gateway/prompt.go), which the turn count (`turnIn`), the classifier's question (`userText`), the conversation's key (`firstWords`, in `ruleKey` and the affinity scope), Copilot's Auto (`lastUserText`) and the prompt breakdown's turns (`userSays`) all go by. It drops `<system-reminder …>` blocks (a `source=` attribute too) and any text that begins as an agent writes for the model alone: Codex's `<environment_context>`, `<user_instructions>`, `<turn_aborted>`, `<user_shell_command>`, `<subagent_notification>` and `# AGENTS.md instructions for …`; Claude Code's and ZCode's `<task-notification>`, `<subagent-notification>`, agent lists ("Available agent types …", "New agent types are now available …"), TodoWrite and task-tool nudges and rewind notices; ZCode's `<plugin_reference>`; the Codex app's `<in-app-browser-context …>`. The Codex app's context before `## My request (for Codex):` is dropped and what follows it kept (the `injected` list beside `agentsFor`). A user message with nothing of the user's in it (and no image or file) begins no turn: after an answer or a tool round it carries the turn on (`within`), so the turn's rule and stick hold and the classifier isn't asked; right after the user's words it leaves their turn as it began. The classifier is asked about the last user message that has words of the user's, only those words (`userText`: past 4000 runes, its first 3000 and last 1000). It is told what came before it too (`turnBefore`, @HirotaNagai on X: a short follow-up said alone, 继续 or fix that, came out the hardest kind): the user's message before it, the same way and cut to 1000 runes (`priorCap`: the first 750 and the last 250), and the assistant's last reply between the two, its text parts alone and their last 1000 runes. A tool call's arguments, a tool's result, thinking, a search's hits and the system prompt are never in either, and a reply of only tool calls is none. Jev gets them in its `state` as `previous_user_message` and `previous_assistant_reply` beside `message`, `previous_message_kind` and `previous_message_reasoning`, each only when there is one, and its intent, level and effort instructions name the ones there are (`jevState`, `priorAsk` in [`decide.go`](../../internal/gateway/decide.go)); a classifier asked in words gets them in `<previous_user_message>` and `<previous_assistant_reply>` before `<message>` (`writePrior`). Both come from the request the rules parsed, so Privacy masks them as it masks the message, and the answer kept for a message is kept for it with what came before (`classify`'s key). `TestTurnBeforeEachProtocol`, `TestTurnBeforeCuts`, `TestJevIsToldWhatCameBefore`, `TestChatClassifierIsToldWhatCameBefore`, `TestClassifyKeepsAnAnswerPerTurnBefore`, `TestJevSeesTheTurnBefore`. `firstWords` hashes the words of the first user message that has any, so an instruction file or notice the agent changes beside them doesn't move the conversation to a new key and lose its stick mid-turn (#1826: ZCode's TodoWrite nudge classified as a new, harder turn, and three keys for one ZCode session). `TestTurnInSkipsWhatTheAgentPutIn`, `TestUserTextSkipsWhatTheAgentPutIn`, `TestFirstWordsAreWhatTheUserSaid`, `TestIntentHoldsPastWhatTheAgentPutIn`.- A rule's members go first (`ruleOver`, `applyRule`): the members it names, in order, then those the matching rules after it name (`ruleOrder`), each not resting, then the group's others to fail over to. A member that is a group in the group is one member here: its models keep the order the group's own routing planned them, where ranking each by the group's listed order pinned a rotate group's first member on every request the rule put it first (#2407, `TestRuleNamingARotateGroupKeepsItsTurns`). That holds within the turn too, at the group's rule and at each nested group's (`nestedRules`): the one the turn stays on (affinity) stays first while it is of the rule's member that goes first, and the member's others follow it ahead of the group's others, so a failure fails over within the member the rule chose before going outside it. One the turn was kept on outside that member, which took over when the member failed, isn't held there: once one of the member is out of its rest, the turn's next request goes back to it (`Affinity.Why` `rule`). Before #1946 (XcodeFish) a held rule's order wasn't applied to a kept turn at all: a coding-quality member failing mid-turn failed over to coding-fast, the parent's first, and the turn stayed there. `TestHeldRuleFailsOverWithinItsMember`. Two groups in the group may share a model (the same provider, model and effort): it is asked once a request, where the walk met it first, and `provider.Member.Also` keeps its later places, each with its own path, `At` (its place in the walk) and Fast. A rule naming the later group has the model as that group does (`Member.In`, `membersNamed`), in that group's own order, and the nested rules below it, Fast and the first token's wait go by that group's way down (`homed`, `homeCands`). Before #2361 (davisjiahao) such a rule found none of the shared models, read unready, and the group ahead of it answered. A pause rule naming the later group still leaves a shared model to the group ahead of it. `rule_shared_test.go`.diff --git a/internal/agent/agents.go b/internal/agent/agents.goindex 03f2558c4..d9d8ef314 100644--- a/internal/agent/agents.go+++ b/internal/agent/agents.go@@ -777,11 +777,32 @@ func (o orderedJSON) MarshalJSON() ([]byte, error) {return append(b, '}'), nil}+// modelEffort is the model's own name for level, one of pi-ai's (none for+// its off): level itself when efforts name it, else the one of efforts+// that names it in a vendor's words (catalog.EffortAliases: Trae's light+// and extra_high, as Our Free Model's plugin lists them), "" when it takes+// none such. dsh and Pi offered only the levels named in pi-ai's words, so+// such a model's light, high and extra_high showed in dsh as high alone+// (nianshou5 on Discord). The name returned is what the agent sends, so+// the vendor gets the level in the words it listed.+func modelEffort(efforts []string, level string) string {+ if slices.Contains(efforts, level) {+ return level+ }+ for _, e := range efforts {+ if catalog.EffortLevel(e) == level {+ return e+ }+ }+ return ""+}+// piThinkingLevels is the thinkingLevelMap for a model's efforts: every one// of Pi's levels (piLevels, pi-ai's EXTENDED_THINKING_LEVELS), the model's-// own mapped to themselves and the others null. Pi builds /thinking from-// the map (getSupportedThinkingLevels): a level set to null is hidden and-// skipped, while one left out is offered (all but xhigh and max), so a map+// own mapped to its name for it (modelEffort) and the others null. Pi+// builds /thinking from the map (getSupportedThinkingLevels): a level set+// to null is hidden and skipped, while one left out is offered (all but+// xhigh and max), so a map// naming only max had Pi offer minimal and medium too, which the vendor// turned away (#243). Pi's off is the model's none when it takes one. A// model without none has off hidden — Pi's off asks a Responses model for@@ -799,11 +820,11 @@ func piThinkingLevels(efforts []string, claudeOff bool) map[string]any {}levels := map[string]any{}for _, l := range piLevels {- e := l+ w := lif l == "off" {- e = "none"+ w = "none"}- if slices.Contains(efforts, e) {+ if e := modelEffort(efforts, w); e != "" {levels[l] = e} else {levels[l] = nildiff --git a/internal/agent/dsh.go b/internal/agent/dsh.goindex 0e775c291..e77551d29 100644--- a/internal/agent/dsh.go+++ b/internal/agent/dsh.go@@ -1461,16 +1461,19 @@ type dshPiLevels struct {var dshThinking = []string{"off", "minimal", "low", "medium", "high", "xhigh", "max"}// dshModelLevels are the levels of dsh's a catalog model takes, each with-// the effort sent for it: its own, and off for its none.+// the effort sent for it: the model's own name for it (modelEffort), so a+// plugin's light and extra_high are dsh's low and xhigh and are sent as+// light and extra_high, and off for its none.func dshModelLevels(efforts []string) ([]string, *dshPiLevels) {var levels []stringvar out dshPiLevelsfor _, l := range dshThinking {- e := l+ w := lif l == "off" {- e = "none"+ w = "none"}- if !contains(efforts, e) {+ e := modelEffort(efforts, w)+ if e == "" {continue}levels = append(levels, l)diff --git a/internal/agent/dsh_effort_alias_test.go b/internal/agent/dsh_effort_alias_test.gonew file mode 100644index 000000000..f14fc5929--- /dev/null+++ b/internal/agent/dsh_effort_alias_test.go@@ -0,0 +1,47 @@+package agent++import (+ "slices"+ "testing"++ "github.com/yetone/magpie/internal/catalog"+)++// TestDshOffersTraeNamedLevels: Our Free Model's plugin lists Trae's+// DeepSeek V4.1 Flash with the levels Trae names, light, high and+// extra_high (its 轻, 高 and 极高). dsh offered high alone, since only+// levels named in pi-ai's words were written (nianshou5 on Discord). Each+// is now offered as the level of dsh's it is, and sent in the model's own+// words; Pi's thinkingLevelMap is built the same way.+func TestDshOffersTraeNamedLevels(t *testing.T) {+ m := catalog.Model{ID: "our-free-model/trae/deepseek-v4.1-flash", Context: 1000000, Output: 64000, Efforts: []string{"light", "high", "extra_high"}}+ levels, got := dshModelLevels(m.Efforts)+ if want := []string{"low", "high", "xhigh"}; !slices.Equal(levels, want) {+ t.Fatalf("dsh levels %v, want %v", levels, want)+ }+ if want := (dshPiLevels{Low: "light", High: "high", XHigh: "extra_high"}); got == nil || *got != want {+ t.Fatalf("dsh reasoningEfforts %+v, want %+v", got, want)+ }+ if e := dshKindConfig(dshKinds[0], []catalog.Model{m}, "", "http://127.0.0.1:3425").Models[0].ReasoningEfforts; e == nil || e.XHigh != "extra_high" || e.Low != "light" {+ t.Fatalf("route entry's reasoningEfforts %+v", e)+ }++ pi := piThinkingLevels(m.Efforts, false)+ for l, want := range map[string]any{"low": "light", "high": "high", "xhigh": "extra_high", "medium": nil, "max": nil, "off": nil, "minimal": nil} {+ if pi[l] != want {+ t.Errorf("Pi's %s = %v, want %v", l, pi[l], want)+ }+ }++ // a model naming pi-ai's own levels is as before, and one naming both+ // spellings is sent its own pi-ai name+ if _, std := dshModelLevels([]string{"none", "low", "high", "max"}); std == nil || *std != (dshPiLevels{Off: "none", Low: "low", High: "high", Max: "max"}) {+ t.Errorf("standard levels %+v", std)+ }+ if e := modelEffort([]string{"light", "low"}, "low"); e != "low" {+ t.Errorf("low with light beside it = %q, want low", e)+ }+ if e := modelEffort([]string{"high"}, "low"); e != "" {+ t.Errorf("a level the model doesn't take = %q, want none", e)+ }+}diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.goindex d003083bb..17070c7ff 100644--- a/internal/catalog/catalog.go+++ b/internal/catalog/catalog.go@@ -1824,21 +1824,37 @@ func MagpieAdded(etag, slug, description string) bool {// first.var EffortRank = []string{"none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"}+// EffortAliases are levels some vendors name in words of their own, each+// with the level of EffortRank's it is: Trae's light and extra_high (its 轻+// and 极高), which a plugin serving Trae's models (Our Free Model's) lists+// as they are (nianshou5 on Discord).+var EffortAliases = map[string]string{"light": "low", "extra_high": "xhigh"}++// EffortLevel is the level of EffortRank's that e names: e itself, or the+// one a vendor's word for it is (EffortAliases).+func EffortLevel(e string) string {+ if l, ok := EffortAliases[strings.ToLower(e)]; ok {+ return l+ }+ return e+}+// NearestEffort is the level of levels nearest want in EffortRank's order,// a tie going up, never "none" unless it is want; want itself when levels// are none, hold it, or want is no level EffortRank knows. The gateway// fits an effort to a model's levels by it on the way out (fitEffort), and// Codex's catalog gives a model the effort set for new sessions by it// (codexcat.ModelDefault), so the level a model starts at is the one it-// would be sent at.+// would be sent at. A level is placed by the one it names (EffortLevel),+// so low is a model's light, and a model's levels go in its own words.func NearestEffort(want string, levels []string) string {- at := slices.Index(EffortRank, want)+ at := slices.Index(EffortRank, EffortLevel(want))if len(levels) == 0 || at < 0 || slices.Contains(levels, want) {return want}best, dist := want, len(EffortRank)for _, l := range levels {- i := slices.Index(EffortRank, l)+ i := slices.Index(EffortRank, EffortLevel(l))if i < 0 || l == "none" {continue}diff --git a/internal/catalog/effort_alias_test.go b/internal/catalog/effort_alias_test.gonew file mode 100644index 000000000..761e39c6f--- /dev/null+++ b/internal/catalog/effort_alias_test.go@@ -0,0 +1,32 @@+package catalog++import "testing"++// TestNearestEffortTakesVendorWords: a model listing Trae's light, high and+// extra_high (Our Free Model's plugin, nianshou5) is asked low as light and+// xhigh as extra_high, in its own words, and its light as it is; a model in+// EffortRank's words is fitted as before.+func TestNearestEffortTakesVendorWords(t *testing.T) {+ trae := []string{"light", "high", "extra_high"}+ for _, tc := range []struct {+ want string+ levels []string+ got string+ }{+ {"low", trae, "light"},+ {"light", trae, "light"},+ {"minimal", trae, "light"},+ {"medium", trae, "high"},+ {"xhigh", trae, "extra_high"},+ {"extra_high", trae, "extra_high"},+ {"max", trae, "extra_high"},+ {"light", []string{"low", "high"}, "low"},+ {"extra_high", []string{"low", "high", "max"}, "max"},+ {"low", []string{"low", "high"}, "low"},+ {"medium", []string{"low", "high", "max"}, "high"},+ } {+ if got := NearestEffort(tc.want, tc.levels); got != tc.got {+ t.Errorf("NearestEffort(%q, %v) = %q, want %q", tc.want, tc.levels, got, tc.got)+ }+ }+}diff --git a/internal/gateway/ir.go b/internal/gateway/ir.goindex 2909c4fce..f25f362ac 100644--- a/internal/gateway/ir.go+++ b/internal/gateway/ir.go@@ -818,6 +818,12 @@ func effortOf(s string) string {case "ultra": // Codex's max, with its own agents to hand work toreturn "max"}+ // a vendor's own word for a level (Trae's light, extra_high), which+ // an agent sends for a model listing it; fitted back to the model's+ // own word on the way out (fitEffort)+ if l, ok := catalog.EffortAliases[strings.ToLower(strings.TrimSpace(s))]; ok {+ return l+ }return ""}diff --git a/internal/gateway/plugin_think_off_test.go b/internal/gateway/plugin_think_off_test.goindex f5f3da0f5..7aad263af 100644--- a/internal/gateway/plugin_think_off_test.go+++ b/internal/gateway/plugin_think_off_test.go@@ -44,6 +44,15 @@ func TestPluginThinkingOff(t *testing.T) {{"suffix off", "/v1/chat/completions", `{"model":"` + pid + `/fake-off:off","messages":[{"role":"user","content":"hi"}]}`, "none"},{"no off, off", "/v1/chat/completions", `{"model":"` + pid + `/fake-on","reasoning_effort":"off","messages":[{"role":"user","content":"hi"}]}`, "low"},{"no off", "/v1/responses", `{"model":"` + pid + `/fake-on","reasoning":{"effort":"none"},"input":[{"role":"user","content":"hi"}]}`, "low"},+ // a level in the vendor's own words, as dsh and Pi send it for+ // their low and xhigh (modelEffort in internal/agent), reaches+ // the plugin as it is (nianshou5)+ {"chat light", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"light","messages":[{"role":"user","content":"hi"}]}`, "light"},+ {"chat extra_high", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"extra_high","messages":[{"role":"user","content":"hi"}]}`, "extra_high"},+ // and an agent's low and xhigh are sent in the model's words+ {"chat low as light", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}`, "light"},+ {"chat xhigh as extra_high", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"xhigh","messages":[{"role":"user","content":"hi"}]}`, "extra_high"},+ {"responses extra_high", "/v1/responses", `{"model":"` + pid + `/fake-trae","reasoning":{"effort":"extra_high"},"input":[{"role":"user","content":"hi"}]}`, "extra_high"},} {t.Run(tt.name, func(t *testing.T) {mu.Lock()diff --git a/internal/plugin/testdata/fake/index.js b/internal/plugin/testdata/fake/index.jsindex 3796dda35..24a645de2 100644--- a/internal/plugin/testdata/fake/index.js+++ b/internal/plugin/testdata/fake/index.js@@ -142,6 +142,8 @@ export const FakePlugin = async ({ client }) => ({const levels = (l) => Object.fromEntries(l.map((e) => [e, { reasoningEffort: e }]))cfg.provider[ID].models["fake-off"] = { name: "Fake Off", reasoning: true, variants: levels(["none", "low", "high", "max"]), limit: { context: 1000, output: 100 } }cfg.provider[ID].models["fake-on"] = { name: "Fake On", reasoning: true, variants: levels(["low", "high", "max"]), limit: { context: 1000, output: 100 } }+ // Trae's levels as Our Free Model's plugin lists them (nianshou5)+ cfg.provider[ID].models["fake-trae"] = { name: "Fake Trae", reasoning: true, variants: levels(["light", "high", "extra_high"]), limit: { context: 1000, output: 100 } }}// $FAKE_ZEN: a model as opencode-zen-free 0.1.3's config hook writes// it, from models.opencode.ai on 2026-10-11 (#1595, tkhs101): it