Files
magpie/internal/agent/codex_relay_levels_test.go
T
yetone f1ac93aa54 codex: Ultra on every other vendor's model that reasons (pingqipai3 on X)
pingqipai3 asked for Codex's Ultra effort on every model, so Codex uses
subagents more. Codex offers a level only where the model's catalog entry
lists it, and magpie listed Ultra only on OpenAI's own models.

What Codex does with it (openai/codex 553c764): Ultra is never sent.
ModelInfo::resolve_reasoning_effort sends the entry's
multi_agent_reasoning_effort, else max, else its highest other level; and
under MultiAgent V2, Ultra is what makes subagents proactive
(effective_multi_agent_mode). So Ultra on another vendor's model asks it
its own top level, which is honest, and turns on V2's proactive subagents.

codexcat.entriesAt now ends the levels of a model that lists some, from a
vendor other than OpenAI, with "ultra" and says multi_agent_version v2
(ultraHere). Left alone: GPT, o-series and Codex models (their Ultra is
provider.OffersUltra's), a model with no levels, Fast and Seals entries
(V1 stays theirs), a vendor's own Codex entry (listedEntry). The default
level is never Ultra. catalogFormat goes to v3, so Codex fetches the list
again. Only Codex's catalog changes; other agents' level lists don't.
docs/subsystems/agent-wiring.md has a row for it.

Run: at origin/main 54b6d4d39 + these three commits (c63a6d674, mica):
gofmt -l clean; go vet ./internal/{codexcat,gui,agent,gateway,provider,
catalog,usage} on darwin, GOOS=linux -tags nogui and GOOS=windows ok;
go test -count=1 of those seven packages: all ok.
Rebased onto origin/main 21ed46106 after that run (main's gateway,
provider and i18n.js changes): provider, gui, codexcat and
gateway-model-info, i18n-keys, gui-zh-tw run again there (mica): Go all ok, GUI 8 of 9; i18n-keys is red on
"No folder" from 72facf72e on main (#6423), not this change.
The full suite runs after the tag.
The provider tests that read Codex's list (TestCPAVariantModelsBorrowLevels,
TestGroupQuietMemberKeepsCodexEffortControl,
TestCodexOffersLevelsForUnknownModels) now expect ultra at the end.
Broken by hand: ultraHere returning false turns TestUltraOnOtherVendorsModels
red (claude-opus-4-8, glm-5.3, deepseek-v4-pro, group/mixed: no ultra, no v2).
Not tried: a real Codex session picking Ultra on a non-GPT model and
watching it spawn subagents; magpie's own Codex effort control
(codexEfforts) still doesn't list Ultra for these models; a Codex app
[desktop] enabled-reasoning-efforts the user set without "ultra" is left
as they set it.
2026-11-13 12:53:04 +08:00

92 lines
6.1 KiB
Go

package agent
import (
"encoding/json"
"os"
"path/filepath"
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// maomao_00001 on Discord: in the Codex app, a relay's GPT model offered
// low, medium and high alone, none of the levels above. A relay names a
// known model as OpenAI's own list does, by a dated snapshot
// (gpt-6.1-sol-2026-09-29), or renames it (codex-gpt-6.1-sol, a tag in
// brackets, one the user said is gpt-6.1-sol in magpie): each is offered
// that model's levels in magpie-models.json, Ultra on one Codex offers it
// on. A model nothing knows keeps low, medium and high, and another
// vendor's model and a model that stops at max keep their own.
func TestCodexCatalogRelaysKnownModelsLevels(t *testing.T) {
home := syncHome(t)
// models.dev's rows, as it listed them on 2026-11-07
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
os.WriteFile(catalog.CachePath(), []byte(`{
"openai":{"id":"openai","name":"OpenAI","npm":"@ai-sdk/openai","models":{
"gpt-6.1-sol":{"id":"gpt-6.1-sol","name":"GPT-6.1 Sol","description":"Near-Astra performance for complex coding, computer use, and professional work at a lower cost.","family":"gpt-sol","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh","max"]}],"tool_call":true,"structured_output":true,"temperature":false,"knowledge":"2026-04-30","release_date":"2026-09-29","last_updated":"2026-09-29","modalities":{"input":["text","image","pdf"],"output":["text"]},"open_weights":false,"limit":{"context":1050000,"input":922000,"output":128000},"experimental":{"modes":{"fast":{"cost":{"input":4,"output":20,"cache_read":0.2,"cache_write":5},"provider":{"body":{"service_tier":"priority"}}},"pro":{"provider":{"body":{"reasoning":{"mode":"pro"}}}},"ultrafast":{"cost":{"input":12,"output":60,"cache_read":0.6,"cache_write":15},"provider":{"body":{"service_tier":"ultrafast"}}}}},"cost":{"input":2,"output":10,"cache_read":0.1,"cache_write":2.5,"tiers":[{"input":4,"output":15,"cache_read":0.2,"cache_write":5,"tier":{"type":"context","size":272000}}],"context_over_200k":{"input":4,"output":15,"cache_read":0.2,"cache_write":5}},"canonical_model_id":"openai/gpt-6.1-sol"},
"gpt-6-luna":{"id":"gpt-6-luna","name":"GPT-6 Luna","description":"OpenAI's most efficient model for focused, high-volume tasks","family":"gpt-luna","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["none","low","medium","high","xhigh","max"]}],"tool_call":true,"structured_output":true,"temperature":false,"knowledge":"2026-05-18","release_date":"2026-09-22","last_updated":"2026-09-22","modalities":{"input":["text","image","pdf"],"output":["text"]},"open_weights":false,"limit":{"context":1050000,"input":922000,"output":128000},"experimental":{"modes":{"fast":{"cost":{"input":0.2,"output":1,"cache_read":0.02,"cache_write":0.25},"provider":{"body":{"service_tier":"priority"}}},"pro":{"provider":{"body":{"reasoning":{"mode":"pro"}}}}}},"cost":{"input":0.1,"output":0.5,"cache_read":0.01,"cache_write":0.125,"tiers":[{"input":0.2,"output":0.75,"cache_read":0.02,"cache_write":0.25,"tier":{"type":"context","size":272000}}],"context_over_200k":{"input":0.2,"output":0.75,"cache_read":0.02,"cache_write":0.25}},"canonical_model_id":"openai/gpt-6-luna"}}},
"zai":{"id":"zai","name":"Z.AI","models":{"glm-5.3-flash":{"id":"glm-5.3-flash","name":"GLM-5.3-Flash","description":"Native multimodal GLM model for efficient coding and long-horizon agent tasks","family":"glm-flash","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","high","max"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"release_date":"2026-08-26","last_updated":"2026-08-26","modalities":{"input":["text","image","video","pdf"],"output":["text"]},"open_weights":true,"limit":{"context":1000000,"output":131072},"cost":{"input":0.15,"output":0.5,"cache_read":0.03,"cache_write":0},"canonical_model_id":"zhipuai/glm-5.3-flash"}}}}`), 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
s := settings.Load()
s.ModelSameAs = map[string]string{"relay/sol-of-mine": "gpt-6.1-sol"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
ids := []string{"gpt-6.1-sol", "gpt-6.1-sol-2026-09-29", "codex-gpt-6.1-sol", "[A] gpt-6.1-sol", "sol-of-mine",
"gpt-6-luna-2026-09-22", "glm-5.3-flash", "model-x-2026-01-01"}
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: ids}); err != nil {
t.Fatal(err)
}
if err := codex(home).Fields[0].Set("relay/gpt-6.1-sol-2026-09-29"); err != nil {
t.Fatal(err)
}
var got struct {
Models []struct {
Slug string `json:"slug"`
Levels []struct {
Effort string `json:"effort"`
} `json:"supported_reasoning_levels"`
} `json:"models"`
}
raw := readFile(filepath.Join(home, ".codex", "magpie-models.json"))
if err := json.Unmarshal([]byte(raw), &got); err != nil {
t.Fatalf("%v: %s", err, raw)
}
sol := []string{"low", "medium", "high", "xhigh", "max", "ultra"}
want := map[string][]string{
"relay/gpt-6.1-sol": sol,
"relay/gpt-6.1-sol-2026-09-29": sol,
"relay/codex-gpt-6.1-sol": sol,
"relay/[A] gpt-6.1-sol": sol,
"relay/sol-of-mine": sol,
// Codex's own catalog stops Luna at max
"relay/gpt-6-luna-2026-09-22": {"none", "low", "medium", "high", "xhigh", "max"},
// another vendor's model is offered Ultra after its own levels,
// which Codex sends as its top one (pingqipai3 on X)
"relay/glm-5.3-flash": {"low", "high", "max", "ultra"},
"relay/model-x-2026-01-01": {"low", "medium", "high", "ultra"},
}
seen := map[string]bool{}
for _, m := range got.Models {
w, ok := want[m.Slug]
if !ok {
continue
}
seen[m.Slug] = true
var ls []string
for _, l := range m.Levels {
ls = append(ls, l.Effort)
}
if !slices.Equal(ls, w) {
t.Errorf("%s offers %v, want %v", m.Slug, ls, w)
}
}
if len(seen) != len(want) {
t.Errorf("%d of %d of the relay's models in magpie-models.json: %s", len(seen), len(want), raw)
}
}