AgentOptions

Struct AgentOptions 

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

Configuration options for an AI agent instance.

AgentOptions controls all aspects of agent behavior including model selection, conversation management, tool usage, and lifecycle hooks. This struct should be constructed using AgentOptions::builder() rather than direct instantiation to ensure required fields are validated.

§Architecture

The options are organized into several functional areas:

  • Model Configuration: model, base_url, api_key, temperature, max_tokens
  • Conversation Control: system_prompt, max_turns, timeout
  • Tool Management: tools, auto_execute_tools, max_tool_iterations
  • Lifecycle Hooks: hooks for monitoring and interception

§Thread Safety

Tools are wrapped in Arc<Tool> to allow efficient cloning and sharing across threads, as agents may need to be cloned for parallel processing.

§Examples

use open_agent::AgentOptions;

let options = AgentOptions::builder()
    .model("qwen2.5-32b-instruct")
    .base_url("http://localhost:1234/v1")
    .system_prompt("You are a helpful coding assistant")
    .max_turns(5)
    .temperature(0.7)
    .build()
    .expect("Valid configuration");

Implementations§

Source§

impl AgentOptions

Source

pub fn builder() -> AgentOptionsBuilder

Creates a new builder for constructing AgentOptions.

The builder pattern is used because:

  1. Some fields are required (model, base_url) and need validation
  2. Many fields have sensible defaults that can be overridden
  3. The API is more discoverable and readable than struct initialization
§Example
use open_agent::AgentOptions;

let options = AgentOptions::builder()
    .model("qwen2.5-32b-instruct")
    .base_url("http://localhost:1234/v1")
    .build()
    .expect("Valid configuration");
Source

pub fn system_prompt(&self) -> &str

Returns the system prompt.

Source

pub fn model(&self) -> &str

Returns the model identifier.

Source

pub fn base_url(&self) -> &str

Returns the base URL.

Source

pub fn api_key(&self) -> &str

Returns the API key.

Source

pub fn max_turns(&self) -> u32

Returns the maximum number of conversation turns.

Source

pub fn max_tokens(&self) -> Option<u32>

Returns the maximum tokens setting.

Source

pub fn temperature(&self) -> f32

Returns the sampling temperature.

Source

pub fn timeout(&self) -> u64

Returns the HTTP timeout in seconds.

Source

pub fn tools(&self) -> &[Arc<Tool>]

Returns a reference to the tools vector.

Source

pub fn auto_execute_tools(&self) -> bool

Returns whether automatic tool execution is enabled.

Source

pub fn max_tool_iterations(&self) -> u32

Returns the maximum tool execution iterations.

Source

pub fn hooks(&self) -> &Hooks

Returns a reference to the hooks configuration.

Trait Implementations§

Source§

impl Clone for AgentOptions

Source§

fn clone(&self) -> AgentOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentOptions

Custom Debug implementation to prevent sensitive data leakage.

We override the default Debug implementation because:

  1. The api_key field may contain sensitive credentials that shouldn’t appear in logs or error messages
  2. The tools vector contains Arc-wrapped closures that don’t debug nicely, so we show a count instead

This ensures that debug output is safe for logging while remaining useful for troubleshooting.

Source§

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

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

impl Default for AgentOptions

Default values optimized for common single-turn use cases.

These defaults are chosen to:

  • Require explicit configuration of critical fields (model, base_url)
  • Provide safe, sensible defaults for optional fields
  • Work with local inference servers that don’t need authentication
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: 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: 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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