pub struct Agent { /* private fields */ }Implementations§
Source§impl Agent
impl Agent
pub fn builder() -> AgentBuilder
pub fn history(&self) -> &[ConversationMessage]
Sourcepub fn channel_handles(&self) -> &AgentChannelHandles
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.
Sourcepub fn populate_channels(
&self,
channel_map: &HashMap<String, Arc<dyn Channel>>,
) -> Vec<String>
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.
pub fn clear_history(&mut self)
pub fn set_memory_session_id(&mut self, session_id: Option<String>)
Sourcepub fn seed_history(&mut self, messages: &[ChatMessage])
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.
Sourcepub fn seed_conversation_history(&mut self, messages: Vec<ConversationMessage>)
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.
pub async fn from_config( config: &Config, agent_alias: &str, ) -> Result<Agent, Error>
Sourcepub async fn from_config_with_session_cwd(
config: &Config,
agent_alias: &str,
session_cwd: Option<&Path>,
) -> Result<Agent, Error>
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.
Sourcepub async fn from_config_with_session_cwd_and_mcp(
config: &Config,
agent_alias: &str,
session_cwd: Option<&Path>,
initialize_mcp: bool,
) -> Result<Agent, Error>
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.
Sourcepub 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>
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.
pub async fn turn(&mut self, user_message: &str) -> Result<String, Error>
Sourcepub async fn turn_streamed(
&mut self,
user_message: &str,
event_tx: Sender<TurnEvent>,
cancel_token: Option<CancellationToken>,
) -> Result<(String, Vec<ConversationMessage>), Error>
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).
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>
pub async fn run_single(&mut self, message: &str) -> Result<String, Error>
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> 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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