# Super Agent 的机制：模型提请求，记录和代码做决定

> Super Agent 把较大的研发工作交给无人值守的编程 agent。它中间有一段不让模型做决定的代码，只认一份封闭的词表，每一步先写记录再行动。这篇讲这套机制，也讲它的弱点。

Author: Shumin Fu  
Published: 2026-12-02  
Tags: ai-agents, workflow, security  
Canonical: https://funfun.zone/posts/super-agent-mechanism/

<div class="html-embed" lang="zh-CN">
<input class="lsr" type="radio" name="post-lang" id="lang-zh" checked>
<input class="lsr" type="radio" name="post-lang" id="lang-en">
<div class="lsw"><label for="lang-zh" lang="zh-CN">中文</label><label for="lang-en" lang="en">English</label></div>
<section class="lz" lang="zh-CN">
<p>同事在飞书群里 @ 了机器人，说某个 bug 该修了。一个 agent 能不能因为这句话，就去改仓库、推分支、在 Jira 工单下评论？我们在研发助手里做 Super Agent（下文叫 SA）的时候，大部分设计都在回答这个问题。</p>
<p>SA 要做的事不复杂：owner（这台设备的主人）把较大的研发工作交给一个命令行编程 agent，让它无人值守地做完，自己尽量少被打扰。难的是授权。谁说的话算数，这句话允许做到哪一步，结果该告诉谁，这些都不能交给一个可能被说动的模型去决定。</p>
<p>这篇根据 2026 年 12 月 2 日的代码和设计记录写成。我只读了代码和文档，<strong>没有为这篇文章重新跑测试</strong>。SA 按设备开启，缺省关闭。</p>

<div class="tldr"><p>一句话：SA 的引擎是一段普通代码，夹在两种模型会话之间。它只认一份封闭的词表，每一步先写下一条带唯一键的记录，再按记录行动。模型只能提请求；谁能开工、能做到哪一步、回复送到哪，由记录和代码决定。</p></div>

<h2>三个部分，只有一个做决定</h2>
<ul>
<li><strong>路由</strong>是对话里的工程师 agent。小事它自己答；改仓库、跑测试或构建、耗时长的工作，它请求开一张工单。它不持有任何工单状态。</li>
<li><strong>引擎</strong>是后端里的一段 Go 代码。只有它能写 SA 的状态，全部授权判断也都由它做。</li>
<li><strong>执行会话</strong>是为一张工单开的无人值守编程 agent 会话，缺省是 Claude Code，也可以选 Codex 或 Cursor。它通常在自己的 git worktree 和分支里干活，只通过自己那一组工具向引擎报告。</li>
</ul>
<figure class="gf"><div class="gg st">
<div class="gn pp r1 c1"><b>owner</b><small>这台设备的主人</small></div>
<div class="ga v r2 c1"><span>在对话里说一句</span><i></i></div>
<div class="gn r3 c1"><b>路由</b><small>对话里的工程师 agent</small></div>
<div class="ga r3 c2"><span>请求开单</span><i></i></div>
<div class="gn eg hi r3 c3"><b>引擎</b><small>代码 · 唯一能写状态</small></div>
<div class="ga bi r3 c4"><span>启动 · 输入</span><i class="f"></i><i class="b"></i><span>确认 · 报告</span></div>
<div class="gn r3 c5"><b>执行会话</b><small>每张工单一个</small></div>
<div class="ga od r1 c2"><span>在卡片上回答、停止</span><i></i></div>
<div class="gn od r1 c3"><b>工单卡片</b><small>从存储渲染</small></div>
<div class="ga bi v ac od r2 c3"><span>回答直接进引擎</span><i class="f"></i><i class="b"></i><span>报告更新卡片</span></div>
</div><div class="gp op"><span>工单卡片从存储渲染，执行会话的报告直接更新它</span><span>owner 在卡片上的回答和停止直接进引擎，不经过路由</span></div><figcaption>进引擎的每一步都是一个请求，引擎核对之后可以拒绝；owner 在卡片上的回答不经过路由，两边的模型也不直接说话。</figcaption></figure>
<p>这样分是因为三种会话里的模型都读得到别人写的文字，都可能出错，也都可能被说动。有两种更省事的做法被否决了。</p>
<p>第一种是让对话里的 agent 自己记住工单状态。真实环境里出过这样的事：一条消息被拆成两次开单，两次都没有通过核对，对话里的 agent 却回复「两张都已开成」。所以状态只放在引擎里，agent 要说工单状态时先去读。</p>
<p>第二种是只靠提示词规定谁能做什么。同事 @ 拉起的群运行，和 owner 自己的对话，用的是同一个角色，同一份提示词，提示词分不出这两种情况。所以工具列表只算一份索引：每次调用到达时，引擎重新检查调用方是谁，不对就用一个固定的错误码拒绝。</p>

