Skip to main content

AgentBuilder

Struct AgentBuilder 

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

Builds an Agent; start from Agent::builder.

Implementations§

Source§

impl AgentBuilder

Source

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

Source

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.

Source

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

The system prompt; agent86’s own identity ([crate::prompt::BASE_IDENTITY]) when not set.

Source

pub fn builtins(self, builtins: Builtins) -> Self

Which of agent86’s tools to offer (Builtins::None when not set).

Source

pub fn tool(self, tool: impl Tool + 'static) -> Self

Offer tool too. A name already taken fails AgentBuilder::build.

Source

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.

Source

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.

Source

pub fn max_steps(self, steps: u32) -> Self

Model calls one turn may make before it stops (40 by default).

Source

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.

Source

pub fn max_wall_clock_s(self, seconds: u64) -> Self

Seconds one turn may run; 0 for no limit (900 by default).

Source

pub fn tool_timeout(self, timeout: Duration) -> Self

Seconds a command or fetch may run (60 by default).

Source

pub fn context_window(self, tokens: u64) -> Self

The tokens of context the model holds, which history is fitted to.

Source

pub fn max_output_tokens(self, tokens: u32) -> Self

The most tokens one model call may write (8192 by default).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn subagents(self, subagents: SubAgents) -> Self

Let the model delegate to sub-agents (see SubAgents).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

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<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> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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