> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 代理客户端协议 (ACP)

> 通过代理客户端协议 (ACP) 暴露深度代理，以与代码编辑器和 IDE 集成。

[代理客户端协议 (ACP)](https://agentclientprotocol.com/get-started/introduction) 标准化了编码代理与代码编辑器或 IDE 之间的通信。
通过 ACP 协议，您可以将自定义的深度代理与任何兼容 ACP 的客户端一起使用，让您的代码编辑器能够提供项目上下文并接收丰富的更新。

<Note>
  ACP 专为代理-编辑器集成而设计。如果您希望您的代理调用由外部服务器托管的工具，请参阅[模型上下文协议 (MCP)](/oss/python/langchain/mcp/)。
</Note>

## 快速开始

安装 ACP 集成包：

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install deepagents-acp
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add deepagents-acp
  ```
</CodeGroup>

然后通过 ACP 暴露一个深度代理。

这将在 stdio 模式下启动一个 ACP 服务器（它从 stdin 读取请求并将响应写入 stdout）。在实践中，您通常将其作为由 ACP 客户端（例如您的编辑器）启动的命令来运行，然后通过 stdio 与服务器通信。

```python icon="server" theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import asyncio

from acp import run_agent
from deepagents import create_deep_agent
from langgraph.checkpoint.memory import MemorySaver

from deepagents_acp.server import AgentServerACP


async def main() -> None:
    agent = create_deep_agent(
        model="google_genai:gemini-3.1-pro-preview",
        # 您可以在此处自定义您的深度代理：设置自定义提示词、
        # 添加您自己的工具、附加中间件或组合子代理。
        system_prompt="You are a helpful coding assistant",
        checkpointer=MemorySaver(),
    )

    server = AgentServerACP(agent)
    await run_agent(server)


if __name__ == "__main__":
    asyncio.run(main())
```

<Card title="示例编码代理" icon="brand-github" href="https://github.com/langchain-ai/deepagents/blob/main/libs/acp/examples/demo_agent.py">
  `deepagents-acp` 包包含一个带有文件系统和 shell 的示例编码代理，您可以直接运行。
</Card>

## 客户端

深度代理可以在任何可以运行 ACP 代理服务器的地方工作。一些知名的 ACP 客户端包括：

* [Zed](https://zed.dev/docs/ai/external-agents)
* [JetBrains IDEs](https://www.jetbrains.com/help/ai-assistant/acp.html)
* Visual Studio Code (通过 [vscode-acp](https://github.com/formulahendry/vscode-acp))
* Neovim (通过兼容 ACP 的插件)

### Zed

`deepagents` 仓库包含一个[示例 ACP 入口点](https://github.com/langchain-ai/deepagents/blob/main/libs/acp/run_demo_agent.sh)，您可以将其注册到 [Zed](https://zed.dev/docs/ai/external-agents)：

1. 克隆 `deepagents` 仓库并安装依赖项：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
git clone https://github.com/langchain-ai/deepagents.git
cd deepagents/libs/acp
uv sync --all-groups
chmod +x run_demo_agent.sh
```

2. 为示例代理配置凭据：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
cp .env.example .env
```

然后在 `.env` 中设置 `ANTHROPIC_API_KEY`。

3. 在 Zed 的 `settings.json` 中配置您的 ACP 代理服务器命令：

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  "agent_servers": {
    "DeepAgents": {
      "type": "custom",
      "command": "/your/absolute/path/to/deepagents/libs/acp/run_demo_agent.sh"
    }
  }
}
```

4. 打开 Zed 的代理面板并启动一个 DeepAgents 线程。

### Toad

如果您想将 ACP 代理服务器作为本地开发工具运行，可以使用 [Toad](https://github.com/batrachianai/toad) 来管理该进程。

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
uv tool install -U batrachian-toad

toad acp "python path/to/your_server.py" .
# 或
toad acp "uv run python path/to/your_server.py" .
```

<Info>
  有关协议细节和编辑器支持，请参阅上游 ACP 文档：

  * 简介：[https://agentclientprotocol.com/get-started/introduction](https://agentclientprotocol.com/get-started/introduction)
  * 客户端/编辑器：[https://agentclientprotocol.com/get-started/clients](https://agentclientprotocol.com/get-started/clients)
</Info>

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/deepagents/acp.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