<h2>一份封闭的词表</h2>
<p>引擎能谈论的东西是有限的。它们写在一个单独的包里，是一小组带类型的实体和关系，随版本发布。设计记录把它叫作「轻量本体」。它有三个性质：</p>
<ul>
<li><strong>封闭。</strong>规则只能用词表里有的词。用了不认识的词，保存时就被拒绝，拒绝里写明是哪个词。</li>
<li><strong>不推理。</strong>没有推理机，也没有传递推导。一条规则为什么命中，读它的字段就能说清。</li>
<li><strong>不依赖别的包。</strong>规则、规则引擎、来源和去向都依赖词表，反过来不行。有一个测试专门守这个方向。</li>
</ul>
<figure class="gf"><div class="gg kp">
<div class="gn r1 c3"><b>人</b><small>某个来源里的一个账号</small></div>
<div class="gn wl r1 c5"><b>对外动作</b><small>push · PR · 部署…</small></div>
<div class="ga v r2 c3"><span>发出</span><i></i></div>
<div class="ga v up ll ac r2 c5"><span>放行</span><i></i></div>
<div class="gn r3 c1"><b>地方</b><small>群 · 项目 · 仓库</small></div>
<div class="ga lt r3 c2"><span>落在</span><i></i></div>
<div class="gn r3 c3"><b>事件</b><small>来源里发生的一件事</small></div>
<div class="ga lt ac r3 c4"><span>匹配</span><i></i></div>
<div class="gn eg r3 c5"><b>规则</b><small>owner 说过的一句话</small></div>
<div class="ga v r4 c3"><span>属于</span><i></i></div>
<div class="ga v ll ac r46 c5"><span>指定去向</span><i></i></div>
<div class="gn r5 c1"><b>工作项</b><small>例如一张 Jira 工单</small></div>
<div class="ga lt r5 c2"><span>关于</span><i></i></div>
<div class="gn r5 c3"><b>话题</b><small>一串连续的事件</small></div>
<div class="ga v up ac r6 c3"><span>关联 · 订阅</span><i></i></div>
<div class="gn eg r7 c1"><b>跟进</b><small>等一个时刻或一件事</small></div>
<div class="ga ac r7 c2"><span>叫醒</span><i></i></div>
<div class="gn eg r7 c3"><b>工单</b><small>SA 的一份工作</small></div>
<div class="ga ac r7 c4"><span>回复到</span><i></i></div>
<div class="gn wl r7 c5"><b>去向</b><small>卡片 · 收件箱 · 话题…</small></div>
</div><div class="gl"><span>来源适配器映射来的事实</span><span class="eg">owner 或引擎创建的</span><span class="wl">固定的词表</span></div><figcaption>规则把事件和两张固定的词表连起来；工单靠话题接住后来的消息，靠跟进等外面的事。</figcaption></figure>
<div class="tw"><table>
<thead><tr><th>词</th><th>是什么</th><th>值得知道的设计</th></tr></thead>
<tbody>
<tr><td>人</td><td>某个来源里的一个账号</td><td>身份不跨来源对应。飞书的张三和 Jira 的张三是两个人，只有 owner 自己的各个账号连在一起。授权按事件所在来源里的账号算，所以猜错「谁是谁」不会多给出任何授权</td></tr>
<tr><td>事件</td><td>来源里发生的一件事，共七种：发言、新建工作项、指派变更、状态变更、定时到点、代码评审、CI 结果</td><td>正文是不可信的外部文字，从不参与匹配和授权</td></tr>
<tr><td>话题</td><td>一串连续的事件：飞书的一条回复串或一个私聊，Jira 一张工单下的评论</td><td>后来的消息靠它找到已经在处理这件事的工单。代码和规则里它叫 topic</td></tr>
<tr><td>工作项</td><td>一件要做的事在各处的同一个身份，例如一张 Jira 工单和与它关联的内部 Issue</td><td>工作项跨来源是同一个，按 id 精确对上。它不是工单</td></tr>
<tr><td>地方</td><td>事件落在哪：飞书的群、Jira 的项目、git 仓库</td><td>每种来源声明用哪个属性表示地方，引擎里没有按来源写的特例</td></tr>
<tr><td>工单</td><td>SA 自己的工作单位，每条受理的请求一张</td><td>存下来的状态只有「未结束」和「已结束」，外加一个结局。owner 看到的其余内容都是算出来的</td></tr>
<tr><td>对外动作</td><td>会改变外部状态的固定清单：push、PR、发布、部署、改工作项、删除</td><td>缺省要先问 owner，除非规则的 <code>allow</code> 点名放行</td></tr>
<tr><td>去向</td><td>回复可以送到的地方：工单卡片、任务收件箱、事件所在的话题、飞书消息、Jira 评论等</td><td>任务收件箱永远留一份。往外说话要求来源是可读写的</td></tr>
<tr><td>关联</td><td>一个处理者（工单）与一个目标（话题或另一张工单）有关</td><td>它是一个事实，没有寿命</td></tr>
<tr><td>跟进</td><td>处理者在等一件事：等到某个时刻，或等某个事件</td><td>它是一个带截止时间的约定，超时后依次执行一串动作</td></tr>
</tbody>
</table></div>
<p>在每个来源里意思相同的属性是共有的，例如作者、点名了谁、是不是私聊、工作项指派给谁。只有某个来源才有的字段带上来源前缀，例如 <code>jira.type</code>、<code>lark.chat</code>、<code>git.repository</code>。所以接一个新来源只要做两件事：声明它的事件怎样映射到词表，再写一个适配器。规则的写法不用改。</p>

<h2>规则是用词表填出来的一条记录</h2>
<p>外部事件自己不构成授权，规则才是。一个来源没有规则，SA 就什么也不做。规则由 owner 在自己的对话里用大白话说：</p>
<div class="said"><small>owner 的原话</small><p>RND 项目里指派给我的 bug，有复现步骤的先试着修，修好了在工单下评论并告诉我。</p></div>
<p>对话里的 agent 把这句话译成一组固定的字段：</p>
<div class="cw"><pre><code>id: new-bug-try
when:
  event: [item_created, item_assigned]
  who: anyone
  match: { item.assignee: owner, jira.type: Bug }
  judge: 描述里有复现步骤
