generate_text() runs the model/tool loop and returns a completed GenerateTextResult.
Use it for one-off, non-streaming model calls where you do not need agent state.
Import
Signature
Parameters
Language model instance. Create one with a provider factory such as
openai("gpt-4o"), anthropic(...), or google(...).Convenience user prompt. If
messages is not provided, prompt is converted to a user message.Explicit message list. When provided,
prompt and system are ignored.Stop condition or list of stop conditions for the tool loop. Defaults to
step_count_is(1).Called before each provider request. May return
StepControl to inject messages or stop at a step boundary.Provider-call retry policy. By default, retries are conservative: transient HTTP statuses (
408, 409, 425, 429, 500, 502, 503, 504) and network/timeout failures are retried; clear client errors such as 400, 401, and 403 are not. Retries happen at the current model step and do not re-run completed tools.Called before a retry attempt with the step number, attempt, delay, and sanitized error string.
Abort signal used to cancel the generation loop, including in-flight provider calls, retry sleeps, embeddings, and async tool calls.
Application metadata exposed as an immutable mapping on injected
ToolExecutionContext values. It is not sent to the provider.Returns
Fields:Structured framework-level reason the loop ended. Inspect this instead of
inferring step limits, hook stops, or tool termination from empty text.
Raises
Raised when
signal is aborted. The exception carries termination when the
runtime can attach structured diagnostics.