事件

许可权限

{ type: "permission", id, tool, category, args, mode }

正在询问一些事情。 它会在等待回回拨之前被排放出来, 也就是让界面在等待点击时给对话框涂上颜色。

before the callbackpermission_result followsthe whole args
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

字段

idstring

工具电话识别特征——同一 tool_start 将携带。

toolstring

要求我们做什么。

categorystring

其 其 其 其 类别.

argsobject

实际的论据。 这是一个人应该展示的。

modestring

此时此刻生效的模式 。

人与圈人模式

const pending = new Map();

const agent = api.agents.create({
  runtime: "local", machine: pc, model, mode: "ask",

  // The promise is what the loop waits on
  onPermission: ({ id }) => new Promise((resolve) => pending.set(id, resolve)),

  // The event is what paints the dialog
  onEvent: (e) => {
    if (e.type === "permission") showDialog(e.id, e.tool, e.category, e.args);
    if (e.type === "permission_result") closeDialog(e.id, e.decision);
  },
});

// When the person clicks
function answer(id, decision) { pending.get(id)?.(decision); pending.delete(id); }
import threading

pending = {}

def on_permission(request):
    # The Python callback is synchronous: block this run's thread until the person answers
    answered = threading.Event()
    pending[request["id"]] = {"event": answered, "decision": "deny"}
    answered.wait()
    return pending.pop(request["id"])["decision"]

def on_event(event):
    if event["type"] == "permission":
        show_dialog(event["id"], event["tool"], event["category"], event["args"])
    if event["type"] == "permission_result":
        close_dialog(event["id"], event["decision"])

agent = api.agents.create(runtime="local", machine=pc, model=model, mode="ask", on_permission=on_permission)

# When the person clicks (from another thread)
def answer(call_id, decision):
    pending[call_id]["decision"] = decision
    pending[call_id]["event"].set()

permission_result

{ type: "permission_result", id, tool, decision }   // "once" | "always" | "deny"
{"type": "permission_result", "id": ..., "tool": ..., "decision": ...}   # "once" | "always" | "deny"

是在你回击的决断后 随决定结果而释放出来的 true 成为 once; false, null 却无所成 deny.

以寄出、出版和金钱,“总是”报称“曾经”

这三个人接受了答案,并将其作为一个单一的认可,结果事件只说一次。下一次的电话被再次询问,无论点击什么。

完全没有排放任何事件

  • A A A read, memory 或 task 总是允许打电话
  • 拒绝修改的计划模式——彻底拒绝,仅 tool_end 被排放。
  • 允许打开四个打开的 全部模式之一 。
  • 电话里写着 “永远”已经记起

因此,缺乏及时性并不是没有行动: tool_start 告诉你什么 东西正在发生。

子智能体事件也会传递到这里

它们随身携带 palclId —— 启动它们的任务电话的识别符号 —— 以及代理、 其名称。 他们自己的代号与任务名称相加, 所以两个运行时不会相撞 。 在将事件作为主运行程序处理之前先测试 palId 。