Fields
idstringThe tool call's identifier — the same one tool_start will carry.
toolstringWhat is being asked for.
categorystringIts category.
argsobjectThe actual arguments. This is what a person should be shown.
modestringThe mode in force at this moment.
The human-in-the-loop pattern
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"It is emitted after your callback resolves, with what was decided. true becomes once; false, null and nothing become deny.
Those three accept the answer and treat it as a single approval, so the result event says once. The next call is asked again, whatever was clicked.
When no event is emitted at all
- A
read,memoryortaskcall — always allowed. - Plan mode refusing a change — refused outright, and only
tool_endis emitted. - Full mode allowing one of the four it opens.
- A call covered by an « always » already remembered.
So the absence of a prompt is not the absence of an action: tool_start is what tells you something is happening.
They carry parentId — the identifier of the task call that started them — and agent, its name. Their own id is prefixed with the task's, so two runs never collide. Test parentId before treating an event as the main run's.