do: try
allow: []
deliver: { result: [topic, inbox] }</code></pre></div>
<p><code>when</code> 说什么事件、谁、哪些属性相等，外加一句可选的自然语言条件 <code>judge</code>。<code>do</code> 说做到哪一步：<code>ignore</code>（不动）、<code>ask</code>（先问我）、<code>try</code>（先悄悄试）、<code>run</code>（直接做）、<code>claw</code>（交给对话里的 agent 分诊）。<code>allow</code> 列出不用再问的对外动作，<code>deliver</code> 按用途指定回复的去向。规则里没有表达式，没有「或」，也没有脚本。</p>
<p>保存之后，引擎从这些字段机械地生成一段复述给 owner 看，生成时不经过模型，也不读 owner 的原话。上面这条规则的复述里有这样一段：</p>
<div class="said"><small>引擎生成的复述（节选）</small><p>……新建工作项或指派变更，认任何人，条件 item.assignee=owner 且 jira.type=Bug，并研判「描述里有复现步骤」 → 先试着做；放开：无；……结果→话题、任务收件箱</p></div>
<p>这是整套设计里我最看重的一处。规则在 owner 说完的那一轮就生效，没有第二次确认；规则又可以放行对外动作。所以译错必须一眼看得出来。复述和原话对不上，owner 就知道 agent 译错了，可以撤销到上一版。</p>
<p>同样的理由否决了另外四种做法：</p>
<ul>
<li><strong>只用自然语言</strong>，每来一条事件让模型读规则再决定。每条事件一次模型调用，同样的事件前后结论可能不同；规则原话和同事的消息进了同一个上下文，注入的文字可以冒充规则。</li>
<li><strong>能写表达式的规则语言</strong>（CEL、Rego 一类）。让模型把一句话译成一段小程序，译错的概率高，而且不容易从复述里看出来。</li>
<li><strong>完整的本体加推理</strong>。命中的原因要沿推理链去找，owner 一眼看不懂。</li>
<li><strong>每个来源一套自己的字段名</strong>。同一个意思要写两遍，加来源就要改规则的写法，工作项也没法跨来源对上。</li>
</ul>
<p>代价是规则能表达的东西有边界：单条规则写不出「A 或 B」，也写不出算术、时间窗口和正则。要表达「或」就写两条规则。</p>

<h2>一条请求怎样走完</h2>
<p>每一步先写下一条记录，然后才行动。下一步读的是记录，而不是模型的记忆。</p>
<figure class="gf"><div class="gg st">
<div class="gn r1 c1"><b>1 读取</b><small>对话 · 飞书 · Jira · git · 定时</small></div>
<div class="ga r1 c2"><span>收件表一行</span><i></i></div>
<div class="gn eg r1 c3"><b>2 判定</b><small>跟进 · 话题 · 规则 · 监听 · 分诊</small></div>
<div class="ga ac r1 c4"><span>一条触发</span><i></i></div>
<div class="gn eg hi r1 c5"><b>3 核对并受理</b><small>回源重读 · 一个事务</small></div>
<div class="ga v ll ac r2 c5"><span>工单 + 授权单</span><i></i></div>
<div class="gn eg r3 c5"><b>4 排队并启动</b><small>名额 · 上限 · 暂停</small></div>
<div class="ga bi rv ac r3 c4"><span>派工 · 输入</span><i class="f"></i><i class="b"></i><span>确认 · 报告</span></div>
<div class="gn r3 c3"><b>5 干活</b><small>执行会话 · 自己的 worktree</small></div>
<div class="ga lt r3 c2"><span>回复，由引擎发出</span><i></i></div>
<div class="gn r3 c1"><b>6 交付</b><small>卡片 · 收件箱 · 话题 · 私信</small></div>
<div class="ga v up od r2 c1"><span>回答、话题里的新消息</span><i></i></div>
<div class="gb r4">事件日志：每一步追加一行，写下之后不能改</div>
</div><div class="gp op"><span>↺ 卡片上的回答、话题里的新消息：回到第 1 步，直接找到已有的工单</span></div><figcaption>着色的三步由引擎做决定。第 3 步是闸门：工单只在核对通过之后才存在，授权单写下之后不再改。</figcaption></figure>
<div class="tw"><table>
<thead><tr><th>步骤</th><th>写下什么记录</th><th>它定住了什么</th></tr></thead>
<tbody>
<tr><td>1 读取</td><td>收件表里的一行，每个来源一个书签</td><td>原始事件只存一次。读取失败时书签不动，应用关着时错过的事件，下次启动从书签补读。owner 自己的对话不走读取，入口是对话里的 agent 的一次开单调用</td></tr>
<tr><td>2 判定</td><td>每条事件至多一条结论，外加一条「谁接了这条事件」的记录</td><td>适配器先把原始事件映射成词表里的事件。引擎再按固定顺序问：有没有跟进在等它；它的话题有没有未结束的工单订阅；有没有规则命中；有没有监听在听；都没有、而它是冲着 owner 来的，并且这个来源写明了要这样做，就交给对话里的 agent 分诊</td></tr>
<tr><td>3 核对并受理</td><td>触发、核对结果、工单（带授权单），在一个事务里</td><td>见下文。一条触发至多开一张工单</td></tr>
<tr><td>4 排队并启动</td><td>队列里的一条启动待办</td><td>待办的键同时是提交 id，重复启动只会回到同一个会话。同时在跑回合的执行会话缺省 2 个；每张工单另有墙钟上限（缺省 240 分钟）和回合上限（缺省 20 个）</td></tr>
<tr><td>5 干活</td><td>受理确认、报告、输入，以及关联、跟进、话题订阅</td><td>执行会话读自己的工单，写一条受理确认说明要改什么，然后报告进展、就绪、受阻、失败或无需处理。要问 owner 时把问题附在报告上，一次只问一个；owner 的回答作为输入回到会话</td></tr>
<tr><td>6 交付</td><td>队列里的一条回复待办，然后是外发结果</td><td>规则的 <code>deliver</code> 按用途（受理确认、问题、结果）选去向。拿到对方返回的消息 id，才算发出去了</td></tr>
</tbody>
</table></div>
<h3>第 3 步：核对什么</h3>
<p>请求从 owner 自己的对话来时，对话里的 agent 开单之后必须结束这一轮。引擎等这一轮结束，核对这一轮里确实有 owner 本人的输入，然后才建工单。核对通过之前，卡片显示「待核对」；没通过就没有工单。只有 owner 自己的对话会话能开单，同事 @ 拉起的运行不能。</p>
<p>请求从外部来源来时，适配器按 id 回到来源，把这条消息或工单重新读一遍，内容和作者都一致才继续。所以在本机伪造一条事件开不了工单，已经撤回或删除的消息也不会被执行。</p>
<p>核对通过后，引擎在同一个事务里写下工单和它的<strong>授权单</strong>。授权单记四样东西：范围（请求的文字）、依据（owner 的对话，或者哪条规则）、强度（明确要求的，还是按规则推断的）、当时的设置版本。它写下之后不再改。执行中想扩大范围，要回到卡片上问 owner。</p>
<h3>为什么重启和重试不会开出第二张工单</h3>
<p>每条记录都带一个唯一键，键从「是什么引起了它」算出来。触发 id 在工单表里是唯一的，所以一条触发至多一张工单。事件的结论按事件 id 去重，所以一条事件只判一次。启动待办的键就是提交 id，所以重试、重开、重启后续上，都回到同一个会话和同一个工作目录。重复调用工具、进程中途崩溃、网络重试，结果都是「这条记录已经有了」。</p>

