Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

dsh: Max reaches GLM-5.3 as max, asked adaptively with its level

yetone3b5a2f612d59
diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md
index 0e5b2af87..103b9a7ad 100644
--- a/docs/subsystems/agent-wiring.md
+++ b/docs/subsystems/agent-wiring.md
@@ -58,7 +58,7 @@ something else shows up as drift.
- Each model magpie writes into ZCode's `providerModelRules` has native web search (`properties.supportsNativeWebSearch`, "原生联网搜索") on while the provider's format is Anthropic Messages, the only format ZCode sends it on (`zcodeWebSearch`). The models magpie turned it on for are kept in the stash under `zcode.web_search`, so a model the user unticked in ZCode (which takes the key out of the rule) stays off, a value in the rule stays, a manual rule is left alone, and a stash that can't be read turns nothing on. On another format magpie's own on is taken out. Disconnect forgets the list.
- The YAML ones go through `yamlKept` and `mergeKept` in [`sync.go`](../../internal/agent/sync.go). Each is tested by a `Test<Agent>KeepsTheUsersSettings`.
- Copilot in JetBrains IDEs keeps its Bring Your Own Key providers in the Copilot language server's `byok.json`, shared with Xcode's and Eclipse's Copilot (`copilotJetBrains` in [`copilotjetbrains.go`](../../internal/agent/copilotjetbrains.go)). magpie writes its own three keys there, `magpie-provider-config`, `magpie-api-key` and `magpie-models-config`, in the bytes the server itself writes, and only when they differ; the user's providers and keys stay. A magpie model the user hid in Manage Models (`isRegistered: false`) stays hidden through a sync. A new file is made 0600 in a 0700 folder, as the server makes it.
-- dsh (DeepSeek Harness) sets one API per llm-pi-ai route, so magpie writes a route per protocol (`dshKinds` in [`dsh.go`](../../internal/agent/dsh.go); 01huadalang on Discord): `magpie` (Chat Completions) for most models, `magpie-responses` (`openai-responses`) for a model served on Responses, `magpie-anthropic` (`anthropic-messages`, the gateway root, `forceAdaptiveThinking` where `AdaptiveThinking`) for one served on Messages, by the model's `APIs` (`dshRouteOf`). A model's `APIs` is the one its provider serves it on best (`Provider.Native`, in `magpieModels`, [`route.go`](../../internal/agent/route.go)), and Pi, omp and droid read it the same way. A routing group has `responses` when every member is best on Responses (`allResponses`, #1594), so its tool-call arguments are relayed as they stream; any other group has none and stays on Chat, a Messages-only group too, as a Claude member's thinking is known by its own model. A route with no models is taken out. An api the user picked for a route in dsh's Models page is kept, and so are keys they added there. The start (`agent-default-model`) names its model's route, and Sync moves a start on one of magpie's routes to the route its model is now on (`dshStartOnItsRoute`), its effort and marks kept. Check asks the route the start names to list its model. A dsh session resumed on a model that has since moved routes asks for the model to be picked again, since dsh finds a model by route and id.
+- dsh (DeepSeek Harness) sets one API per llm-pi-ai route, so magpie writes a route per protocol (`dshKinds` in [`dsh.go`](../../internal/agent/dsh.go); 01huadalang on Discord): `magpie` (Chat Completions) for most models, `magpie-responses` (`openai-responses`) for a model served on Responses, `magpie-anthropic` (`anthropic-messages`, the gateway root, `forceAdaptiveThinking` where `AdaptiveThinking` or `AdaptiveWithEffort`, so Max reaches GLM-5.3 as max) for one served on Messages, by the model's `APIs` (`dshRouteOf`). A model's `APIs` is the one its provider serves it on best (`Provider.Native`, in `magpieModels`, [`route.go`](../../internal/agent/route.go)), and Pi, omp and droid read it the same way. A routing group has `responses` when every member is best on Responses (`allResponses`, #1594), so its tool-call arguments are relayed as they stream; any other group has none and stays on Chat, a Messages-only group too, as a Claude member's thinking is known by its own model. A route with no models is taken out. An api the user picked for a route in dsh's Models page is kept, and so are keys they added there. The start (`agent-default-model`) names its model's route, and Sync moves a start on one of magpie's routes to the route its model is now on (`dshStartOnItsRoute`), its effort and marks kept. Check asks the route the start names to list its model. A dsh session resumed on a model that has since moved routes asks for the model to be picked again, since dsh finds a model by route and id.
- dsh takes a model's listed `maxTokens` as every request's output and reserves it, with 65536 of headroom, out of `contextWindow` before deciding when to compact (compaction-basic's `resolveCompactSpec`: the smaller of 80% of the window and window − maxTokens − 65536). A vendor's reply limit near its window had dsh compact at 41248 of a 500000 group (#2823) or fail with no budget (524288/524288, LoKi on Discord; 131072/65536), so magpie lists it held to what leaves dsh half the window to compact in (window/2 − 65536), or to a quarter of the window where that is more (every window under 262144, as VS Code and Copilot in JetBrains hold it), on every route and in the older `llm-deepseek` entry (`dshMaxTokens`). A quarter alone cut DeepSeek's 393216 on its 1000000 window to 250000 (#3298); now it keeps all of it and dsh compacts at 541248, while 500000/393216 is held to 184464 and compacts at 250000. A Max output the user set stays as they set it (`outputOr`), even one that leaves dsh no budget. `TestDshOutputLeavesCompactionRoom`.
- While magpie serves, `KeepDshWired` writes the routes again every 30 seconds, since dsh writes over its patch list. A round that writes nothing is kept (`dshRounds`), and the next round does nothing when nothing it reads has changed since. It checks the bytes of dsh's files (every profile's `cordis.patch.yml`, the home layer, `settings.yaml`, `.env`, `.credentials.yaml`, `config.yaml`) and the gateway's address. It also checks `provider.StampNow`: no Changed, plugin change or `filememo.Forget`, the same environment, and the providers', settings' and catalog's files unchanged. The models are built again when that stamp moves, and at least every `dshModelsFor` (5 minutes) for what no stamp sees, such as another app's account file or a date-retired model. Building the whole catalog and every route each round allocated 12 GB of a user's 35.7 GB in 48 minutes (`TestDshRoundWithNothingChangedBuildsNothing`, `TestDshRoundAfterAChangeWritesAgain`).
- DeepSeek Harness Desktop (macOS arm64 and Windows x64; no Linux build) reads the same `$DSH_HOME` or `~/.dsh` as the CLI, as its own profile `profiles/desktop` (`resolveDshHome` and `resolveDesktopPaths` in the app's `lib/main.js`; `defaultDshHome` in github.com/deepseek-ai/deepseek-harness's `packages/util/home-paths/src/index.ts` and `apps/desktop/src/paths.ts`), so it takes magpie's routes with no wiring of its own (#2279, liangjinyuan-sihan). Only that app, from deepseek-ai/deepseek-harness (bundle id `com.deepseek.dsh`, productName DeepSeek Harness in `apps/desktop/scripts/electron-builder-config.mjs`), is dsh's: the community "DeepSeek Hermes" (motongv/deepseek-hermes-desktop) v0.1.1337 took for it is not listed or written for (WuSix on Discord, `TestDshOnlyTheOfficialApp`). It is found by `/Applications/DeepSeek Harness.app`, by `%LOCALAPPDATA%\Programs\DeepSeek Harness`, or by the folder its current-user installer records under `HKCU\Software\1bf39983-50d0-5fe0-9ef4-cece76f67c5e` (`InstallLocation`), whose Uninstall key gives the version (`registered` in [`desktopapp.go`](../../internal/agent/desktopapp.go)), so a user who picked another folder is found. With the app installed but never opened there is no `~/.dsh`: the row is still listed, and connecting writes `profiles/desktop/cordis.patch.yml` from dsh's own template (`dshProfileTemplate`) with magpie's routes, which the app keeps on its first start, since it writes only the files that are missing. The notice says the app starts on it the first time it opens (`noticeDsh5`). Disconnect before that first start removes the profile magpie made when nothing else is in it (`dshTidyUnopened`); once the app has opened it, the profile stays and only magpie's entries go (`TestDshDesktopNeverOpened`, `TestDshDesktopRegisteredFolder`; the registry as 0.2.1-rc.2's installer writes it, `TestDshWindowsAsTheInstallerRegistersIt`).
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md
index 638ae70ca..fd541dd89 100644
--- a/docs/subsystems/gateway-routing.md
+++ b/docs/subsystems/gateway-routing.md
@@ -179,7 +179,7 @@ recorded as a prediction failure (`noPrediction`).
- 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)).
- Gemini's OpenAI-compatible API (AI Studio's, or a proxy in front of Gemini on this computer or the LAN: `geminiCompat`) is asked for the model's thoughts in `extra_body.google.thinking_config`. A 400 or 422 whose error names `extra_body`, `include_thoughts` or thinking at all (`refusesThinkingConfig`) marks the provider unfit for the field (`thinking_config`), and it is asked again with `reasoning_effort` alone. Gemini 3 can't stop thinking, so reasoning turned off goes at `minimal`, its least, or at the model's lowest level where it has no `minimal` (`geminiLevels`: those of the model's levels it hasn't turned away, or of Gemini 3's where its own aren't known or none is left). Gemini 3 turns away a level the model hasn't with a 400 that names the level (`geminiRefusedLevel`): AI Studio's "Thinking level MINIMAL is not supported for this model. Please retry with other thinking level." for gemini-3.8-flash, Vertex AI's "Thinking level is unsupported: THINKING_LEVEL_MINIMAL". It names thinking too, but isn't the field turned away. The level is marked refused for that model (`levelRefused`), and the model is asked again at the nearest level it has left, still for its thoughts, and at that level from then on. A level turned away again, with none left, is the client's 400. Passed through, a Chat client's own `none` or `minimal` that Gemini turns away this way is asked again at the model's lowest level (`onEffort`), and that level goes at the lowest from then on (`turnedAway`); the other still goes as sent, as AI Studio takes `none` from gemini-3.8-flash. A refusal that names the levels the model takes (`effortLevelsNamed`, Command Code's for Qoder's `none`) marks reasoning off as a whole (`offRefused`): both go at the lowest from then on; one that lists the other among the levels taken (`otherOffNamed`, quoted, OpenAI's for gpt-5.1's `minimal`) marks only the level turned away. Both routes read and write the same marks. Vertex AI's OpenAI-compatible API marks each streamed chunk of thoughts in the delta's `extra_content.google.thought`, and such a chunk is read as thinking.
- A Claude that thinks only adaptively (`adaptiveOnly` in [`anthropic.go`](../../internal/gateway/anthropic.go): Opus, Sonnet and Haiku from 4.6 on, Fable and Mythos 5 and 5.1, read by `claudeVersion` however a relay spells them) is never sent a thinking budget, which they answer with 400. magpie's own request from a Chat or Responses client (`buildAnthropic`) goes as `thinking: {type: "adaptive", display: "summarized"}` with the effort in `output_config.effort`, so the client sees the reasoning Opus 4.7 and later otherwise leave out (display `omitted` by default), and a relay that refuses `display` is asked again without it (`refuseShapes`), as is one that refuses auto mode's `safeguards` (Copilot's Messages API: 400 "safeguards: Extra inputs are not permitted" on claude-opus-5.5, #1756; `shapeSafeguards`, `TestSafeguardsRefusedLeftOut`), and neither is sent it again while magpie runs; a client's `thinking: {type: "enabled", budget_tokens}` is turned into the same in `forwardOnce` (`adaptiveThinking`), the budget as its nearest effort, above `high` as `max`, and `display: "summarized"` unless the client named its own display, so the thinking that enabled shows stays shown (the refused shapes are taken out after it, and `refuseShapes` reads the display as it is sent); and Pi, dsh and omp are written to ask it adaptively (`AdaptiveThinking`: `forceAdaptiveThinking`, omp's `anthropic-adaptive`; #1470). A client's `xhigh` goes as `xhigh`, except to Opus and Sonnet 4.6, which have no `xhigh` and are asked `max` (`noXhigh`, #1471).
-- A vendor's model that takes its level in `output_config.effort` beside thinking on (`effortInOutputConfig` in [`anthropic.go`](../../internal/gateway/anthropic.go): Z.ai's GLM-5.2 and GLM-5.3, and MiniMax's MiniMax-M3.1-Flash and its -Preview) is sent the effort there next to the budget: built from a Chat or Responses client's effort (`buildAnthropic`, when it sends a budget), or added to an Anthropic client's request from its budget's nearest level, fitted to the model's levels (`withOutputEffort`, in `passthrough`). A budget alone left GLM at its default, and under an 8192 cap gave MiniMax's medium to max one budget, 7168 (shin4 on plugins#316). Every other model, Claude and MiniMax-M3 included, gets the budget alone. `TestGLMEffortInOutputConfig`, `TestMiniMaxPluginGetsTheNativeEffort`, `TestNativeEffortLeavesOthersAlone`.
+- A vendor's model that takes its level in `output_config.effort` beside thinking on (`effortInOutputConfig` in [`anthropic.go`](../../internal/gateway/anthropic.go): Z.ai's GLM-5.2 and GLM-5.3, and MiniMax's MiniMax-M3.1-Flash and its -Preview) is sent the effort there next to the budget: built from a Chat or Responses client's effort (`buildAnthropic`, when it sends a budget), or added to an Anthropic client's request from its budget's nearest level, fitted to the model's levels (`withOutputEffort`, in `passthrough`). A budget alone left GLM at its default, and under an 8192 cap gave MiniMax's medium to max one budget, 7168 (shin4 on plugins#316). A client that asks such a model adaptively, with its level in `output_config.effort`, has both kept (Z.ai takes adaptive with the level, tried live on GLM-5.3); dsh is written to ask them so (GLM-5.2 and GLM-5.3: `AdaptiveWithEffort`, `forceAdaptiveThinking` in `dshKindConfig`; MiniMax not yet, #3496), since pi-ai's budget path clamps Max to high's 16384 and its Max reached GLM-5.3 as high (01huadalang on Discord, 10-24). Every other model, Claude and MiniMax-M3 included, gets the budget alone. `TestGLMEffortInOutputConfig`, `TestMiniMaxPluginGetsTheNativeEffort`, `TestNativeEffortLeavesOthersAlone`, `TestAdaptiveOnOutputEffortModelAsksItsLevel`, `TestDshMaxReachesOutputEffortModels`.
- A request to an Anthropic endpoint that turns thinking off is sent as the model takes it (`thinkingOffAsTaken`, in `forwardOnce`, so relayed requests, count_tokens, magpie's own thinking-off and retries all get it; the model is read as the vendor names it, from the body, or from the path for Bedrock and Vertex). Claude Sonnet 5.5 refuses `thinking: {type: "disabled"}` and is sent `{type: "between_tools"}` alone, at effort `high` at most. Opus 5.5, Fable 5 and Mythos 5 refuse it at every effort and are sent no thinking, at effort `low` unless one was asked, with `classifierRoom` added to a reply limit below it, as Claude Code does. Opus 5 and Haiku 5.5 take it only up to `high`, so `xhigh` and `max` are asked as `high`. `between_tools` sent to any other Claude goes as `disabled`, or as none where that is refused too. Other vendors' models, older Claudes and later lines than these go as they came (#1454). A Sonnet 5.5 by a name these rules can't read, answering 400 that asks for `between_tools` (`asksBetweenTools`), is asked again with it, once; a refusal of `disabled` at any effort (`thinkingOffRefused`) is asked again with thinking left to the model, as `alwaysThinks` is. So is a relay that reads `disabled` as reasoning effort `none` and turns that level away naming the ones it takes (Sub2API's gpt-6.1-sol, "does not support reasoning effort \"none\"; use low, medium, high, xhigh or max", #1465); `refusesThinkingOff` is the one list of these refusals for both routes. A relayed request refused so marks the model (`markUnfit(offRefused)`), and its later requests go with thinking left to the model at once until magpie restarts, as auto mode's classifier asks on every action.
- A Chat or Responses client's reasoning turned off (`none`, `ThinkOff`), translated to an Anthropic endpoint (`buildAnthropic`), goes as `thinking: {type: "disabled"}`; it went as thinking at a 4096-token budget before (#1636). A model that refuses it (`refusesThinkingOff`: `alwaysThinks`, `mandatoryReasoning`, `thinkingOffRefused`, or `none` turned away naming the levels taken) is asked again at its least (`thinkingBackOn`), and `markUnfit(offRefused)` sends it so at once until magpie restarts. A translated request's level can differ from the one asked: `none` and `minimal` go as `low` where the model's levels don't say it stops (`effortOf`). The route keeps the level asked; the try, the usage log and Routing's "went" say the one built (`noteWireEffort`, `wireEffort` in [`wire_effort.go`](../../internal/gateway/wire_effort.go)). Gemini's builders say theirs their own way and are logged as asked.
- A model the user ticked no levels of (`ModelReasonless` in [settings](../../internal/settings/settings.go), `SetModelReasonless`; the provider editor's Names & levels, or `magpie model efforts <provider/model> off`) is sent no reasoning field on any route, whatever the agent asks: the candidate loop strips the body with `withoutAnyReasoning` ([`quiet.go`](../../internal/gateway/quiet.go): Chat's `reasoning_effort`, `reasoning`, `thinking`, `enable_thinking` and `include`'s `reasoning.encrypted_content`, Responses' `reasoning`, Anthropic's `thinking` of any type and `output_config.effort`, Gemini's `thinkingConfig`), the Anthropic relay doesn't add `thinking:{type:disabled}` for it, and `forwardTranslated` clears `Effort`, `ThinkOff` and `Thinking` for its other callers. It offers no levels (`Efforts`, `entryFor`), is `Quiet`, and as a routing-group member doesn't take the group's levels away. The learned refusals above cover only reasoning *off* and Gemini levels; a vendor that answers a plain `reasoning_effort` with 422 (yuexian7 on Discord) is not learned, so this is the user's switch. `TestReasonlessModelSentNoReasoning`, `TestReasonlessAnthropicRelay`, `TestGroupReasonlessMemberKeepsLevels`, `model-reasonless.test.cjs`.
diff --git a/internal/agent/dsh.go b/internal/agent/dsh.go
index d1907bb82..b81e5e639 100644
--- a/internal/agent/dsh.go
+++ b/internal/agent/dsh.go
@@ -1336,7 +1336,9 @@ type dshPiModel struct {
// dshPiCompat is a model's compat switches. On Anthropic's Messages API
// pi-ai asks a model for a thinking budget unless forceAdaptiveThinking is
-// set, and a Claude that thinks only adaptively turns a budget away.
+// set, and a Claude that thinks only adaptively turns a budget away. Z.ai's
+// GLM-5.2 and GLM-5.3 are told so too: a budget can't ask them for max
+// (dshKindConfig).
type dshPiCompat struct {
ForceAdaptiveThinking bool `yaml:"forceAdaptiveThinking,omitempty"`
}
@@ -1555,7 +1557,10 @@ func dshKindConfig(k dshKind, models []catalog.Model, api, gw string) dshPiRoute
e.Input = []string{"text"}
}
_, e.ReasoningEfforts = dshModelLevels(m.Efforts)
- if api == "anthropic-messages" && gateway.AdaptiveThinking(m.ID) {
+ // pi-ai's budget path clamps max to high (16384), so a model that
+ // takes adaptive thinking with its level (Z.ai's GLM-5.3) is asked
+ // adaptively too: pi-ai then sends the level itself, max as max
+ if api == "anthropic-messages" && (gateway.AdaptiveThinking(m.ID) || gateway.AdaptiveWithEffort(m.ID)) {
e.Compat = &dshPiCompat{ForceAdaptiveThinking: true}
}
r.Models = append(r.Models, e)
diff --git a/internal/agent/dsh_max_effort_test.go b/internal/agent/dsh_max_effort_test.go
new file mode 100644
index 000000000..28b565a44
--- /dev/null
+++ b/internal/agent/dsh_max_effort_test.go
@@ -0,0 +1,43 @@
+package agent
+
+import (
+ "testing"
+
+ "github.com/yetone/magpie/internal/catalog"
+)
+
+// TestDshMaxReachesOutputEffortModels: pi-ai asks a model on Messages for a
+// budget unless it is told to think adaptively, and its budget path clamps
+// max to high (16384), so DSH's Max on zcode's GLM-5.3 reached it as high
+// (01huadalang on Discord, 10-24). Z.ai's GLM-5.2 and GLM-5.3, which take
+// adaptive thinking with their level, are told to think adaptively on
+// magpie's Anthropic route, which has pi-ai send the level itself; on the
+// other routes, for MiniMax (not tried adaptive, #3496) and for a model
+// that takes a budget, nothing changes.
+func TestDshMaxReachesOutputEffortModels(t *testing.T) {
+ for _, tc := range []struct {
+ id string
+ route string
+ want bool
+ }{
+ {"zcode/GLM-5.3", "anthropic-messages", true},
+ {"zai/glm-5.2", "anthropic-messages", true},
+ {"minimax/MiniMax-M3.1-Flash", "anthropic-messages", false},
+ {"anth/claude-sonnet-5", "anthropic-messages", true},
+ {"kimi/kimi-k3", "anthropic-messages", false},
+ {"zai/glm-4.6", "anthropic-messages", false},
+ {"zcode/GLM-5.3", "openai-completions", false},
+ {"zcode/GLM-5.3", "openai-responses", false},
+ } {
+ m := catalog.Model{ID: tc.id, Context: 1000000, Output: 128000, Efforts: []string{"low", "high", "max"}}
+ for _, k := range dshKinds {
+ if k.api != tc.route {
+ continue
+ }
+ got := dshKindConfig(k, []catalog.Model{m}, tc.route, "http://127.0.0.1:3425").Models[0]
+ if adaptive := got.Compat != nil && got.Compat.ForceAdaptiveThinking; adaptive != tc.want {
+ t.Errorf("%s on %s: forceAdaptiveThinking %v, want %v", tc.id, tc.route, adaptive, tc.want)
+ }
+ }
+ }
+}
diff --git a/internal/gateway/adaptive_output_effort_test.go b/internal/gateway/adaptive_output_effort_test.go
new file mode 100644
index 000000000..3d1b66ab9
--- /dev/null
+++ b/internal/gateway/adaptive_output_effort_test.go
@@ -0,0 +1,47 @@
+package gateway
+
+import (
+ "testing"
+)
+
+// TestAdaptiveOnOutputEffortModelAsksItsLevel: DSH asks a model that takes
+// its level in output_config.effort (zcode's GLM-5.3) adaptively, so that
+// its Max is not clamped to a 16384 budget (01huadalang on Discord, 10-24).
+// The level goes upstream as asked, max as max, thinking still adaptive
+// (Z.ai took it so, live), and the Routing log and usage say the level. A
+// budget alone is still read as before, 16384 as high.
+func TestAdaptiveOnOutputEffortModelAsksItsLevel(t *testing.T) {
+ t.Setenv("FAKE_ZCODE", "1")
+ up := &adaptiveVendor{}
+ pid := besideFake(t, "zcode", up)
+ for _, tc := range []struct {
+ thinking, effort string
+ maxTokens int
+ want, kind string
+ }{
+ {`{"type":"adaptive","display":"summarized"}`, "max", 128000, "max", "adaptive"},
+ {`{"type":"adaptive","display":"summarized"}`, "high", 128000, "high", "adaptive"},
+ {`{"type":"adaptive","display":"summarized"}`, "low", 128000, "low", "adaptive"},
+ {`{"type":"adaptive","display":"summarized"}`, "max", 8000, "max", "adaptive"},
+ {`{"type":"enabled","budget_tokens":16384,"display":"summarized"}`, "", 128000, "high", "enabled"},
+ } {
+ oc := ""
+ if tc.effort != "" {
+ oc = `"output_config":{"effort":"` + tc.effort + `"},`
+ }
+ body := `{"model":"` + pid + `/GLM-5.3","max_tokens":` + itoa(tc.maxTokens) + `,"thinking":` + tc.thinking + `,` + oc + `"stream":true,"messages":[{"role":"user","content":"hi"}]}`
+ rt := postProto(t, New(), "/v1/messages", body)
+ got := up.last()
+ th, _ := got["thinking"].(map[string]any)
+ ocu, _ := got["output_config"].(map[string]any)
+ if rt.Effort != tc.want || rt.Tries[len(rt.Tries)-1].Effort != tc.want || ocu["effort"] != tc.want {
+ t.Errorf("%s %s: route %q, try %q, upstream output_config %v; want %s", tc.thinking, tc.effort, rt.Effort, rt.Tries[len(rt.Tries)-1].Effort, got["output_config"], tc.want)
+ }
+ if th["type"] != tc.kind || got["max_tokens"] != float64(tc.maxTokens) {
+ t.Errorf("%s %s: upstream thinking %v at max_tokens %v, want %s at %d", tc.thinking, tc.effort, got["thinking"], got["max_tokens"], tc.kind, tc.maxTokens)
+ }
+ if u := lastUsage(t).Effort; u != tc.want {
+ t.Errorf("%s %s: usage effort %q, want %s", tc.thinking, tc.effort, u, tc.want)
+ }
+ }
+}
diff --git a/internal/gateway/anthropic.go b/internal/gateway/anthropic.go
index db7ed5c9b..acfa41a1a 100644
--- a/internal/gateway/anthropic.go
+++ b/internal/gateway/anthropic.go
@@ -790,8 +790,21 @@ func outputEffortAt(host, model string) bool {
return host == deepseekHost || effortInOutputConfig.MatchString(model)
}
+// AdaptiveWithEffort is, for agents told how to ask a model, one of
+// effortInOutputConfig's that takes thinking adaptive with its level in
+// output_config.effort: Z.ai's GLM-5.2 and GLM-5.3 (tried live on GLM-5.3,
+// 10-24: max thought about three times high's). An agent whose budget
+// can't say max (pi-ai clamps it to high's) asks them so. MiniMax's
+// M3.1-Flash isn't, until it is tried (#3496).
+func AdaptiveWithEffort(model string) bool { return glmOutputEffort.MatchString(model) }
+
+// glmOutputEffort is effortInOutputConfig's Z.ai half.
+var glmOutputEffort = regexp.MustCompile(`(?i)glm-5\.[23](?:$|[-.:/\[])`)
+
// withOutputEffort is body asking, in output_config.effort, for the level
// of levels nearest the reasoning it asks for; body when it asks for none.
+// Thinking asked for adaptively (DSH asks these models so, its Max not
+// clamped to a high budget) stays adaptive: Z.ai takes it with the level.
func withOutputEffort(body []byte, levels []string) []byte {
e := requestEffort(provider.Anthropic, body)
var v struct {
diff --git a/internal/plugin/testdata/fake/index.js b/internal/plugin/testdata/fake/index.js
index 6fda91413..d90c75216 100644
--- a/internal/plugin/testdata/fake/index.js
+++ b/internal/plugin/testdata/fake/index.js
@@ -103,6 +103,13 @@ export const FakePlugin = async ({ client }) => ({
cfg.provider[ID].models["MiniMax-M3.1-Flash-Preview"] = { ...mm, name: "M3.1-Flash-Preview", variants: efforts }
cfg.provider[ID].models["MiniMax-M3"] = { ...mm, name: "MiniMax-M3", variants: { none: { thinking: { type: "disabled" } }, high: { thinking: { type: "adaptive" } } } }
}
+ // $FAKE_ZCODE: GLM-5.3 as ZCode's plugin (zcode 0.1.x) gives it, on
+ // Anthropic's API with a thinking budget per level
+ if (process.env.FAKE_ZCODE) {
+ const budget = { low: 4096, high: 16000, max: 31999 }
+ const variants = Object.fromEntries(["low", "high", "max"].map((e) => [e, { thinking: { type: "enabled", budgetTokens: budget[e] } }]))
+ cfg.provider[ID].models["GLM-5.3"] = { name: "GLM-5.3", provider: { npm: "@ai-sdk/anthropic" }, reasoning: true, variants, limit: { context: 1000000, output: 128000 } }
+ }
// $FAKE_SEARCHES: the provider's upstream searches by itself (#2027),
// as a plugin in front of Claude's API says
if (process.env.FAKE_SEARCHES) cfg.provider[ID].searches = true