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
impl AgentBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty builder; Agent::builder is the usual entry point.
Sourcepub fn model(self, config: Config, model: impl Into<String>) -> Self
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.
Sourcepub fn client(self, client: Client, model: impl Into<String>) -> Self
pub fn client(self, client: Client, model: impl Into<String>) -> Self
Sets the model by an already-built client plus model id.
Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Sets the system prompt.
Sourcepub fn tool<H: ToolHandler + 'static>(self, handler: H) -> Self
pub fn tool<H: ToolHandler + 'static>(self, handler: H) -> Self
Adds a typed tool handler. Duplicate names are reported at
build time.
Sourcepub fn tool_dyn(self, tool: Box<dyn DynTool>) -> Self
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.
Sourcepub fn pricing(self, pricing: Pricing) -> Self
pub fn pricing(self, pricing: Pricing) -> Self
Sets the pricing table cost budgets are computed against.
Sourcepub fn max_response_tokens(self, max_tokens: u32) -> Self
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).
Sourcepub fn record_prompts(self, record_prompts: bool) -> Self
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.
Sourcepub fn labels(self, labels: BTreeMap<String, String>) -> Self
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.
Sourcepub fn name(self, name: impl Into<String>) -> Self
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.
Sourcepub fn build(self) -> Result<Agent, AgentBuildError>
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.