droid: a reasoning model's entry has reasoningEffort, a built-in's baseModelId
tao5010 on Discord: Droid's /model offered no thinking level for any
magpie model. magpie wrote customModels with neither reasoningEffort nor
baseModelId, and droid 1.3.0 (its customModel schema and picker read
from the 1.3.0 bundle) gives a custom model it can't match to a built-in
the levels ["none"], and sends no reasoning field whatever is picked.
With reasoningEffort it offers off, low, medium and high plus that
value, which is the default. With baseModelId it uses that built-in's
own list.
What magpie writes now:
- A model that reasons (Reasoning, or levels known) gets reasoningEffort:
its default effort if droid's enum takes it, else medium, else the
nearest level it has (high, low, xhigh, max, minimal). It is never none,
off, dynamic or a value outside the enum.
- A model whose own id is one of droid 1.3.0's built-in ids exactly
(codex/gpt-5.4 is gpt-5.4) also gets baseModelId.
- A routing group gets reasoningEffort only when its members share
levels, and never a baseModelId.
- A model that doesn't reason gets neither.
- Both fields are droidKept, so a value the user set, or a field they
took out, stays as they left it.
Run (on mote):
- TestDroidReasoningEffort was red on the old droid.go, with every
expected value <nil>.
- Broken by hand, each part goes red: without the two droidKept names
(the user's value is overwritten), without the group check in
droidEffort (a group with no shared levels gets medium), and without
the group check on baseModelId (group/gpt-5.4 gets baseModelId
gpt-5.4).
- gofmt, go vet, plus Linux (nogui) and Windows vet of internal/agent.
- go test -timeout 45m ./internal/agent/...: ok (633.6s)
- Real droid 1.3.0 in a sandbox HOME on mote, with the settings.json
this code writes, and droid exec against a fake gateway that logs
each request:
- oa/gpt-5.4 (baseModelId) sent reasoning effort low for -r low.
- deepseek/flash sent reasoning_effort low.
- group/gpt-5.4 sent low and xhigh.
- resp/grok-5 sent xhigh.
- A reasonless model and a group whose members share no levels sent
no reasoning field.
- The file parsed with no error. Earlier runs showed that an unknown
baseModelId is ignored without breaking the entry.
Not tried:
- The TUI's /model picker itself, which needs a Factory sign-in.
- A real upstream model behind the fake gateway.
- An older droid than 1.3.0.
This commit is contained in:
+104
-1
@@ -29,6 +29,20 @@ package agent
|
||||
// stays theirs (droidKept): what magpie last wrote is stashed, and a value
|
||||
// other than it is the user's. baseUrl and apiKey are the wiring, put back
|
||||
// at every sync.
|
||||
//
|
||||
// A model that reasons is given reasoningEffort, the effort droid starts
|
||||
// it at: droid offers a custom model it doesn't know as one of its own
|
||||
// models no levels at all (droid 1.3.0's B3: ["none"], and no reasoning
|
||||
// field is sent whatever the user picks), and one with reasoningEffort
|
||||
// off, low, medium and high, with that one as the default (tao5010 on
|
||||
// Discord: none of 123 magpie models had thinking levels in /model).
|
||||
// One whose own id (the last part of magpie's) is a model droid has built
|
||||
// in is given that id as baseModelId too, so droid takes its levels and
|
||||
// default from its own table, off included, rather than from a guess at
|
||||
// the name (droidBuiltins). A routing group gets reasoningEffort only
|
||||
// when its members share levels (provider's group entries keep the levels
|
||||
// every member takes), and never a baseModelId: its members are different
|
||||
// models. Both are droidKept, so a value the user set stays.
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -43,6 +57,7 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/jsonc"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
@@ -65,6 +80,12 @@ type droidEntry struct {
|
||||
Provider string `json:"provider"`
|
||||
MaxContextLimit int `json:"maxContextLimit,omitempty"`
|
||||
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
||||
// ReasoningEffort is the effort droid starts the model at; a model
|
||||
// that doesn't reason has none (droidEffort)
|
||||
ReasoningEffort string `json:"reasoningEffort,omitempty"`
|
||||
// BaseModelID is the model of droid's own this one is, whose levels
|
||||
// droid then offers (droidBuiltin)
|
||||
BaseModelID string `json:"baseModelId,omitempty"`
|
||||
// droid takes a model on Chat Completions as seeing no images unless
|
||||
// told otherwise, so this is always written
|
||||
NoImageSupport bool `json:"noImageSupport"`
|
||||
@@ -91,6 +112,10 @@ func droidEntriesAt(gw string) []droidEntry {
|
||||
e.Provider = "anthropic"
|
||||
}
|
||||
e.BaseURL = droidBase(gw, e.Provider)
|
||||
e.ReasoningEffort = droidEffort(m)
|
||||
if e.ReasoningEffort != "" && !provider.IsGroupRef(m.ID) {
|
||||
e.BaseModelID = droidBuiltin(m.ID)
|
||||
}
|
||||
// the catalog's own label ("pro · DeepSeek") is what the picker
|
||||
// shows; droid finds the model by its id, whatever its name
|
||||
if e.DisplayName = m.Name; e.DisplayName == "" {
|
||||
@@ -110,6 +135,84 @@ func droidBase(gw, prov string) string {
|
||||
return gw + "/v1"
|
||||
}
|
||||
|
||||
// droidLevels are the efforts droid's settings take for a custom model
|
||||
// (droid 1.3.0's reasoningEffort enum) that start it reasoning, in the
|
||||
// order magpie picks a default from when the model's list names none.
|
||||
var droidLevels = []string{"medium", "high", "low", "xhigh", "max", "minimal"}
|
||||
|
||||
// droidEffort is the reasoningEffort magpie gives m: the effort its
|
||||
// vendor's list says it starts at, else medium, else the nearest level it
|
||||
// has. "" for a model that doesn't reason, or a group whose members share
|
||||
// no levels.
|
||||
func droidEffort(m catalog.Model) string {
|
||||
if provider.IsGroupRef(m.ID) {
|
||||
if len(m.Efforts) == 0 {
|
||||
return ""
|
||||
}
|
||||
} else if !m.Reasoning && len(m.Efforts) == 0 {
|
||||
return ""
|
||||
}
|
||||
has := func(l string) bool { return len(m.Efforts) == 0 || slices.Contains(m.Efforts, l) }
|
||||
if d := m.DefaultEffort; slices.Contains(droidLevels, d) && has(d) {
|
||||
return d
|
||||
}
|
||||
for _, l := range droidLevels {
|
||||
if has(l) {
|
||||
return l
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// droidBuiltins are the models droid 1.3.0 has built in (its model id
|
||||
// enum, the Factory router's "auto" and "auto-fast" aside): the values its
|
||||
// settings take for baseModelId. droid drops a baseModelId it doesn't know
|
||||
// and keeps the entry, so an older droid reads one named here as none.
|
||||
var droidBuiltins = []string{
|
||||
"claude-3-5-sonnet-20241022", "claude-3-7-sonnet-20250219",
|
||||
"claude-sonnet-4-20250514", "claude-opus-4-1-20250805",
|
||||
"claude-3-5-haiku-20241022", "claude-sonnet-4-5-20250929",
|
||||
"claude-opus-4-5-20251101", "claude-haiku-4-5-20251001",
|
||||
"claude-sonnet-4-6", "claude-opus-4-6", "claude-opus-4-6-fast",
|
||||
"claude-opus-4-7", "claude-opus-4-7-fast", "claude-opus-4-8",
|
||||
"claude-opus-4-8-fast", "claude-opus-5", "claude-opus-5-fast",
|
||||
"claude-opus-5-5", "claude-opus-5-5-fast", "claude-sonnet-5",
|
||||
"claude-sonnet-5-5", "claude-haiku-5-5", "claude-fable-5",
|
||||
"claude-fable-5.1", "atlas-07-21", "aster-07-15", "gpt-5-2025-08-07",
|
||||
"gpt-5-mini-2025-08-07", "gpt-5-nano-2025-08-07", "gpt-5-codex",
|
||||
"gpt-5.1", "gpt-5.1-codex", "gpt-5.1-codex-max", "gpt-5.2",
|
||||
"gpt-5.2-codex", "gpt-5.3-codex", "gpt-5.3-codex-fast", "gpt-5.4",
|
||||
"gpt-5.4-fast", "gpt-5.4-mini", "gpt-5.4-mini-fast", "gpt-5.5",
|
||||
"gpt-5.5-fast", "gpt-5.5-pro", "gpt-5.6-sol", "gpt-5.6-sol-fast",
|
||||
"gpt-5.6-terra", "gpt-5.6-terra-flex", "gpt-5.6-luna",
|
||||
"gpt-5.6-luna-flex", "gpt-6-astra", "gpt-6-astra-ultrafast",
|
||||
"gpt-6-astra-flex", "gpt-6.1-sol", "gpt-6.1-sol-ultrafast",
|
||||
"gpt-6.1-terra", "gpt-6-sol", "gpt-6-sol-fast", "gpt-6-sol-flex",
|
||||
"gpt-6-luna", "gpt-6-luna-fast", "gpt-6-luna-flex", "gemini-2.5-flash",
|
||||
"gemini-2.5-pro", "gemini-3-pro-preview", "gemini-3-flash-preview",
|
||||
"gemini-3.1-pro-preview", "gemini-3.5-flash", "gemini-3.6-flash",
|
||||
"gemini-3.7-flash", "gemini-3.8-flash", "gemini-4-argon",
|
||||
"garnet-07-15", "grok-4.5", "grok-4.6", "grok-4.7", "glm-4.6",
|
||||
"glm-4.7", "kimi-k2.5", "kimi-k2.6", "kimi-k2.7-code", "kimi-k3",
|
||||
"qwen3.8-max", "deepseek-v4.1-flash-1017", "deepseek-v4.1-flash",
|
||||
"deepseek-v4-flash-0731", "deepseek-v4-pro", "minimax-m2.5",
|
||||
"minimax-m2.7", "minimax-m3", "minimax-m3.1-flash", "glm-5", "glm-5.1",
|
||||
"glm-5.2", "glm-5.2-fast", "glm-5.3", "glm-5.3-flash",
|
||||
"mistral-medium-3.5", "mistral-large-4", "inkling", "nemotron-3-ultra",
|
||||
"nemotron-3.5-super", "muse-spark-1.2", "muse-spark-1.3",
|
||||
"muse-spark-open", "beam-1.0",
|
||||
}
|
||||
|
||||
// droidBuiltin is the model of droid's own whose id is the last part of
|
||||
// magpie's id ref ("codex/gpt-5.5" is gpt-5.5), or "".
|
||||
func droidBuiltin(ref string) string {
|
||||
name := strings.ToLower(ref[strings.LastIndex(ref, "/")+1:])
|
||||
if slices.Contains(droidBuiltins, name) {
|
||||
return name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// droid's own reading of a custom model's name (droid 0.231.0, xs and g2
|
||||
// in its bundle): one that isn't on "openai" while its name matches
|
||||
// droidGPT is warned about as OpenAI's, and then one on neither
|
||||
@@ -143,7 +246,7 @@ func droidWants(model string) string {
|
||||
|
||||
// droidKept are the fields of magpie's entries a value the user set stays
|
||||
// in. baseUrl follows the provider; apiKey is the wiring.
|
||||
var droidKept = []string{"provider", "displayName", "maxContextLimit", "maxOutputTokens", "noImageSupport"}
|
||||
var droidKept = []string{"provider", "displayName", "maxContextLimit", "maxOutputTokens", "noImageSupport", "reasoningEffort", "baseModelId"}
|
||||
|
||||
// droidWrote is what magpie gave the droidKept fields of an entry, as JSON,
|
||||
// a field it left out missing.
|
||||
|
||||
@@ -415,3 +415,88 @@ func TestDroidKeepsAnEntryEditedByHand(t *testing.T) {
|
||||
t.Error("record kept after disconnect")
|
||||
}
|
||||
}
|
||||
|
||||
// tao5010 on Discord: droid offered none of magpie's models any thinking
|
||||
// level. droid gives a custom model it doesn't know levels only when its
|
||||
// entry has reasoningEffort (droid 1.3.0), and takes a built-in's own
|
||||
// through baseModelId.
|
||||
func TestDroidReasoningEffort(t *testing.T) {
|
||||
_, path := droidHome(t)
|
||||
provider.Save(provider.Provider{ID: "oa", Name: "OA", Key: "k", Responses: "http://127.0.0.1:1/v1",
|
||||
Models: []string{"gpt-5.4", "plain"}})
|
||||
for ref, levels := range map[string][]string{
|
||||
"deepseek/pro": {"low", "medium", "high"},
|
||||
"deepseek/flash": {"low", "high"},
|
||||
"resp/grok-5": {"xhigh"},
|
||||
"oa/gpt-5.4": {"low", "medium", "high"},
|
||||
} {
|
||||
if err := provider.SetModelEfforts(ref, levels); err != nil {
|
||||
t.Fatal(ref, err)
|
||||
}
|
||||
}
|
||||
if err := provider.SetModelReasonless("oa/plain", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, g := range []provider.Group{
|
||||
{ID: "gpt-5.4", Name: "Both", Members: []string{"deepseek/pro", "oa/gpt-5.4"}},
|
||||
{ID: "apart", Name: "Apart", Members: []string{"deepseek/flash", "resp/grok-5"}},
|
||||
} {
|
||||
if err := provider.SaveGroup(g); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
a := droid(os.Getenv("HOME"))
|
||||
if err := a.Apply("model", "magpie/deepseek/pro"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := map[string][2]any{ // reasoningEffort, baseModelId
|
||||
"custom:magpie/deepseek/pro": {"medium", nil},
|
||||
"custom:magpie/deepseek/flash": {"high", nil},
|
||||
"custom:magpie/resp/grok-5": {"xhigh", nil},
|
||||
"custom:magpie/oa/gpt-5.4": {"medium", "gpt-5.4"},
|
||||
"custom:magpie/oa/plain": {nil, nil},
|
||||
"custom:magpie/group/gpt-5.4": {"medium", nil}, // never a built-in
|
||||
"custom:magpie/group/apart": {nil, nil},
|
||||
}
|
||||
check := func(when string, want map[string][2]any) {
|
||||
t.Helper()
|
||||
ms, _, _ := droidFile(t, path)
|
||||
for id, w := range want {
|
||||
e, ok := ms[id]
|
||||
if !ok {
|
||||
t.Errorf("%s: %s missing", when, id)
|
||||
continue
|
||||
}
|
||||
if e["reasoningEffort"] != w[0] || e["baseModelId"] != w[1] {
|
||||
t.Errorf("%s: %s reasoningEffort %v baseModelId %v, want %v %v", when, id, e["reasoningEffort"], e["baseModelId"], w[0], w[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
check("written", want)
|
||||
|
||||
// what the user sets stays theirs, a field they took out stays out
|
||||
var f map[string]any
|
||||
json.Unmarshal([]byte(readFile(path)), &f)
|
||||
for _, m := range f["customModels"].([]any) {
|
||||
e := m.(map[string]any)
|
||||
switch e["id"] {
|
||||
case "custom:magpie/deepseek/pro":
|
||||
e["reasoningEffort"] = "high"
|
||||
e["baseModelId"] = "deepseek-v4"
|
||||
case "custom:magpie/oa/gpt-5.4":
|
||||
delete(e, "baseModelId")
|
||||
}
|
||||
}
|
||||
b, _ := json.MarshalIndent(f, "", " ")
|
||||
os.WriteFile(path, b, 0o644)
|
||||
want["custom:magpie/deepseek/pro"] = [2]any{"high", "deepseek-v4"}
|
||||
want["custom:magpie/oa/gpt-5.4"] = [2]any{"medium", nil}
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check("after sync", want)
|
||||
if err := a.Apply("model", "magpie/oa/gpt-5.4"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check("after apply", want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user