Fields
textstringEverything the model wrote in this turn.
finalbooleantrue when the turn asked for no tool — so this is the answer, and the loop is ending.
Most text is not the answer
A model usually writes a sentence before calling a tool — « I will read the file first. » Those arrive with final: false. Only the last one, the turn with no tool call, is the answer.
onEvent: (e) => {
if (e.type !== "text") return;
if (e.final) showAnswer(e.text);
else showThinkingAloud(e.text);
}def on_event(event):
if event["type"] == "text":
show_answer(event["text"])text_delta
{ type: "text_delta", delta: "I will read " }# The Python engine emits each turn's text as one "text" event;
# to stream it token by token, call api.models.turn(on_text=...) directly.
{"type": "text", "text": "I will read the four notes…"}One per piece as the provider produces it. It is the only event that arrives during a turn — everything else is emitted between two things.
The deltas of a turn add up to exactly its text event. A display that appends the deltas and then appends the text shows every answer twice. Stream the deltas and use text to replace what you streamed, or ignore one of the two.
A delegated run emits one final text
When a message starts with @agent, the named agent does the work and its report is the answer: one text with final: true, then done.
The run returns the last one
result.text is the most recent text of the run — which on a run ending at a ceiling may not be final. Checking stopReason is what tells you whether it is an answer.
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.