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: AgentConfigThe agent’s configuration (from TOML discovery).
status: AgentStatusCurrent 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
impl Agent
Sourcepub fn new(
config: AgentConfig,
ui_tx: UnboundedSender<AgentMessage>,
safe_paths: SafePaths,
mcp_server_bin: PathBuf,
) -> Self
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.
Sourcepub async fn connect(
&mut self,
cwd: &str,
capabilities: ClientCapabilities,
extra_roots: &[String],
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub async fn disconnect(&mut self)
pub async fn disconnect(&mut self)
Disconnect from the agent, killing the subprocess and clearing state.
Sourcepub async fn send_prompt(
&self,
content: Vec<ContentBlock>,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn send_prompt( &self, content: Vec<ContentBlock>, ) -> Result<(), Box<dyn Error + Send + Sync>>
Send a prompt to the agent’s active session.
Sourcepub async fn set_mode(
&self,
mode_id: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
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".