模块 supervisor — 对子代理的监督

🟢 该模块让父代理能够启动子代理, 订阅其子代理的选定事件,并在事件匹配时获得注入到自身上下文的内容——可选择暂停 子代理。子代理中无需钩子:这是事件总线 (events.subscribers)和公共端口 agent_os.Agents 之上的外部 control-plane。

工具 supervisor

一个带有 action 字段的工具 kind: supervisor:

action 字段 作用
spawn template, task?, session_key? 非阻塞启动子代理;返回 pid
subscribe event?, inject, child?, role?, pause_child?, resume_after?, run_turn?, once? 父代理订阅子代理事件;返回 id
unsubscribe id 取消订阅
subscriptions — 活动订阅列表
send pid, content, role? 向子代理注入消息
pause / resume pid 暂停/恢复子代理
stop pid, signal? pause | interrupt | terminate(默认 interrupt)
status pid 子代理进程快照
session pid, limit? 运行中子代理的实时会话:其上下文的最新消息(role, content, tool_call_id, tool_calls);limit 默认为 50

订阅与投递

随附代理 observer

该模块通过 config 捆绑包提供一个现成的观察者代理 observer (agents/observer/):它声明 tool_files: [tools/supervisor.yaml] 并拥有 所有 supervise 操作 — spawn, subscribe, session, send, pause/resume/stop。在模块启用时随 config/agents/ 一起加载(来自 config/agents 的同名代理 优先)。典型场景: observer 启动 coder 并监视其崩溃。

示例

该工具也可以在自己的代理中声明:

# config/agents/supervisor-agent/tools/supervisor.yaml
kind: supervisor
name: supervise
description: Запускай код-агента и следи за его падениями.
  1. { "action": "spawn", "template": "coder", "task": "Почини сборку" } → pid。
  2. { "action": "subscribe", "child": "<pid>", "event": { "kind": "tool_result", "success": false }, "inject": "崩溃了:{{ event.content }}。帮忙修复。", "pause_child": true, "resume_after": true, "run_turn": true }。
  3. 父代理独立工作;当子代理崩溃时,获得注入到自身 上下文的内容(子代理可选暂停)。
  4. { "action": "session", "pid": "<pid>", "limit": 50 } — 查看 子代理当前正在做什么。

全局规则(替代方案)

对于不绑定到特定父代理的声明式规则,有 reactions 模块:操作 inject(包括 target: parent)和 signal 允许从规则中通知/停止进程。