Agent Runtime 扩展点
状态:2026-11-14,hook 部分更新于 2026-11-16。已实现:角色 context、skill、tool、model、guard、reviewer、observer 与 service;可选接口 InputGuard、ResultGuard、CompletionGuard、InputLister 与 Embedder(pkg/plugin/
状态:2026-11-14,hook 部分更新于 2026-11-16。已实现:角色 context、skill、tool、model、guard、reviewer、observer 与 service;可选接口 InputGuard、ResultGuard、CompletionGuard、InputLister 与 Embedder(pkg/plugin/roles.go),以及 Rewriter、ToolNarrower、ModelGuard 与 StepGuard(pkg/plugin/rewrite.go、hookpoints.go,Hook 模型);hook 分层(policy.hooks)、并行 gate 与已观察事实日志(internal/host/engine/hookpoint.go、steps.go、internal/host/observed);与 Claude Code 对齐的 manifest 命令 hook,即 P22(internal/bundle/hooks.go、hookroles.go;参考:hook);Host 的检查与超时(internal/host/engine/hooks.go、guards.go、observe.go);以及 plugins/agent/plugin.yaml 中的 agent 配置字段。提案:提案登记表 中的 P7、P8、P9、P11、P17、P18、P19、P20 与 P21;P39 与 P40 在出现实际使用者之前暂缓。依据是 2026-11-14 调研综述。本文是插件和运维者改变 Agent Runtime 行为的完整扩展面。
1. 扩展形式
agent 没有自己的扩展注册表。插件在 plugin.yaml 中声明角色,并被放入 agent 实例的 uses,从而扩展 agent;运维者通过 agent 的 config 扩展它。按优先顺序:
| 形式 | 声明位置 | 绑定方式 | 新增一个是否需要改 Host |
|---|---|---|---|
| agent 配置字段 | plugins/agent/plugin.yaml 中的 config_schema | agent 实例的 config | 否 |
| 使用已有角色的插件 | 插件 manifest 的 roles: | agent 的 uses、被用实例的 scope、exclude、grants,以及运维 policy | 否 |
| manifest 命令 hook | plugin.yaml 中的 hooks:(无需代码的 guard) | 同角色 | 否(新事件:bundle 改动) |
| 角色的可选接口 | pkg/plugin/roles.go 中的 Go 接口,角色实现可额外满足 | 同角色 | ADR |
Caller 或 RuntimeHost 方法 | pkg/plugin/roles.go | 所有 runtime | ADR |
| 新角色 | pkg/plugin/roles.go 与 pkg/plugin/manifest.go 中的 KnownRoles | 同所有角色 | ADR |
身份与权限从不来自插件:每个角色方法收到的都是 Host 填写的 CallContext,每次调用都限于调用方的 uses。process 插件通过 JSON-RPC(pkg/plugin/rpc)实现同样的接口;下文每个新接口也都有对应的 JSON-RPC 方法和一致性测试。
2. 各扩展在一次 run 中的作用位置
flowchart TB
A["Trigger 决定 start"] --> B["InputGuard.CheckInput"]
B --> C["run 开始:Caller.Tools(固定)· Caller.Skills<br/>Caller.ContextItems → ContextProvider.Context<br/>(Caller.Instructions:P9 · Caller.Subagents:P8)"]
C --> D["每个 step:Caller.Chat → Model.Chat<br/>(Purpose:P20 · 压缩:P5)"]
D --> E["每次工具调用:agent 的 allow/ask/deny<br/>Guard.Check(Ask:P17)· Reviewer.Review(PolicyHost:P18)· 人<br/>Tool.Invoke · ResultGuard.CheckResult"]
E --> F["一批调用之后:(Caller.CheckStep:P7)<br/>(Caller.StepContext:P19)"]
F --> D
D --> G["最终回答:CompletionGuard.CheckCompletion<br/>(Withhold:P21)"]
G -->|反馈| D
G --> H["Result → Host 提交 run"]
H --> I["Observer.Observe run.finished<br/>(类型化事件、conversation 授权:P11)"]guard、reviewer 和 hook 在 Caller.CallTool 与 Host 的输入检查内部生效,因此适用于所有 runtime,而不只是 plugins/agent。上下文、技能、工具、模型,以及(P7、P9、P19 之后的)step 检查、指令和 step 上下文,是 agent 通过 Caller 主动请求的;其他 runtime 可以请求,也可以不请求。
3. 已实现能力目录
超时是 Host 常量(internal/host/engine/hooks.go 中的 contextTimeout、guardTimeout;guards.go 中的 checkTimeout、reviewTimeout)。
| 角色或接口 | 方法 | 时机 | 权力 | 失败 | 超时 |
|---|---|---|---|---|---|
context | ContextProvider.Context(cc, ContextInput) | run 开始时一次,经 Caller.ContextItems | 添加参考条目;不能下指令 | 省略,记 context.provider_failed | 5 s |
skill | SkillSource.Skills、LoadSkill | run 开始时取卡片;load_skill 或 $name 时取正文与文件 | 添加卡片与文本;不授予任何权限 | 列表出错则该实例缺席;两个实例提供同名技能则都缺席(skill.ambiguous) | — |
tool | Tool.Tools(cc)、Invoke | 每次 run 列出并固定;每次调用时执行 | 提供工具;两个实例提供同名工具则拒绝 | 错误成为给模型的错误结果 | 工具自身 |
model | Model.Chat;可选 InputLister、Embedder | 每个 step,经 Caller.Chat;Caller.Embed | 产生回复与向量 | run 失败(P4 提议回退) | run 超时 |
guard | Guard.Check(cc, ToolIntent) | 每次工具调用前,调用链上每个实例 | 拒绝 | 出错或超时即拒绝 | 5 s,若该实例 pre_tool 最长 hook 超时 + 1 s 更长则取之 |
guard + InputGuard | CheckInput(cc, ContextInput) | runtime 看到输入之前;runtime 的 uses 中的 guard | 拒绝本次 run(input.denied) | 出错或超时即拒绝 | 10 s,若 最长 hook 超时 + 1 s 更长则取之 |
guard + ResultGuard | CheckResult(cc, intent, res) | 每个工具结果之后、模型看到之前 | 扣留结果或附加说明;账本保留原文 | 出错或超时即扣留 | 10 s,若 最长 hook 超时 + 1 s 更长则取之 |
guard + CompletionGuard | CheckCompletion(cc, CompletionInput) | 每个最终回答,每次 run 最多两轮(maxChecks,plugins/agent/loop.go) | 给出要求继续工作的反馈 | 扣下回答并说明未能检查,记 guard.completion_failed(自 2026-11-18 起失败即拦截,负责人的决定) | 10 s,若 最长 hook 超时 + 1 s 更长则取之 |
reviewer | Reviewer.Review(cc, intent) | 需要审批的调用,在询问人之前 | 批准、拒绝或上交;需要 grants: [review];不能批准审批人为 admin 的调用(自 2026-11-18 起,负责人的决定),只能拒绝 | 上交给人 | 30 s,若 最长 hook 超时 + 1 s 更长则取之 |
guard + Rewriter | Rewrite(cc, ToolIntent) | 每次工具调用的 gate 阶段之前;链式,先 Runtime 层,最后运维层 | 有 grants: [rewrite] 时替换参数(ADR 0005);对最终参数做 schema 检查、gate 和审批 | 拒绝调用 | 5 s,若最长 hook 超时 + 1 s 更长则取之 |
guard + ToolNarrower | FilterTools(cc, tools) | run 列出其工具时 | 移除工具(取交集);调用被移除的工具会被拒绝 | 忽略,记 guard.filter_failed | 10 s |
guard + ModelGuard | BeforeModel(cc, req)、AfterModel(cc, req, resp) | 每次模型调用前后;链式顺序同 Rewriter | 拒绝调用;有 rewrite 授权时改写消息或回复文本 | 拒绝调用 | 10 s |
guard + StepGuard | CheckStep(cc, StepInput),通过 Caller.CheckStep 询问 | 一批工具调用结算之后、下一次模型调用之前 | 添加上下文(来自运维层时为指令)或停止 run | 跳过,记 guard.step_skipped | 10 s |
observer | Observer.Observe(ev, BackgroundHost) | 某个事实提交之后:run.finished、session.opened、session.closed、tool.finished、question.asked、question.settled、compaction.done、delivery.sent、delivery.failed(日志 observed_events) | 无;只读;忽略未知类型 | 从持久游标重试;失败 8 次后跳过(observer.event_skipped) | 2 min |
service | Service.Serve(BackgroundHost) | 实例存续期间 | 自己的工作,如建索引 | 退避重启,1 s 起翻倍至 5 min | — |
| agent 配置字段 | 作用 | 状态 |
|---|---|---|
model、name、instructions、timezone | 模型实例与运维者文本 | 已实现 |
max_steps、max_tool_calls、max_output_tokens | run 的限额(内核) | 已实现 |
allow、ask、deny | agent 自身权限规则的工具名模式 | 已实现;参数规则见 P27 |
instructions_from、instructions_budget | 系统提示词中的插件指令 | P9 |
step_context_from | 被询问 step 上下文的实例 | P19 |
subagents、subagents_from | delegate 的子 agent 定义 | P8 |
compact_model、context_window、compact_at、compact_tail_tokens | 压缩(压缩) | P5 |
fallback_models | 主模型失败时依次尝试的模型 | P4 |
require_tools、skill_list_budget、skill_full_count、skill_full_tokens、skill_index_chars、edit_tool | agent 必需的工具、技能列表大小、技能列表何时完整何时为索引(飞书 #426)、编辑工具形式 | P10、P13、Planned |
命令 hook。 manifest 插件的 hooks: 无需代码即可填充角色(P22,2026-11-16 已实现):pre_tool、post_tool、user_input、stop 与 subagent_stop 填充 guard 角色,session_start 填充 context 角色,pre_compact 填充 observer 角色,permission_request 填充 reviewer 角色(仅限有 grants: [review] 时;否则跳过并记录日志)。它们使用 Claude Code 的 JSON 协议,不经 shell 运行。所有匹配的 hook 按 manifest 顺序运行,回答按 deny > ask > allow 合并;ask 需要人工审批;来自 user_input 的 additionalContext 成为本次 run 的上下文条目,来自未阻断的 pre_tool 的成为该调用结果的注释。载荷包含 session_id、cwd、tool_use_id、permission_mode 与 stop_hook_active。未设置 timeout 时 hook 10 s 超时,Host 的上限随之增长;失败的 hook 会拒绝,除非 on_error: ignore。完整的协议、顺序与合并规则见 hook(TestHooksMergeAndAsk、TestContextAndStopEvents、TestReviewAndPreCompact、TestHookBudget)。
4. 权限决定
flowchart LR
P["模型发起的工具调用"] --> R["agent 规则<br/>deny · ask · allow"]
R -->|ask| Q1["问题 approve:key"]
R -->|allow| C
Q1 --> C["Caller.CallTool<br/>账本 · 固定列表 · 深度"]
C --> G["Guard.Check,调用链上每个 guard<br/>allow < ask(P17)< deny"]
G --> A{"ToolSpec.Approval、实例 approval,<br/>或有 guard 要求审批?"}
A -->|是| V["Reviewer.Review,然后是人"]
A -->|否| I
V --> I["记录 started · Tool.Invoke"]
I --> RG["ResultGuard.CheckResult"]决定构成顺序 allow < ask < deny,每一步只能提高它。agent 的 deny 把工具从模型的列表中移除;它的 ask 在 CallTool 之前询问。在 CallTool(internal/host/engine/toolcall.go)内部,guard 先于任何审批运行,所以没有人会被要求批准一个随后会被拒绝的调用。有授权的 reviewer 先决定:任一拒绝即拒绝,批准需要所有 reviewer 都批准,其余情况交给人。agent 的规则和 Host 的审批共用键 approve:<call key>,因此一次调用至多询问一次。参数由写入检查点的模型回复固定,所以审批不会在参数改变后继续有效。
5. 提案
5.1 P17:guard 判定 ask
已实现(ADR 0002):下文的字段、按最严格审批人合并、列出提出要求的 guard 的提问文本、输入检查中 Ask 视为拒绝,以及 guard.asked(internal/host/engine/hooks.go、toolcall.go、TestGuardAsksForApproval)。提问 key 是 D17 中 Host 自有的 host:approve:<call key>:<请求摘要>。
type GuardDecision struct {
Deny bool `json:"deny"`
Ask bool `json:"ask,omitempty"` // P17: this call needs approval
Reason string `json:"reason,omitempty"` // to the approver; on deny, to the model
Approver string `json:"approver,omitempty"` // P17: "", "admin" or "any", as in ToolSpec
}- ◆合并。
CallTool按顺序询问调用链上的每个 guard,遇到第一个Deny即停止。否则只要有Ask,该调用就与设置了ToolSpec.Approval一样需要审批。在要求审批的 guard 与工具自身的Approver之间取最严格的审批人,顺序为any< 请求者("")<admin。 - ◆问题。 一个键为
approve:<call key>的问题;提示中在参数上方按<instance>: <reason>列出每个要求审批的 guard。有授权的 reviewer 先决定。Ask在CheckInput或CheckStep中没有意义,在那里按Deny处理。 - ◆失败。 不变:出错或 5 s 超时即拒绝。
- ◆恢复。 重启后从账本重新进入该调用:guard 再次运行(此时拒绝就拒绝),未决问题按键找回,所以只问人一次。
- ◆日志。
guard.asked,带instance、tool、call_key。
5.2 P18:PolicyHost
guard、reviewer、completion guard 和 step guard 可能需要模型(分类器、智能审批、评审)。没有 P18,它们只能绕过 Host 的计量和 uses。
// PolicyHost lets a policy role call a model while it decides.
type PolicyHost interface {
Chat(ctx context.Context, cc CallContext, model string, req ChatRequest) (ChatResponse, error)
}
// PolicyHostBinder is optionally implemented by guard and reviewer plugins.
type PolicyHostBinder interface{ BindPolicyHost(h PolicyHost) }- ◆绑定。 实例启动时绑定一次;在 JSON-RPC 上是 host 方法
policy/chat,携带该次检查的 id。现有 guard 无需修改即可编译。 - ◆限制。
model必须在该策略实例自己的uses中。只有该cc的检查正在进行时才接受调用,否则返回policy.no_check。每次检查:Check与CheckStep一次模型调用,Review与CheckCompletion两次;max_tokens至多 2,048;不带工具;不流式。超出即policy.budget_exceeded。 - ◆计量。 用量计入 run 的
limits(tokens_per_run);ChatRequest.Purpose为policy(P20),记录在model.called中。 - ◆恢复。 策略调用没有副作用,不进账本;被中断的检查重新运行。
5.3 P7:StepGuard
type StepInput struct {
Step int `json:"step"` // 1-based step that just settled
Calls []StepCall `json:"calls"` // its settled calls, in call order
Usage Usage `json:"usage"` // run total so far
}
type StepCall struct {
Name string `json:"name"`
Provider string `json:"provider"`
Key string `json:"key"`
IsError bool `json:"is_error"`
Summary string `json:"summary"` // first 500 characters of the result the model saw
}
type StepDecision struct {
Deny string `json:"deny,omitempty"` // ends the run
Feedback string `json:"feedback,omitempty"` // a notice before the next step
}
type StepGuard interface { // optional, on the guard role
CheckStep(ctx context.Context, cc CallContext, in StepInput) (StepDecision, error)
}
// Caller.CheckStep(ctx, in StepInput) (StepDecision, error)- ◆时机。 agent 在每批工具调用之后、下一次模型调用之前调用
Caller.CheckStep。Host 按顺序询问 runtime 的uses中的 guard,遇到第一个Deny即停止。 - ◆效果。
Deny使 run 以失败结束,错误码agent.step_denied,附带原因;用户收到本地化消息agent.step_denied。每个 guard 的Feedback(各至多 2,000 字符)作为一条 user 角色消息<orq:reminder source="<instance>" kind="step_feedback">…</orq:reminder>追加(提醒)。 - ◆失败。 出错或 10 s 超时即拒绝。
- ◆恢复。 决定连同 step 编号存入检查点;恢复的 run 不会对已完成的 step 再问一次。
- ◆命令 hook。 新事件
step,对应 Claude Code 的PostToolBatch:continue: false或decision: "block"即拒绝;continue为 true 时reason成为Feedback。
5.4 P19:step 上下文
在 run 开始之后补充参考材料(改动的文件、git 状态、新子话题的记忆),而不改变前缀。放置位置与 token 计算见 上下文;接口如下:
type ContextItem struct {
ID string `json:"id,omitempty"` // P19: stable per provider
Title string `json:"title,omitempty"`
Content string `json:"content"`
}
type StepContextInput struct {
Step int `json:"step"`
Calls []StepCall `json:"calls"` // the previous step's calls, as in P7
Known []ItemRef `json:"known,omitempty"` // items this provider already added in this run
}
type ItemRef struct {
ID string `json:"id"`
Digest string `json:"digest"` // sha256 of Content, hex
}
type StepContextProvider interface { // optional, on the context role
StepContext(ctx context.Context, cc CallContext, in StepContextInput) ([]ContextItem, error)
}
// Caller.StepContext(ctx, in StepContextInput) ([]ContextItem, error)- ◆每批工具调用之后询问,只问 agent 的
step_context_from中列出的实例,按列出顺序。 - ◆条目作为一条 user 角色消息
<orq:reference>追加在工具结果之后,从不插入前缀。ID 与摘要都与已知条目相同的条目被丢弃。 - ◆超时 3 s,所有提供者合计每个 step 至多 4,000 字符;失败时省略并记
context.step_failed。 - ◆条目保存在检查点中;压缩之后,已知条目完整重发一次。
5.5 P9:InstructionSource
type Instruction struct {
ID string `json:"id"` // ^[a-z0-9][a-z0-9._-]{0,63}$, unique per instance
Text string `json:"text"` // at most 4,000 characters
}
type InstructionSource interface { // optional, on the context role
Instructions(ctx context.Context, cc CallContext) ([]Instruction, error)
}
// Caller.Instructions(ctx) ([]Instruction, error)config:
instructions_from:
- instance: org-style
required: false
instructions_budget: 8000 # characters, all sources together- ◆只询问
instructions_from中列出的实例,按列出顺序;其他任何东西都不能添加指令。 - ◆在第一个 step 读取一次。文本存入检查点,因此恢复的 run 发送逐字节相同的系统提示词。这些文本应在多次 run 之间保持稳定:每次 run 都变的来源会破坏提示词缓存。
- ◆以
# Instructions from <instance>小节放在运维者的instructions之后;系统提示词说明二者冲突时以运维者文本为准(系统提示词)。超出预算时丢弃排在最后的来源,并记agent.instructions_truncated。 - ◆失败或超时(5 s)的来源被省略并记
instructions.provider_failed;若required: true,run 以agent.instructions_missing失败。
5.6 P11:类型化观察事件与 conversation 授权
已于 2026-11-16 按以下形式实现:观察事实日志(internal/host/observed),类型包括 run.started、run.finished、model.called、tool.finished(下文称 tool.called)、question.asked、question.settled、compaction.done(下文称 run.compacted)、guard.denied、session.opened、session.closed、delivery.sent、delivery.failed(pkg/plugin/decisions.go);manifest 的 events:(默认 run.finished 加上插件命令 hook 观察的类型);conversation 授权,没有它时 Input、Output、问题文本和 guard 的原因都为空。subagent.finished 尚未实现。
| 类型 | Data |
|---|---|
run.started | {runtime, generation} |
run.finished | {state, err_code}(现有事件) |
model.called | {model, purpose, usage, stop_reason, duration_ms, err_code} |
tool.called | {name, provider, key, outcome: ok|error|denied|withheld|unknown, duration_ms} |
question.asked、question.answered | {key, kind, status} |
run.compacted | {before_tokens, after_tokens, messages_removed, summary} |
subagent.finished | {agent, state, usage} |
guard.denied | {instance, stage: input|tool|step|completion, reason} |
user.forgotten | {user, tenant}:对该用户执行了 orquelo sessions forget;它不属于任何 run,会送达所有列出它的观察者,插件据此删除它从此人派生的内容(2026-11-21 实现,P105;记忆插件删除此人在会话和共享范围中保存的条目) |
- ◆每个事件保留现有
ObservedEvent的公共字段(ID、Type、RunID、Connection、Conversation、Principal),另加At和类型化的Data json.RawMessage。observer 接收其 manifest 中events:列出的类型(默认[run.finished])。 - ◆内容字段(
Input、Output、summary、工具参数与结果)只为拥有运维授权grants: [conversation]的 observer 实例填写;否则为空。目前所有 observer 都会拿到Input和Output,所以这是 ADR 中的兼容性变更。Memory 插件(P12)需要该授权。 - ◆投递仍是从持久游标至少一次,ID 在重投时保持不变。没有 run 内的流式 hook:进度交给 Presentation,只有已提交的事实可被观察。
- ◆运行轨迹 S3(2026-11-21)新增类型
delivery.attempted{delivery, attempt, ok, error, dur_ms}、output.presented{kind, dur_ms}、progress.sent{ok, dur_ms}、checkpoint.saved{}与attachment.fetched{name, ok, dur_ms}(运行轨迹第 10 节)。tool.finished增加outcome(ok、error、denied)与reason,运行前就被拒绝的调用也会写入;guard.denied增加调用的key,以及被守卫扣下的结果所用的阶段result。S4b 新增route.decided、context.provided、hook.decided(ask 与 rewrite)、review.decided与background.done,并在run.started中增加setup_ms;其数据见pkg/plugin/decisions.go。S7 让 runtime 与工具通过可选 host 接口SpanReporter(host/report_spans)上报它们自己执行的步骤;这些步骤保存在reported_spans中,而不是作为事实。 - ◆运行轨迹 4.2(2026-11-28,飞书 #262)新增类型
model.retried{call, after_ms, error}、run.recovered{attempt}和tool.replayed{key, tool, attempt}。
5.7 P21:扣留最终回答
type CompletionDecision struct {
Feedback string `json:"feedback,omitempty"`
Withhold string `json:"withhold,omitempty"` // P21: reason; the answer is not delivered
}Withhold 优先于 Feedback,在每一轮都生效,包括最后一轮。run 的最终文本被替换为指明该 guard 的本地化通知 agent.answer_withheld;原文不保留在任何地方:答案在写入历史和检查点之前先经检查,恢复的 run 返回该通知,且 RunInput.CompletionGuarded 为真时 runtime 不在检查前流式展示答案(2026-11-17 修改,飞书反馈 #35,审查 R06;此前原文保留在检查点中,恢复时可能被返回)。guard.withheld 的日志不含内容。这与 ResultGuard 对工具结果的权力相同,因此只会收紧。stop 命令 hook 可以返回 {"decision":"withhold","reason":"..."}(Orquelo 的扩展)。
5.8 P22:命令 hook 与 Claude Code 对齐
已于 2026-11-16 实现,step 事件(等待 P7)和每个 hook 10,000 字符的上限除外;已实现的协议见 hook。cwd 是插件目录:Host 不知道 run 的工作区。
- ◆载荷。 增加
cwd(已知时为 run 的工作区,否则为插件目录)、tool_use_id(需要ToolIntent.Key)、permission_mode: "default",以及stop_hook_active(从第二轮起为 true;需要CompletionInput.Round)。 - ◆
additionalContext。 来自user_input的成为上下文条目:bundle 同时实现ContextProvider,返回为该 run 保存的条目。来自未阻断的pre_tool的成为同一调用上的ResultDecision.Note。每个 hook 至多 10,000 字符(Codex 超过 2,500 token 时落盘)。 - ◆
ask。permissionDecision: "ask"映射到 P17。 - ◆
step。 即 P7 的事件。 - ◆导入器。 使用
updatedInput的脚本被报告为 "ignored: arguments are not rewritten"。
5.9 P8:子 agent 定义与 AgentSource
config:
subagents:
- name: reviewer # ^[a-z0-9][a-z0-9-]{0,63}$
description: Reviews a diff for bugs. # ≤ 1,024 chars, shown in the delegate tool
instructions: You review code ... # the child's operator text
tools: [read, grep, glob] # patterns within the parent's tools
model: openai # an instance in the parent's uses
skills: [code-review]
max_steps: 20
timeout: 10m
subagents_from: [team-agents] # instances whose AgentSource is offeredtype AgentCard struct{ Name, Description string }
type AgentDef struct {
Name, Description, Instructions string
Tools, Skills []string
Model string
MaxSteps int
Timeout time.Duration
}
type AgentSource interface { // optional, on the skill role
Agents(ctx context.Context, cc CallContext) ([]AgentCard, error)
LoadAgent(ctx context.Context, cc CallContext, name string) (AgentDef, error)
}
// Caller.Subagents(ctx) ([]AgentCard, error); Caller.LoadAgent(ctx, name) (AgentDef, error)- ◆固定规则。 子 agent 不能
delegate,没有ask_user,也没有Send;深度为 1;每次 run 至多同时运行 4 个子 agent,第 5 个被拒绝而不是排队。超出父 agent 工具范围的工具模式是加载错误。 - ◆来源。 manifest 插件声明
agents:(带 front matter 的 Markdown);导入器转换 Claude Code 的agents/*.md和 Gemini CLI 的 agent 文件。两个来源提供同名定义时与技能一样都缺席。 - ◆hook。 子 agent 像 run 一样调用
ContextItems,因此不需要启动 hook。CompletionGuard在子 agent 的回答上运行,并设置CompletionInput.Agent(对应SubagentStop);subagent.finished可被观察(P11)。
5.10 P20:ChatRequest.Purpose
Purpose 取 step、final、compaction、subagent、policy、title 之一。Host 将其记录在 model.called 中,并可按用途施加限额(P18);模型插件可以忽略它。ModelInfo(上下文窗口、输出上限、输入类型、推理、提示词家族)见 LLM 层;扩展通过 Caller.ModelInfo 读取。
5.11 压缩扩展面(随 P5)
- ◆没有否决 hook,也没有插件压缩器:否决的结果是上下文溢出。自定义摘要器是
compact_model中指定的一个model实例。 - ◆
run.compacted(P11)让 Memory 了解哪些内容离开了窗口。 - ◆P9 的指令不受压缩影响;P19 的已知条目在压缩之后完整发送一次。
5.12 暂缓:P40 与 P39
- ◆P40,参数改写。
GuardDecision.Args json.RawMessage,只对拥有grants: [rewrite]的 guard 实例生效。guard 按uses顺序运行,每个看到前一个的改写;之后每个 guard 在最终参数上再运行一次,第二次改写即拒绝。账本保留原始参数和生效参数,审批显示生效参数,结果附加说明arguments changed by <instance>。目前没有使用者(路径规范化、注入--dry-run)。 - ◆P39,模型路由。
model插件上的可选接口Router.Route(cc, RouteInput{Purpose, Step, EstimatedTokens}) (instance string, error),其目标必须在它自己的uses中;Caller.Chat每次调用解析一次,并在model.called中记录选中的实例。等待 P4。
6. 所有扩展都遵守的规则
- ◆只收紧。
context只添加,guard只限制(拒绝、要求审批、扣留),reviewer只决定审批且仅在拥有grants: [review]时,observer只读。没有任何扩展能授予权限、放宽他人的决定、替换系统提示词或改写模型输出。 - ◆每次 run 固定。 run 固定在其 generation 上,工具列表固定在
run_tools(internal/host/broker/pin.go)。指令(P9)和子 agent 卡片(P8)每次 run 读取一次。 - ◆顺序确定。 按
uses顺序询问实例,对调用链上每个实例各一次。安装时间和进程启动顺序从不起决定作用。 - ◆作用域决定是否出现。
scope不覆盖本次 run 的主体和会话的实例不被询问;exclude隐藏单个工具和技能;policy.deny_tools在所有地方移除工具。 - ◆输入输出有界。 每个方法只拿到它需要的东西;没有角色能拿到检查点、凭据或可变状态的句柄。扩展返回的每段文本都有字符上限,每次调用都有 Host 超时。
- ◆失败策略按点固定。 guard 失败即关闭;上下文和指令被省略,除非
required;reviewer 上交;完成检查被跳过;observer 重试。 - ◆副作用即工具调用。 需要在 run 中产生副作用的插件提供工具,经过账本和审批。observer 和 service 通过
BackgroundHost和自己的数据目录工作。 - ◆恢复复用记录。 工具结果按键取自账本;上下文条目、指令、step 决定、step 上下文和完成反馈都在检查点中。
- ◆builtin 插件是普通插件,与 process 插件和 manifest 插件一样通过相同的角色和限制被访问。
7. 不采纳的做法
| 出处 | 扩展点 | 不采纳的原因 |
|---|---|---|
Pi、OpenCode、OpenClaw systemPrompt | 每轮替换系统提示词 | 破坏 agent 自身规则和缓存;不同的提示词是另一个 runtime 插件。P9 增加有界小节 |
| Gemini CLI、OpenCode、Hermes、Codex | 请求、HTTP 或流拦截器;合成的模型回复 | 供应商相关的事属于模型插件;拦截器无法跨进程边界,也无法恢复 |
| Hermes、Pi、Gemini CLI | 改写模型输出 | 写入检查点的回复才是事实;P21 改为扣留 |
OpenCode permission.evaluate、Crush hook allow、Claude Code allow | 插件放宽决定 | 只收紧;自动批准留给 reviewer 及其授权 |
Gemini CLI BeforeToolSelection 并集 | 重新启用工具的 hook | Orquelo 只收窄 |
OpenClaw contextEngine 槽位 | 替换上下文组装 | 布局归 agent 所有(P5、P19);Memory 是插件(P12) |
| Claude Code、Codex、Gemini CLI、Kimi CLI | SessionEnd(SessionStart 已作为 context 角色的 session_start hook 实现) | 会话因空闲轮换或 /new 关闭,没有可以执行的 run;已提交的事实以 run.finished 到达 observer |
| Claude Code、Codex、Crush | PreCompact 否决 | 否决的结果是溢出;pre_compact hook(observer)只能列出需要保留的事实 |
| Hermes、Pi | 逐个增量的流观察者 | 进度是临时的,交给 Presentation |
Codex async、Claude Code HTTP hook | 发出即不管或 HTTP 处理器 | 异步需求由 observer 满足;HTTP 处理器就是一个 process 插件 |
8. 与其他系统的对齐
事实与引用见 调研综述 的“扩展点”专题。所有被调研的系统都允许任一 hook 拒绝;除 Orquelo 目前之外,所有系统都允许扩展按参数把调用提升为需要审批、给策略提供模型、并在轮次开始之后补充上下文。这三点就是 P17、P18 和 P19。
| 其他系统中的 hook | Orquelo 的对应物 | 变化 |
|---|---|---|
Claude Code/Codex PreToolUse、OpenClaw before_tool_call、Hermes pre_tool_call、Gemini CLI BeforeTool、Pi tool_call、OpenCode tool.execute.before、Crush/Kimi/OpenHands PreToolUse | 带 Deny 或 Ask 的 Guard.Check(P17);hook pre_tool | 不改写(P40 暂缓);ask 与 requireApproval 映射为 Ask |
Claude Code/Codex PermissionRequest、Codex 审批 contributor、Hermes 智能审批、OpenHands analyzer | 带 PolicyHost 的 Reviewer.Review(P18) | 只能批准规则和 guard 已放行的调用 |
Claude Code/Codex UserPromptSubmit、OpenClaw before_agent_run | InputGuard.CheckInput;上下文经 P22 | 拒绝,不改写 |
Claude Code PostToolBatch、Pi terminate/turn_end、Crush exit 49 | StepGuard(P7);hook step | 拒绝结束 run;反馈是一条通知 |
Codex world state、Pi context、Gemini CLI BeforeModel 上下文 | StepContextProvider(P19) | 只追加,按 ID 与摘要去重 |
Codex 提示词槽位与指令提供者、Hermes 提示词小节、OpenClaw prepend/appendSystemContext | InstructionSource(P9) | 运维者显式开启,有界,每次 run 冻结 |
Claude Code/Codex PostToolUse、OpenClaw 结果中间件、Hermes transform_tool_result、Gemini CLI AfterTool | ResultGuard.CheckResult;hook post_tool | 扣留或说明;记录不变 |
Claude Code/Codex Stop、OpenClaw before_agent_finalize、Hermes pre_verify、Pi agent_before_settle、OpenHands critic | CompletionGuard(反馈;P21 扣留) | 两轮 |
Claude Code/Codex SubagentStart、SubagentStop;OpenClaw 子 agent hook | 子 agent 调用 ContextItems;CompletionGuard 检查子 agent;subagent.finished(P8、P11) | 没有单独的启动 hook |
Claude Code/Codex PreCompact/PostCompact、Hermes post_compaction、OpenCode/Pi 压缩结果 | compact_model;run.compacted | 无否决,无插件压缩器 |
Codex PreModelRequest/PostModelRequest、Hermes pre/post_api_request、OpenClaw model_call_* | 带 Purpose 的 model.called(P11、P20) | 只观察 |
OpenClaw before_model_resolve、OpenCode model.resolve | fallback_models(P4);Router(P39) | 由配置或路由模型插件决定 |
Hermes transform_llm_output、脱敏模式 | CompletionDecision.Withhold(P21) | 扣留,从不改写 |
| 通知与会话结束 hook | observer(P11) | 只观察 |
OpenClaw 渠道 hook(message_sending)、Hermes 网关 hook | Trigger、Presentation 与 Delivery 插件 | 不属于 Runtime |
导入器把 Claude Code 的 PreToolUse、PostToolUse、UserPromptSubmit、Stop、SubagentStop、SessionStart、PreCompact 和 PermissionRequest hook 转换为 manifest 命令 hook,并补上它们填充的角色(hook)。其他 hook 被报告为未纳入。
9. 已实现与变更
| 项 | 状态 |
|---|---|
| 角色、可选接口、命令 hook、顺序、超时、失败策略 | 已实现 |
guard ask | P17(ADR) |
PolicyHost | P18(ADR) |
StepGuard、Caller.CheckStep、hook step | P7(ADR) |
step 上下文、ContextItem.ID | P19(ADR) |
InstructionSource、instructions_from | P9(ADR) |
类型化观察事件、events:、grants: [conversation] | P11(ADR) |
CompletionDecision.Withhold | P21(ADR) |
hook 载荷、additionalContext、ask;ToolIntent.Key、CompletionInput.Round | P22(bundle;字段需 ADR) |
subagents、AgentSource | P8(插件定义需 ADR) |
ChatRequest.Purpose | P20(ADR) |
| 参数改写、模型路由 | P40、P39,暂缓 |
10. 验收
已实现,在 macOS 上:TestGuardsAndReviewer、TestHooks、TestSkillCollisionsAreRefusedUntilExcluded、TestRunsKeepTheToolCatalogTheyStartedWith(internal/host/engine);TestCommandHooks、TestFailingHookDeniesUnlessIgnored、TestPathVariablesAndInstructions(internal/bundle);TestPermissionRules、TestContextItemsComeBeforeTheInput、TestCompletionFeedbackReopensTheTurn(plugins/agent);以及 M6 零改动验收(记录)。
提案需要的验收:
- ◆P17:
TestGuardAskRequiresApproval、TestGuardAskAndDenyDenies、TestGuardAskSurvivesRestart(重启后只有一个问题)。 - ◆P18:
TestPolicyHostChatOnlyDuringCheck、TestPolicyHostUsageCountsAgainstRun、TestPolicyHostRespectsUses。 - ◆P7:拒绝以
agent.step_denied结束 run;出错即拒绝;在 step 与其检查之间重启只询问一次。 - ◆P19:相同条目不重发;压缩之后完整发送一次;恢复的 run 不为已完成的 step 询问。
- ◆P9:只有
instructions_from中的实例提供指令;required来源失败使 run 失败;恢复的 run 发送逐字节相同的系统提示词。 - ◆P11:没有
grants: [conversation]的 observer 拿到空的内容字段;重投的事件保持 ID。 - ◆P21:被扣留的回答不投递,通知指明该 guard。
- ◆P22:导入的 hook 输出
permissionDecision: "ask"时调用等待审批;user_input的additionalContext作为参考材料进入请求。 - ◆P8:子 agent 不能委派或提问;第 5 个并发子 agent 被拒绝。
- ◆每个新接口:一个基于 JSON-RPC 的 process 插件一致性测试。Linux 与 Windows 需要原生运行;逐项记录 Host 是否发生变化。