Skip to main content

AgentOptionsBuilder

Struct AgentOptionsBuilder 

Source
pub struct AgentOptionsBuilder { /* private fields */ }
Expand description

Builds AgentOptions with runtime validation.

model and base_url are required. Unset temperature and max_tokens are omitted from requests; other settings use the defaults documented below.

use open_agent::{AgentOptions, ApiProtocol};

let options = AgentOptions::builder()
    .model("my-model")
    .base_url("http://localhost:1234/v1")
    .protocol(ApiProtocol::OpenAiChat)
    .system_prompt("Answer concisely.")
    .timeout(120)
    .build()?;

Implementations§

Source§

impl AgentOptionsBuilder

Source

pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self

Adds a caller-supplied HTTP header to every model request.

A later call with the same name replaces the earlier value, even when the casing differs. Caller headers take precedence over the defaults selected by Self::protocol. Names and values are validated by Self::build, which identifies the offending name in its configuration error.

Source§

impl AgentOptionsBuilder

Builder methods for configuring agent options.

All methods follow the builder pattern: they consume self, update a field, and return self for method chaining. The generic impl Into<String> parameters allow passing &str, String, or any other type that converts to String.

Source

pub fn system_prompt(self, prompt: impl Into<String>) -> Self

Sets the system prompt. Defaults to empty; an empty prompt is omitted.

Source

pub fn model(self, model: impl Into<String>) -> Self

Sets the required model identifier. Empty or whitespace-only names are rejected.

Source

pub fn base_url(self, url: impl Into<String>) -> Self

Sets the required base URL, beginning with http:// or https://.

The selected protocol adds /chat/completions or /messages. Unlike BaseUrl::new, the builder does not trim before checking the scheme.

Source

pub fn api_key(self, key: impl Into<String>) -> Self

Sets the authentication key; defaults to "not-needed".

An empty key suppresses the SDK authentication header. Caller headers may override protocol defaults.

Source

pub fn max_turns(self, turns: u32) -> Self

Stores a compatibility value that the SDK does not enforce. Defaults to 1.

This setting does not limit conversation length or enable multi-turn support. Use max_tool_iterations for automatic tool rounds; limit conversation turns in your application.

Source

pub fn max_tokens(self, tokens: u32) -> Self

Sets a positive generation-token limit.

Unset by default: omission lets the server choose. An explicit cap may truncate a response, including reasoning generated before visible text.

Source

pub fn include_reasoning(self, include: bool) -> Self

Emits reasoning through StreamEvent::Reasoning and Client::reasoning. Defaults to false.

Reasoning is kept separate from content and history regardless of this flag.

Source

pub fn temperature(self, temp: f32) -> Self

Sets a sampling temperature in the inclusive range 0.0–2.0.

Unset by default, which omits the field. Providers may impose a narrower range or reject any explicit temperature.

Source

pub fn protocol(self, protocol: ApiProtocol) -> Self

Selects the request path, credentials, body, and stream vocabulary.

Defaults to ApiProtocol::OpenAiChat. Use ApiProtocol::Anthropic for a messages endpoint.

Source

pub fn timeout(self, timeout: u64) -> Self

Sets the timeout for each HTTP request, including its stream. Defaults to 60 seconds.

This does not bound an entire conversation or automatic tool loop.

Source

pub fn auto_execute_tools(self, auto: bool) -> Self

Enables automatic tool calls and continuation. Defaults to false.

Manual mode returns tool calls to the caller. Automatic mode buffers the response and returns final text after the tool loop.

Source

pub fn max_tool_iterations(self, iterations: u32) -> Self

Limits automatic tool rounds. Defaults to 5; each round may contain multiple calls.

At the limit, Client::finish_reason reports FinishReason::MaxToolIterations.

Source

pub fn tool(self, tool: Tool) -> Self

Appends one tool. Handlers are shared through Arc.

Source

pub fn tools(self, tools: Vec<Tool>) -> Self

Appends tools without replacing those already registered.

Source

pub fn hooks(self, hooks: Hooks) -> Self

Replaces the hook registry. See Hooks for event ordering and examples.

Source

pub fn build(self) -> Result<AgentOptions>

Validates configuration and applies defaults.

§Errors

Returns an error for missing model/base URL, empty names or endpoints, unsupported URL schemes, invalid header names/values, out-of-range temperature, or zero max_tokens. Provider-specific parameter restrictions are enforced by the server.

Trait Implementations§

Source§

impl Debug for AgentOptionsBuilder

Shows configuration identifiers and tool count, omitting credentials.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AgentOptionsBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more