Skip to main content

Agent

Struct Agent 

Source
pub struct Agent {
Show 14 fields pub model: String, pub system_prompt: Option<String>, pub tools: Arc<ToolRegistry>, pub policy: Policy, pub scope: Scope, pub hooks: Option<HookRegistry>, pub approver: Option<Arc<dyn Approver>>, pub provider: Option<Arc<dyn Provider>>, pub max_tool_iterations: usize, pub auto_compact_after: usize, pub workspace_root: PathBuf, pub sandbox: Option<Arc<SandboxManager>>, pub os_sandbox: Option<Arc<OsSandboxRunner>>, pub messages: RwLock<Vec<Message>>, /* private fields */
}
Expand description

The agent — owns the loop, tools, provider, policy, scope, hooks, cache.

Fields§

§model: String§system_prompt: Option<String>§tools: Arc<ToolRegistry>§policy: Policy§scope: Scope§hooks: Option<HookRegistry>§approver: Option<Arc<dyn Approver>>§provider: Option<Arc<dyn Provider>>§max_tool_iterations: usize§auto_compact_after: usize§workspace_root: PathBuf§sandbox: Option<Arc<SandboxManager>>§os_sandbox: Option<Arc<OsSandboxRunner>>§messages: RwLock<Vec<Message>>

Implementations§

Source§

impl Agent

Source

pub fn new() -> Self

Source

pub fn set_model(&mut self, model: impl Into<String>)

Source

pub fn set_system_prompt(&mut self, prompt: impl Into<String>)

Source

pub fn set_tools(&mut self, tools: ToolRegistry)

Source

pub fn set_policy(&mut self, policy: Policy)

Source

pub fn set_scope(&mut self, scope: Scope)

Source

pub fn set_hooks(&mut self, hooks: HookRegistry)

Source

pub fn set_approver(&mut self, approver: Arc<dyn Approver>)

Source

pub fn set_provider(&mut self, provider: Arc<dyn Provider>)

Source

pub fn set_workspace_root(&mut self, path: impl Into<PathBuf>)

Source

pub fn cancel(&self)

Source

pub fn cancellation_handle(&self) -> CancellationHandle

Source

pub fn load_project_context(&mut self)

Load project instruction files (AGENTS.md / CLAUDE.md / .cursor/rules) from workspace_root and merge into the system prompt.

Source

pub fn set_sandbox(&mut self, sb: Arc<SandboxManager>)

Source

pub fn set_os_sandbox(&mut self, os: Arc<OsSandboxRunner>)

Source

pub fn enable_os_sandbox(&mut self) -> Result<(), SandboxError>

Enable OS sandbox for bash using auto-detected seatbelt/bwrap backend.

Source

pub fn subscribe(&mut self, callback: impl Fn(&Event) + Send + Sync + 'static)

Source

pub fn clear_messages(&self)

Source

pub fn message_count(&self) -> usize

Source

pub async fn prompt(&mut self, text: &str) -> Result<(), AgentError>

Run a prompt through the agent loop. Streams events to subscribers, executes tools, cycles turns.

Source

pub fn compact(&self, reason: &str)

Trait Implementations§

Source§

impl Default for Agent

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !Freeze for Agent

§

impl !RefUnwindSafe for Agent

§

impl !UnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

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