Skip to main content

Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }

Implementations§

Source§

impl Agent

Source

pub fn builder() -> AgentBuilder

Source

pub fn history(&self) -> &[ConversationMessage]

Source

pub fn channel_handles(&self) -> &AgentChannelHandles

Late-bound channel-map handles for the five channel-driven tools. Populated by from_config_with_session_cwd; empty when an Agent is constructed via the builder directly. Callers (e.g. the ACP server) use channel_handles().register_channel(...) to wire a back-channel into all five tool maps in one shot.

Source

pub fn populate_channels( &self, channel_map: &HashMap<String, Arc<dyn Channel>>, ) -> Vec<String>

Populate late-bound channel-map handles with configured channels.

Seeds ask_user, reaction, poll, escalate, and channel_send handles from the provided map. Called by CLI and orchestrator paths after agent construction but before the agent loop starts.

Returns the list of registered channel names for logging.

Source

pub fn clear_history(&mut self)

Source

pub fn set_memory_session_id(&mut self, session_id: Option<String>)

Source

pub fn seed_history(&mut self, messages: &[ChatMessage])

Hydrate the agent with prior chat messages (e.g. from a session backend).

Ensures a system prompt is prepended if history is empty, then appends all non-system messages from the seed. System messages in the seed are skipped to avoid duplicating the system prompt.

Source

pub fn seed_conversation_history(&mut self, messages: Vec<ConversationMessage>)

Hydrate the agent with a full ConversationMessage history (e.g. restored from an ACP session store). Preserves all variants including AssistantToolCalls and ToolResults — use this for ACP restore; use seed_history for flat channel session hydration.

Source

pub async fn from_config( config: &Config, agent_alias: &str, ) -> Result<Agent, Error>

Source

pub async fn from_config_with_session_cwd( config: &Config, agent_alias: &str, session_cwd: Option<&Path>, ) -> Result<Agent, Error>

Build an Agent with an optional per-session working directory override.

session_cwd, when supplied, becomes SecurityPolicy::workspace_dir for this agent — i.e. the boundary used by file_read/write/edit and the cwd used by the shell tool. Memory storage, identity files, scheduled task DBs, and other on-disk state continue to live under config.data_dir.

This is what ACP sessions use to pin tool path resolution to the IDE-provided cwd without relocating the agent’s data directory.

Source

pub async fn from_config_with_session_cwd_and_mcp( config: &Config, agent_alias: &str, session_cwd: Option<&Path>, initialize_mcp: bool, ) -> Result<Agent, Error>

Build an Agent while optionally skipping eager MCP initialization.

ACP clients expect session/new to return promptly. User-configured MCP servers are external processes/services and can block startup while they time out, so ACP uses this with initialize_mcp = false.

Source

pub async fn from_config_with_session_cwd_and_mcp_backchannel( config: &Config, agent_alias: &str, session_cwd: Option<&Path>, initialize_mcp: bool, canvas_store: Option<CanvasStore>, ) -> Result<Agent, Error>

Build an Agent for direct ACP/WS sessions that have a client approval back-channel. This keeps shell approval on the runtime-controlled path.

canvas_store should be the shared tools::CanvasStore from the gateway / daemon supervisor so that canvas frames pushed by this agent reach the /ws/canvas/:id WebSocket subscribers. Pass None only in standalone contexts (e.g. zeroclaw acp) where no gateway is running.

Source

pub async fn turn(&mut self, user_message: &str) -> Result<String, Error>

Source

pub async fn turn_streamed( &mut self, user_message: &str, event_tx: Sender<TurnEvent>, cancel_token: Option<CancellationToken>, ) -> Result<(String, Vec<ConversationMessage>), Error>

Execute a single agent turn while streaming intermediate events.

Behaves identically to turn but forwards TurnEvents through the provided channel so callers (e.g. the WebSocket gateway) can relay incremental updates to clients.

The returned tuple contains the final assistant response string and all new ConversationMessages added during this turn (captured before any trim_history call so callers can persist them correctly even when the history is already at its configured limit).

Source

pub async fn turn_streamed_with_steering_state( &mut self, user_message: &str, event_tx: Sender<TurnEvent>, cancel_token: Option<CancellationToken>, steering_rx: Option<&mut Receiver<String>>, ) -> Result<StreamedTurnSuccess, StreamedTurnError>

Source

pub async fn run_single(&mut self, message: &str) -> Result<String, Error>

Source

pub async fn run_interactive(&mut self) -> Result<(), Error>

Auto Trait Implementations§

§

impl Freeze for Agent

§

impl !RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

§

impl !UnwindSafe 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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> 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more