> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/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(
        # 您可以在此处自定义您的深度代理：设置自定义提示、
        # 添加您自己的工具、附加中间件或组合子代理。
        system_prompt="您是一个有用的编码助手",
        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 IDE](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/batrachian/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="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\deepagents\acp.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
