pub async fn run_tool_loop(
model: &dyn TextModel,
prompt: Prompt,
executor: &dyn ToolExecutor,
budget: ToolBudget,
) -> Result<ToolLoopOutcome, ToolLoopError>Expand description
Runs prompt to completion through model, running any tool calls with
executor, within budget (issue #665).
Every offered tool’s parameters schema is validated before the first
model call, and every call’s arguments are validated against its tool’s
schema before any executor sees them — a call with arguments that are
not a JSON object, or that do not conform, becomes an error
ToolResult the model is shown, never an execution.
§Errors
ToolLoopError::Modelif the prompt’s images cross aPrompt::check_imagesbound, if the model is asked to carry tools or images it does not support, or a call to it fails.ToolLoopError::InvalidToolSchemaif an offered tool’s schema uses a keyword this validator cannot honour; the check runs before the first model call.ToolLoopError::StepBudgetExhaustedif the loop would make more thanToolBudget::max_stepscalls — including a budget of0, which makes no call at all.ToolLoopError::TokenBudgetExhaustedif a completion that still asks for a tool carries the cumulative input + output tokens pastToolBudget::max_total_tokens; the tools are not run. A completion with no tool calls is the final answer and is returned whatever it cost.