Skip to main content
A run can contain multiple model calls and tool roundtrips. Inspect the sequence below to see why model completion, tool completion, and run completion are different events.

The boundaries that matter

run() gives you a final result. stream() gives you an iterator that may span several model calls. Consume it to completion or explicitly cancel/close it when its owner is done.

Configure stopping behavior

Set tool-roundtrip and token/cost limits appropriate to the task. Pass a cancellation signal for connection-owned work. Tools that call external services should forward the signal where supported. Cancellation, cost limits, and execution policy cover the controls.

Inspect failures at the right layer

A provider can reject a request before a tool runs. Tool validation can reject arguments. Approval can deny the action. A tool can fail after contacting a remote service. These require different responses; retrying the whole run indiscriminately can repeat a side effect. For diagnostics, start with run status, correlation IDs, model configuration, tool outcome, and timing. Observability defaults to metadata; configure content capture deliberately. See recovery for outcomes that cannot be inferred from a local error alone.