> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 构建自定义 ACP Agent

> 构建一个通过 Agent Client Protocol 在 Devin Desktop 中运行的自定义 Agent。

本页介绍构建可在 Devin Desktop 中运行的自定义 [ACP](/zh/desktop/acp) Agent 需要实现的内容。

如需查看完整的协议规范，请参见 [agentclientprotocol.com](https://agentclientprotocol.com/)。官方客户端库提供了 [Rust](https://agentclientprotocol.com/libraries/rust)、[TypeScript](https://agentclientprotocol.com/libraries/typescript)、[Python](https://agentclientprotocol.com/libraries/python)、[Kotlin](https://agentclientprotocol.com/libraries/kotlin) 和 [Java](https://agentclientprotocol.com/libraries/java) 版本。

<div id="basics">
  ## 基础
</div>

ACP Agent 会作为本地子进程运行，由 Devin Desktop 按需启动。所有通信都通过 stdio 上的 JSON-RPC 进行。

<div id="methods-you-must-implement">
  ### 你必须实现的方法
</div>

你的 Agent 至少需要处理 Devin Desktop 的以下方法：

* [`initialize`](https://agentclientprotocol.com/protocol/initialization) — 协商协议版本，声明 Agent 的能力，并返回 Agent 信息 (名称、版本) 。
* [`session/new`](https://agentclientprotocol.com/protocol/session-setup) — 为工作目录创建一个新会话，并返回会话 ID。Devin Desktop 会传入 `cwd` 以及所有已配置的 MCP 服务器。
* [`session/prompt`](https://agentclientprotocol.com/protocol/prompt-turn) — 接收用户消息，推进提示轮次，并在完成时返回 `stopReason`。
* [`session/cancel`](https://agentclientprotocol.com/protocol/prompt-turn) — 当用户取消时，中止该会话中所有正在进行的工作。

<div id="prompt-turn-lifecycle">
  ### 提示轮次生命周期
</div>

在 `session/prompt` 轮次期间，你的 Agent 会以 JSON-RPC 通知的形式，将更新流式发送回 Devin Desktop：

* 带有 `agent_message_chunk` 的 `session/update`，用于流式传输助手文本。
* 带有 `tool_call` 和 `tool_call_update` 的 `session/update`，用于在 Devin Desktop UI 中显示工具调用及其状态。
* `session/request_permission`，用于在运行敏感工具调用前征求用户许可。
* 如果你的 Agent 维护了[agent plan](https://agentclientprotocol.com/protocol/agent-plan)，则会发送带有 `plan` 的 `session/update`。

当你的 Agent 返回带有 `stopReason` (例如 `end_turn`、`cancelled`、`max_tokens`) 的 `session/prompt` 响应时，该轮次结束。

<div id="testing">
  ## 测试
</div>

要在 Devin Desktop 中测试你的 Agent：

1. 在你的[本地 registry 配置](/zh/desktop/acp#local-registry-config)中为你的 Agent 添加一个条目，将 `cmd` 指向本地 Agent 二进制文件 (或封装脚本) 的路径。
2. 修改你的 Agent，并按需重建。
3. 在 Command Palette 中运行 `Reload ACP Connections` 以加载最新版本——每次迭代之间都无需重启 Devin Desktop。

<div id="limitations">
  ## 局限性
</div>

Devin Desktop 目前尚未支持 ACP 规范的所有内容。在构建面向 Devin Desktop 的 Agent 时，以下是需要注意的主要差异：

* **不支持会话模式。** [会话模式](https://agentclientprotocol.com/protocol/session-modes) 不会在 Devin Desktop UI 中显示。如果你的 Agent 需要让用户在不同模式之间进行选择 (例如 plan / build / review) ，请改为将这些模式作为 [会话配置选项](https://agentclientprotocol.com/protocol/session-config-options) 提供，并使用 `"mode"` 类别。
* **不提供终端能力。** Devin Desktop 不会声明 [终端能力](https://agentclientprotocol.com/protocol/terminals)，因此 Agent 无法在 Devin Desktop UI 中创建终端。Agent 应在自己的子进程中运行命令，并通过 `tool_call` 更新流式传回输出。