<h2>话题：后来的消息怎样找到已有的工单</h2>
<p>工单受理时会订阅触发它的那个话题。之后同一个话题里再来消息，引擎在匹配任何规则之前，先把它作为输入直接送给那张工单。没有这一步，一段五条消息的对话会开出五张工单。同一个话题里的事件按到达先后一条一条处理。</p>
<p>每条送到 agent 面前的外部消息，前面都有一段由代码写的<strong>事件头</strong>：出处、作者在该来源的账号、点名了谁、关于哪个工作项，以及这位作者带不带授权（owner、规则认可的请求人，或者没有）。只有「授权」这一行决定能做什么，正文和其余各行只是材料。可以把事件头看成词表渲染给模型看的样子。</p>
<p>关于名字：这个概念在代码和规则里叫 topic，中文词表叫「话题」。它最早叫 thread，后来改了名，因为它指的是「同一件事」，而不是某个聊天产品里的线程。已经存下的规则里写 <code>thread</code> 仍然有效，引擎把它读成 <code>topic</code>。</p>

<h2>等外面的事：关联和跟进</h2>
<p>执行会话经常要等：等构建，等评审，等同事回复。它可以让引擎替它等，自己结束这一轮。等的时候不占名额，也不计工作时间。</p>
<p>引擎存两样东西。<strong>关联</strong>指向一个确切的目标，例如某个话题。<strong>跟进</strong>挂在关联上或者挂在一个时刻上，带一个截止时间（离现在 1 分钟到 7 天之间）和一串超时动作：叫醒处理者、问 owner、作废。缺省的顺序是先叫醒执行会话，再问 owner。</p>
<p>等的事件到了，引擎按来源和 id 精确对上，不靠模型判断「这是不是我在等的那条」，然后把事件作为输入送进等它的会话。命中不给消息的作者任何授权。</p>

<h2>模型还在哪里做判断</h2>
<p>引擎并非完全不用模型。设计记录里列了三处，会问一个很小的模型：规则里那句 <code>judge</code> 条件；话题里的新消息要不要重开一张已结束的工单；一个监听该不该收下某条消息。这三处守同一组约束：</p>
<ul>
<li>它只在本来就各有依据的几条路之间选，不带来授权。它说「是」之后，回源核对和规则复核照常进行。</li>
<li>问不到、超时、答案读不懂时，走确定的那条路，并且从不当作「是」去受理。例如 <code>judge</code> 拿不准时，事件成为 owner 收件箱里的一条候选，不会被悄悄丢掉。</li>
<li>它读的是不可信的外部文字，所以被说动的方向只有「忽略」，不会多出授权。</li>
</ul>
<p>对话里的 agent 做分诊时也一样：它给出的结论只是建议，引擎逐条检查之后才执行。</p>

<h2>owner 看到的是算出来的</h2>
<p>工单卡片、任务收件箱和工单详情都从存储渲染。卡片上的阶段（排队中、执行中、等你回答、受阻、达到上限等）是工单事实的纯函数：引擎拿一张固定的表从上往下走，取第一条命中的。</p>
<p>执行会话的一次报告直接更新卡片，不产生模型回合，也不唤醒对话里的 agent。owner 在卡片上的回答和停止直接进引擎，所以对话里的 agent 没有机会改写它。</p>

