minion-orchestrator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMinion Orchestrator
Minion编排器
Contract
协议
Minions is a Postgres-native job queue for durable, observable background work.
This single skill handles two lanes:
- Deterministic shell jobs ()
gbrain jobs submit shell ... - LLM subagent jobs ()
gbrain agent run ...
When to route to Minions: durable, observable work that must survive restarts,
fan out across many parallel tasks, or persist across sessions. Routing policy
is defined in — the project default is
(native subagents first, Minions after specific pain signals
fire); Mode A (all-through-Minions) is opt-in.
skills/conventions/subagent-routing.mdpain_triggeredGuarantees:
- Jobs survive gateway restart (Postgres-backed)
- Every job has structured progress, token accounting, and session transcripts
- Running agents can be steered mid-flight via inbox messages
- Jobs can be paused, resumed, or cancelled at any time
- Parent-child DAGs with configurable failure policies
Minions是一个基于Postgres的原生任务队列,用于处理持久化、可观测的后台任务。
这一单一技能涵盖两类任务:
- 确定性shell任务()
gbrain jobs submit shell ... - LLM子代理任务()
gbrain agent run ...
何时路由至Minions:需要持久化、可观测,且必须在重启后仍能运行、需并行分发多个任务,或跨会话持久化的任务。路由策略定义于——项目默认策略为(优先使用原生子代理,触发特定异常信号后再使用Minions);模式A(所有任务均通过Minions)为可选启用模式。
skills/conventions/subagent-routing.mdpain_triggered特性保障:
- 任务可在网关重启后继续执行(基于Postgres存储)
- 每个任务都有结构化进度、令牌统计和会话记录
- 运行中的代理可通过收件箱消息进行中途控制
- 任务可随时暂停、恢复或取消
- 支持带有可配置失败策略的父子DAG(有向无环图)
Route the Request: Shell Job vs Subagent
路由请求:Shell任务 vs 子代理
| Condition | Action |
|---|---|
| User asks for deterministic command/script run | Shell job (CLI: |
| User asks to "run in minions" + explicit command/argv | Shell job (CLI, |
| User asks for research/reasoning/iterative agent | Subagent job (CLI: |
| User asks to steer/pause/resume an agent | Subagent job lifecycle tools (MCP-callable) |
| Single simple operation under ~30s | Consider inline execution first |
| Needs restart durability/observability | Submit as Minion job |
| Parallel work (2+ streams) | |
If intent is ambiguous, ask one clarification:
"Do you want a deterministic shell command job, or an LLM agent job?"
| 条件 | 操作 |
|---|---|
| 用户要求执行确定性命令/脚本 | Shell任务(CLI: |
| 用户要求“在minions中运行” + 明确命令/参数 | Shell任务(CLI,通过 |
| 用户要求进行研究/推理/迭代式代理任务 | 子代理任务(CLI: |
| 用户要求控制/暂停/恢复代理 | 子代理任务生命周期工具(可通过MCP调用) |
| 单个简单操作耗时约30秒以内 | 优先考虑内联执行 |
| 需要重启后仍能持久化/可观测 | 提交为Minion任务 |
| 并行任务(2个及以上流) | |
若意图不明确,需询问澄清:
“您需要的是确定性shell命令任务,还是LLM代理任务?”
Shell Jobs (Deterministic Scripts)
Shell任务(确定性脚本)
Use for reproducible command execution, ETL steps, cron work, and scriptable
tasks where no LLM reasoning loop is needed.
适用于可复现的命令执行、ETL步骤、定时任务,以及无需LLM推理循环的脚本化任务。
Preconditions (read before submitting your first shell job)
前置条件(提交首个shell任务前请阅读)
- must be set on the worker environment. Without it, the shell handler refuses to register and submissions sit in
GBRAIN_ALLOW_SHELL_JOBS=1silently. Gate lives inwaiting.src/core/minions/handlers/shell.ts - Security: flipping authorizes arbitrary command execution on the worker. On a shared queue, this is a remote code execution surface. Treat as privileged infrastructure authorization.
GBRAIN_ALLOW_SHELL_JOBS=1 - Execution mode — pick one:
- Postgres + daemon: runs a persistent worker that claims and executes jobs from the queue.
gbrain jobs work - PGLite + --follow: runs inline. The daemon mode is not available on PGLite (exclusive file lock). See
gbrain jobs submit ... --follow.docs/guides/minions-shell-jobs.md
- Postgres + daemon:
- MCP boundary: shell-job submission is CLI-only. over MCP throws an
submit_job name="shell"with codeOperationError("'shell' jobs cannot be submitted over MCP") becausepermission_deniedis inshell. Agents CAN observe shell jobs viaPROTECTED_JOB_NAMES/get_job/list_jobs(not protected), but cannot submit them. Operator or autopilot submits; agent observes.get_job_progress - Verify setup: after configuration, run (CLI) to confirm the worker is registered and consuming the queue.
gbrain jobs stats
- 工作环境必须设置。 若未设置,shell处理程序将拒绝注册,提交的任务会静默处于
GBRAIN_ALLOW_SHELL_JOBS=1状态。限制逻辑位于waiting。src/core/minions/handlers/shell.ts - 安全性:设置将授权工作节点执行任意命令。在共享队列环境中,这存在远程代码执行风险。需视为特权基础设施授权。
GBRAIN_ALLOW_SHELL_JOBS=1 - 执行模式——二选一:
- Postgres + 守护进程:启动一个持久化工作节点,从队列中获取并执行任务。
gbrain jobs work - PGLite + --follow:以内联方式运行。 PGLite不支持守护进程模式(文件独占锁)。详见
gbrain jobs submit ... --follow。docs/guides/minions-shell-jobs.md
- Postgres + 守护进程:
- MCP边界:shell任务提交仅支持CLI。通过MCP调用会抛出
submit_job name="shell",错误码为OperationError(“'shell'任务无法通过MCP提交”),因为permission_denied属于shell。 代理可通过PROTECTED_JOB_NAMES/get_job/list_jobs观测shell任务(这些操作不受保护),但无法提交。仅操作员或自动驾驶系统可提交;代理仅可观测。get_job_progress - 验证设置:配置完成后,运行(CLI)确认工作节点已注册并正在消费队列。
gbrain jobs stats
Submit (CLI, operator or autopilot)
提交(CLI,操作员或自动驾驶系统)
Shell jobs take their command via as a JSON object with (string)
or (array), plus and optional .
--paramscmdargvcwdenvCommand string form:
gbrain jobs submit shell --params '{"cmd":"echo hello","cwd":"/abs/path"}'Argv form (no shell expansion):
gbrain jobs submit shell --params '{"argv":["bash","-lc","echo hello"],"cwd":"/abs/path"}'Inline execution on PGLite or any one-shot deployment:
gbrain jobs submit shell --params '{"cmd":"echo hello","cwd":"/tmp"}' --followQueue/lifecycle flags exposed by : ,
, , , , ,
, , , ,
.
gbrain jobs submit --help--queue--priority--delay--max-attempts--max-stalled--backoff-type--backoff-delay--backoff-jitter--timeout-ms--idempotency-key--dry-runShell任务通过传入JSON对象指定命令,包含(字符串)或(数组),以及和可选的。
--paramscmdargvcwdenv命令字符串形式:
gbrain jobs submit shell --params '{"cmd":"echo hello","cwd":"/abs/path"}'Argv形式(无shell扩展):
gbrain jobs submit shell --params '{"argv":["bash","-lc","echo hello"],"cwd":"/abs/path"}'在PGLite或任何一次性部署中内联执行:
gbrain jobs submit shell --params '{"cmd":"echo hello","cwd":"/tmp"}' --followgbrain jobs submit --help--queue--priority--delay--max-attempts--max-stalled--backoff-type--backoff-delay--backoff-jitter--timeout-ms--idempotency-key--dry-runMonitor (agents or operator)
监控(代理或操作员)
These operations are MCP-callable and safe for agent use:
list_jobs --name shell --status active
get_job ID
get_job_progress IDCheck structured result fields (exit code, stdout/stderr tails, attempts,
timings) from . Use (CLI) for worker/queue
health dashboard.
get_jobgbrain jobs stats以下操作可通过MCP调用,且对代理安全:
list_jobs --name shell --status active
get_job ID
get_job_progress ID从中查看结构化结果字段(退出码、stdout/stderr尾部、尝试次数、时间统计)。使用(CLI)查看工作节点/队列健康仪表板。
get_jobgbrain jobs statsControl (MCP-callable)
控制(可通过MCP调用)
cancel_job id=ID
replay_job id=IDreplay_jobUse idempotency keys for recurring shell workloads to avoid duplicate runs.
cancel_job id=ID
replay_job id=IDreplay_job对周期性shell工作负载使用幂等键,避免重复运行。
Subagent Jobs (LLM Orchestration)
子代理任务(LLM编排)
Use for open-ended reasoning, tool-using research, and fan-out synthesis.
User-facing entrypoint: is the canonical way
to submit subagent work. It handles the elevated-trust plumbing —
and are both in , so direct MCP
submission requires , which
supplies.
gbrain agent run <prompt>subagentsubagent_aggregatorPROTECTED_JOB_NAMES{allowProtectedSubmit: true}gbrain agent run适用于开放式推理、工具调用型研究,以及分发式合成任务。
用户入口:是提交子代理任务的标准方式。它处理高信任度的管道——和均属于,因此直接通过MCP提交需要,而会自动提供该参数。
gbrain agent run <prompt>subagentsubagent_aggregatorPROTECTED_JOB_NAMES{allowProtectedSubmit: true}gbrain agent runPhase 1: Submit
阶段1:提交
gbrain agent run "Research Acme Corp revenue" --tools "search,query"--toolsBRAIN_TOOL_ALLOWLISTsrc/core/minions/tools/brain-allowlist.tsquerysearchget_pagelist_pagesfile_listfile_urlget_backlinkstraverse_graphresolve_slugsget_ingest_logput_pageallowed_tools references unknown toolFor parallel work with a fan-out manifest:
gbrain agent run --fanout-manifest companies.jsonThe manifest describes N children + 1 aggregator. Each child runs
under the hood; the aggregator runs
and claims AFTER every child terminates. See
and
.
name="subagent"name="subagent_aggregator"src/core/minions/handlers/subagent.tssrc/core/minions/handlers/subagent-aggregator.tsFlags (from ):
src/commands/agent.ts- — named subagent definition
--subagent-def <name> - — override model
--model <id> - — cap the LLM loop
--max-turns <N> - — allow-listed brain tools (see above)
--tools <csv> - — hard timeout per job
--timeout-ms <N> - — N children + 1 aggregator
--fanout-manifest <file> - /
--follow— stream logs + wait (default on TTY)--no-follow - — submit and return immediately
--detach
Queue/priority/retry tuning is not exposed by ; submit the
raw handler via (requires CLI trust) if you
need those knobs.
gbrain agent runsubagentgbrain jobs submitgbrain agent run "Research Acme Corp revenue" --tools "search,query"--toolsBRAIN_TOOL_ALLOWLISTsrc/core/minions/tools/brain-allowlist.tsquerysearchget_pagelist_pagesfile_listfile_urlget_backlinkstraverse_graphresolve_slugsget_ingest_logput_pageallowed_tools references unknown tool使用分发清单处理并行任务:
gbrain agent run --fanout-manifest companies.json清单描述了N个子代理 + 1个聚合器。每个子代理在后台运行;聚合器运行,并在所有子代理终止后执行。详见和。
name="subagent"name="subagent_aggregator"src/core/minions/handlers/subagent.tssrc/core/minions/handlers/subagent-aggregator.ts标志(来自):
src/commands/agent.ts- — 命名子代理定义
--subagent-def <name> - — 覆盖默认模型
--model <id> - — 限制LLM循环次数
--max-turns <N> - — 允许使用的brain工具(见上文)
--tools <csv> - — 任务硬超时时间
--timeout-ms <N> - — N个子代理 + 1个聚合器
--fanout-manifest <file> - /
--follow— 流式日志 + 等待(终端环境默认启用)--no-follow - — 提交后立即返回
--detach
gbrain agent rungbrain jobs submitsubagentPhase 2: Monitor
阶段2:监控
list_jobs --status active # MCP — what's running?
get_job ID # MCP — full details + logs + tokens
get_job_progress ID # MCP — structured progress snapshot
gbrain jobs stats # CLI — queue health dashboard
gbrain agent logs ID --follow # CLI — streaming transcript + heartbeatProgress includes: step count, total steps, message, token usage, last tool called.
list_jobs --status active # MCP — 当前运行的任务?
get_job ID # MCP — 完整详情 + 日志 + 令牌统计
get_job_progress ID # MCP — 结构化进度快照
gbrain jobs stats # CLI — 队列健康仪表板
gbrain agent logs ID --follow # CLI — 流式会话记录 + 心跳进度信息包括:步骤计数、总步骤数、消息、令牌使用量、最后调用的工具。
Phase 3: Steer
阶段3:控制
Send a message to redirect a running agent:
send_job_message id=ID payload={"directive":"focus on revenue, skip headcount"}The agent handler reads inbox messages on each iteration and injects them as
context. Messages are acknowledged (read receipts tracked).
Only the parent job or admin can send messages (sender validation).
发送消息重定向运行中的代理:
send_job_message id=ID payload={"directive":"focus on revenue, skip headcount"}代理处理程序会在每次迭代时读取收件箱消息,并将其作为上下文注入。消息会被确认(已读状态会被跟踪)。
仅父任务或管理员可发送消息(发送者验证)。
Phase 4: Lifecycle
阶段4:生命周期
pause_job id=ID # freeze without losing state
resume_job id=ID # pick up where it left off
cancel_job id=ID # hard stop
replay_job id=ID # re-run with same or modified params
replay_job id=ID data_overrides={"depth":"deep"} # replay with changesAll lifecycle ops are MCP-callable.
pause_job id=ID # 冻结任务,不丢失状态
resume_job id=ID # 从暂停处继续执行
cancel_job id=ID # 强制停止
replay_job id=ID # 使用相同或修改后的参数重新运行
replay_job id=ID data_overrides={"depth":"deep"} # 修改参数后重新运行所有生命周期操作均可通过MCP调用。
Phase 5: Review Results
阶段5:查看结果
get_job ID # result, token counts, transcriptToken accounting: every job tracks , , .
Child tokens roll up to parent automatically on completion.
tokens_inputtokens_outputtokens_cache_readget_job ID # 结果、令牌统计、会话记录令牌统计:每个任务都会跟踪、、。子任务的令牌使用量会在完成后自动汇总到父任务。
tokens_inputtokens_outputtokens_cache_readOutput Format
输出格式
When reporting job status to the user:
Job #ID (name) — status
Progress: step/total — last action
Tokens: input_count in / output_count out (+ cache_read cached)
Runtime: Xs
Children: N pending, M completedWhen reporting completion:
Job #ID completed in Xs
Tokens used: input / output / cache_read
Result: <summary>When reporting batch status (parent with children):
Parent #ID — waiting-children
#A subagent(Acme) — active, 3/5 steps, 2.5k tokens
#B subagent(Beta) — completed, 1.8k tokens
#C subagent(Gamma) — paused
Total tokens so far: 4.3k向用户报告任务状态时:
任务 #ID(名称) — 状态
进度:已完成步骤/总步骤 — 最后操作
令牌:输入 input_count / 输出 output_count(+ 缓存读取 cache_read)
运行时间:X秒
子任务:N个待处理,M个已完成报告任务完成时:
任务 #ID 已完成,耗时X秒
令牌使用量:输入 / 输出 / 缓存读取
结果:<摘要>报告批量任务状态(父任务带多个子任务)时:
父任务 #ID — 等待子任务完成
#A subagent(Acme) — 运行中,3/5步骤,2.5k令牌
#B subagent(Beta) — 已完成,1.8k令牌
#C subagent(Gamma) — 已暂停
当前总令牌使用量:4.3kAnti-Patterns
反模式
- Don't spawn a Minion for a single search query (use search tool directly)
- Don't fire-and-forget without checking results
- Don't spawn > 5 concurrent agents without checking first
gbrain jobs stats - For subagent work, don't use with
sessions_spawnwhen Minions is available (useruntime: "subagent"instead)gbrain agent run - Don't poll in a tight loop (use
get_jobfor lightweight checks)get_job_progress
- 不要为单个搜索查询生成Minion任务(直接使用搜索工具)
- 不要提交任务后就不管不顾,不检查结果
- 在未查看的情况下,不要生成超过5个并发代理
gbrain jobs stats - 对于子代理任务,当Minions可用时,不要使用并设置
sessions_spawn(应使用runtime: "subagent")gbrain agent run - 不要在循环中频繁调用(使用
get_job进行轻量级检查)get_job_progress
Tools Used
使用的工具
- Submit a background job — (MCP, non-protected names only; shell jobs are CLI-only, subagent jobs via
submit_job)gbrain agent run - Get job details — (MCP)
get_job - List jobs with filters — (MCP)
list_jobs - Cancel a job — (MCP)
cancel_job - Pause a job — (MCP)
pause_job - Resume a paused job — (MCP)
resume_job - Replay a completed/failed job — (MCP)
replay_job - Send sidechannel message — (MCP)
send_job_message - Get structured progress — (MCP)
get_job_progress - Queue stats — (CLI; no MCP equivalent)
gbrain jobs stats
- 提交后台任务 — (MCP,仅支持非受保护名称;shell任务仅支持CLI,子代理任务通过
submit_job提交)gbrain agent run - 获取任务详情 — (MCP)
get_job - 过滤列出任务 — (MCP)
list_jobs - 取消任务 — (MCP)
cancel_job - 暂停任务 — (MCP)
pause_job - 恢复暂停的任务 — (MCP)
resume_job - 重放已完成/失败的任务 — (MCP)
replay_job - 发送侧通道消息 — (MCP)
send_job_message - 获取结构化进度 — (MCP)
get_job_progress - 队列统计 — (CLI;无MCP等效操作)
gbrain jobs stats