pub struct AcpAgent { /* private fields */ }Expand description
A component representing an external ACP agent running in a separate process.
AcpAgent implements the agent_client_protocol::ConnectTo trait for spawning and communicating with
external agents or proxies via stdio. It handles process spawning, stream setup, and
byte stream serialization automatically. This is the primary way to connect to agents
that run as separate executables.
This is a wrapper around agent_client_protocol::schema::McpServer that provides convenient parsing
from command-line strings or JSON configurations.
§Use Cases
- External agents: Connect to agents written in any language (Python, Node.js, Rust, etc.)
- Proxy chains: Spawn intermediate proxies that transform or intercept messages
- Conductor components: Use with
agent_client_protocol_conductor::Conductorto build proxy chains - Subprocess isolation: Run potentially untrusted code in a separate process
§Examples
Parse from a command string:
let agent = AcpAgent::from_str("python my_agent.py --verbose").unwrap();Parse from JSON:
let agent = AcpAgent::from_str(r#"{"type": "stdio", "name": "my-agent", "command": "python", "args": ["my_agent.py"], "env": []}"#).unwrap();Use as a component to connect to an external agent:
use agent_client_protocol::{Client, Builder};
use agent_client_protocol_tokio::AcpAgent;
use std::str::FromStr;
let agent = AcpAgent::from_str("python my_agent.py")?;
// The agent process will be spawned automatically when connected
Client.builder()
.connect_to(agent)
.await?
.connect_with(|cx| async move {
// Use the connection to communicate with the agent process
Ok(())
})
.await?;Implementations§
Source§impl AcpAgent
impl AcpAgent
Sourcepub fn new(server: McpServer) -> Self
pub fn new(server: McpServer) -> Self
Create a new AcpAgent from an agent_client_protocol::schema::McpServer configuration.
Sourcepub fn zed_claude_code() -> Self
pub fn zed_claude_code() -> Self
Create an ACP agent for Zed Industries’ Claude Code tool.
Just runs npx -y @zed-industries/claude-code-acp@latest.
Sourcepub fn zed_codex() -> Self
pub fn zed_codex() -> Self
Create an ACP agent for Zed Industries’ Codex tool.
Just runs npx -y @zed-industries/codex-acp@latest.
Sourcepub fn google_gemini() -> Self
pub fn google_gemini() -> Self
Create an ACP agent for Google’s Gemini CLI.
Just runs npx -y -- @google/gemini-cli@latest --experimental-acp.
Sourcepub fn server(&self) -> &McpServer
pub fn server(&self) -> &McpServer
Get the underlying agent_client_protocol::schema::McpServer configuration.
Sourcepub fn into_server(self) -> McpServer
pub fn into_server(self) -> McpServer
Convert into the underlying agent_client_protocol::schema::McpServer configuration.
Sourcepub fn with_debug<F>(self, callback: F) -> Self
pub fn with_debug<F>(self, callback: F) -> Self
Add a debug callback that will be invoked for each line sent/received.
The callback receives the line content and the direction (stdin/stdout/stderr). This is useful for logging, debugging, or monitoring agent communication.
§Example
let agent = AcpAgent::from_str("python my_agent.py")
.unwrap()
.with_debug(|line, direction| {
eprintln!("{:?}: {}", direction, line);
});Sourcepub fn spawn_process(
&self,
) -> Result<(ChildStdin, ChildStdout, ChildStderr, Child), Error>
pub fn spawn_process( &self, ) -> Result<(ChildStdin, ChildStdout, ChildStderr, Child), Error>
Spawn the process and get stdio streams. Used internally by the Component trait implementation.
Source§impl AcpAgent
impl AcpAgent
Sourcepub fn from_args<I, T>(args: I) -> Result<Self, Error>where
I: IntoIterator<Item = T>,
T: ToString,
pub fn from_args<I, T>(args: I) -> Result<Self, Error>where
I: IntoIterator<Item = T>,
T: ToString,
Create an AcpAgent from an iterator of command-line arguments.
Leading arguments of the form NAME=value are parsed as environment variables.
The first non-env argument is the command, and the rest are arguments.
§Example
let agent = AcpAgent::from_args([
"RUST_LOG=debug",
"cargo",
"run",
"-p",
"my-crate",
]).unwrap();