Skip to main content

AgentBuilder

Struct AgentBuilder 

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

Builder for constructing an Agent with custom configuration.

Supports two modes:

  1. Standalone – the builder loads the model itself (simple, one agent):
let agent = AgentBuilder::new()
    .backend(Backend::Cpu)
    .model_path("model.gguf")
    .build()
    .expect("Failed to build agent");
  1. Shared engine – multiple agents share one model (no redundant loading):
let engine = Arc::new(InferenceEngine::load(InferenceConfig {
    backend: Backend::Vulkan,
    model_path: "model.gguf".into(),
    n_gpu_layers: 99,
    ..Default::default()
}).unwrap());

let agent_a = AgentBuilder::new()
    .engine(engine.clone())
    .system_prompt("You are agent A.")
    .build().unwrap();

let agent_b = AgentBuilder::new()
    .engine(engine.clone())
    .system_prompt("You are agent B.")
    .build().unwrap();

Implementations§

Source§

impl AgentBuilder

Source

pub fn new() -> Self

Source

pub fn engine(self, engine: Arc<InferenceEngine>) -> Self

Use a shared InferenceEngine instead of loading a new model.

When set, backend(), model_path(), n_gpu_layers(), dll_*(), cache_dir(), and app_name() are ignored — the engine already has those configured.

Source

pub fn backend(self, backend: Backend) -> Self

Set the compute backend (CPU, CUDA, Vulkan, etc.)

Source

pub fn model_path(self, path: &str) -> Self

Path to the GGUF model file.

Source

pub fn n_gpu_layers(self, n: i32) -> Self

Number of layers to offload to GPU (-1 = all, 0 = none).

Source

pub fn app_name(self, name: &str) -> Self

Application name (used for cache directory).

Source

pub fn cache_dir(self, dir: PathBuf) -> Self

Directory for caching downloaded DLLs.

Source

pub fn explicit_dll_path(self, path: PathBuf) -> Self

Explicit path to the llama.cpp DLL (bypasses download).

Source

pub fn dll_version(self, version: &str) -> Self

DLL version tag to download.

Source

pub fn chat_template(self, template: &str) -> Self

Set a custom chat template (Jinja).

Source

pub fn system_prompt(self, prompt: &str) -> Self

System prompt that instructs the model on its role and tool usage.

Source

pub fn n_ctx(self, n: u32) -> Self

Context window size in tokens.

Source

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

Maximum agent loop iterations (0 = unlimited).

Source

pub fn max_tokens_per_completion(self, n: usize) -> Self

Maximum tokens per model completion.

Source

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

Sampling temperature.

Source

pub fn top_k(self, k: i32) -> Self

Top-K sampling parameter.

Source

pub fn min_p(self, p: f32) -> Self

Min-P sampling parameter.

Source

pub fn repeat_penalty(self, p: f32) -> Self

Repetition penalty.

Source

pub fn stop_sequence(self, stop: &str) -> Self

Add a stop sequence.

Source

pub fn auto_approve(self) -> Self

Auto-approve all tool calls (YOLO mode — dangerous!).

Source

pub fn permission_callback( self, cb: impl Fn(&PermissionRequest) -> PermissionDecision + Send + Sync + 'static, ) -> Self

Set a permission callback for interactive approval.

Source

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

Add a custom tool.

Source

pub fn skip_builtin_tools(self) -> Self

Skip registering built-in tools (bash, read, write, edit, glob).

Source

pub fn no_skills(self) -> Self

Disable skill discovery entirely.

Source

pub fn skills_path(self, path: PathBuf) -> Self

Add an extra directory to search for skills.

Source

pub fn activate_skill(self, name: &str) -> Self

Explicitly activate a skill by name.

Source

pub fn no_agents_md(self) -> Self

Disable AGENTS.md discovery entirely.

Source

pub fn scheduler(self, scheduler: Arc<InferenceScheduler>) -> Self

Set an inference scheduler to limit concurrent inferences.

Use InferenceScheduler::new(1) to serialize all inference (one agent at a time), or a higher value for controlled parallelism. Without a scheduler, agents run truly parallel (safe, but GPU-heavy).

Source

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

Build the agent.

If a shared engine was provided via .engine(), it is reused. Otherwise, a new engine is created from the standalone fields.

Trait Implementations§

Source§

impl Default for AgentBuilder

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.