Skip to main content

Module generate_text

Module generate_text 

Source
Expand description

Multi-step text generation (generate_text).

The loop converts the prompt, calls the model, parses tool calls, resolves approvals, executes client tools and repeats until no client tool calls remain or a stop condition is met.

Design: docs/01-architecture/07-generation-loop-and-streaming.md, docs/01-architecture/06-tool-system.md.

Structs§

ApprovalContext
Information available to an ApprovalPolicy.
ApprovalPolicyFn
Adapter turning a synchronous closure into an ApprovalPolicy.
ChunkTimingStats
Statistics over the gaps between consecutive content parts.
GenerateText
Builder and future of a generate_text call.
GenerateTextResult
Result of a completed generation loop.
GeneratedFile
A generated file.
HasToolCall
Stops when the last step called one of the listed tools.
Include
Which large payloads are copied into step results.
Never
Never stops on its own (the loop ends when no tool calls remain).
ParsedToolCall
A tool call after parsing and validation.
PrepareStepContext
Information available to a PrepareStep callback.
RefineToolInputs
Refinement functions by tool name.
RepairRequest
Information handed to a ToolCallRepair.
StepCount
Stops when the number of completed steps equals n.
StepOverrides
Overrides returned by a PrepareStep callback. Unset fields keep the prior state for messages, instructions and contexts; other fields keep call defaults.
StepPerformance
Timing and throughput of a step.
StepRequest
Request metadata of a step.
StepResponse
Response metadata of a step.
StepResult
The result of one step: a model call plus the tool executions it caused.
ToolApprovalRequestContent
A request to approve a tool call before it executes.
ToolApprovalResponseContent
An approval decision made automatically by the approval policy.
ToolExecutionError
A failed tool execution (non-fatal: reported back to the model).
ToolOutputDenied
A tool call whose execution was denied.
ToolResult
A tool result.

Enums§

ApprovalStatus
Outcome of approval resolution for one tool call.
StepContent
A content part of a step.
ToolErrorInfo
Serializable description of a tool error.

Constants§

SIGNATURE_DOMAIN
Domain separator of the signature payload.

Traits§

ApprovalPolicy
Decides whether a tool call needs approval.
PrepareStep
Computes overrides before each step.
StopCondition
Decides after each step whether the loop stops.
ToolCallRepair
Repairs tool calls the model got wrong (unknown tool or invalid input).

Functions§

approval_policy
Wraps a synchronous closure as an approval policy.
generate_text
Starts building a non-streaming text generation call.
has_any_tool_call
Stops when the last step contains a call to any of tool_names.
has_tool_call
Stops when the last step contains a call to tool_name.
never
A condition that never stops the loop.
step_count
Stops when n steps have been completed.

Type Aliases§

RefineToolInputFn
Rewrites a validated tool input before execution.