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
impl Agent
pub fn new() -> Self
pub fn set_model(&mut self, model: impl Into<String>)
pub fn set_system_prompt(&mut self, prompt: impl Into<String>)
pub fn set_tools(&mut self, tools: ToolRegistry)
pub fn set_policy(&mut self, policy: Policy)
pub fn set_scope(&mut self, scope: Scope)
pub fn set_hooks(&mut self, hooks: HookRegistry)
pub fn set_approver(&mut self, approver: Arc<dyn Approver>)
pub fn set_provider(&mut self, provider: Arc<dyn Provider>)
pub fn set_workspace_root(&mut self, path: impl Into<PathBuf>)
pub fn cancel(&self)
pub fn cancellation_handle(&self) -> CancellationHandle
Sourcepub fn load_project_context(&mut self)
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.
pub fn set_sandbox(&mut self, sb: Arc<SandboxManager>)
pub fn set_os_sandbox(&mut self, os: Arc<OsSandboxRunner>)
Sourcepub fn enable_os_sandbox(&mut self) -> Result<(), SandboxError>
pub fn enable_os_sandbox(&mut self) -> Result<(), SandboxError>
Enable OS sandbox for bash using auto-detected seatbelt/bwrap backend.
pub fn subscribe(&mut self, callback: impl Fn(&Event) + Send + Sync + 'static)
pub fn clear_messages(&self)
pub fn message_count(&self) -> usize
Sourcepub async fn prompt(&mut self, text: &str) -> Result<(), AgentError>
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.
pub fn compact(&self, reason: &str)
Trait Implementations§
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> 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
Mutably borrows from an owned value. Read more
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>
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 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>
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