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
impl AgentBuilder
Sourcepub fn import_client_config(self, conf: ClientConfig) -> Self
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.
Sourcepub fn import_prompt_config(self, conf: PromptConfig) -> Self
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.
Sourcepub fn import_model_config(self, conf: ModelConfig) -> Self
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.
Sourcepub fn set_provider(self, provider: Provider) -> Self
pub fn set_provider(self, provider: Provider) -> Self
Select the LLM provider implementation.
Sourcepub fn set_base_url<T>(self, base_url: T) -> Self
pub fn set_base_url<T>(self, base_url: T) -> Self
Override the base URL for the provider client.
Sourcepub fn set_api_key<T>(self, api_key: T) -> Self
pub fn set_api_key<T>(self, api_key: T) -> Self
Set the API key used by the provider client.
Sourcepub fn set_organization<T>(self, organization: T) -> Self
pub fn set_organization<T>(self, organization: T) -> Self
Set the organization or tenant identifier for requests.
Sourcepub fn set_extra_headers(self, extra_headers: HashMap<String, String>) -> Self
pub fn set_extra_headers(self, extra_headers: HashMap<String, String>) -> Self
Provide additional HTTP headers to include on each request.
Sourcepub fn set_stream(self, set: bool) -> Self
pub fn set_stream(self, set: bool) -> Self
Set the streaming value for Ollam Will enable Token Notifications
Sourcepub fn set_temperature(self, v: f32) -> Self
pub fn set_temperature(self, v: f32) -> Self
Set the sampling temperature.
Sourcepub fn set_presence_penalty(self, v: f32) -> Self
pub fn set_presence_penalty(self, v: f32) -> Self
Set presence penalty.
Sourcepub fn set_frequency_penalty(self, v: f32) -> Self
pub fn set_frequency_penalty(self, v: f32) -> Self
Set frequency penalty.
Sourcepub fn set_num_ctx(self, v: u32) -> Self
pub fn set_num_ctx(self, v: u32) -> Self
Set maximum context length (in tokens/chunks).
Sourcepub fn set_repeat_last_n(self, v: i32) -> Self
pub fn set_repeat_last_n(self, v: i32) -> Self
Repeat penalty for the last N tokens.
Sourcepub fn set_keep_alive(self, v: String) -> Self
pub fn set_keep_alive(self, v: String) -> Self
Set keep alive of the model
Sourcepub fn set_repeat_penalty(self, v: f32) -> Self
pub fn set_repeat_penalty(self, v: f32) -> Self
Set penalty for repeated tokens.
Sourcepub fn set_num_predict(self, v: i32) -> Self
pub fn set_num_predict(self, v: i32) -> Self
Number of tokens to predict.
Sourcepub fn set_system_prompt<T: Into<String>>(self, prompt: T) -> Self
pub fn set_system_prompt<T: Into<String>>(self, prompt: T) -> Self
System prompt that initializes conversation history.
Sourcepub fn set_stop_prompt<T: Into<String>>(self, stop_prompt: T) -> Self
pub fn set_stop_prompt<T: Into<String>>(self, stop_prompt: T) -> Self
Optional prompt to insert on each tool‐call branch.
Sourcepub fn set_stopword<T: Into<String>>(self, stopword: T) -> Self
pub fn set_stopword<T: Into<String>>(self, stopword: T) -> Self
Optional stopword to detect end of generation.
Sourcepub fn strip_thinking(self, strip: bool) -> Self
pub fn strip_thinking(self, strip: bool) -> Self
Whether to strip <think>
blocks from model output.
pub fn set_flow_fn(self, flow: Flow) -> Self
pub fn set_flow<F>(self, f: F) -> Self
Sourcepub fn add_mcp_server(self, server: McpServerType) -> Self
pub fn add_mcp_server(self, server: McpServerType) -> Self
Add an MCP server endpoint.
Sourcepub fn set_template(self, template: Template) -> Self
pub fn set_template(self, template: Template) -> Self
Set a template for the agent’s first prompt
Sourcepub fn set_max_iterations(self, max_iterations: usize) -> Self
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
Sourcepub fn set_clear_history_on_invocation(self, clear: bool) -> Self
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
pub fn set_response_format_str(self, schema_json: &str) -> Self
pub fn set_response_format_value(self, schema: Value) -> Self
pub fn set_response_format_from<T: JsonSchema>(self) -> Self
pub fn set_response_format_spec(self, schema: SchemaSpec) -> Self
pub fn set_schema_name(self, name: impl Into<String>) -> Self
pub fn set_schema_strict(self, strict: bool) -> Self
Sourcepub async fn build_with_notification(
self,
) -> Result<(Agent, Receiver<Notification>), AgentBuildError>
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.