# tool_end

Canonical URL: https://developers.iagenify.com/sdk/agent/events/tool-end/
Language: en

`{ type: "tool_end", id, tool, ok, summary, meta, durationMs, refused? }`

The call finished, failed or was refused. summary is one line to show; meta is what the tool wants you to know, including what it cost.

Status: ok tells you which · refused is not an error · meta.credits is per tool

## Fields {#fields}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | Matches the `tool_start`, when there was one. |
| `tool` | string |  | The tool's name. |
| `ok` | boolean |  | `true` if it ran and returned. `false` if it threw, or was refused. |
| `summary` | string |  | One line, meant to be shown — « 3 files », « 2/5 done », or the refusal's reason. |
| `meta` | object |  | What the tool reports: a path, a count, `credits`, a subagent's figures. |
| `durationMs` | integer |  | How long it took. `0` on a call that never ran. |
| `refused` | boolean |  | Present and `true` when a permission said no, or a mode refused it. |

## Three endings, two flags {#three-endings}

| Ending | ok | refused | summary holds |
| --- | --- | --- | --- |
| It worked | `true` | absent | what it did |
| It threw | `false` | absent | the error message |
| It was refused | `false` | `true` | why — the mode, or « Refused by the user. » |

> **A refusal is a normal outcome**
>
> The result goes back to the model, which adapts. Showing it as an error makes a steered run look broken; showing it as a refusal is what it is.

## meta, per tool {#meta}

| Tool | meta carries |
| --- | --- |
| `read`, `write`, `move` | the path it acted on |
| `todo_write` | the whole list |
| `search`, `fetch`, `convert`, media | `credits` |
| `task` | the subagent's name, model, turns, tool calls, credits, stop reason and report |
| `skill` | the skill's name and how many files it has |

## meta.credits is the tool's own cost {#credits}

It is already included in the next `turn` event's `totalCredits`. Show it per line if you like; do not add it to a running total you built from turns.

## A task ends once, with its figures {#task}

```javascript
if (e.type === "tool_end" && e.tool === "task") {
  const { agent, turns, toolCalls, credits, stopReason } = e.meta;
  console.log(`${agent}: ${turns} turns, ${toolCalls} calls, ${credits} credits (${stopReason})`);
}
```

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

- [tool_start](/sdk/agent/events/tool-start): The other half of the pair.
- [Agent tools](/sdk/agent/tools): What each tool reports.

```python
# A subagent's report is the result of its "task" call; its own events carry parentAgent
def on_event(event):
    if event["type"] == "tool_end" and event["tool"] == "task":
        print("subagent finished:", event["summary"])
```
