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.
This commit is contained in:
+15
-1
@@ -1636,7 +1636,7 @@ export const agent = {
|
||||
prefix: "openai/", // written before magpie's model id
|
||||
ua: ["aider", "litellm"],
|
||||
}
|
||||
export function connect({ gateway, model, models }) {
|
||||
export function connect({ gateway, model, models, decisionModels }) {
|
||||
return { "openai-api-base": gateway.v1, "openai-api-key": gateway.key }
|
||||
}
|
||||
```
|
||||
@@ -1659,6 +1659,20 @@ call costs. Each is left out when it isn't known (a routing group has no
|
||||
"pricing": { "prompt": "0.0000003", "completion": "0.0000012", "input_cache_read": "0.00000003" } }
|
||||
```
|
||||
|
||||
`connect` also gets `decisionModels`: magpie's decision models (Jev, Clef,
|
||||
a vendor's or a plugin's model marked `decides`, as the routing groups'
|
||||
pickers offer them), and the routing groups made of them. They are kept
|
||||
out of `models`, which an agent offers for a conversation, and out of
|
||||
`/v1/models`. Each has `id`, `name`, `provider` (a group has `group: true`
|
||||
instead) and `endpoints`, the gateway paths it is asked on: `/v1/systemone`,
|
||||
and `/v1/decisions`, which the gateway translates to System One for it.
|
||||
It is `[]` when there are none:
|
||||
|
||||
```json
|
||||
{ "id": "openrouter/~typesafe/jev-latest", "name": "Jev · OpenRouter", "provider": "openrouter",
|
||||
"endpoints": ["/v1/systemone", "/v1/decisions"] }
|
||||
```
|
||||
|
||||
An agent that takes the gateway only from how it is started, not from a
|
||||
file, says so in `launch`: `{ env: { GEMINI_API_KEY: "{key}",
|
||||
GOOGLE_GEMINI_BASE_URL: "{url}" }, model: "--model" }`. While its model is
|
||||
|
||||
@@ -42,7 +42,7 @@ something else shows up as drift.
|
||||
| WSL folders that are links | Through `\\wsl.localhost` Windows can't follow a link the distro has: with `~/.codex` a link to `/mnt/c/Users/<user>/.codex`, a mkdir of it says it exists and nothing below it can be made, written, read or listed (#4502, linusxiong). The probe asks `readlink -f` there where each agent folder, its `skills` and the folders beside them lead (`wslLinkPaths`, `distro.Links`; a `$HOME` that is itself through a link is left as it was) and which drive each Windows mount is (`distro.Drives`). `distro.open` opens a path at or below a link where it leads: on a Windows drive the drive's own path (`C:\Users\<user>\.codex`), elsewhere in the distro through its root again; `native` spells such a path back through the link for the agent. A link `readlink -f` couldn't resolve is never guessed at: its agent is unreached (`Agent.Unreached`), says why in its notice and refuses each change and sync. Every writer goes through it: the agents' own files (`place.join`, `place.open`), the library's targets (`wslOpen`, a `wsl` problem per agent), RTK (`rtkAt`, `agent.WSLOpen`), the Sessions page's reads (`sessions.WSLHome.Open`) and the Copilot CLI's sign-in (`provider.CopilotWSLDirs`). Links deeper than the probed paths aren't resolved (`TestWSLOpenThroughLinks`, `TestWSLAgentFolderIsALink`, `TestWSLAgentFolderLinkUnresolved`, `TestWSLProbeLinks`, `TestWSLFolderIsALinkToC`, `TestRTKWSLFolderIsALink`). | [`wsl.go`](../../internal/agent/wsl.go), [`targets.go`](../../internal/library/targets.go), [`rtk_wsl.go`](../../internal/library/rtk_wsl.go) |
|
||||
| WSL CLI versions and updates | A twin's CLI is read and updated in its distro, as the host's is (`cliupdate_wsl.go`; mewcoder on X): the Agents row shows the version, the newest and an Update button for every `cliSpecs` kind a distro has a command for, and Update all takes them in. Where the binary is comes from the probe (`distro.Paths`, else the command asked of the distro's PATH); one `wsl.exe -d <distro> -e sh` script says where its links lead, its `--version` and exit code (`wslCLIScript`, kept ten minutes in `wslProbes`, asked again by Rescan and after an update), with the CLI's own folder, its npm prefix, `~/.local/bin` and `~/.bun/bin` first on PATH, since `wsl.exe -e` has no login PATH and a node CLI would not find node. How it was installed is read from that Linux path by the same rules (`wslHowInstalled`: its own updater via `cliSpec.self`, Homebrew's Cellar, npm, bun or pnpm; volta, yarn and an npm prefix the user can't write, `/usr/lib`, are left alone), and the update runs in the distro through wsl.exe (`wslRunUpdate`) with a Linux brew asked for its newest in the distro too. A distro that isn't running is never started to be asked: its rows show no version and an update says to start it. Not carried over: the host's proxy settings (the distro has its own network), and Grok Build's newest is read from this computer's channel setting. Kinds with no command of their own (Goose, mu) show nothing, as on the host. | [`cliupdate_wsl.go`](../../internal/agent/cliupdate_wsl.go), [`cliupdate.go`](../../internal/agent/cliupdate.go) |
|
||||
| Settings tuned from use | Usage › Context's "Tuned for you" advises, per agent, the settings that would have spent the fewest tokens on the user's own calls of the range, and puts one in on a click. Package `tune` replays the calls `sessions.Calls` reads from the agents' session files under each candidate value (`Compact`, `CacheTTL`), each model's tokens weighed at what magpie bills them where the agent asked for a model magpie wrote (a provider/model id resolves as the gateway resolves it and is weighed at that provider's price, `pricedWeights`, so a Claude model on Copilot has its 1-hour cache write at the 5-minute one Copilot bills, #3435), else at its maker's list ratios (`tune.WeightsFor`); `tuneOf` picks the agents and models (Claude Code per model, Codex pooled). `TuneRead`, `TuneApply` and `TuneUndo` know where each setting lives: Claude Code's `modelSettings.<model>.autoCompactWindow` (where its `/autocompact` saves), `promptCacheTtl` and `subagentPromptCacheTtl` in `~/.claude/settings.json`. Where Codex compacts, and Claude Code wherever magpie's own window is what it runs at, is one value with Long conversations in the agents' settings sheet (`settings.CompactAt`/`FullContext`, source `long`; 7eleven on Discord): the card reads it, Use sets it through `provider.SetCompactAt`, and Sync writes it into each agent's config as it does for the sheet; the note says it is Long conversations, shared by Codex and Claude Code (`compact-one-value.test.cjs`). The advice is weighed by tokens alone: it is labelled "Fewest tokens", and a compaction window it would change says it doesn't measure how well the agent keeps the task after a compaction, and that a lower window compacts more often (#1854, `context-tune.test.cjs`). A compaction row's "Other window…" opens the app menu with every value of the curve, each with its estimated tokens against the setting now (fewer or more, the setting itself marked "Your setting now", hayden4608 on Discord), "Fewest tokens" beside the leanest, and about how many compactions it would have made (`Point.compacts`, from the same replay), and puts the one picked in like Use (#1860). An agent whose files time its compactions also has their wait weighed (HirotaNagai on X): Claude Code's `compact_boundary` line says `compactMetadata.durationMs`, which `sessions` puts on the first call after it, and Codex compacts by a call of its own (the record a `compacted` line names, in rollouts since 2026-09), whose time is the compaction's (`Call.Compact`; an older rollout's compaction has no call and stays untimed). With 3 or more timed for a model (`minTimed`), `Facts.took` is their median seconds, each window says its wait (`Point.wait`, its compactions × `took`), and the row says what a compaction took, the wait at the advice against the window now, and the cheaper window the advice passed over for waiting longer (`Compaction.cheapest`, `wait_cheapest`) when it saves 3% or more; the advice is labelled "Tokens + wait", its caveat says tokens and waiting only, and the picker says each window's wait with "Fewest tokens" on the cheapest (`context-tune.test.cjs`). An agent or model with fewer timed reads and is advised as before. | [`internal/tune`](../../internal/tune/tune.go), [`tune.go`](../../internal/agent/tune.go), [`internal/gui/tune.go`](../../internal/gui/tune.go) |
|
||||
| Agents a plugin adds | A plugin's `magpie.agent` module (or a `*.agent.js` file) says where an agent magpie has no setup of its own keeps its model (`config`, `format`, `model`, `prefix`), and its `connect` returns the other keys to write. One with no `model` is connect only (#2374): its one field is `provider`, magpie or nothing, as an app whose one setting is magpie as its provider; `connect` is called without a model, must return keys, and is called again on a catalog change (`Sync`); `ListsModels` is set, so its list is the models picked for it. One whose agent keeps the model a new session starts on in a file apart from its provider list says so with `startup` (`config`, `format`, `model`, and `keys` written beside the model as they are) and has no `model`: PiG keeps its providers in `models.json` and `defaultProvider`/`defaultModel` in `settings.json` (str_ on Discord: its row only listed models, where Pi's picks the one it starts on). Its field is `model` again; picking one of magpie's writes `connect`'s keys into `config` and the model and `startup.keys` into `startup.config`, each file stashed under its own `plugin:<id>:<path>` (the startup one marked by its first string key, so a model picked in the agent among magpie's, with `defaultProvider` still `magpie`, reads as magpie's). A model of the agent's own picked in it while `connect`'s keys are still in `config` is `Beside`: connected, not drift, and Disconnect leaves that pick and takes the rest out. A magpie without `startup` reads the same module as connect only (`TestPluggedStartupModel`, `TestPluggedStartupOwnPickKept`, `TestPluggedStartupRestoreGone`). `agentplug` compiles each in moejs (via `jsmod`, as gateway middleware is), reloads it when plugins.json or the file changes, and keeps why one didn't load. `plugged` makes each an `Agent` with `Plugin` set, listed after magpie's own; an id one of magpie's own agents has is refused (`PluginErrors`). `connect` is given each model as `magpieModels` builds it, with `/v1/models`' `native_endpoints` (`provider.NativeEndpoints`; a routing group's, `provider.GroupEndpoints`, the APIs every member relays as it is; carried as `catalog.Model.Endpoints`) and `pricing` (`catalog.OpenRouterPricing` of the same `EntryPricer` price), each left out when not known ([`plugged_connect_facts_test.go`](../../internal/agent/plugged_connect_facts_test.go)). | [`agentplug.go`](../../internal/agentplug/agentplug.go), [`plugged.go`](../../internal/agent/plugged.go) |
|
||||
| Agents a plugin adds | A plugin's `magpie.agent` module (or a `*.agent.js` file) says where an agent magpie has no setup of its own keeps its model (`config`, `format`, `model`, `prefix`), and its `connect` returns the other keys to write. One with no `model` is connect only (#2374): its one field is `provider`, magpie or nothing, as an app whose one setting is magpie as its provider; `connect` is called without a model, must return keys, and is called again on a catalog change (`Sync`); `ListsModels` is set, so its list is the models picked for it. One whose agent keeps the model a new session starts on in a file apart from its provider list says so with `startup` (`config`, `format`, `model`, and `keys` written beside the model as they are) and has no `model`: PiG keeps its providers in `models.json` and `defaultProvider`/`defaultModel` in `settings.json` (str_ on Discord: its row only listed models, where Pi's picks the one it starts on). Its field is `model` again; picking one of magpie's writes `connect`'s keys into `config` and the model and `startup.keys` into `startup.config`, each file stashed under its own `plugin:<id>:<path>` (the startup one marked by its first string key, so a model picked in the agent among magpie's, with `defaultProvider` still `magpie`, reads as magpie's). A model of the agent's own picked in it while `connect`'s keys are still in `config` is `Beside`: connected, not drift, and Disconnect leaves that pick and takes the rest out. A magpie without `startup` reads the same module as connect only (`TestPluggedStartupModel`, `TestPluggedStartupOwnPickKept`, `TestPluggedStartupRestoreGone`). `agentplug` compiles each in moejs (via `jsmod`, as gateway middleware is), reloads it when plugins.json or the file changes, and keeps why one didn't load. `plugged` makes each an `Agent` with `Plugin` set, listed after magpie's own; an id one of magpie's own agents has is refused (`PluginErrors`). `connect` is given each model as `magpieModels` builds it, with `/v1/models`' `native_endpoints` (`provider.NativeEndpoints`; a routing group's, `provider.GroupEndpoints`, the APIs every member relays as it is; carried as `catalog.Model.Endpoints`) and `pricing` (`catalog.OpenRouterPricing` of the same `EntryPricer` price), each left out when not known ([`plugged_connect_facts_test.go`](../../internal/agent/plugged_connect_facts_test.go)). Decision models are never in `models`; `connect` gets them as `decisionModels` (`pluggedDecisionModels`: `provider.OfferedDeciders`, what `/v1/models` lists under `X-Magpie-Deciders`, then the decision routing groups, each with `id`, `name`, `provider` or `group: true`, and `endpoints` `/v1/systemone` and `/v1/decisions`; `TestPluggedConnectSeesDecisionModels`). | [`agentplug.go`](../../internal/agentplug/agentplug.go), [`plugged.go`](../../internal/agent/plugged.go) |
|
||||
| Environment-only agents | Agents that read the gateway only from the environment get a `Launch` command. Antigravity CLI (agy) also gets a function `agy` in each shell's profile while it is on one of magpie's models, so typing `agy` in a new terminal starts it on magpie (bestony on Discord). The function runs `magpie agy run`, which starts the agy on PATH with `GEMINI_API_KEY`, `GOOGLE_GEMINI_BASE_URL`, `--settings <~/.gemini/antigravity-cli/magpie-settings.json>` and `--model` (no `--model` when the user gives one) while that file's model is magpie's, and unchanged otherwise. magpie writes `modelProvider`, `model` and the custom models (the user's own too, as agy takes the key whole) only into that file of its own, never into agy's `settings.json`: `modelProvider: gemini` there made every agy an API-key session with no Google account, so no remote control, which needs the sign-in (baysonfox on X). A `settings.json` an older magpie wired is given back (the stashed model and provider) at the next `Sync` or pick. `agy remote-control …` and `--remote-control` go through the function and `magpie agy run` as plain agy, on the user's sign-in (`AgyRemote`); remote control inside a session on magpie's models is not possible. PowerShell's asks `magpie agy env` for them, since the Windows app is a GUI program PowerShell doesn't wait for. `Typed` says the function is there; the row then says plain `agy` works in a new terminal, and the `Launch` command is for a terminal open before. agy has no settings-only route: 1.4.7 refuses to start without `GEMINI_API_KEY` in the environment even with a key on the custom model. Cursor Private Inference instead gets user-level variables (`cursorLocalOn`, `KeepCursorLocalEnv`), and magpie writes none of Cursor's own files. It is found by its product.json in the apps folders, in the folder Windows' list of installed programs names (`cursorLocalInstalls`, any folder picked in its installer), or as its Linux AppImage (`Cursor_Private_Inference-…AppImage`) in the folders downloads are kept in (#1254). Its effort field is kept in magpie (`provider.AgentEffort`) and asked by the gateway, its levels those of the models it lists (`pickedEfforts`, #1003). Antigravity's app has the same field while it is on magpie: its picker lists the gateway's models with no level of its own, so one of Antigravity's families of levels went at its default (MDX-Tom, #4838). | [`cursorlocal.go`](../../internal/agent/cursorlocal.go) |
|
||||
| Built-ins a plugin serves | `agentMovers` names the community agent plugin a built-in agent moves onto (`agy`: `@magpie-community/agent-agy`). While that plugin is installed and on, `dropMoved` leaves the built-in out (`onMachine`, and `wslKind.served` in a distro), and the plugin's agent takes its id and aliases. Its desc says what the built-in did in code. `config` is magpie's own `magpie-settings.json` and `base` agy's `settings.json` (`Desc.Base`, `bf` in `plugged`): `connect` and `own` get `base` parsed, the user's own model is written there, `get` reads it off magpie, and stepping out removes the config whole, so `settings.json` is never written while on magpie and remote control keeps its Google sign-in (0cc91af3d). `launch` (`{env, model, args, plain}`) gives it the same shell function and `magpie <id> run`/`env` (`launchSpec` in [`plugged_launch.go`](../../internal/agent/plugged_launch.go); `startCmd` in [`start_cli.go`](../../internal/cli/start_cli.go) finds any agent with `Start` by id or alias, `agent.Starter`): `args` `{"--settings": "{config}"}` go before the model flag, filled with the config as the agent's system spells it (`env` prints them as `settings=<file>`, which the PowerShell function reads), and a `plain` argument (`remote-control`) runs the agent as it is, in `startRun` (`Starting.Plained`) and in a distro's or PowerShell's function, which have no magpie to ask (`TestPluggedDistroFunctionArgsAndPlain`, `TestPluggedPowerShellFunctionArgsAndPlain`). `effort`, `wsl` and `aliases` are the rest. A `launch.env` value is `{key}`, `{url}` or `{v1}` with a path at most (`envValueOK`), an `args` value only `{config}`, and a `plain` word a subcommand or flag, so nothing else a plugin says reaches a shell profile (`TestLaunchSaysOnlyWhatAShellTakesAsItIs`, `TestBaseIsForAHandedConfig`). What the built-in wired is handed over the first time the plugin's agent reads its file with nothing stashed (`handedOver`, `agyHandover` in [`plugged_moved.go`](../../internal/agent/plugged_moved.go)): a `settings.json` an older built-in wired is given back first, by the built-in's own `Sync` (its `migrate`, then `magpie-settings.json` written); then, while `magpie-settings.json` names one of magpie's models, its keys become the plugin's `Had` as not there before, so the plugin's own model or Disconnect takes the file away and leaves `settings.json` as the user had it. Turning the plugin off disconnects it as any plugin agent's (below), and the built-in is back (`TestAgyPlugin`, `TestAgyHandedToPlugin`, `TestAgyOldWiringHandedToPlugin`, `TestAgyHandedOverUnwire`). | [`plugged_moved.go`](../../internal/agent/plugged_moved.go), [`plugged_launch.go`](../../internal/agent/plugged_launch.go) |
|
||||
| Claude Science | Its daemon (`claude-science`) reads the API's address only from its environment's `ANTHROPIC_BASE_URL` and has no setting for it. Connect restarts the daemon with that variable set to the gateway (`scienceOn`: `stop`, then `serve --detached --no-browser` on the port `status` said it was on) and notes the daemon in `claude-science.json` (url, pid, port); Disconnect restarts it without the variable, one in magpie's own environment taken out too. No variable is set for the user and no file of the app's is written. Setting it again while magpie's daemon runs on this gateway does nothing (`Pick` sets the field after `connect`). `KeepClaudeScience` starts it again on the gateway, on its port, when it isn't running (a restart of the computer). The app (0.1.72, Electron) attaches its window to a daemon running; with none it starts its own (`serve --stdio --adopt-install`, `launch_context` `app-child`) in its own environment, without the variable, and its "let the app run it instead" (and its offer once the app updated past the daemon) stops magpie's to do the same (shuitunlulu_ on Discord: Claude Science went back off magpie). So the keeper also puts magpie's daemon back, on the port the other was on, in place of one with another pid, one started for the gateway's old address, or its own older than the program installed (`--version`, asked again only when the file changed) (`scienceStale`), but only when `status` says no session runs in it (`active_frames` and `active_conversations` 0; a status without them is busy), never one launchd or systemd keeps (`launch_context`), and at most three times an hour (`scienceRetakes`). It reads `operon.lock` every 10 s and asks `status` when the lock's pid changed or a minute went by. A window on the daemon stopped shows the app's "stopped from the command line" screen, whose "start it again in the app" attaches it to magpie's. `Check` reads the daemon's `operon.lock`, not `status` (most of a second for a 130 MB Bun program), and calls a daemon with another pid drift until the keeper replaces it. It is found in the Mac app's bundle (`Claude Science.app/Contents/Resources/bin`), `%LOCALAPPDATA%\Programs\ClaudeScience` on Windows, `~/.local/bin`, else on PATH. The app still needs its own Claude sign-in; the gateway never passes it on (see gateway-routing). In a WSL distro (shuitunlulu_ on Discord) it is a WSL twin (`wslKinds`, found by `claude-science` on the probe's PATH, keeping its own notice) whose daemon magpie runs there through `wsl.exe` (`scienceInWSL`, `scienceWSLScript`; the same `scienceHost` steps as this machine's, its note `claude-science-wsl-<distro>.json`). The daemon takes http only to a loopback address, so in mirrored networking it gets the gateway's address, and under NAT a relay magpie starts in the distro: `socat` on `127.0.0.1:<gateway port>` to Windows' address on the WSL network (`scienceRelayScript`, its pid and target in `~/.claude-science/magpie-relay`, stopped with its forks as a process group on Disconnect or when the target moved). It is given `http://127.0.0.1:<port>/<WSL key>`, the key in the path, as it sends its own sign-in as the key (gateway-routing's WSL under NAT). Connect says so when the distro has no socat. The keeper runs nothing in WSL until a distro's note exists, then starts both again in each running distro (`wslScienceHosts`). Its `Check` adds the firewall drift any agent pointed at Windows' WSL address gets (`unreachable`), as its one value isn't a model of magpie's, which is what `Drift` asks that of. | [`claudescience.go`](../../internal/agent/claudescience.go), [`claudescience_wsl.go`](../../internal/agent/claudescience_wsl.go), [`science.go`](../../internal/gateway/science.go) |
|
||||
|
||||
@@ -509,7 +509,10 @@ func plugged(at place, p *agentplug.Agent) *Agent {
|
||||
in := map[string]any{
|
||||
"gateway": map[string]any{"url": at.gw(), "v1": at.v1(), "key": gk},
|
||||
"models": models,
|
||||
"agent": map[string]any{"id": id, "config": f.path},
|
||||
// magpie's decision models, apart from the chat models agents
|
||||
// offer for a conversation (pluggedDecisionModels)
|
||||
"decisionModels": pluggedDecisionModels(id),
|
||||
"agent": map[string]any{"id": id, "config": f.path},
|
||||
}
|
||||
if bf != nil {
|
||||
in["agent"].(map[string]any)["base"] = bf.path
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
@@ -96,3 +97,82 @@ export function connect({ gateway, model, models }) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An agent plugin's connect is given magpie's decision models as
|
||||
// decisionModels, apart from models (baranwang on X: a plugin wiring
|
||||
// magpie's judging models into its agent had no way to learn them):
|
||||
// each with its id, its provider and the gateway paths it is asked on,
|
||||
// a routing group of them too, and none of them in models, which agents
|
||||
// offer for a conversation.
|
||||
func TestPluggedConnectSeesDecisionModels(t *testing.T) {
|
||||
home := pluggedHome(t, `
|
||||
export const agent = { id: "judged", name: "Judged", config: "~/.judged.json", model: "model" };
|
||||
export function connect({ models, decisionModels }) {
|
||||
return { "seen": JSON.stringify({ models, decisionModels }) };
|
||||
}
|
||||
`)
|
||||
// no request reaches it: connect is only told of it
|
||||
if err := provider.Save(provider.Provider{ID: "mixed", Name: "Mixed", Key: "k", Chat: "http://127.0.0.1:9/v1", Decide: "http://127.0.0.1:9/v1", Models: []string{"deepseek-v4.1-flash", "typesafe/jev"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.SaveGroup(provider.Group{ID: "judges", Name: "Judges", Members: []string{"mixed/typesafe/jev"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a, err := Find("judged")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := a.Field("model").Set("magpie/deepseek/pro"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := os.ReadFile(filepath.Join(home, ".judged.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var file struct{ Seen string }
|
||||
if err := json.Unmarshal(b, &file); err != nil {
|
||||
t.Fatalf("%v:\n%s", err, b)
|
||||
}
|
||||
type decider struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Group bool `json:"group"`
|
||||
Endpoints []string `json:"endpoints"`
|
||||
}
|
||||
var seen struct {
|
||||
Models []struct{ ID string } `json:"models"`
|
||||
Deciders []decider `json:"decisionModels"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(file.Seen), &seen); err != nil {
|
||||
t.Fatalf("%v:\n%s", err, file.Seen)
|
||||
}
|
||||
byID := map[string]decider{}
|
||||
for _, d := range seen.Deciders {
|
||||
byID[d.ID] = d
|
||||
}
|
||||
want := []string{"/v1/systemone", "/v1/decisions"}
|
||||
jev, ok := byID["mixed/typesafe/jev"]
|
||||
if !ok || jev.Provider != "mixed" || jev.Group || jev.Name == "" || !slices.Equal(jev.Endpoints, want) {
|
||||
t.Errorf("decisionModels' mixed/typesafe/jev = %+v (found %v), want provider mixed, a name, endpoints %v:\n%s", jev, ok, want, file.Seen)
|
||||
}
|
||||
g, ok := byID[provider.GroupPrefix+"judges"]
|
||||
if !ok || !g.Group || g.Name != "Judges" || !slices.Equal(g.Endpoints, want) {
|
||||
t.Errorf("decisionModels' group = %+v (found %v), want group Judges on %v:\n%s", g, ok, want, file.Seen)
|
||||
}
|
||||
chat := false
|
||||
for _, m := range seen.Models {
|
||||
if m.ID == "mixed/typesafe/jev" || m.ID == provider.GroupPrefix+"judges" {
|
||||
t.Errorf("models has decision model %s:\n%s", m.ID, file.Seen)
|
||||
}
|
||||
chat = chat || m.ID == "mixed/deepseek-v4.1-flash"
|
||||
}
|
||||
if !chat {
|
||||
t.Errorf("models lost mixed's chat model:\n%s", file.Seen)
|
||||
}
|
||||
for _, d := range seen.Deciders {
|
||||
if d.ID == "deepseek/pro" || d.ID == "mixed/deepseek-v4.1-flash" {
|
||||
t.Errorf("decisionModels has chat model %s", d.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
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
|
||||
}
|
||||
@@ -17,6 +17,10 @@
|
||||
//
|
||||
// and it runs in moejs in magpie's own process, as gateway middleware
|
||||
// does: there is no Node here, so a package it imports is bundled into it.
|
||||
// connect's input also has decisionModels, magpie's decision models and
|
||||
// their routing groups, which models (chat models) leaves out, each with
|
||||
// the gateway paths it is asked on (internal/agent's
|
||||
// pluggedDecisionModels).
|
||||
//
|
||||
// An agent whose model is picked in the agent itself (Raycast's own
|
||||
// picker, among the models connect writes) leaves model out: it is connect
|
||||
|
||||
@@ -922,7 +922,7 @@ claude mcp add --transport http magpie-tools http://127.0.0.1:3425/mcp/magpie/to
|
||||
<tr><td><code>effort</code>, <code>wsl</code>, <code>aliases</code></td><td><code>effort: true</code> でエージェントに推論の強さの欄が付きます。<code>wsl: true</code> で WSL ディストリビューションにも表示されます。<code>aliases</code> は <code>magpie <名前></code> が受け付ける別名です。</td></tr>
|
||||
</table></div>
|
||||
<h3>connect</h3>
|
||||
<p><code>connect(input)</code> はモデルの横に書き込む他のキーを、キーのパスと値で返します。<code>async</code> でも構いません。受け取るのは <code>gateway</code>(<code>url</code>、<code>/v1</code> で終わる URL の <code>v1</code>、エージェント専用のキー <code>key</code>。リクエストはその id で数えられます)、<code>model</code>(<code>id</code>、<code>name</code>、<code>context</code>、<code>output</code>、<code>images</code>、<code>efforts</code>、そして <code>/v1/models</code> と同じ名前の <code>native_endpoints</code>(リクエストが変換されずにそのまま通るゲートウェイのパス、例えば <code>["/v1/chat/completions"]</code>)と <code>pricing</code>(1 トークンあたりの USD、10 進の文字列:<code>prompt</code>、<code>completion</code>、<code>input_cache_read</code>、<code>input_cache_write</code>。分からないものは含まれず、空や 0 にはなりません))、<code>models</code>(magpie がエージェントに出すすべてのモデル、同じ形)、<code>agent</code>(<code>id</code>、<code>config</code>)です。<code>connect</code> がないプラグインはモデルだけを書きます。magpie のモデルが変わると <code>connect</code> がもう一度呼ばれるので、書いたモデル一覧は最新のまま保たれます。</p>
|
||||
<p><code>connect(input)</code> はモデルの横に書き込む他のキーを、キーのパスと値で返します。<code>async</code> でも構いません。受け取るのは <code>gateway</code>(<code>url</code>、<code>/v1</code> で終わる URL の <code>v1</code>、エージェント専用のキー <code>key</code>。リクエストはその id で数えられます)、<code>model</code>(<code>id</code>、<code>name</code>、<code>context</code>、<code>output</code>、<code>images</code>、<code>efforts</code>、そして <code>/v1/models</code> と同じ名前の <code>native_endpoints</code>(リクエストが変換されずにそのまま通るゲートウェイのパス、例えば <code>["/v1/chat/completions"]</code>)と <code>pricing</code>(1 トークンあたりの USD、10 進の文字列:<code>prompt</code>、<code>completion</code>、<code>input_cache_read</code>、<code>input_cache_write</code>。分からないものは含まれず、空や 0 にはなりません))、<code>models</code>(magpie がエージェントに出すすべてのモデル、同じ形)、<code>decisionModels</code>(magpie の判断モデル——Jev、Clef、プラグインが <code>decides</code> を付けたモデル——とそれらのルーティンググループ。<code>models</code> にも <code>/v1/models</code> にも含まれません。それぞれ <code>id</code>、<code>name</code>、<code>provider</code> または <code>group: true</code>、呼び出すパスの <code>endpoints</code>:<code>["/v1/systemone", "/v1/decisions"]</code>。なければ <code>[]</code>)、<code>agent</code>(<code>id</code>、<code>config</code>)です。<code>connect</code> がないプラグインはモデルだけを書きます。magpie のモデルが変わると <code>connect</code> がもう一度呼ばれるので、書いたモデル一覧は最新のまま保たれます。</p>
|
||||
<p><code>own({ config, base, model })</code> をエクスポートすると、行のピッカーに出すエージェント自身のモデルを返せます。パース済みの設定ファイル(ないときは <code>{}</code>。<code>base</code> があればそれも)と今のモデルを受け取り、<code>{ value, model, direct }</code> のリストを返します。<code>value</code> はモデルとして書き込む値、<code>model</code> はベンダーでの名前、<code>direct</code> は直接つながるベンダー(<code>Google</code>、<code>OpenAI</code>、<code>Anthropic</code>)です。ない場合、ピッカーには今のモデルだけが出ます。</p>
|
||||
<h3>magpie がすること</h3>
|
||||
<ul>
|
||||
|
||||
@@ -922,7 +922,7 @@ claude mcp add --transport http magpie-tools http://127.0.0.1:3425/mcp/magpie/to
|
||||
<tr><td><code>effort</code>, <code>wsl</code>, <code>aliases</code></td><td><code>effort: true</code> gives the agent the Effort field; <code>wsl: true</code> lists it in WSL distros too; <code>aliases</code> are other names <code>magpie <name></code> takes.</td></tr>
|
||||
</table></div>
|
||||
<h3>connect</h3>
|
||||
<p><code>connect(input)</code> returns the other keys to write beside the model, by key path, each with its value; it may be <code>async</code>. It is given <code>gateway</code> (<code>url</code>, <code>v1</code> — the URL ending in <code>/v1</code> — and <code>key</code>, the agent’s own key, which counts its requests under its id), <code>model</code> (<code>id</code>, <code>name</code>, <code>context</code>, <code>output</code>, <code>images</code>, <code>efforts</code>, and as <code>/v1/models</code> names them <code>native_endpoints</code>, the gateway paths a request for it goes on untranslated such as <code>["/v1/chat/completions"]</code>, and <code>pricing</code>, USD a token as decimal strings: <code>prompt</code>, <code>completion</code>, <code>input_cache_read</code>, <code>input_cache_write</code>; each left out when not known, never empty or 0), <code>models</code> (every model magpie offers the agent, the same way) and <code>agent</code> (<code>id</code>, <code>config</code>). A plugin without <code>connect</code> writes only the model. It is called again when magpie’s models change, so a list it writes stays current.</p>
|
||||
<p><code>connect(input)</code> returns the other keys to write beside the model, by key path, each with its value; it may be <code>async</code>. It is given <code>gateway</code> (<code>url</code>, <code>v1</code> — the URL ending in <code>/v1</code> — and <code>key</code>, the agent’s own key, which counts its requests under its id), <code>model</code> (<code>id</code>, <code>name</code>, <code>context</code>, <code>output</code>, <code>images</code>, <code>efforts</code>, and as <code>/v1/models</code> names them <code>native_endpoints</code>, the gateway paths a request for it goes on untranslated such as <code>["/v1/chat/completions"]</code>, and <code>pricing</code>, USD a token as decimal strings: <code>prompt</code>, <code>completion</code>, <code>input_cache_read</code>, <code>input_cache_write</code>; each left out when not known, never empty or 0), <code>models</code> (every model magpie offers the agent, the same way), <code>decisionModels</code> (magpie’s decision models — Jev, Clef, a model a plugin marks <code>decides</code> — and the routing groups of them, kept out of <code>models</code> and <code>/v1/models</code>, each <code>id</code>, <code>name</code>, <code>provider</code> or <code>group: true</code>, and <code>endpoints</code>, the paths it is asked on: <code>["/v1/systemone", "/v1/decisions"]</code>; <code>[]</code> for none) and <code>agent</code> (<code>id</code>, <code>config</code>). A plugin without <code>connect</code> writes only the model. It is called again when magpie’s models change, so a list it writes stays current.</p>
|
||||
<p><code>own({ config, base, model })</code>, when exported, gives the agent’s own models for the row’s picker: it gets the config file parsed (<code>{}</code> for none), <code>base</code> too when the agent has one, and the model the agent is on, and returns a list of <code>{ value, model, direct }</code>, <code>value</code> what is written as the model, <code>model</code> its name at the vendor and <code>direct</code> the vendor it goes to (<code>Google</code>, <code>OpenAI</code>, <code>Anthropic</code>). Without it the picker lists the model the agent is on.</p>
|
||||
<h3>What magpie does with it</h3>
|
||||
<ul>
|
||||
|
||||
@@ -922,7 +922,7 @@ claude mcp add --transport http magpie-tools http://127.0.0.1:3425/mcp/magpie/to
|
||||
<tr><td><code>effort</code>, <code>wsl</code>, <code>aliases</code></td><td><code>effort: true</code> 给 Agent 加上推理强度一栏;<code>wsl: true</code> 让它在 WSL 发行版里也列出;<code>aliases</code> 是 <code>magpie <名字></code> 也认的其他名字。</td></tr>
|
||||
</table></div>
|
||||
<h3>connect</h3>
|
||||
<p><code>connect(input)</code> 返回要在模型旁边一起写入的其他键,按键路径给出各自的值;可以是 <code>async</code>。它拿到 <code>gateway</code>(<code>url</code>、<code>v1</code>——以 <code>/v1</code> 结尾的地址——和 <code>key</code>,即这个 Agent 自己的 key,请求会按它的 id 计入用量)、<code>model</code>(<code>id</code>、<code>name</code>、<code>context</code>、<code>output</code>、<code>images</code>、<code>efforts</code>,以及与 <code>/v1/models</code> 同名的 <code>native_endpoints</code>——请求不经转换直接走的网关路径,如 <code>["/v1/chat/completions"]</code>——和 <code>pricing</code>——每 token 的美元价格,十进制字符串:<code>prompt</code>、<code>completion</code>、<code>input_cache_read</code>、<code>input_cache_write</code>;不知道的就不给,绝不是空或 0)、<code>models</code>(magpie 给这个 Agent 的所有模型,格式相同)和 <code>agent</code>(<code>id</code>、<code>config</code>)。没有 <code>connect</code> 的插件只写模型。magpie 的模型有变化时会再调用一次 <code>connect</code>,它写的模型列表因此保持最新。</p>
|
||||
<p><code>connect(input)</code> 返回要在模型旁边一起写入的其他键,按键路径给出各自的值;可以是 <code>async</code>。它拿到 <code>gateway</code>(<code>url</code>、<code>v1</code>——以 <code>/v1</code> 结尾的地址——和 <code>key</code>,即这个 Agent 自己的 key,请求会按它的 id 计入用量)、<code>model</code>(<code>id</code>、<code>name</code>、<code>context</code>、<code>output</code>、<code>images</code>、<code>efforts</code>,以及与 <code>/v1/models</code> 同名的 <code>native_endpoints</code>——请求不经转换直接走的网关路径,如 <code>["/v1/chat/completions"]</code>——和 <code>pricing</code>——每 token 的美元价格,十进制字符串:<code>prompt</code>、<code>completion</code>、<code>input_cache_read</code>、<code>input_cache_write</code>;不知道的就不给,绝不是空或 0)、<code>models</code>(magpie 给这个 Agent 的所有模型,格式相同)、<code>decisionModels</code>(magpie 的决策模型——Jev、Clef、插件标了 <code>decides</code> 的模型——以及由它们组成的路由组;它们不在 <code>models</code> 和 <code>/v1/models</code> 里。每个有 <code>id</code>、<code>name</code>、<code>provider</code> 或 <code>group: true</code>,以及 <code>endpoints</code>,即调用它的路径:<code>["/v1/systemone", "/v1/decisions"]</code>;没有时是 <code>[]</code>)和 <code>agent</code>(<code>id</code>、<code>config</code>)。没有 <code>connect</code> 的插件只写模型。magpie 的模型有变化时会再调用一次 <code>connect</code>,它写的模型列表因此保持最新。</p>
|
||||
<p>导出 <code>own({ config, base, model })</code> 时,它给出这一行选择器里 Agent 自己的模型:拿到解析好的配置文件(没有时为 <code>{}</code>,有 <code>base</code> 时也一并给出)和 Agent 当前的模型,返回 <code>{ value, model, direct }</code> 的列表:<code>value</code> 是写入的模型值,<code>model</code> 是它在厂商那里的名字,<code>direct</code> 是它直连的厂商(<code>Google</code>、<code>OpenAI</code>、<code>Anthropic</code>)。不导出时,选择器只列出 Agent 当前的模型。</p>
|
||||
<h3>magpie 怎么用它</h3>
|
||||
<ul>
|
||||
|
||||
@@ -11856,7 +11856,7 @@ magpie plugin add ./agent-aider # or a single *.agent.js file
|
||||
|
||||
### connect
|
||||
|
||||
`connect(input)` returns the other keys to write beside the model, by key path, each with its value; it may be `async`. It is given `gateway` (`url`, `v1` — the URL ending in `/v1` — and `key`, the agent’s own key, which counts its requests under its id), `model` (`id`, `name`, `context`, `output`, `images`, `efforts`, and as `/v1/models` names them `native_endpoints`, the gateway paths a request for it goes on untranslated such as `["/v1/chat/completions"]`, and `pricing`, USD a token as decimal strings: `prompt`, `completion`, `input_cache_read`, `input_cache_write`; each left out when not known, never empty or 0), `models` (every model magpie offers the agent, the same way) and `agent` (`id`, `config`). A plugin without `connect` writes only the model. It is called again when magpie’s models change, so a list it writes stays current.
|
||||
`connect(input)` returns the other keys to write beside the model, by key path, each with its value; it may be `async`. It is given `gateway` (`url`, `v1` — the URL ending in `/v1` — and `key`, the agent’s own key, which counts its requests under its id), `model` (`id`, `name`, `context`, `output`, `images`, `efforts`, and as `/v1/models` names them `native_endpoints`, the gateway paths a request for it goes on untranslated such as `["/v1/chat/completions"]`, and `pricing`, USD a token as decimal strings: `prompt`, `completion`, `input_cache_read`, `input_cache_write`; each left out when not known, never empty or 0), `models` (every model magpie offers the agent, the same way), `decisionModels` (magpie’s decision models — Jev, Clef, a model a plugin marks `decides` — and the routing groups of them, kept out of `models` and `/v1/models`, each `id`, `name`, `provider` or `group: true`, and `endpoints`, the paths it is asked on: `["/v1/systemone", "/v1/decisions"]`; `[]` for none) and `agent` (`id`, `config`). A plugin without `connect` writes only the model. It is called again when magpie’s models change, so a list it writes stays current.
|
||||
|
||||
`own({ config, base, model })`, when exported, gives the agent’s own models for the row’s picker: it gets the config file parsed (`{}` for none), `base` too when the agent has one, and the model the agent is on, and returns a list of `{ value, model, direct }`, `value` what is written as the model, `model` its name at the vendor and `direct` the vendor it goes to (`Google`, `OpenAI`, `Anthropic`). Without it the picker lists the model the agent is on.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user