Events

done

{ type: "done", text, todos, usage, stopReason, model }

The run ended. It carries exactly what run() returns — the same object, delivered to the callback instead of to the caller.

last eventsame as the returnchildren's done is dropped
Using Python?

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

Fields

{
  type: "done",
  text: "I read the four notes. Two are unfinished: …",
  todos: [{ content: "Check the figures", status: "completed" }],
  usage: { credits: 31, turns: 6, toolCalls: 9 },
  stopReason: "end_turn",
  model: "gemini-3.5-flash"
}
{
    "type": "done",
    "todos": [{"content": "Check the figures", "status": "completed"}],
    "usage": {"credits": 31, "turns": 6, "toolCalls": 9},
    "stopReason": "end_turn",
}
textstring

The last text the model wrote. Not necessarily an answer — see stopReason.

todosarray

The plan as it finished.

usageobject

{ credits, turns, toolCalls } — the whole run, subagents included.

stopReasonstring

end_turn · stopped · max_steps · budget.

modelstring

The agent's model. For which model served a given turn, read the turn events.

Read stopReason before using text

max_steps and budget leave an unfinished thought

The run ends where it was, so text is whatever the model last wrote — possibly mid-plan. Only end_turn means « it finished saying what it had to say ».

A subagent's done never reaches you

It is dropped when forwarding a child's events — a child finishing is not the run finishing, and an interface listening for done would end early. Its figures arrive instead on the task call's tool_end.

Both forms

const result = await agent.run({
  inputs: "…",
  onEvent: (e) => { if (e.type === "done") render(e); },   // for the interface
});

console.log(result.stopReason);                            // the same object
result = agent.run(
    inputs="…",
    on_event=lambda e: render(e) if e["type"] == "done" else None,   # for the interface
)

print(result["stopReason"])   # the same stop reason, with text and model added

usage counts everything

Turns, paid tools, compaction summaries, and everything every subagent did — the same total the budget was checked against.