Cortex · API
run.events
run.events is an async iterable of the run’s typed events, in order; the last event, run-end, carries the result. tool-start is emitted before the tool executes, and output is streamed while it is generated: output-delta carries text, output-partial the object parsed so far. The model’s two turns are scripted and arrive six characters at a time; no model is called.
const boxOffice = defineAgent({
id: 'box-office',
instructions: 'Look the night up with the seatsLeft tool, then give the answer.',
tools: [seatsLeft],
output: { schema: z.object({ left: z.number() }) },
});
const run = boxOffice.run('How many seats are left on 2026-10-24?', { llm });
for await (const event of run.events) seen.push(event);Run, event by event
calls seatsLeft {"night":"2026-10-24"}[
'run-start',
'step-start 1',
'tool-start seatsLeft {"night":"2026-10-24"}',
]Runs in this page on the installed package. The input and the expected output are defined by the example.