Codex's lead names each subagent's model itself in spawn_agent, and
Codex's [agents] config can't overrule it. The Agents page's Codex row
now has a "subagent model" square (the app's model picker, Default
first). Its options are only models a ChatGPT account in magpie serves,
because a subagent's task is sealed for ChatGPT accounts.
- settings.CodexSubagentModel holds it. It is an agent Field
(subagent_model), so the TUI/CLI, profiles, davsync's "agents" part
and WSL twins carry it too. The setter refuses another provider's
model. It keeps a ChatGPT account's model that isn't served now, so a
backup restored on another computer still applies (ApplyFields stops
at the first failed Set). POST /api/settings keeps it.
- The gateway (codexSubagentPick) moves a collab_spawn request onto it.
codexBackend does this for Codex's own bare models; serve() does it
for any other model. When no ChatGPT account on in magpie serves it,
or a held gateway key may not use it, the request stays on the model
asked for. Route.Subagent records asked/to/kept. The lead's turns,
titles, guardian and the rest are never moved. Off (the default)
changes nothing.
- Routing page: kindWhy says the subagent was put on the model set, or
stayed on its own and why. "only account on for" names the model it
went on. Strings added in zh, zh-TW, ja and de.
- docs/subsystems: gateway-routing.md and agent-wiring.md describe it.
Run (darwin, rebased on origin/main):
- gofmt -l internal/: clean.
- go vet -tags nogui on gateway, provider, agent, gui and settings:
darwin, GOOS=linux and GOOS=windows.
- go build ./...
- HOME=<temp> go test -tags nogui ./...: all ok.
TestSettingsSaveKeepsWhatItDoesNotSend flagged the new field; it is
now set there.
- GUI tests, Chromium + WebKit:
- codex-subagent-model.test.cjs: 20/20 (en, zh, zh-TW, ja, de at
1100 and 560 px).
- Also green: routing-kind, subagent-effort, codex-memories,
codex-memories-settings, i18n-keys, gui-ja, gui-de, gui-zh-tw and
click-scroll.
Failing without the change (codexSubagentPick returning nil):
- TestCodexSubagentPutOnTheModelSet
- TestCodexSubagentOnAnotherProviderPutOnTheModelSet
- TestCodexSubagentModelNotServedKeepsTheAsked
- TestCodexSubagentModelHeldKeyKeepsTheAsked
TestCodexSubagentModelLeavesOtherRequests guards the other side: the
lead's turns, titles and guardian stay untouched.
Not tried with a real Codex CLI and ChatGPT account. A subagent spawn
needs a signed-in Codex home, and this session may not touch the live
~/.codex. The fake ChatGPT backend tests cover both routes.
91 lines
3.1 KiB
Go
91 lines
3.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// Codex's lead picks the model of each subagent it spawns by itself, in
|
|
// spawn_agent's model argument (willz on Discord: gpt-6-astra), and its
|
|
// own config can't overrule that pick: [agents] default_subagent_model is
|
|
// only the default for a spawn that names none. settings.CodexSubagentModel
|
|
// is the model magpie puts Codex's subagents on, whatever the lead asked
|
|
// for: the gateway rewrites a subagent's request (x-openai-subagent
|
|
// collab_spawn) to it. A subagent's task is sealed by the ChatGPT backend
|
|
// when its lead ran there, and only a ChatGPT account opens it again, so
|
|
// the model is one a ChatGPT account in magpie serves (CodexSubagentModels).
|
|
// "" leaves every subagent on the model its lead asked for.
|
|
|
|
// CodexSubagentModel is the model Codex's subagents are put on, "" for
|
|
// the one the lead asks for.
|
|
func CodexSubagentModel() string {
|
|
return strings.TrimSpace(heldSettings().CodexSubagentModel)
|
|
}
|
|
|
|
// CodexSubagentModels are the models a ChatGPT account in magpie serves,
|
|
// the ones Codex's subagents may be put on, in the catalog's order.
|
|
func CodexSubagentModels() []Entry {
|
|
var out []Entry
|
|
for _, e := range Served() {
|
|
if e.Group == "" && e.Provider.Account != nil && e.Provider.Account.Agent == "codex" {
|
|
out = append(out, e)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// CodexSubagentUnserved says why Codex's subagents can't be put on id now,
|
|
// "" when a ChatGPT account in magpie serves it.
|
|
func CodexSubagentUnserved(id string) string {
|
|
for _, e := range CodexSubagentModels() {
|
|
if e.ID == id {
|
|
return ""
|
|
}
|
|
}
|
|
if len(CodexSubagentModels()) == 0 {
|
|
return "no ChatGPT account is on in magpie"
|
|
}
|
|
return "no ChatGPT account on in magpie serves it"
|
|
}
|
|
|
|
// SetCodexSubagentModel puts Codex's subagents on id, a ChatGPT account's
|
|
// model; "" leaves them on the model their lead asks for. One no ChatGPT
|
|
// account in magpie serves now is kept all the same — a backup or profile
|
|
// put back on a computer whose accounts differ, or an account signed in
|
|
// again later — and the gateway leaves subagents on the model asked for
|
|
// until one serves it, saying why in the route trace. Another provider's
|
|
// model is refused: it couldn't read a subagent's sealed task.
|
|
func SetCodexSubagentModel(id string) error {
|
|
id = strings.TrimSpace(id)
|
|
if id != "" && !codexAccountModel(id) {
|
|
return fmt.Errorf("Codex's subagents can't be put on %s: a subagent's task is sealed for ChatGPT accounts, so its model must be one a ChatGPT account in magpie serves (codex/…)", id)
|
|
}
|
|
s := settings.Load()
|
|
if s.CodexSubagentModel == id {
|
|
return nil
|
|
}
|
|
s.CodexSubagentModel = id
|
|
if err := settings.Save(s); err != nil {
|
|
return err
|
|
}
|
|
Changed() // a held settings read sees it
|
|
return nil
|
|
}
|
|
|
|
// codexAccountModel says id names a model of a ChatGPT account's, served
|
|
// now or not: codex/<model>, or one of a provider that is a ChatGPT
|
|
// account.
|
|
func codexAccountModel(id string) bool {
|
|
pid, model, ok := strings.Cut(id, "/")
|
|
if !ok || model == "" {
|
|
return false
|
|
}
|
|
if pid == "codex" {
|
|
return true
|
|
}
|
|
p, err := Find(pid)
|
|
return err == nil && p.Account != nil && p.Account.Agent == "codex"
|
|
}
|