智能体护栏

用 Jev 在智能体动工具前快速判断是否越权,挡住删库一类的高危操作。

模型
jev-1.14.0
耗时
1086 ms
token
467
单次花费
$0.00001961
每千次
$0.020

痛点

智能体(agent)能自己调 shell、读写文件,一条越权命令就会把数据清掉。每一工具调用前都让大语言模型(LLM)再审一遍,又慢又贵,多数情况下也没必要。

Jev 判断什么

state(上下文状态)是 {"task": "帮用户清理项目里的临时文件", "proposed_action": {"tool": "shell", "command": "rm -rf ~/projects"}}。让 Jev 看的是「这条命令该不该执行」,不是「这条命令怎么写」。

risk(Score,打分题):问「How risky is the proposed action for the user's files?」,档位(level)["Read-only or harmless", "Changes a few files inside the intended folder", "Deletes or overwrites data outside the intended scope"]。这次分数 1.97(档位序号从 0 开始),各档概率(probability)档位 0 为 0%、档位 1 为 2%、档位 2 为 98%,置信度(confidence)0.97。读法:最高档概率 0.98,说明几乎确定这条命令会删掉预期范围之外的数据,直接当高危处理。

within_scope(Noul,是非题):问「Is the proposed action within the scope of the task?」。这次「是」的概率只有 0.29,多数判断认为这条命令超出了任务范围。读法:低于 0.5 就该停下。

next_step(Choice,选择题):问「What should the agent do next?」,选项 {"run": "Run the action as proposed", "ask_user": "Pause and ask the user to confirm", "narrow": "Rewrite the command to a narrower, safer one"}。这次选了 ask_user,概率 run=0.0, ask_user=0.6, narrow=0.4,置信度 0.4。读法:置信度只有 0.4,说明这道题分歧大,按 ask_user 走的同时准备好 narrow 兜底。

代码侧按这个顺序用:risk 触顶就拒;within_scope 概率低于阈值就拒;next_step 取返回值对应的分支即可。

和大模型怎么配合

Jev 先判断。代码按三道题的结果走规则:risk 命中最高档直接拒绝,不调大语言模型;within_scope 概率低于自己定的阈值(如 0.5)也直接拒绝;next_step 是 ask_user 就弹确认框,是 narrow 就改命令,是 run 才放行。只在 next_step 给出歧义答案、或置信度低于阈值、或风险档位落在中间档时,把 state 交给大语言模型或人工复核(human review)。

这次调用 jev-1.14.0 耗时 1086 毫秒、输入 467 个 token,单次约 0.00002 美元,按这次输入规模算每 1000 次约 0.0196 美元。

上线前注意

  • 题型(primitives)里的题目保持英文写;state 里 task、command 等字段保留调用方原始语言,示例是中文就传中文。
  • 阈值要先用自己 20–30 条真实数据校准过再上线,不要直接套默认值。
  • 置信度低、或是非题概率落在 0.5 附近时,交给人或大语言模型复核,不要硬走规则。
  • rm -rf、mkfs、chmod -R、dd 这类命令建议在 Jev 之外再加一层关键字拦截,不只靠打分题。

真实调用

请求

bash
curl https://api.typesafe.ai/v1/systemone \
  -H "Authorization: Bearer $TYPESAFE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "jev-1.14.0",
  "state": {
    "task": "帮用户清理项目里的临时文件",
    "proposed_action": {
      "tool": "shell",
      "command": "rm -rf ~/projects"
    }
  },
  "questions": {
    "risk": {
      "type": "score",
      "instructions": "How risky is the proposed action for the user's files?",
      "criteria": [
        "Read-only or harmless",
        "Changes a few files inside the intended folder",
        "Deletes or overwrites data outside the intended scope"
      ]
    },
    "within_scope": {
      "type": "noul",
      "instructions": "Is the proposed action within the scope of the task?"
    },
    "next_step": {
      "type": "choice",
      "instructions": "What should the agent do next?",
      "criteria": {
        "run": "Run the action as proposed",
        "ask_user": "Pause and ask the user to confirm",
        "narrow": "Rewrite the command to a narrower, safer one"
      }
    }
  }
}'

返回

json
{
  "model": "jev-1.14.0",
  "answers": {
    "risk": {
      "type": "score",
      "score": 1.97,
      "confidence": 0.97,
      "legend": {
        "0": "Read-only or harmless",
        "1": "Changes a few files inside the intended folder",
        "2": "Deletes or overwrites data outside the intended scope"
      },
      "probabilities": {
        "0": 0,
        "1": 0.02,
        "2": 0.98
      }
    },
    "within_scope": {
      "type": "noul",
      "noul": 0.29
    },
    "next_step": {
      "type": "choice",
      "choice": "ask_user",
      "confidence": 0.4,
      "probabilities": {
        "run": 0,
        "ask_user": 0.6,
        "narrow": 0.4
      }
    }
  },
  "usage": {
    "input_tokens": 467,
    "output_tokens": 72
  }
}

人话解读

  • Score:档位 2(Deletes or overwrites data outside the intended scope),分数 1.97,置信度 0.97
  • Noul:「是」的概率 0.29
  • Choice:选了 ask_user,置信度 0.40