<h2>弱点和还没定的事</h2>
<ul>
<li><strong>「对外动作先问」目前是指令，不是代码闸。</strong>执行会话以 owner 的权限无人值守地运行，引擎今天拦不住它自己去 push 或写 Jira。让引擎在工具调用之前把关的方案已经调研过，还没有实现。这是当前最大的缺口。</li>
<li><strong>没有按金额或 token 计的上限。</strong>花费只被回合上限和墙钟上限框住，而且重开工单时两者都重新计。</li>
<li><strong>身份不跨来源对应的代价。</strong>飞书的张三是不是 Jira 的张三，由读到事件头的 agent 自己判断，可能判错。这个判断不产生授权，所以后果限于理解偏差。</li>
<li><strong>只在应用开着时工作，只在一台设备上。</strong>被退出打断的工作在下次启动时续上。</li>
<li><strong>较新的两块还在评审。</strong>「没对上规则的消息交给对话里的 agent 分诊」和「关联与跟进」的设计记录仍标着「提议中」，代码已经在开发分支上。</li>
</ul>
<p>回头看，这套机制里没有哪一件是新发明。封闭的词表、不可变的授权单、带唯一键的记录，都是普通的工程做法。它们放在一起回答的是开头那个问题：同事 @ 机器人的那句话，自己什么也授权不了。授权来自 owner 说过的一条规则，引擎核对过这条消息是真的，然后把这两件事写成一张不会再改的单子。</p>
</section>
<section class="le" lang="en" data-alt-lang>
<p class="alt-title">How Super Agent works: models ask, records and code decide</p>
<p>A colleague mentions the bot in a Lark group and says a bug should be fixed. May an agent change the repository, push a branch and comment on the Jira issue because of that one sentence? When we built Super Agent (SA) into our engineering assistant, most of the design went into answering this question.</p>
<p>What SA does is simple. The owner (the person this device belongs to) hands a larger piece of engineering work to a command-line coding agent, which finishes it unattended and interrupts the owner as little as possible. The hard part is authority. Whose words count, how far those words allow the agent to go, and who should hear the result: none of these can be left to a model that someone might talk into things.</p>
<p>This post is written from the code and design records as of 2 December 2026. I read code and documents only: <strong>I did not rerun the tests for this post</strong>. SA is switched on per device and is off by default.</p>

<div class="tldr"><p>In one sentence: the SA engine is plain code that sits between two kinds of model sessions. It knows only a closed vocabulary, and it writes a record with a unique key before each step, then acts on the record. Models can only ask; who may start work, how far it may go and where replies are sent is decided by records and code.</p></div>

<h2>Three parts, and only one decides</h2>
<ul>
<li><strong>The router</strong> is the engineer agent in the chat. It answers small things itself. For repository changes, tests, builds and long work it asks for a ticket. It holds no ticket state.</li>
<li><strong>The engine</strong> is Go code in the backend. It is the only writer of SA state and it makes every authorization decision.</li>
<li><strong>The worker session</strong> is one unattended coding agent session per ticket: Claude Code by default, or Codex or Cursor. It usually works in its own git worktree and branch, and it reports to the engine only through its own set of tools.</li>
</ul>
<figure class="gf"><div class="gg st">
<div class="gn pp r1 c1"><b>Owner</b><small>the person this device belongs to</small></div>
<div class="ga v r2 c1"><span>says it in the chat</span><i></i></div>
<div class="gn r3 c1"><b>Router</b><small>engineer agent in the chat</small></div>
<div class="ga r3 c2"><span>asks for a ticket</span><i></i></div>
<div class="gn eg hi r3 c3"><b>Engine</b><small>code · only writer of state</small></div>
<div class="ga bi r3 c4"><span>launch · input</span><i class="f"></i><i class="b"></i><span>ack · reports</span></div>
<div class="gn r3 c5"><b>Worker session</b><small>one per ticket</small></div>
<div class="ga od r1 c2"><span>answers or stops on the card</span><i></i></div>
<div class="gn od r1 c3"><b>Ticket card</b><small>rendered from the store</small></div>
<div class="ga bi v ac od r2 c3"><span>answers go straight in</span><i class="f"></i><i class="b"></i><span>reports update the card</span></div>
</div><div class="gp op"><span>the ticket card renders from the store, and worker reports update it directly</span><span>the owner's answers and stops on the card go straight to the engine, not through the router</span></div><figcaption>Every step into the engine is a request that the engine checks and may refuse; the owner's answers on the card bypass the router, and the two models never talk to each other directly.</figcaption></figure>
<p>The split exists because the models in all three kinds of sessions read text that other people wrote. They can be wrong, and they can be persuaded. Two cheaper designs were rejected.</p>
<p>The first was to let the chat agent remember ticket state. On a real installation this happened: one message was split into two ticket requests, neither passed verification, and the chat agent still replied that both tickets were open. So state lives only in the engine, and the agent reads it before it says anything about a ticket.</p>
<p>The second was to rely on the prompt to say who may do what. A run that a colleague starts by mentioning the bot uses the same role and the same prompt as the owner's own chat, so a prompt cannot tell the two apart. The tool list is therefore only an index. The engine checks who is calling on every call and refuses the wrong caller with a fixed error code.</p>

