Events

permission

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

Something is being asked. It is emitted before your callback is awaited — which is what lets an interface paint the dialog while the promise waits for a click.

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.

Fields

idstring

The tool call's identifier — the same one tool_start will carry.

toolstring

What is being asked for.

categorystring

Its category.

argsobject

The actual arguments. This is what a person should be shown.

modestring

The 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.

For send, publish and money, « always » is reported as « once »

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, memory or task call — always allowed.
  • Plan mode refusing a change — refused outright, and only tool_end is 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.

A subagent's events arrive here too

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.