pub struct AgentBuilder { /* private fields */ }Expand description
Builds an Agent; start from Agent::builder.
Implementations§
Source§impl AgentBuilder
impl AgentBuilder
Sourcepub fn provider(self, provider: Arc<dyn Provider>) -> Self
pub fn provider(self, provider: Arc<dyn Provider>) -> Self
The model. Build one with [crate::provider]’s adapters or implement
Provider yourself (only stream is required).
Sourcepub fn workspace(self, path: impl Into<PathBuf>) -> Self
pub fn workspace(self, path: impl Into<PathBuf>) -> Self
The directory the tools are jailed to. Required, so an embedded agent never silently works on the process’s current directory.
Sourcepub fn system_prompt(self, text: impl Into<String>) -> Self
pub fn system_prompt(self, text: impl Into<String>) -> Self
The system prompt; agent86’s own identity ([crate::prompt::BASE_IDENTITY])
when not set.
Sourcepub fn builtins(self, builtins: Builtins) -> Self
pub fn builtins(self, builtins: Builtins) -> Self
Which of agent86’s tools to offer (Builtins::None when not set).
Sourcepub fn tool(self, tool: impl Tool + 'static) -> Self
pub fn tool(self, tool: impl Tool + 'static) -> Self
Offer tool too. A name already taken fails AgentBuilder::build.
Sourcepub fn approval(self, mode: ApprovalMode) -> Self
pub fn approval(self, mode: ApprovalMode) -> Self
The approval mode for side-effecting calls: auto runs them, deny
refuses them, and ask (the default) asks the AgentBuilder::approver,
declining every one when there is none.
Sourcepub fn approver(
self,
approver: impl Fn(&str, &ApprovalPreview) -> bool + Send + Sync + 'static,
) -> Self
pub fn approver( self, approver: impl Fn(&str, &ApprovalPreview) -> bool + Send + Sync + 'static, ) -> Self
Who is asked in ask mode: given the tool’s name and what the call would do
(its arguments, and a diff for a file write), true lets it run. Called on
the turn’s thread, one question at a time.
Sourcepub fn max_steps(self, steps: u32) -> Self
pub fn max_steps(self, steps: u32) -> Self
Model calls one turn may make before it stops (40 by default).
Sourcepub fn max_cost_usd(self, usd: f64) -> Self
pub fn max_cost_usd(self, usd: f64) -> Self
The spend, in US dollars, at which a turn stops; 0 for no cap (5 by
default). Only priced models count toward it.
Sourcepub fn max_wall_clock_s(self, seconds: u64) -> Self
pub fn max_wall_clock_s(self, seconds: u64) -> Self
Seconds one turn may run; 0 for no limit (900 by default).
Sourcepub fn tool_timeout(self, timeout: Duration) -> Self
pub fn tool_timeout(self, timeout: Duration) -> Self
Seconds a command or fetch may run (60 by default).
Sourcepub fn context_window(self, tokens: u64) -> Self
pub fn context_window(self, tokens: u64) -> Self
The tokens of context the model holds, which history is fitted to.
Sourcepub fn max_output_tokens(self, tokens: u32) -> Self
pub fn max_output_tokens(self, tokens: u32) -> Self
The most tokens one model call may write (8192 by default).
Sourcepub fn guardrails(self, guardrails: GuardrailsConfig) -> Self
pub fn guardrails(self, guardrails: GuardrailsConfig) -> Self
Ingress, egress, and observation scanning (agent86’s defaults when not set:
warn, warn, on). Its approval is ignored; use AgentBuilder::approval.
Sourcepub fn trace_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn trace_dir(self, dir: impl Into<PathBuf>) -> Self
Write the flight recorder’s trace.jsonl in dir, redacted as the CLI’s
is. Off when not set.
Sourcepub fn mcp_server(self, name: impl Into<String>, server: McpServer) -> Self
pub fn mcp_server(self, name: impl Into<String>, server: McpServer) -> Self
Start the MCP server server with the agent and offer its tools, named
mcp__<name>__<tool> and asked about unless the server marks them
read-only. A server that fails to start fails AgentBuilder::build; the
servers stop when the agent is dropped.
Sourcepub fn memory(self, memory: Memory) -> Self
pub fn memory(self, memory: Memory) -> Self
Give the agent long-term memory: the session is saved after every step and
at the end of each turn, finished turns are recalled into similar later
ones, and the model gets remember and recall. One Memory can be
shared by several agents.
Sourcepub fn session(self, id: impl Into<String>) -> Self
pub fn session(self, id: impl Into<String>) -> Self
Continue the session id from AgentBuilder::memory (any session saved
there, by this API, agent86, or Python’s agent86).
Sourcepub fn skills_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn skills_dir(self, dir: impl Into<PathBuf>) -> Self
Offer the skills in dir, a directory of <name>/SKILL.md folders, in
agent86’s (and Claude Code’s) skill format. The model sees their names and
descriptions and loads one with use_skill, whose allowed-tools then
limit it; Turn::skill runs one directly. The folders join the jail for
reading, since skills bundle files. Called again, an earlier directory wins a
name both hold.
Sourcepub fn subagents(self, subagents: SubAgents) -> Self
pub fn subagents(self, subagents: SubAgents) -> Self
Let the model delegate to sub-agents (see SubAgents).
Sourcepub fn model(self, name: impl Into<String>, model: Model) -> Self
pub fn model(self, name: impl Into<String>, model: Model) -> Self
Name a model, for a specialist whose definition says model: <name> and for
AgentBuilder::triage. A specialist naming a model that is not here runs
on the turn’s model, with a notice.
Sourcepub fn triage(
self,
cheap: impl Into<String>,
frontier: impl Into<String>,
) -> Self
pub fn triage( self, cheap: impl Into<String>, frontier: impl Into<String>, ) -> Self
Route each turn by its task, as agent86’s [model] router = "triage" does:
a short, plain ask goes to the model named cheap, anything else to
frontier (both named with AgentBuilder::model); compaction summaries
use cheap. The AgentBuilder::provider is still required, and serves
nothing while routing is on.
Sourcepub fn otel(self, otel: Otel) -> Self
pub fn otel(self, otel: Otel) -> Self
Export OpenTelemetry spans: a turn span per turn, parent of a
model_call per model call and a tool_call per tool call, with the GenAI
attribute names agent86 uses. Exported on a worker thread, flushed at the end
of each turn and when the agent is dropped; a collector that cannot be
reached becomes a note (Agent::notes), never an error.
Sourcepub fn on_limit(
self,
decide: impl Fn(&LimitHit) -> Option<u32> + Send + Sync + 'static,
) -> Self
pub fn on_limit( self, decide: impl Fn(&LimitHit) -> Option<u32> + Send + Sync + 'static, ) -> Self
Asked when a turn reaches a limit (its step budget, a sub-agent’s, or the
output cap before any text): given what was reached and the values offered,
return the new limit to go on with, or None to stop there as without this
callback. A raise lasts for the agent’s life, or for one specialist’s run
when LimitHit::run_only says so. Called on the turn’s thread, one
question at a time with approvals.
Sourcepub fn on_secret_request(
self,
answer: impl Fn(&SecretRequest) -> Option<String> + Send + Sync + 'static,
) -> Self
pub fn on_secret_request( self, answer: impl Fn(&SecretRequest) -> Option<String> + Send + Sync + 'static, ) -> Self
Offer the model request_secret, and ask answer when it is called: given
the variable’s name and the model’s reason, return the value (held for the
agent’s life, at least 6 characters) or None to decline. Tools that run
commands get it as that environment variable, and every path back to the
model, the conversation, and the trace shows only ${secret:NAME}. Names
that would change how programs run (PATH, LD_PRELOAD, …) are refused
before answer is asked. Nothing is kept in a keyring.
Sourcepub fn ui(self, ui: Ui) -> Self
pub fn ui(self, ui: Ui) -> Self
Declare a renderer (ADR 0005): offer the model render_ui, through which
it draws interactive UI as A2UI 1.0 messages in the renderer’s catalogs.
Each validated message reaches Agent::run’s callback as
TurnEvent::Ui, for the program to draw with its own widgets (Google’s
React and Lit renderers take them as they are). The system prompt gains a
section with the catalogs’ instructions and components on every request;
sub-agents never draw.
Sourcepub fn secret(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn secret(self, name: impl Into<String>, value: impl Into<String>) -> Self
Hold a secret the program already has (an API token for a command the
agent will run), with the same rules as AgentBuilder::on_secret_request:
tools get it as the environment variable name, the model sees only
${secret:NAME}, and write_file and edit_file may put it in a file the
approver sees. name must be a valid variable name and the value at least 6
characters, or AgentBuilder::build fails.
Sourcepub fn build(self) -> Result<Agent, BuildError>
pub fn build(self) -> Result<Agent, BuildError>
Assemble the agent. Reads nothing but the workspace path, the memory database, skill and specialist directories when given, and starts the MCP servers given.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AgentBuilder
impl !UnwindSafe for AgentBuilder
impl Forget for AgentBuilder
impl Freeze for AgentBuilder
impl Move for AgentBuilder
impl Send for AgentBuilder
impl Sync for AgentBuilder
impl Unpin for AgentBuilder
impl UnsafeUnpin for AgentBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more