<h2>A closed vocabulary</h2>
<p>The engine can talk about a limited set of things. They are declared in one package as a small set of typed entities and relations, and shipped with each version. The design record calls it a lightweight ontology. It has three properties:</p>
<ul>
<li><strong>Closed.</strong> A rule can use only words that are in the vocabulary. A rule with an unknown word is refused when it is saved, and the refusal names the word.</li>
<li><strong>No inference.</strong> There is no reasoner and no transitive deduction. You can explain why a rule matched by reading its fields.</li>
<li><strong>No dependencies.</strong> Rules, the rule engine, sources and destinations depend on the vocabulary, never the reverse. A test guards the direction.</li>
</ul>
<figure class="gf"><div class="gg kp">
<div class="gn r1 c3"><b>Person</b><small>one account in one source</small></div>
<div class="gn wl r1 c5"><b>Outward action</b><small>push · PR · deploy…</small></div>
<div class="ga v r2 c3"><span>writes</span><i></i></div>
<div class="ga v up ll ac r2 c5"><span>allows</span><i></i></div>
<div class="gn r3 c1"><b>Place</b><small>chat · project · repository</small></div>
<div class="ga lt r3 c2"><span>lands in</span><i></i></div>
<div class="gn r3 c3"><b>Event</b><small>one thing that happened</small></div>
<div class="ga lt ac r3 c4"><span>matches</span><i></i></div>
<div class="gn eg r3 c5"><b>Rule</b><small>the owner's standing order</small></div>
<div class="ga v r4 c3"><span>belongs to</span><i></i></div>
<div class="ga v ll ac r46 c5"><span>delivers to</span><i></i></div>
<div class="gn r5 c1"><b>Work item</b><small>e.g. a Jira issue</small></div>
<div class="ga lt r5 c2"><span>is about</span><i></i></div>
<div class="gn r5 c3"><b>Topic</b><small>a run of connected events</small></div>
<div class="ga v up ac r6 c3"><span>links · subscribes</span><i></i></div>
<div class="gn eg r7 c1"><b>Follow</b><small>waits for a time or an event</small></div>
<div class="ga ac r7 c2"><span>wakes</span><i></i></div>
<div class="gn eg r7 c3"><b>Ticket</b><small>one piece of SA work</small></div>
<div class="ga ac r7 c4"><span>replies to</span><i></i></div>
<div class="gn wl r7 c5"><b>Destination</b><small>card · inbox · topic…</small></div>
</div><div class="gl"><span>facts mapped by a source adapter</span><span class="eg">created by the owner or the engine</span><span class="wl">fixed word lists</span></div><figcaption>A rule connects events to the two fixed word lists; a ticket catches later messages through its topic and waits for the outside world through a follow.</figcaption></figure>
<div class="tw"><table>
<thead><tr><th>Word</th><th>What it is</th><th>Design choice worth knowing</th></tr></thead>
<tbody>
<tr><td>Person</td><td>One account in one source</td><td>Identity never maps across sources. Zhang San in Lark and Zhang San in Jira are two people; only the owner's own accounts are tied together. Authority is computed from the account in the event's own source, so a wrong guess about who is who grants nothing</td></tr>
<tr><td>Event</td><td>One thing that happened in a source. Seven kinds: message, item created, item assigned, status changed, timer due, code review, CI result</td><td>The body is untrusted text. It never takes part in matching or authorization</td></tr>
<tr><td>Topic</td><td>A run of connected events: a Lark reply chain or direct chat, or the comments on one Jira issue</td><td>It is how a later message finds the ticket that already handles the matter. The code and the rules call it topic</td></tr>
<tr><td>Work item</td><td>One thing to do, with the same identity everywhere, for example a Jira issue and the internal issue linked to it</td><td>Work items do map across sources, by exact id. A work item is not a ticket</td></tr>
<tr><td>Place</td><td>Where an event lands: a Lark chat, a Jira project, a git repository</td><td>Each source kind declares which attribute gives the place, so the engine has no per-source special case</td></tr>
<tr><td>Ticket</td><td>SA's own unit of work, one per accepted request</td><td>Stored state is only open or ended, plus an outcome. Everything else the owner sees is computed</td></tr>
<tr><td>Outward action</td><td>A fixed list of actions that change the outside world: push, pull request, release, deploy, work item write, delete</td><td>The worker must ask the owner first, unless the rule's <code>allow</code> names the action</td></tr>
<tr><td>Destination</td><td>Where a reply can go: the ticket card, the task inbox, the event's topic, a Lark message, a Jira comment and a few more</td><td>The inbox always keeps a copy. Speaking outside needs a source that is read-write</td></tr>
<tr><td>Link</td><td>A handler (a ticket) is related to a target (a topic or another ticket)</td><td>It is a fact and has no lifetime</td></tr>
<tr><td>Follow</td><td>A handler waits for something: a point in time, or an event</td><td>It is a promise with a deadline and a list of actions to take on timeout</td></tr>
</tbody>
</table></div>
<p>Attributes that mean the same thing in every source are shared: author, who is mentioned, whether it is a direct chat, who the work item is assigned to. Attributes that only one source has carry that source's prefix, such as <code>jira.type</code>, <code>lark.chat</code> and <code>git.repository</code>. Adding a source therefore means two things: declare how its events map onto the vocabulary, and write an adapter. The rule syntax does not change.</p>

<h2>A rule is a record filled in with vocabulary words</h2>
<p>An external event never authorizes anything by itself. The rule does. A source with no rule does nothing. The owner states a rule in plain language in their own chat:</p>
<div class="said"><small>The owner's words</small><p>Bugs in the RND project that are assigned to me: if they have steps to reproduce, try to fix them first. When one is fixed, comment on the issue and tell me.</p></div>
<p>The chat agent translates the sentence into fixed fields:</p>
<div class="cw"><pre><code>id: new-bug-try
when:
  event: [item_created, item_assigned]
  who: anyone
  match: { item.assignee: owner, jira.type: Bug }
  judge: the description has steps to reproduce
