# permission

Canonical URL: https://developers.iagenify.com/sdk/agent/events/permission/
Language: en

`{ 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.

Status: before the callback · permission_result follows · the whole args

## Fields {#fields}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | The tool call's identifier — the same one `tool_start` will carry. |
| `tool` | string |  | What is being asked for. |
| `category` | string |  | Its [category](/sdk/agent/permissions/categories). |
| `args` | object |  | The actual arguments. This is what a person should be shown. |
| `mode` | string |  | The mode in force at this moment. |

## The human-in-the-loop pattern {#pattern}

```javascript
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); }
```

## permission_result {#result}

```javascript
{ 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 {#not-emitted}

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

- [Permissions](/sdk/agent/permissions): The callback and the order of decisions.
- [tool_start](/sdk/agent/events/tool-start): What follows an approval.

```python
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()
```

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