From 1786bc3c3da490d836cfa49b8d581fae9f080979 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 24 Sep 2026 11:15:59 +0800 Subject: [PATCH] agent: Pi offers xhigh and max for models that have them Pi shows xhigh and max only for models whose thinkingLevelMap names them, and magpie wrote just "reasoning", so a model whose top level is max (GLM-5.3, DeepSeek) stopped at high and a max setting was sent as high (#5). Checked on the wire: --thinking max sent reasoning_effort high before, max after. Picking the model or thinking level in magpie again rewrites Pi's models.json. --- internal/agent/agents.go | 22 +++++++++++++++++++++- internal/agent/pi_test.go | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 internal/agent/pi_test.go diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 9cd64f31..e099cd02 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -163,7 +163,11 @@ func magpieProviderJSON(shape string) any { var ms []map[string]any for _, m := range models { // reasoning lets Pi offer its thinking levels for the model - ms = append(ms, map[string]any{"id": m.ID, "name": m.Name, "reasoning": len(m.Efforts) > 0}) + e := map[string]any{"id": m.ID, "name": m.Name, "reasoning": len(m.Efforts) > 0} + if levels := piThinkingLevels(m.Efforts); levels != nil { + e["thinkingLevelMap"] = levels + } + ms = append(ms, e) } if ms == nil { ms = []map[string]any{} @@ -173,6 +177,22 @@ func magpieProviderJSON(shape string) any { return nil } +// piThinkingLevels is the thinkingLevelMap for a model's efforts. Pi offers +// xhigh and max only for models that map them, so without it a model whose +// top level is max stopped at high in Pi. +func piThinkingLevels(efforts []string) map[string]any { + var levels map[string]any + for _, e := range efforts { + if e == "xhigh" || e == "max" { + if levels == nil { + levels = map[string]any{} + } + levels[e] = e + } + } + return levels +} + func opencode(home, cfg string) *Agent { dir := filepath.Join(cfg, "opencode") path := filepath.Join(dir, "opencode.json") diff --git a/internal/agent/pi_test.go b/internal/agent/pi_test.go new file mode 100644 index 00000000..84a78d1e --- /dev/null +++ b/internal/agent/pi_test.go @@ -0,0 +1,23 @@ +package agent + +import ( + "reflect" + "testing" +) + +func TestPiThinkingLevels(t *testing.T) { + for _, c := range []struct { + efforts []string + want map[string]any + }{ + {[]string{"low", "high", "max"}, map[string]any{"max": "max"}}, + {[]string{"low", "medium", "high", "xhigh"}, map[string]any{"xhigh": "xhigh"}}, + {[]string{"none", "low", "high", "xhigh", "max"}, map[string]any{"xhigh": "xhigh", "max": "max"}}, + {[]string{"low", "medium", "high"}, nil}, + {nil, nil}, + } { + if got := piThinkingLevels(c.efforts); !reflect.DeepEqual(got, c.want) { + t.Errorf("%v: got %v, want %v", c.efforts, got, c.want) + } + } +}