Files
magpie/internal/agent/plugged_deciders.go
T
yetone ed82d8fab1 agent: a plugin's connect is given magpie's decision models as decisionModels
An agent plugin's connect() got only chat models in `models`, and
/v1/models leaves decision models out too, so a plugin had no way to
learn magpie's Jev, Clef or plugin `decides` models, though
/v1/systemone and /v1/decisions answer them (baranwang on X,
tweet 2121551068022915149).

connect's input now has `decisionModels`, apart from `models`:
provider.OfferedDeciders (what /v1/models lists under
X-Magpie-Deciders), then the decision routing groups, each
{ id, name, provider | group: true,
  endpoints: ["/v1/systemone", "/v1/decisions"] }, [] for none.
`models` and /v1/models are unchanged. Docs: reference.md,
agent-wiring.md, site plugins page (en, zh, ja) and llms-full.txt.

Run at 87f358b70's tree rebased on 659ca3f02 (a gateway-only parent; the
plugged tests re-run there: ok), on wsl-run, magpie-desktop; mote was at load 75-150, mica's disk full):
- go test -tags nogui -count=1 ./internal/agent ./internal/agentplug: ok
  (agent 191s)
- go vet (linux), GOOS=windows and GOOS=darwin go vet of both: ok
- site: node --test worker.test.mjs -n llms-full: ok
- gofmt -l: clean
Broken by hand: connect given decisionModels [] makes
TestPluggedConnectSeesDecisionModels red (jev and the group missing).
Not run: the full go test ./... before the tag (another session's full
suite held the WSL box, mote over its load); run after, recorded on
the issue/next commit. No real third-party agent plugin tried with it.
2026-11-14 18:55:12 +08:00

40 lines
1.5 KiB
Go

package agent
import (
"cmp"
"github.com/yetone/magpie/internal/provider"
)
// decisionEndpoints are the gateway paths a decision model is asked on:
// System One, its own API, and OpenAI's Decisions API, which the gateway
// translates to System One for it (decisions_systemone.go).
var decisionEndpoints = []string{"/v1/systemone", "/v1/decisions"}
// pluggedDecisionModels are magpie's decision models as an agent plugin's
// connect is given them, apart from models: the models a routing group's
// pickers offer (provider.OfferedDeciders, what /v1/models lists under
// X-Magpie-Deciders), then the routing groups of them, each with the
// paths it is asked on. models is chat models only, which an agent offers
// for a conversation; a decision model there would be offered for one
// and fail (baranwang on X: a plugin wiring magpie's judging models into
// its agent had no way to learn them). [] for none, never nil.
func pluggedDecisionModels(agent string) []map[string]any {
ds := provider.OfferedDeciders(nil)
for i := range ds {
ds[i].Name = cmp.Or(ds[i].Name, ds[i].Model)
}
labels := provider.LabelsFor(agent, ds)
out := make([]map[string]any, 0, len(ds))
for i, e := range ds {
out = append(out, map[string]any{"id": e.ID, "name": labels[i], "provider": e.Provider.ID, "endpoints": decisionEndpoints})
}
for _, g := range provider.Groups() {
if g.Hidden || g.Disabled || !g.Decides() {
continue
}
out = append(out, map[string]any{"id": g.Ref(), "name": cmp.Or(g.Name, g.ID), "group": true, "endpoints": decisionEndpoints})
}
return out
}