Files
plugins/packages/system-prompt
yetone ff9d3a6446 system-prompt 0.1.1: models matches a model's own name, and a routing group's try on it
@liucl on X (11-09): a prompt only for gemini-3.8-flash. `models` was
checked with String(body.model ?? ctx.model).startsWith(m), but an agent
wired to magpie names its model magpie's way, provider first
(google/gemini-3.8-flash, openrouter/google/gemini-3.8-flash), or names a
routing group (group/...). So "models": ["gemini-3.8-flash"] never
matched, though the README said "models whose names begin with one of
these prefixes".

A prefix now matches the whole id or the part after any "/" of it, case
aside; full-id prefixes (google/, deepseek) work as before. magpie's
middleware gets the agent's body at onRequest (ctx.model is modelOf(body),
serveAgent in internal/gateway/middleware.go), so a group request names
the group there. The member is known on each try: onProvider gets
ctx.provider {id, model} and can change that try's body
(docs/subsystems/gateway-middleware.md, triedOn). A request onRequest
didn't match is matched there against the member's model (and id/model),
so only the tries on gemini-3.8-flash get the prompt. ctx.state.given
keeps a try from adding it a second time after onRequest did.

Run on mote: packages/system-prompt bun test, 24 pass 0 fail (13 new
cases); bun scripts/check.mjs, all ok. In magpie's own engine: a
throwaway test in a detached magpie worktree at origin/main (removed, not
committed) loaded this module through internal/middleware's Begin,
Request and Tried in moejs: google/ and openrouter/google/gemini-3.8-flash
got it once, gemini-3.8-pro none, group/fast got it on the google
gemini-3.8-flash try and not on a deepseek try, no failures counted.
Broken by hand: with the old startsWith in onRequest, the 4 name cases go
red; with onProvider not exported, the 2 group-try cases; without
ctx.state.given, the "not given it twice" case.
Not tried: a real agent through a real magpie gateway and Gemini account.
Without override, an agent's own system prompt is kept and none is
added, as before; the README's example sets override.
2026-11-09 14:54:54 +08:00
..
middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon.
2026-10-05 20:49:42 +08:00

@magpie-community/middleware-system-prompt

New API's 系统提示词 (a channel's system_prompt and its override switch) as magpie gateway middleware. It gives the requests agents send a system prompt of yours, in each API's own place for one:

API Where the prompt goes
Anthropic system
Chat the first system or developer message
Responses instructions
Gemini systemInstruction

Install it from magpie's Plugins › Discover, or with magpie plugin add @magpie-community/middleware-system-prompt. Set its options under Plugins › Installed › Options, or with magpie plugin options system-prompt '<json>'.

Options

{ "system_prompt": "Reply in the language the user writes in.",
  "override": true, "position": "append",
  "agents": ["claude"], "models": ["deepseek"] }
  • No system prompt yet. A request without one gets yours.

  • override. A request that has its own prompt keeps it unchanged, unless override is true. Then yours goes in as well, placed by position:

    • "append" (the default) puts yours after it. Agents cache their own prompt, so adding after it keeps that cache.
    • "prepend" puts yours before it, as New API does. This makes the provider read the whole prompt again on every turn.
  • agents. When given, the prompt applies only to these agents, by magpie's agent ids: claude, codex, opencode, and so on.

  • models. When given, the prompt applies only to models whose names begin with one of these prefixes, case aside. A prefix may begin magpie's whole model id (google/gemini) or the model's own name after its provider (gemini-3.8-flash matches google/gemini-3.8-flash and openrouter/google/gemini-3.8-flash). In a routing group the prompt goes only to the tries on a model in models: to give Gemini 3.8 Flash a prompt and no other model, whether it is asked directly or through a group, use (override, since most agents send a prompt of their own)

    { "system_prompt": "Answer in Chinese.", "override": true, "models": ["gemini-3.8-flash"] }
    

Codex sends its own model instructions, and changing them can change how its models behave. Use agents to leave Codex out if you don't want that.

中文:New API 的「系统提示词」,作为 magpie 网关中间件。默认把你的提示词加在 agent 自己的提示词之后,这样不会破坏提示缓存。models 按模型名前缀匹配(不分大小写),可以写完整 id(如 google/gemini),也可以只写模型名(如 gemini-3.8-flash,会匹配 google/gemini-3.8-flash、openrouter/google/gemini-3.8-flash);路由组里只有发往这些模型的请求会加上提示词。例如只给 gemini-3.8-flash 加提示词:{"system_prompt": "用中文回答。", "override": true, "models": ["gemini-3.8-flash"]}。