pub struct AgentBuilder { /* private fields */ }Expand description
Builder for constructing an Agent with custom configuration.
Supports two modes:
- 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");- 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
impl AgentBuilder
pub fn new() -> Self
Sourcepub fn engine(self, engine: Arc<InferenceEngine>) -> Self
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.
Sourcepub fn backend(self, backend: Backend) -> Self
pub fn backend(self, backend: Backend) -> Self
Set the compute backend (CPU, CUDA, Vulkan, etc.)
Sourcepub fn model_path(self, path: &str) -> Self
pub fn model_path(self, path: &str) -> Self
Path to the GGUF model file.
Sourcepub fn n_gpu_layers(self, n: i32) -> Self
pub fn n_gpu_layers(self, n: i32) -> Self
Number of layers to offload to GPU (-1 = all, 0 = none).
Sourcepub fn explicit_dll_path(self, path: PathBuf) -> Self
pub fn explicit_dll_path(self, path: PathBuf) -> Self
Explicit path to the llama.cpp DLL (bypasses download).
Sourcepub fn dll_version(self, version: &str) -> Self
pub fn dll_version(self, version: &str) -> Self
DLL version tag to download.
Sourcepub fn chat_template(self, template: &str) -> Self
pub fn chat_template(self, template: &str) -> Self
Set a custom chat template (Jinja).
Sourcepub fn system_prompt(self, prompt: &str) -> Self
pub fn system_prompt(self, prompt: &str) -> Self
System prompt that instructs the model on its role and tool usage.
Sourcepub fn max_iterations(self, n: usize) -> Self
pub fn max_iterations(self, n: usize) -> Self
Maximum agent loop iterations (0 = unlimited).
Sourcepub fn max_tokens_per_completion(self, n: usize) -> Self
pub fn max_tokens_per_completion(self, n: usize) -> Self
Maximum tokens per model completion.
Sourcepub fn temperature(self, temp: f32) -> Self
pub fn temperature(self, temp: f32) -> Self
Sampling temperature.
Sourcepub fn repeat_penalty(self, p: f32) -> Self
pub fn repeat_penalty(self, p: f32) -> Self
Repetition penalty.
Sourcepub fn stop_sequence(self, stop: &str) -> Self
pub fn stop_sequence(self, stop: &str) -> Self
Add a stop sequence.
Sourcepub fn auto_approve(self) -> Self
pub fn auto_approve(self) -> Self
Auto-approve all tool calls (YOLO mode — dangerous!).
Sourcepub fn permission_callback(
self,
cb: impl Fn(&PermissionRequest) -> PermissionDecision + Send + Sync + 'static,
) -> Self
pub fn permission_callback( self, cb: impl Fn(&PermissionRequest) -> PermissionDecision + Send + Sync + 'static, ) -> Self
Set a permission callback for interactive approval.
Sourcepub fn skip_builtin_tools(self) -> Self
pub fn skip_builtin_tools(self) -> Self
Skip registering built-in tools (bash, read, write, edit, glob).
Sourcepub fn skills_path(self, path: PathBuf) -> Self
pub fn skills_path(self, path: PathBuf) -> Self
Add an extra directory to search for skills.
Sourcepub fn activate_skill(self, name: &str) -> Self
pub fn activate_skill(self, name: &str) -> Self
Explicitly activate a skill by name.
Sourcepub fn no_agents_md(self) -> Self
pub fn no_agents_md(self) -> Self
Disable AGENTS.md discovery entirely.
Sourcepub fn scheduler(self, scheduler: Arc<InferenceScheduler>) -> Self
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).
Sourcepub fn build(self) -> Result<Agent, AgentError>
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.