OpenProgram Docs

规则与运行方式

class Policy:
    on: set[str]          # event types watched
    lane: "gate" | "observer"
    cooldown_s: float     # silence after acting
    name: str             # defaults to the class name

    def evaluate(self, event, state) -> Action | None: ...
    def dedup_key(self, event, state) -> str: ...   # what counts as "the same situation"
gateobserver
时机事前:只看 tool.before事后:任意事件
路径同步,经 tool.before gate总线订阅者;先折叠状态,再唤醒 on 中的规则
速度要快:不调 LLM,不读网络,不读需要推断的状态可以慢,但绝不能拖慢 Agent
返回Gate.allow()、Gate.deny(reason)、Gate.ask(reason)Notify、Inject、Prepare
多条规则命中取最严:deny、ask、allow各自出手
子 Agent覆盖;gate 在审批包装之外,bypass 跳不过同一事件流覆盖

两条车道:cooldown_s 按 dedup_key 用事件时钟检查。evaluate 抛错时记录,并按不出手处理。

动作

动作设计当前
Gate.deny拦截,理由给模型与设计一致
Gate.ask经审批流程询问用户按 deny 拦截,措辞提示手动放行后重试
Notify不打断的提醒proactive.notify WebSocket 帧
Inject模型下一轮前的提示,不打扰用户只记录 proactive.inject 事件;转向尚未接通
Prepare只读后台任务先核实,再决定是否 Notify只记录 proactive.prepare_requested;没有执行者

新增规则

  1. 在 openprogram/runtime/proactive/policies/ 写一个类,定义 on、lane、cooldown_s。
  2. 写 evaluate。
  3. register_policy 注册(同名重复注册被忽略)。

引擎、事件流和折叠都不用动。打扰预算和自动熔断不在范围内,cooldown_s 是唯一的旋钮。gate 机制见事件层。

实现状态

引擎、注册表和三条规则都已存在并有测试。worker 启动时没有调用 install_proactive() 和 install_mvp_policies(),所以生产环境中没有规则运行。

三条模板规则

Last updated · 2026-11-25