magpie writes Pi's ~/.pi/agent/models.json with api "openai-completions". xiaomanweiman found that T3 Code's pi plugin then puts all 71 tools in the context, while on "openai-responses" only 3 core tools load and the rest come lazily. v0.1.4039 kept an api set by hand; this adds a choice so no one has to edit the file. Pi's opened row in Agents has a Protocol row, picked in the app's menu (no native select): Each model's own (today's default, unchanged), OpenAI Chat Completions, OpenAI Responses, Anthropic Messages. These are the KnownApi names in pi-ai 1.4.0 (/opt/homebrew/bin/pi) that magpie's gateway serves (dshAPIs). The choice is stashed as pi.protocol and written into the magpie provider block (piProviderOn/piModelOn). Anthropic Messages also gives each model the gateway root as its baseUrl, since Anthropic's SDK adds /v1 itself. Effort levels and prompt caching follow the api actually written. An api typed in models.json by hand still wins (piAPIsKept) and shows as the picked value. The CLI has `magpie pi protocol <api|default>`. It is Pi only: not its forks (OmO, Prime Agent, ...) or Aside. It is hidden while the pi-magpie extension serves the models, and it reads nothing at a stopped WSL distro (#3896). Tests: - internal/agent/pi_protocol_test.go: TestPiProtocolPicked. - internal/gui/tests/pi-protocol.test.cjs: Chromium and WebKit, en, zh, zh-TW, ja, de. It checks the row, the menu (4 items, no select, the current one ticked) and what /api/set gets. - Strings in i18n.js in every language. Broken by hand: with the protocol not written, TestPiProtocolPicked goes red. With the menu label left untranslated, pi-protocol.test.cjs goes 16 of 20 red. Real use: a nogui build ran in a sandbox HOME on 127.0.0.1:3562, against a fake OpenAI Chat upstream, with the real pi 1.4.0 `-p "say pong"` and a logging tap: - completions: POST /v1/chat/completions - responses: POST /v1/responses - anthropic-messages: POST /v1/messages?beta=true - default: /v1/chat/completions Each answered PONG-FROM-FAKE. An api typed by hand (openai-responses) survived `magpie sync`, and `magpie pi protocol` showed it. Run at this head (rebased on origin/main459d668b3): - mote: gofmt -l clean; go vet of internal/agent, internal/gui and internal/cli ok; go test -count=1 of those three packages ok (an earlier run there found TestWSLColdPlaceOpensNothing and TestCoreScriptBudget red, both fixed here; the budget is met by trimming this change's code, not by raising it). - mote at the pre-rebase tree: GOOS=linux go vet -tags nogui ./..., a windows vet, and go build, all ok. - mica: pi-protocol.test.cjs 20/20, and the 65 agent-*, pi-*, i18n-* and connect-* GUI files. Their only reds are 55 in agent-details-ready, agent-switch-accounts and agent-menu-label. The same 55 fail on origin/main459d668b3alone, and are filed as #6373, #6369, #5925, #6029 and #6371. Not run: the full `go test ./...` and the whole GUI suite. Both machines' suite locks were queued behind other sessions' suites for hours. Not tried: Pi forks, or a real vendor upstream behind each protocol (the upstream was a fake).
Subsystem design references
These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.
| Subsystem | Reference |
|---|---|
| Built-in subscriptions moving to plugins | Provider and plugin ownership |
| Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) | Plugin runtime |
| Plugins that run on the gateway's requests and replies | Gateway middleware |
| Tools that plugins give, offered to every agent as an MCP server | Plugin tools |
| Plugins that await context recall and observe completed replies | Asynchronous gateway request hooks |
| Claude subscription turns across Claude Code runs | Claude subscription bridge |
| How the gateway picks a provider, key or account, and falls back | Gateway routing and fallback |
| Gateway Session Aggregation | Gateway Session Aggregation |
| Connecting an agent's config to the gateway, drift, disconnect, WSL twins | Agent wiring |
| Providers, keys, subscription accounts, refresh and allowance | Providers and accounts |
| Instructions, MCP servers, skills and RTK written into agents | Library |
| One MCP server, magpie, given to every agent in place of the Library's servers | MCP router |
| Memory shared by every agent: the memory MCP server, the digest in instructions, the Memory tab | Memory |
| One skill, magpie-skills, listing the Library's skills in place of each agent's own | Skill router |
Tray, panel, window, magpie web and the page's JSON API |
GUI app shell |
| Encrypted backups and setup synchronization over WebDAV, S3 or GitHub | Sync and backup |
A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.
Maintain a reference
Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.
Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.
For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.
Describe a PR's semantic changes
For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.
For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.
This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.
Review a change
- Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
- Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
- Check that changed contracts appear in the owning reference and that source links still resolve.
- Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.
A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.