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.
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[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.

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.

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

See Also