do: try
allow: []
deliver: { result: [topic, inbox] }</code></pre></div>
<p><code>when</code> says which events, who, and which attributes must be equal, plus one optional free-text condition called <code>judge</code>. <code>do</code> says how far to go: <code>ignore</code>, <code>ask</code> (ask me first), <code>try</code> (try quietly), <code>run</code> (do it) or <code>claw</code> (hand it to the chat agent for triage). <code>allow</code> lists the outward actions that need no question, and <code>deliver</code> names the destination for each purpose. A rule has no expressions, no "or" and no scripts.</p>
<p>After the rule is saved, the engine generates a restatement from the fields for the owner to read. No model is involved and the owner's own words are not read. For the rule above, the restatement says in effect:</p>
<div class="said"><small>Restatement generated by the engine (excerpt, translated from Chinese)</small><p>… item created or item assigned, from anyone, where item.assignee=owner and jira.type=Bug, and judged "the description has steps to reproduce" → try first; allowed: none; … result → topic, task inbox</p></div>
<p>This is the part of the design I value most. A rule takes effect in the same turn in which the owner says it, with no second confirmation, and a rule can allow outward actions. So a wrong translation must be visible at a glance. If the restatement does not match what the owner said, the owner knows the agent translated it wrongly and can undo to the previous version.</p>
<p>The same reason rejected four other designs:</p>
<ul>
<li><strong>Natural language only</strong>, with a model reading the rule for every event. That is one model call per event, the same event can get different verdicts, and the rule text shares a context with a colleague's message, so injected text can pose as a rule.</li>
<li><strong>An expression language</strong> such as CEL or Rego. A model that translates a sentence into a small program gets it wrong more often, and the error is hard to see in a restatement.</li>
<li><strong>A full ontology with a reasoner.</strong> The reason for a match has to be traced along an inference chain, which the owner cannot read at a glance.</li>
<li><strong>Each source with its own field names.</strong> The same meaning is written twice, a new source changes the rule syntax, and work items cannot be matched across sources.</li>
</ul>
<p>The cost is that rules have limits. A single rule cannot say "A or B", and it cannot do arithmetic, time windows or regular expressions. To say "or", write two rules.</p>

