Routing group: a rule's use-effort is ignored for Anthropic requests without thinking (output_config.effort wins, or the budget is cut by max_tokens)
magpie version
0.1.4623 (latest; same code in 0.1.4582)
Where
Gateway only
OS
macOS 27 (arm64)
Agent, provider and model
Anthropic Messages requests (curl; Claude Code's side requests have the same shape) → local magpie gateway → an auto routing group whose intent rules set use-effort:
4 intent "code review, …" → group/strong at xhigh (served by Opus 5.5 over Anthropic Messages)
9 intent "an easy task, …" → opencode-go/glm-5.3-flash at low (Chat protocol)
Steps to reproduce
Summary. A rule's use-effort is applied only when the request already has thinking.
- A request with
output_config.effortbut nothinkinggoes out at the request's own effort. - A request with no reasoning fields at all goes out at whatever level the thinking budget reads back as after it is cut to
max_tokens - 1.
magpie group rule help says use-effort is "the reasoning
Send three requests that differ only in their reasoning fields. Each uses max_tokens: 8192, one user message and a fresh x-session-id. Read the route right after each one:
SID=$(uuidgen | tr 'A-Z' 'a-z')
curl -sS http://127.0.0.1:3425/v1/messages \
-H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
-H "x-api-key: $MAGPIE_KEY" -H "x-session-id: $SID" \
-d '{"model":"group/smart-split","max_tokens":8192,"output_config":{"effort":"high"},
"messages":[{"role":"user","content":"What is 2 + 2? Reply with just the number."}]}' >/dev/null
curl -sS "http://127.0.0.1:3425/v1/magpie/route?session=$SID&wait=0" -H "x-api-key: $MAGPIE_KEY" \
| jq '.route | {asked_effort, model, effort, rule: (.rule | {n, useEffort}), tries: [.tries[] | {model, effort}]}'
Repeat with "thinking":{"type":"adaptive"},"output_config":{"effort":"high"}, and with no reasoning fields at all. For rule 4, use a one-line diff review prompt.
What happened, and what you expected
All requests returned 200 on their first try. The route effort, tries[0].effort and the effort column of magpie usage --csv agree in every case.
| Reasoning fields sent | asked_effort |
Rule 9 (low) sent |
Rule 4 (xhigh) sent |
|---|---|---|---|
thinking: adaptive + output_config.effort: high |
high | low ✅ | xhigh ✅ |
| none | — | low ✅ | medium ❌ |
output_config.effort: high, no thinking |
— | high ❌ | high ❌ |
The third row is what Claude Code's side requests look like (title and similar calls carry the session's effort but no thinking). In three long Claude Code runs on 0.1.4582, 139 rule-9 GLM requests with an empty asked_effort went out at high instead of low, and 6 rule-4 requests went out at high instead of xhigh. Main-loop requests, which carry thinking, got the rule's level every time.
Expected. When a rule sets use-effort, the member is asked for that level (fitted to its levels) whether or not the request has thinking or output_config.effort.
Cause (source at v0.1.4623).
- The rule's level comes from
ruleEffortand is applied at gateway.go#L4377-L4380 throughwithModelEffort→withFixedEffort. - For an Anthropic request without
thinking,withFixedEffortonly addsthinking: {type: enabled, budget_tokens: min(budgetOf(level), max_tokens-1)}. It leaves an existing top-leveloutput_config.effort(and the per-messageoutput_configthatturnEffortreads) as it was. - Downstream,
output_config.efforttakes precedence over the budget:- Anthropic request parsing reads the budget as
low, then overrides it withoutput_config.effort: high, so GLM is senthigh. adaptiveThinkingkeeps the existingoutput_config.efforttoo.
- Anthropic request parsing reads the budget as
- With no effort field at all, the level is read back from the budget (
effortOfBudget): xhigh's 32000 becomes 8191 undermax_tokens: 8192, which reads asmedium.
A possible fix:
- When
withFixedEffortadds thinking to a request that had none, also set (or drop)output_config.effort, top-level and per-message, to the rule's level. - For adaptive models, write
output_config.effortdirectly instead of relying on a budget thatmax_tokenscan cut.
A separate design question: should a rule's use-effort turn reasoning on for side requests that asked for none? It does today; GLM's replies to them come back with a thinking block.
Related: #6621, the same output_config.effort-without-thinking shape but without rules involved. The code above is unchanged in v0.1.4582…v0.1.4623.
Error text or logs
No errors: every request returned 200. The evidence is the route, try and usage effort fields shown above.
I have a fix ready on fork branch eisen0419:fix/7389-routing-group-use-effort-anthropic (e511b373, based on e5c2eb94):
- Root cause: When a routing group rule sets
use-efforton a native Anthropic/v1/messagesrequest that omitsthinking(or carries a differentoutput_config.effort), the gateway did not inject the upstream model's thinking shape or rewrite top-level/per-messageoutput_config.effortconsistently, and budget-based requests could havebudget_tokensclipped below the requested level without raisingmax_tokens. - Fix: Apply routing-rule / fixed-member / side / subagent effort overrides on native and translated Anthropic
/v1/messagesusing the turn's wire snapshot (effortShapeModelAtonwiresOf):- Emit adaptive thinking +
output_config.effortfor adaptive-only Claudes and Gemini 3+ relays, budget +output_config.effortforoutputEffortAtmodels/hosts (including DeepSeek's host), and budget-only (rewriting any client-suppliedoutput_config.effortwithout adding a synthetic field) for budget Claudes and budget vendors, raisingmax_tokenspastbudgetOf(level)while honoringwithMaxOutput/withReplyCap. - Under tight caps (
0 < cap <= 1024), omit synthetic thinking/effort when the model is non-adaptive or requiresthinking.type: "enabled", while preserving adaptive thinking when accepted; skip synthetic thinking beside forcedtool_choicewhile still rewriting client-suppliedoutput_config.effort; read per-message and unicode-escapedoutput_config.effortinwithAdaptiveAsEnabled; record clipped translated budgets viaeffortOfBudget; updatedocs/subsystems/gateway-routing.md.
- Emit adaptive thinking +
- Verification:
gofmt, targetedgo test -race -count=1 ./internal/gateway(includingrule_use_effort_anthropic_test.goandwire_test.go),go test -count=1 -run TestDocs ./internal/testenv,go test -count=1 ., and 3-OSgo vetall pass.