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
impl AgentOptionsBuilder
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
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.
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.
Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Sets the system prompt. Defaults to empty; an empty prompt is omitted.
Sourcepub fn model(self, model: impl Into<String>) -> Self
pub fn model(self, model: impl Into<String>) -> Self
Sets the required model identifier. Empty or whitespace-only names are rejected.
Sourcepub fn base_url(self, url: impl Into<String>) -> Self
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.
Sourcepub fn api_key(self, key: impl Into<String>) -> Self
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.
Sourcepub fn max_turns(self, turns: u32) -> Self
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.
Sourcepub fn max_tokens(self, tokens: u32) -> Self
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.
Sourcepub fn include_reasoning(self, include: bool) -> Self
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.
Sourcepub fn temperature(self, temp: f32) -> Self
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.
Sourcepub fn protocol(self, protocol: ApiProtocol) -> Self
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.
Sourcepub fn timeout(self, timeout: u64) -> Self
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.
Sourcepub fn auto_execute_tools(self, auto: bool) -> Self
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.
Sourcepub fn max_tool_iterations(self, iterations: u32) -> Self
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.
Sourcepub fn tools(self, tools: Vec<Tool>) -> Self
pub fn tools(self, tools: Vec<Tool>) -> Self
Appends tools without replacing those already registered.
Sourcepub fn hooks(self, hooks: Hooks) -> Self
pub fn hooks(self, hooks: Hooks) -> Self
Replaces the hook registry. See Hooks for event ordering and examples.
Sourcepub fn build(self) -> Result<AgentOptions>
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.
impl Debug for AgentOptionsBuilder
Shows configuration identifiers and tool count, omitting credentials.