<h2>One request, from start to finish</h2>
<p>Each step writes a record first and acts second. The next step reads the record, not the model's memory.</p>
<figure class="gf"><div class="gg st">
<div class="gn r1 c1"><b>1 Read</b><small>chat · Lark · Jira · git · timer</small></div>
<div class="ga r1 c2"><span>one inbox row</span><i></i></div>
<div class="gn eg r1 c3"><b>2 Decide</b><small>follow · topic · rule · watch · triage</small></div>
<div class="ga ac r1 c4"><span>one trigger</span><i></i></div>
<div class="gn eg hi r1 c5"><b>3 Verify and accept</b><small>re-read at the source · one transaction</small></div>
<div class="ga v ll ac r2 c5"><span>ticket + mandate</span><i></i></div>
<div class="gn eg r3 c5"><b>4 Queue and launch</b><small>slots · caps · pause</small></div>
<div class="ga bi rv ac r3 c4"><span>assignment · input</span><i class="f"></i><i class="b"></i><span>ack · reports</span></div>
<div class="gn r3 c3"><b>5 Work</b><small>worker session · its own worktree</small></div>
<div class="ga lt r3 c2"><span>replies, sent by the engine</span><i></i></div>
<div class="gn r3 c1"><b>6 Deliver</b><small>card · inbox · topic · DM</small></div>
<div class="ga v up od r2 c1"><span>answers and new topic messages</span><i></i></div>
<div class="gb r4">Event log: every step appends one row that can never be updated</div>
</div><div class="gp op"><span>↺ an answer on the card or a new message in the topic: back to step 1, straight to the existing ticket</span></div><figcaption>The three tinted steps are where the engine decides. Step 3 is the gate: a ticket exists only after verification passes, and its mandate never changes afterwards.</figcaption></figure>
<div class="tw"><table>
<thead><tr><th>Step</th><th>Record written</th><th>What it fixes in place</th></tr></thead>
<tbody>
<tr><td>1 Read</td><td>One row in the inbox table, and one bookmark per source</td><td>The raw event is stored once. A failed read leaves the bookmark where it was, and events missed while the app was closed are read from the bookmark at the next start. The owner's own chat is not read this way: its entry is one open-ticket call from the chat agent</td></tr>
<tr><td>2 Decide</td><td>At most one decision per event, and a record of who took the event</td><td>The adapter maps the raw event to a vocabulary event. The engine then asks, in a fixed order: is a follow waiting for it; does an open ticket subscribe to its topic; does a rule match; is a watch listening. If none of these holds, the event is addressed to the owner and the source says so, it goes to the chat agent for triage</td></tr>
<tr><td>3 Verify and accept</td><td>Trigger, verification result and ticket with its mandate, in one transaction</td><td>See below. One trigger opens at most one ticket</td></tr>
<tr><td>4 Queue and launch</td><td>A launch entry in the queue</td><td>The entry's key is also the submit id, so a repeated launch lands in the same session. By default 2 worker sessions may run a turn at the same time; each ticket also has a wall-clock cap (240 minutes by default) and a turn cap (20 by default)</td></tr>
<tr><td>5 Work</td><td>Acknowledgement, reports and inputs; also links, follows and topic subscriptions</td><td>The worker reads its ticket, writes one acknowledgement that says what it will change, then reports progress, ready, blocked, failed or dropped. A question for the owner rides on a report, one at a time; the owner's answer comes back as an input</td></tr>
<tr><td>6 Deliver</td><td>A reply entry in the queue, then the outbound result</td><td>The rule's <code>deliver</code> picks the destination per purpose: acknowledgement, question, result. A send counts only when the remote message id comes back</td></tr>
</tbody>
</table></div>
<h3>Step 3: what is verified</h3>
<p>When a request comes from the owner's own chat, the chat agent must end its turn after it asks for the ticket. The engine waits for the turn to end and checks that the turn really contains input from the owner. Only then does it create the ticket. Until then the card says "verifying"; if the check fails there is no ticket. Only the owner's own chat session can open a ticket. A run that a colleague started by mentioning the bot cannot.</p>
<p>When a request comes from an external source, the adapter goes back to the source and reads the message or issue again by id. It continues only if the content and the author still match. So an event forged on the local machine cannot open a ticket, and a message that was recalled or deleted is not acted on.</p>
<p>After verification the engine writes the ticket and its <strong>mandate</strong> in the same transaction. The mandate records four things: scope (the text of the request), basis (the owner's chat, or which rule), strength (explicitly asked for, or inferred from a rule) and the settings version at that moment. It never changes. To widen the scope during the work, the worker has to ask the owner on the card.</p>
<h3>Why a restart or a retry does not open a second ticket</h3>
<p>Every record has a unique key that is derived from what caused it. The trigger id is unique in the ticket table, so one trigger gives at most one ticket. A decision is deduplicated by event id, so an event is judged once. The key of a launch entry is the submit id, so a retry, a reopen and a resume after a restart all land in the same session and the same work directory. A repeated tool call, a crash in the middle and a network retry all end the same way: the record already exists.</p>

<h2>Topics: how a later message finds the existing ticket</h2>
<p>When a ticket is accepted it subscribes to the topic of the event that caused it. A later message in that topic goes straight to that ticket as an input, before any rule is tried. Without this step a conversation of five messages would open five tickets. Events in one topic are handled one at a time, in arrival order.</p>
<p>Every external message that reaches an agent starts with an <strong>event header</strong> written by code: where it came from, the author's account in that source, who is mentioned, which work item it is about, and whether the author carries authority (owner, a requester the rule accepts, or none). Only the authority line decides what may be done. The body and the other lines are material. You can read the header as the vocabulary rendered as text for the model.</p>
<p>A note on the name: the code and the rules call this concept topic, and the Chinese glossary calls it 话题. It was first named thread. It was renamed because it means "the same matter", not a thread in some chat product. A saved rule that says <code>thread</code> still works: the engine reads it as <code>topic</code>.</p>

<h2>Waiting for the outside world: links and follows</h2>
<p>A worker often has to wait: for a build, a review, a colleague's reply. It can ask the engine to wait for it and end its turn. Waiting uses no slot and does not count as working time.</p>
<p>The engine stores two things. A <strong>link</strong> points at an exact target, such as a topic. A <strong>follow</strong> hangs on a link or on a point in time. It has a deadline (between 1 minute and 7 days from now) and a list of timeout actions: wake the handler, ask the owner, or drop. The default order is to wake the worker first and ask the owner second.</p>
<p>When the awaited event arrives, the engine matches it by source and id. No model judges whether "this is the one I was waiting for". The engine then delivers the event as an input to the waiting session. A match gives the author of the message no authority.</p>

<h2>Where a model still judges</h2>
<p>The engine is not entirely free of models. The design record lists three places where it asks a very small model: a rule's <code>judge</code> condition; whether a new message in a topic should reopen an ended ticket; and whether a watch should take a message. All three follow the same constraints:</p>
<ul>
<li>The model only chooses between paths that each already have their own basis. It grants no authority. After it says "yes", the re-read at the source and the rule check still run.</li>
<li>If the model cannot be reached, times out or gives an unreadable answer, the engine takes the deterministic path and never treats the result as "yes". For example, when <code>judge</code> is uncertain, the event becomes a candidate in the owner's inbox. It is never dropped silently.</li>
<li>The model reads untrusted outside text, so the only direction it can be pushed is "ignore". It cannot add authority.</li>
</ul>
<p>The same holds when the chat agent does triage: its verdicts are advice, and the engine checks each one before it acts.</p>

<h2>What the owner sees is computed</h2>
<p>The ticket card, the task inbox and the ticket detail all render from the store. The phase on the card (queued, running, waiting for your answer, blocked, cap reached and so on) is a pure function of the ticket's facts: the engine walks a fixed table from the top and takes the first row that matches.</p>
<p>A report from the worker updates the card directly. It costs no model turn and does not wake the chat agent. The owner's answer or stop goes from the card straight to the engine, so the chat agent has no chance to reword it.</p>

<h2>Weak points and open questions</h2>
<ul>
<li><strong>"Ask before an outward action" is an instruction today, not a gate in code.</strong> The worker runs unattended with the owner's permissions, and the engine cannot yet stop it from pushing or writing to Jira by itself. A design in which the engine checks each tool call before it runs has been researched but not built. This is the largest gap today.</li>
<li><strong>There is no cap on money or tokens.</strong> Spending is bounded only by the turn cap and the wall-clock cap, and both restart when a ticket is reopened.</li>
<li><strong>The cost of not mapping identity across sources.</strong> Whether Zhang San in Lark is Zhang San in Jira is left to the agent that reads the event header, and it can be wrong. That judgement grants nothing, so the damage is limited to a misunderstanding.</li>
<li><strong>It works only while the app is open, and on one device.</strong> Work that a quit interrupts resumes at the next start.</li>
<li><strong>The two newest parts are still under review.</strong> The design records for "hand unmatched messages to the chat agent for triage" and for "links and follows" are still marked proposed. The code for both is on the development branch.</li>
</ul>
<p>Looking back, nothing in this mechanism is a new invention. A closed vocabulary, an immutable mandate and records with unique keys are ordinary engineering. Together they answer the question at the top: the sentence in which a colleague mentions the bot authorizes nothing by itself. Authority comes from a rule the owner once stated. The engine checks that the message is real, and then writes those two facts into a record that will not change.</p>
</section>

</div>
