权限不是一个政策文件文件, 也不是远程设置。 它是一个函数, 需要所有决定的事物都来召唤它, 所以它可以说是 write 下 下 src/ 到处都没有
调回
const agent = api.agents.create({
runtime: "local",
machine: pc,
model: "gemini-3.5-flash",
mode: "ask",
onPermission: async ({ id, tool, category, args, mode }) => {
if (category === "exec") return "deny";
if (tool === "write" && args.path.startsWith("src/")) return "always";
return "once";
},
});def on_permission(request):
# request: {"id", "tool", "category", "args", "mode"}
if request["category"] == "exec":
return "deny"
if request["tool"] == "write" and request["args"].get("path", "").startswith("src/"):
return "always"
return "once"
agent = api.agents.create(
runtime="local",
machine=pc,
model="gemini-3.5-flash",
mode="ask",
on_permission=on_permission,
)idstring工具调用工具的识别标识符。 由 tool_start 和 tool_end.
toolstring工具的名字 e.g. write, bash, write_storage.
categorystring其中一个 10 10 个。六个工具根据他们的论点来计算。
argsobject模型实际上要求什么——路径、命令、过滤器、钥匙。
modestring此时此刻生效的模式 。
三、三个答案
| 返回返回 | 含义 |
|---|---|
"once" 或 true | 允许此电话 。 |
"always" | 允许它,而且不要再次要求——见 持久性 以那包罗万象。 |
"deny", false, null 或无 | 拒绝。 工具返回“ 被用户拒绝 ” , 循环继续 。 |
拒绝不是一个错误
失败的工具结果可以追溯到模型, 代理商被告知不要重试一个被拒绝的工具,而是要调整或解释。 因此拒绝是一种正常的运行方式,而不是打破它的方式。
事事由由决定
read,memory和task允许直接返回。不调回。- 内 计划计划 模式,其他所有内容都被直接拒绝。不调回。
send,publish,money每一次,在每种模式中,每次。- 内 满 模式,其他所有东西都可以使用。
- 一位被人们记住的“永远”的呼唤被尊重。
- 内 自动自动,
write允许。 - 否则就叫回调
两种方式都宣布
onEvent: (e) => {
if (e.type === "permission") console.log("asking", e.tool, e.category, e.args);
if (e.type === "permission_result") console.log("answered", e.decision); // "once" | "always" | "deny"
}def on_event(event):
if event["type"] == "permission":
print("asking", event["tool"], event["category"], event["args"])
if event["type"] == "permission_result":
print("answered", event["decision"]) # "once" | "always" | "deny"下 permission 活动在等待回调之前就被发布,因此接口可以在承诺尚未兑现时显示提示时间——这正是如何构建“人行环”界面:事件描绘了对话框,点击按钮时承诺的解析。
不带回回调
任何要求都被拒绝, 信息上说它需要批准, 没有人可以批准它。 onPermission 因此,无论采用何种模式,都接近只读。
分剂通过同一个
子试剂的工具以父母的模式到达父母的回调。 委托不是绕过许可的方式—— 即 task 自由本身正是因为它里面的一切不是自由的。