AgentBuilder

Struct AgentBuilder 

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

A builder for Agent.

Allows configuration of model, endpoint, tools, penalties, flow, etc. Uses the builder pattern so you can chain calls.

Example:

use reagent_rs::AgentBuilder;

async {
    let mut agent = AgentBuilder::default()
        // model must be set, everything else has
        // defualts and is optional
        .set_model("qwen3:0.6b")
        .set_system_prompt("You are a helpful assistant.")
        .set_temperature(0.6)
        .set_num_ctx(2048)
        // call build to return the agent
        .build()
        .await;
};

Implementations§

Source§

impl AgentBuilder

Source

pub fn import_client_config(self, conf: ClientConfig) -> Self

Import generic client settings from a ClientConfig. Existing values already set on the builder are preserved unless overwritten by conf. Only fields present in conf are applied.

Source

pub fn import_prompt_config(self, conf: PromptConfig) -> Self

Import prompt-related settings from a PromptConfig. Existing values already set on the builder are preserved unless overwritten by conf. Only fields present in conf are applied.

Source

pub fn import_model_config(self, conf: ModelConfig) -> Self

Import model sampling and decoding parameters from a ModelConfig. Existing values already set on the builder are preserved unless overwritten by conf. Only fields present in conf are applied.

Source

pub fn set_name<T>(self, name: T) -> Self
where T: Into<String>,

Set the name of the agent (used in logging)

Source

pub fn set_provider(self, provider: Provider) -> Self

Select the LLM provider implementation.

Source

pub fn set_base_url<T>(self, base_url: T) -> Self
where T: Into<String>,

Override the base URL for the provider client.

Source

pub fn set_api_key<T>(self, api_key: T) -> Self
where T: Into<String>,

Set the API key used by the provider client.

Source

pub fn set_organization<T>(self, organization: T) -> Self
where T: Into<String>,

Set the organization or tenant identifier for requests.

Source

pub fn set_extra_headers(self, extra_headers: HashMap<String, String>) -> Self

Provide additional HTTP headers to include on each request.

Source

pub fn set_stream(self, set: bool) -> Self

Set the streaming value for Ollam Will enable Token Notifications

Source

pub fn set_temperature(self, v: f32) -> Self

Set the sampling temperature.

Source

pub fn set_top_p(self, v: f32) -> Self

Set nucleus sampling probability.

Source

pub fn set_presence_penalty(self, v: f32) -> Self

Set presence penalty.

Source

pub fn set_frequency_penalty(self, v: f32) -> Self

Set frequency penalty.

Source

pub fn set_num_ctx(self, v: u32) -> Self

Set maximum context length (in tokens/chunks).

Source

pub fn set_repeat_last_n(self, v: i32) -> Self

Repeat penalty for the last N tokens.

Source

pub fn set_keep_alive(self, v: String) -> Self

Set keep alive of the model

Source

pub fn set_repeat_penalty(self, v: f32) -> Self

Set penalty for repeated tokens.

Source

pub fn set_seed(self, v: i32) -> Self

Set RNG seed for sampling.

Source

pub fn set_stop<T: Into<String>>(self, v: T) -> Self

Set the hard stop string.

Source

pub fn set_num_predict(self, v: i32) -> Self

Number of tokens to predict.

Source

pub fn set_top_k(self, v: u32) -> Self

Top-K sampling.

Source

pub fn set_min_p(self, v: f32) -> Self

Minimum probability threshold.

Source

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

Select the underlying model name.

Source

pub fn set_system_prompt<T: Into<String>>(self, prompt: T) -> Self

System prompt that initializes conversation history.

Source

pub fn set_stop_prompt<T: Into<String>>(self, stop_prompt: T) -> Self

Optional prompt to insert on each tool‐call branch.

Source

pub fn set_stopword<T: Into<String>>(self, stopword: T) -> Self

Optional stopword to detect end of generation.

Source

pub fn strip_thinking(self, strip: bool) -> Self

Whether to strip <think> blocks from model output.

Source

pub fn set_flow_fn(self, flow: Flow) -> Self

Source

pub fn set_flow<F>(self, f: F) -> Self
where F: for<'a> Fn(&'a mut Agent, String) -> FlowFuture<'a> + Send + Sync + 'static,

Source

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

Add a local tool.

Source

pub fn add_mcp_server(self, server: McpServerType) -> Self

Add an MCP server endpoint.

Source

pub fn set_template(self, template: Template) -> Self

Set a template for the agent’s first prompt

Source

pub fn set_max_iterations(self, max_iterations: usize) -> Self

Set max_iterations. This controlls maximum amount of times the agent may perform a “conversation iteration”. Also serves as a breakpoint if the agent is stuck in a loop

Source

pub fn set_clear_history_on_invocation(self, clear: bool) -> Self

if set to true, will clear the conversation histroy on each invocation of the agent

Source

pub fn set_response_format_str(self, schema_json: &str) -> Self

Source

pub fn set_response_format_value(self, schema: Value) -> Self

Source

pub fn set_response_format_from<T: JsonSchema>(self) -> Self

Source

pub fn set_response_format_spec(self, schema: SchemaSpec) -> Self

Source

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

Source

pub fn set_schema_strict(self, strict: bool) -> Self

Source

pub async fn build_with_notification( self, ) -> Result<(Agent, Receiver<Notification>), AgentBuildError>

Build an Agent and return also the notification receiver.

Creates an internal mpsc channel of size 100.

Source

pub async fn build(self) -> Result<Agent, AgentBuildError>

Finalize all settings and produce an Agent, or an error if required fields missing or invalid.

Trait Implementations§

Source§

impl Debug for AgentBuilder

Source§

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

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

impl Default for AgentBuilder

Source§

fn default() -> AgentBuilder

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: 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, 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<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
Source§

impl<T> ErasedDestructor for T
where T: 'static,