Skip to main content
This page documents result types returned by core generation and agent turn APIs.

GenerateTextResult

Returned by generate_text().
str
Accumulated generated text.
list[StepResult]
Step history for the model/tool loop.
str | None
Finish reason for the final provider response.
Usage | None
Total usage across all steps.
dict[str, Any]
Raw response metadata from the provider implementation.
dict[str, Any]
Additional provider metadata.
TurnTermination | None
Framework-level reason the model/tool loop ended. This is distinct from the provider’s finish_reason.
list[ToolCall]
Flattened tool calls from all steps.
list[ToolResult]
Flattened tool results from all steps.

TextStreamResult

Returned by stream_text().
AsyncIterator[TextStreamEvent]
Replayable async iterator yielding typed text, reasoning, tool lifecycle, step lifecycle, and final events.
AsyncIterator[str]
Replayable text-only projection of event_stream.
Awaitable[str]
Complete accumulated text after stream consumption.
Awaitable[Usage | None]
Usage after stream completion.
Awaitable[str | None]
Finish reason after stream completion.
Awaitable[TurnTermination | None]
Framework-level termination diagnostic after stream completion.
Awaitable[list[StepResult]]
Step history after stream completion.
event_stream and text_stream share one provider request. They can be consumed in either order or concurrently, and later consumers replay events already received.

TurnResult

Returned by Agent.run(), AgentTurn.result(), and AgentTurn.wait().
str
ID of the turn.
str
ID of the agent that ran the turn.
str
Final accumulated assistant text.
str | None
Final stream finish reason.
Usage | None
Usage after turn completion.
list[StepResult]
Step history for this turn.
float
Unix timestamp when the turn started.
float
Unix timestamp when the turn ended.
Message
Final assistant message appended to agent history.
TurnTermination | None
Structured terminal diagnostic for the turn.

TurnTermination

finish_reason belongs to the model provider. TurnTermination records why ai-query stopped the surrounding loop.
final_step_number is the last attempted model step. It is 0 when the operation stops before the first provider call. Successful operations expose this object on GenerateTextResult, StreamFinishedEvent, TextStreamResult.termination, and TurnResult. AbortError and ordinary exceptions expose a termination attribute when the runtime can attach one. TurnFailed.termination contains the same diagnostic for event consumers.

StepResult

One model/tool-loop step.
str
Text produced in the step.
list[ToolCall]
Tool calls requested by the model in the step.
list[ToolResult]
Results from executing tool calls in the step.
str | None
Provider finish reason for this step.
Usage | None
Token usage for this step only.

StreamChunk

Provider stream chunk consumed by stream_text().

ReasoningEvent

Provider reasoning/thinking event.

StepControl

Returned from on_step_start to control the next step.
list[Message]
Messages appended to the current model context before the provider call.
bool
If true, stops at the step boundary.
str | None
Optional reason copied into the hook_stop termination diagnostic.

RetryPolicy

Configures provider-call retries for generate_text(), stream_text(), and agents. Default classification retries transient HTTP statuses (408, 409, 425, 429, 500, 502, 503, 504) and network/timeout failures. It does not retry clear client errors such as 400, 401, and 403. Set retry_on to override the classifier.

RetryEvent

Passed to on_retry before the runtime waits and starts another provider attempt.

StepStartEvent

Passed to on_step_start.

StepFinishEvent

Passed to on_step_finish.
usage is the provider-reported usage for this step.

ToolCall

ToolResult

result remains Any for backward compatibility. Tools returning rich text, image, or file content use ToolOutput; scalar and JSON-compatible results keep their existing behavior.

See Also