Skip to main content

AgentBuilder

Struct AgentBuilder 

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

Builds an Agent:

use salvor_llm::Config;
use salvor_runtime::{Agent, Budgets};

let agent = Agent::builder()
    .model(Config::from_env(), "claude-opus-4-8")
    .system_prompt("You are a research agent.")
    .budgets(Budgets {
        max_steps: Some(40),
        ..Budgets::default()
    })
    .build()?;

Implementations§

Source§

impl AgentBuilder

Source

pub fn new() -> Self

An empty builder; Agent::builder is the usual entry point.

Source

pub fn model(self, config: Config, model: impl Into<String>) -> Self

Sets the model by client configuration plus model id. The client is constructed at build time.

Source

pub fn client(self, client: Client, model: impl Into<String>) -> Self

Sets the model by an already-built client plus model id.

Source

pub fn system_prompt(self, prompt: impl Into<String>) -> Self

Sets the system prompt.

Source

pub fn tool<H: ToolHandler + 'static>(self, handler: H) -> Self

Adds a typed tool handler. Duplicate names are reported at build time.

Source

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

Adds an already type-erased tool. This is how MCP-backed tools (and any other runtime-defined DynTool) join the agent, on equal footing with native handlers.

Source

pub fn budgets(self, budgets: Budgets) -> Self

Sets the declared budgets.

Source

pub fn pricing(self, pricing: Pricing) -> Self

Sets the pricing table cost budgets are computed against.

Source

pub fn max_response_tokens(self, max_tokens: u32) -> Self

Sets the max_tokens cap sent with each model request (default DEFAULT_MAX_RESPONSE_TOKENS).

Source

pub fn record_prompts(self, record_prompts: bool) -> Self

Turns on recording of the full model request body for runs of this agent (default off). This is the resolved effective setting; the CLI and server compute it from the per-agent record_prompts config and the SALVOR_RECORD_PROMPTS default before calling this. It is PII-sensitive (the body may hold user data or secrets) and is deliberately kept out of the definition hash. See Agent::record_prompts.

Source

pub fn labels(self, labels: BTreeMap<String, String>) -> Self

Sets correlation tags to stamp on every fresh run of this agent (a build id, an environment name). Unset by default. Like record_prompts, this is operator/deployment metadata rather than part of what the agent runs, so it is excluded from Agent::def_hash (see that method’s docs). Sanity bounds on the labels themselves are not checked here; they are enforced where a run is actually created (see crate::validate_labels), so this setter is infallible.

Source

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

Sets a short human label for this agent (unset by default). Like record_prompts and labels, this is descriptive metadata rather than part of what the agent runs, so it is excluded from Agent::def_hash (see that method’s docs). Sanity bounds on the name itself are not checked here; a config-file caller enforces them where the config is parsed (see salvor_cli::agent_config::MAX_NAME_LEN), so this setter is infallible, mirroring labels.

Source

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

Builds the agent, computing its definition hash.

§Errors

AgentBuildError::MissingModel when neither model nor client was called; AgentBuildError::DuplicateTool when two tools share a name; AgentBuildError::CostBudgetWithoutPricing when max_cost_usd is declared with no Pricing; AgentBuildError::Client when the client cannot be constructed from the given configuration.

Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
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