pub struct ToolLoopAgentBuilder<Opt, Out> { /* private fields */ }Expand description
Builder for ToolLoopAgent. Besides the methods below it accepts every
call setting of generate_text (prompt-independent ones).
Implementations§
Source§impl<Opt, Out> ToolLoopAgentBuilder<Opt, Out>
impl<Opt, Out> ToolLoopAgentBuilder<Opt, Out>
Sourcepub fn system(self, instructions: impl Into<Instructions>) -> Self
pub fn system(self, instructions: impl Into<Instructions>) -> Self
Sets system instructions.
Sourcepub fn prompt(self, text: impl Into<String>) -> Self
pub fn prompt(self, text: impl Into<String>) -> Self
Sets a single user prompt (mutually exclusive with messages).
Sourcepub fn messages(self, messages: impl IntoIterator<Item = Message>) -> Self
pub fn messages(self, messages: impl IntoIterator<Item = Message>) -> Self
Sets the conversation messages (mutually exclusive with prompt).
Sourcepub fn allow_system_in_messages(self) -> Self
pub fn allow_system_in_messages(self) -> Self
Allows system messages inside messages.
Sourcepub fn settings(self, settings: CallSettings) -> Self
pub fn settings(self, settings: CallSettings) -> Self
Replaces all sampling settings.
Sourcepub fn max_output_tokens(self, n: u32) -> Self
pub fn max_output_tokens(self, n: u32) -> Self
Sets the maximum number of output tokens.
Sourcepub fn temperature(self, t: f64) -> Self
pub fn temperature(self, t: f64) -> Self
Sets the sampling temperature.
Sourcepub fn presence_penalty(self, p: f64) -> Self
pub fn presence_penalty(self, p: f64) -> Self
Sets the presence penalty.
Sourcepub fn frequency_penalty(self, p: f64) -> Self
pub fn frequency_penalty(self, p: f64) -> Self
Sets the frequency penalty.
Sourcepub fn stop_sequences(
self,
sequences: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn stop_sequences( self, sequences: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Sets stop sequences.
Sourcepub fn reasoning(self, effort: ReasoningEffort) -> Self
pub fn reasoning(self, effort: ReasoningEffort) -> Self
Sets the reasoning effort.
Sourcepub fn tool_choice(self, choice: ToolChoice) -> Self
pub fn tool_choice(self, choice: ToolChoice) -> Self
Sets the tool choice.
Sourcepub fn active_tools(
self,
names: impl IntoIterator<Item = impl Into<ToolName>>,
) -> Self
pub fn active_tools( self, names: impl IntoIterator<Item = impl Into<ToolName>>, ) -> Self
Restricts the tools sent to the model.
Sourcepub fn tool_order(
self,
names: impl IntoIterator<Item = impl Into<ToolName>>,
) -> Self
pub fn tool_order( self, names: impl IntoIterator<Item = impl Into<ToolName>>, ) -> Self
Sets the order in which tools are sent (listed first, rest alphabetical).
Sourcepub fn tools_context(self, context: JsonValue) -> Self
pub fn tools_context(self, context: JsonValue) -> Self
Sets the shared tools context (validated against each tool’s context schema).
Sourcepub fn runtime_context(self, context: JsonValue) -> Self
pub fn runtime_context(self, context: JsonValue) -> Self
Sets application state for step preparation, approval and lifecycle hooks. This value is separate from tool execution context and is never sent to models.
Sourcepub fn tool_approval(self, policy: impl ApprovalPolicy + 'static) -> Self
pub fn tool_approval(self, policy: impl ApprovalPolicy + 'static) -> Self
Sets the call-level approval policy.
Sourcepub fn tool_approval_secret(self, secret: SecretBox<[u8]>) -> Self
pub fn tool_approval_secret(self, secret: SecretBox<[u8]>) -> Self
Sets the secret used to sign approval requests.
Sourcepub fn tool_callers(self, callers: ToolCallers) -> Self
pub fn tool_callers(self, callers: ToolCallers) -> Self
Restricts which callers may trigger each tool.
Sourcepub fn repair_tool_call(self, repair: impl ToolCallRepair + 'static) -> Self
pub fn repair_tool_call(self, repair: impl ToolCallRepair + 'static) -> Self
Sets the tool call repair function.
Sourcepub fn refine_tool_input(
self,
name: impl Into<ToolName>,
refine: impl Fn(JsonValue) -> BoxFuture<'static, Result<JsonValue, Error>> + Send + Sync + 'static,
) -> Self
pub fn refine_tool_input( self, name: impl Into<ToolName>, refine: impl Fn(JsonValue) -> BoxFuture<'static, Result<JsonValue, Error>> + Send + Sync + 'static, ) -> Self
Rewrites the validated input of name before execution.
Sourcepub fn max_tool_concurrency(self, n: usize) -> Self
pub fn max_tool_concurrency(self, n: usize) -> Self
Limits how many tools execute concurrently within a step.
Sourcepub fn stop_when(self, condition: impl StopCondition + 'static) -> Self
pub fn stop_when(self, condition: impl StopCondition + 'static) -> Self
Adds a stop condition (any-of). Without conditions the loop stops after one step.
Sourcepub fn prepare_step(self, prepare: impl PrepareStep + 'static) -> Self
pub fn prepare_step(self, prepare: impl PrepareStep + 'static) -> Self
Sets the per-step preparation callback.
Sourcepub fn max_retries(self, n: u32) -> Self
pub fn max_retries(self, n: u32) -> Self
Sets the maximum number of retries (exponential backoff).
Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Replaces the retry policy.
Sourcepub fn cancellation(self, token: CancellationToken) -> Self
pub fn cancellation(self, token: CancellationToken) -> Self
Sets the cancellation token.
Sourcepub fn provider_options(self, options: ProviderOptions) -> Self
pub fn provider_options(self, options: ProviderOptions) -> Self
Adds provider options.
Sourcepub fn download(self, download: Arc<dyn DownloadFn>) -> Self
pub fn download(self, download: Arc<dyn DownloadFn>) -> Self
Sets the download function for file URLs.
Sourcepub fn include(self, include: Include) -> Self
pub fn include(self, include: Include) -> Self
Controls which payloads are kept in step results.
Sourcepub fn clock(self, clock: Arc<dyn Clock>) -> Self
pub fn clock(self, clock: Arc<dyn Clock>) -> Self
Sets the clock used for response.timestamp when the provider sends none.
Sourcepub fn id_generator(self, generator: Arc<dyn IdGenerator>) -> Self
pub fn id_generator(self, generator: Arc<dyn IdGenerator>) -> Self
Sets the id generator.
Sourcepub fn telemetry(self, options: TelemetryOptions) -> Self
pub fn telemetry(self, options: TelemetryOptions) -> Self
Sets telemetry options.
Sourcepub fn on_start(self, f: impl HookFn<StartEvent>) -> Self
pub fn on_start(self, f: impl HookFn<StartEvent>) -> Self
Runs when the call starts.
Sourcepub fn on_step_start(self, f: impl HookFn<StepStartEvent>) -> Self
pub fn on_step_start(self, f: impl HookFn<StepStartEvent>) -> Self
Runs when a step starts.
Sourcepub fn on_language_model_call_start(
self,
f: impl HookFn<ModelCallStartEvent>,
) -> Self
pub fn on_language_model_call_start( self, f: impl HookFn<ModelCallStartEvent>, ) -> Self
Runs before each model call.
Sourcepub fn on_language_model_call_end(
self,
f: impl HookFn<ModelCallEndEvent>,
) -> Self
pub fn on_language_model_call_end( self, f: impl HookFn<ModelCallEndEvent>, ) -> Self
Runs after each model call.
Sourcepub fn on_tool_execution_start(
self,
f: impl HookFn<ToolExecutionStartEvent>,
) -> Self
pub fn on_tool_execution_start( self, f: impl HookFn<ToolExecutionStartEvent>, ) -> Self
Runs before each tool execution.
Sourcepub fn on_tool_execution_end(
self,
f: impl HookFn<ToolExecutionEndEvent>,
) -> Self
pub fn on_tool_execution_end( self, f: impl HookFn<ToolExecutionEndEvent>, ) -> Self
Runs after each tool execution.
Sourcepub fn on_step_end(self, f: impl HookFn<StepResult>) -> Self
pub fn on_step_end(self, f: impl HookFn<StepResult>) -> Self
Runs when a step finishes.
Source§impl<Opt, Out> ToolLoopAgentBuilder<Opt, Out>
impl<Opt, Out> ToolLoopAgentBuilder<Opt, Out>
Sourcepub fn id(self, id: impl Into<String>) -> Self
pub fn id(self, id: impl Into<String>) -> Self
Sets the agent id (also the default telemetry function_id).
Sourcepub fn instructions(self, instructions: impl Into<Instructions>) -> Self
pub fn instructions(self, instructions: impl Into<Instructions>) -> Self
Sets the system instructions (alias of system).
Sourcepub fn output<T>(self, output: Output<T>) -> ToolLoopAgentBuilder<Opt, T>
pub fn output<T>(self, output: Output<T>) -> ToolLoopAgentBuilder<Opt, T>
Sets the structured output.
Sourcepub fn call_options<O>(self) -> ToolLoopAgentBuilder<O, Out>
pub fn call_options<O>(self) -> ToolLoopAgentBuilder<O, Out>
Sets the per-call options type, resetting preparation and validation callbacks configured for the previous type.
Sourcepub fn prepare_call(self, prepare: impl PrepareCall<Opt> + 'static) -> Self
pub fn prepare_call(self, prepare: impl PrepareCall<Opt> + 'static) -> Self
Sets the function that rewrites settings per call.
Sourcepub fn call_options_schema(self, schema: Schema<Opt>) -> Selfwhere
Opt: Serialize + 'static,
pub fn call_options_schema(self, schema: Schema<Opt>) -> Selfwhere
Opt: Serialize + 'static,
Validates and normalizes call options before preparing a generation or stream.
The schema receives serialized options and its validated value replaces them.
Validation failures return Error::InvalidArgument before callbacks or model
calls start. Without this option, call options need not implement Serialize.
Changing the option type with Self::call_options clears this schema.
§Examples
use ferrin_core::ToolLoopAgent;
use ferrin_schema::Schema;
use serde_json::{Value, json};
let agent = ToolLoopAgent::builder("provider:model")
.call_options::<Value>()
.call_options_schema(Schema::from_json_schema(json!({
"type": "object", "required": ["tenant"],
"properties": { "tenant": { "type": "string" } }
})))
.build();Sourcepub fn build(self) -> ToolLoopAgent<Opt, Out>
pub fn build(self) -> ToolLoopAgent<Opt, Out>
Finishes the agent.