Skip to main content

Agent

Struct Agent 

Source
pub struct Agent {
    pub config: AgentConfig,
    pub status: AgentStatus,
    pub session_id: Option<String>,
    pub client: Option<Arc<JsonRpcClient>>,
    pub auto_approve: Arc<AtomicBool>,
    /* private fields */
}
Expand description

Manages the lifecycle of an ACP agent subprocess.

Fields§

§config: AgentConfig

The agent’s configuration (from TOML discovery).

§status: AgentStatus

Current connection status.

§session_id: Option<String>

The active session id, if connected.

§client: Option<Arc<JsonRpcClient>>

JSON-RPC client for communication with the agent.

§auto_approve: Arc<AtomicBool>

Whether to automatically approve permission requests (shared with message handler).

Implementations§

Source§

impl Agent

Source

pub fn new( config: AgentConfig, ui_tx: UnboundedSender<AgentMessage>, safe_paths: SafePaths, mcp_server_bin: PathBuf, ) -> Self

Create a new agent manager in the AgentStatus::Disconnected state.

§Arguments
  • config - The agent configuration from TOML discovery.
  • ui_tx - Channel to send messages to the UI layer.
  • safe_paths - Directories considered safe for agent writes.
  • mcp_server_bin - Path to the par-term binary for MCP server.
Source

pub async fn connect( &mut self, cwd: &str, capabilities: ClientCapabilities, extra_roots: &[String], ) -> Result<(), Box<dyn Error + Send + Sync>>

Spawn the agent subprocess, perform the ACP handshake, and establish a session.

On success the agent transitions to AgentStatus::Connected and a background task is spawned to route incoming messages to the UI channel.

Source

pub async fn disconnect(&mut self)

Disconnect from the agent, killing the subprocess and clearing state.

Source

pub async fn send_prompt( &self, content: Vec<ContentBlock>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Send a prompt to the agent’s active session.

Source

pub async fn set_mode( &self, mode_id: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Set the agent’s session interaction mode.

Valid modes: "default", "acceptEdits", "bypassPermissions", "dontAsk", "plan".

Source

pub async fn cancel(&self) -> Result<(), Box<dyn Error + Send + Sync>>

Cancel the current prompt execution.

Source

pub async fn respond_permission( &self, request_id: u64, option_id: &str, cancelled: bool, ) -> Result<(), Box<dyn Error + Send + Sync>>

Respond to a permission request from the agent.

Trait Implementations§

Source§

impl Drop for Agent

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.

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