Skip to main content

Agent

Struct Agent 

Source
pub struct Agent<O: Serialize + Send + Sync + 'static = ()> { /* private fields */ }
Expand description

Builder for configuring and constructing a runnable agent.

Type parameter O is the optional structured output type (use () for unstructured text).

Implementations§

Source§

impl<O: Serialize + Send + Sync + 'static> Agent<O>

Source

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

Create a new agent builder.

Source

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

Set a human-readable description.

Source

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

Set the primary model name.

Source

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

Set a fallback model used when the primary is rate-limited or unavailable.

Source

pub const fn effort(self, effort: EffortLevel) -> Self

Set the reasoning effort level.

Source

pub const fn thinking(self, thinking: ThinkingConfig) -> Self

Configure extended thinking / chain-of-thought.

Source

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

Add a tool available to the agent.

Source

pub fn allowed_tools( self, tools: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Restrict the agent to only these tool names (allowlist).

Source

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

Exclude specific tools by name (denylist within allowlist).

Source

pub fn plugin(self, plugin: impl Plugin + 'static) -> Self

Add a plugin.

Source

pub fn middleware(self, mw: impl Middleware + 'static) -> Self

Add a middleware component.

Source

pub fn hooks(self, hooks: HookRegistry) -> Self

Configure hooks.

Source

pub const fn output_mode(self, mode: OutputMode) -> Self

Set the structured output mode.

Source

pub fn output_schema(self, schema: Value) -> Self

Provide a JSON Schema for structured output validation.

Source

pub const fn tool_output_format(self, format: OutputFormat) -> Self

Set the default serialization format for tool and VFS output.

Controls how structured data is rendered before being passed back to the LLM as tool results. Defaults to OutputFormat::Json. Individual tools can override this per-call.

Source

pub const fn get_tool_output_format(&self) -> OutputFormat

Returns the configured tool output format.

Source

pub const fn max_turns(self, turns: u32) -> Self

Set the maximum number of agent turns per run.

Source

pub const fn max_budget(self, budget_usd: f64) -> Self

Set the maximum cumulative cost budget (USD).

Source

pub fn system_prompt(self, config: SystemPromptConfig) -> Self

Configure the system prompt.

Source

pub const fn permission_mode(self, mode: PermissionMode) -> Self

Set the permission mode.

Source

pub fn permission_rule(self, rule: PermissionRule) -> Self

Add a permission rule.

Source

pub fn sandbox(self, config: SandboxConfig) -> Self

Configure the sandbox.

Source

pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self

Set an environment variable available to the agent.

Source

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

Set the working directory for the agent.

Source

pub const fn debug(self) -> Self

Enable debug mode (verbose logging).

Source

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

Write debug output to a file.

Source

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

Register an MCP server by name.

Source

pub fn before_agent<F>(self, f: F) -> Self
where F: Fn(&RunContext) -> BoxFuture<'static, Result<(), AgentError>> + Send + Sync + 'static,

Register a before-agent callback.

Source

pub fn after_agent<F>(self, f: F) -> Self
where F: Fn(&RunContext, &Result<(), AgentError>) -> BoxFuture<'static, ()> + Send + Sync + 'static,

Register an after-agent callback.

Source

pub fn on_model_error<F>(self, f: F) -> Self
where F: Fn(&RunContext, &AgentError) -> BoxFuture<'static, ModelErrorAction> + Send + Sync + 'static,

Register a model error callback.

Source

pub fn agent_name(&self) -> &str

Agent name.

Source

pub fn agent_description(&self) -> &str

Agent description.

Source

pub fn model_name(&self) -> &str

Primary model identifier.

Source

pub fn fallback_model_name(&self) -> Option<&str>

Fallback model identifier, if configured.

Source

pub const fn max_turn_count(&self) -> Option<u32>

Maximum turns, if set.

Source

pub const fn budget_limit(&self) -> Option<f64>

Maximum budget (USD), if set.

Source

pub const fn is_debug(&self) -> bool

Whether debug mode is enabled.

Trait Implementations§

Source§

impl<O: Serialize + Send + Sync + 'static> Debug for Agent<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<O: Default + Serialize + Send + Sync + 'static> Default for Agent<O>

Source§

fn default() -> Agent<O>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<O> Freeze for Agent<O>

§

impl<O = ()> !RefUnwindSafe for Agent<O>

§

impl<O> Send for Agent<O>

§

impl<O> Sync for Agent<O>

§

impl<O> Unpin for Agent<O>
where O: Unpin,

§

impl<O> UnsafeUnpin for Agent<O>

§

impl<O = ()> !UnwindSafe for Agent<O>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> 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> 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