模型现在已经足够强大,能够独立工作数小时甚至数天。你不必时刻监视它们的每一个操作,但仍需能够随时随地进行检查。智能体不能仅存在于单一应用程序内部。即使你关闭窗口或切换设备,工作也应继续进行。
在 GitHub Copilot 中,你可以在一个地方启动智能体会话,并在另一个地方继续该会话。这种会话连续性由 Agent Host Protocol(AHP)提供支持,这是一个开放标准,最初在 VS Code 中构建,并已在 GitHub 范围内得到采用。以下是其工作原理、我们在构建过程中学到的经验,以及如何利用它将你的智能体集成到你自己的应用和工作流中。
为何每个客户端一种集成的方式不再奏效
GitHub Copilot 最初是作为 VS Code 中的扩展开发的,该扩展捆绑了自己的运行环境(harness)。这让你能够在 VS Code 中访问你的智能体,但也将它们的生命周期与编辑器绑定在一起。扩展程序依附于单个 VS Code 窗口。关闭该窗口,智能体就会消失。更新 VS Code,随着应用程序重启,所有智能体都会停止。连接到远程机器时,你会获得一个全新的扩展主机实例,且其提交版本被锁定在你当前的 VS Code 工作台版本上。
与此同时,Copilot 应用正在开发中,与现有的 GitHub iOS 和 Android 移动应用并行推进。每个产品都在进行各自独特的云基智能体集成,以实现会话连续性这一目标。
这些集成中的每一个都为单一产品解决了问题,但开发人员仍然希望能够将他们的智能体引入自己的工作流——无论是编辑器、终端、手机还是他们自己构建的工具——而如果每个客户端都需要其独有的定制集成,他们就做不到这一点。这就是为什么开发人员需要一个协议:一个在 VS Code 各个版本、GitHub Copilot 应用、移动应用以及任何可能托管智能体的其他客户端之间独立版本化的标准语言。共享协议意味着每个客户端都能看到相同的智能体、历史记录和状态,而无需定制集成,你也不会被绑定到某个应用程序对智能体会话的理解上。
为每个客户端上的智能体设计协议
该协议需要允许多个客户端无缝地与同一组智能体交互。例如,从手机在云端启动会话,然后在笔记本电脑上继续该会话。它应能容忍网络中断、重新连接以及并发客户端变更。此外,它需要具备足够的功能丰富度,让你能够从每个客户端进行实际工作。
同时,该协议需要避免干涉智能体的行为。与产生语言服务器协议(Language Server Protocol)和调试适配器协议(Debug Adapter Protocol)的领域不同,智能体领域正在快速演变。因此,AHP 避免编码智能体的工作方式,而是专注于你希望如何与它们交互。
此外,该协议还需要足够简单,以便在你的客户端或服务器上自行实现。虽然完整的功能集必然广泛,但核心协议需要保持精简。
这些需求的结果是 Agent Host Protocol(AHP)。它以 URI 标识的“通道”为核心,通道是该协议中最粗粒度的功能单元。每个服务器必须实现根通道、会话通道和聊天通道,但也可以实现更多提供终端支持、MCP 附加功能或 OTel 报告等功能的通道。
在每个通道中,都存在一个基于 reducer 的状态对象,它驱动着客户端的大部分逻辑。服务器是状态的仲裁者,每个客户端发送一系列操作,这些操作要么改变状态,要么触发副作用,例如发送聊天消息。这带来了一些非常好的特性:在网络条件较差时,重连和回放变得轻而易举——客户端会发送所有排队中的操作,展示正确的“加载中”状态,并等待服务器协调并确认这些操作后再予以确认。客户端和服务器的调试都非常直观。此外,基于 reducer 的状态也与 React 等流行的 UI 框架配合良好。
交付五个客户端和两个主机
在 VS Code 中采用 Agent Host Protocol(代理主机协议)需要在底层构建一个新的测试框架和代理技术栈。曾经提供 VS Code 所有 AI 和代理功能的 Copilot Chat 扩展已经开发了三年多,代码量超过 40 万行 TypeScript(不含测试)。但是,作为一个 VS Code 扩展,它的结构围绕 VS Code 窗口的生命周期展开,并且完全依赖于 VS Code 扩展 API。无论是这个生命周期还是这些 API,在独立的代理主机进程中都无法使用。
随着我们在 2026 年初开始构建 Agent Host Protocol,Copilot SDK 也在同步开发中,因此利用它作为新代理技术栈的基础是顺理成章的。这是一个巨大的转变。构建一个仅能打招呼并能编辑文件的测试框架实现很容易——在最初的几周里,我们甚至使用代理主机来开发代理主机本身——但构建一个涵盖开发者对 Copilot Chat 习以为常的长尾功能集合的实现则是另一回事。
GitHub 拥有 Copilot 云代理已有几年历史,允许开发者从任何设备在云端运行任务。而在 VS Code 悄悄开发 Agent Host Protocol 的同时,GitHub 正寻求扩展这一能力,以便通过 Copilot 应用或在云沙箱中协调在你自己设备上运行的会话。这正是 AHP(Agent Host Protocol)旨在解决的 N:M 问题,因此采用相同的技术完全合乎逻辑。
从一开始,GitHub Agent Host 的需求就与 VS Code 的实现有所不同。VS Code 在本地运行主机,并可以通过 SSH、容器、WSL 或 Dev Tunnels 将其主机部署到其他计算资源上,它实际上也是作为 VS Code Server 捆绑包的一部分包含在内的。而 GitHub Agent Host 需要在云端运行,并适应更广泛的基础设施、环境和安全限制。
这些不同的需求正是它们被写成不同语言的独立实现的原因:VS Code 的实现在 TypeScript 中,而 GitHub 的实现在 Rust 中。目前,拥有两个代理主机是对协议本身的一次很好的压力测试。当两个完全不同的团队和一组代理独立实现同一协议时,它的表现如何?
事实证明效果相当不错。与 MCP 类似,Agent Host Protocol 通过自定义方法和对象上的 _meta 数据提供了逃生舱口,消费者可以利用这些机制进行带外信令。在各自投入数月埋头开发后,我们迈向统一过程中的第一个任务是清点每个实现对协议的扩展方式。其中许多扩展合理地保持为 GitHub 特有,例如 GitHub Agent Host 使用元数据链接到项目看板。在其他情况下,差异则表明协议存在缺口;例如,早期版本无法准确表示没有 PTY(伪终端)支持的 shell 类型工具输出。还有一些则是错误的假设,比如 VS Code 的客户端假设从代理主机接收到的会话 URI 具有特定的结构。只有单一实现的协议并非真正的可移植;随着我们让客户端和服务器学会相互通信,AHP 在实践中变得可移植,而不仅仅停留在理论上。
今天,Agent Host 协议在 VS Code 和 GitHub 的所有平台上提供了同样的连续性。在 GitHub Copilot 应用中本地运行、在云端沙箱中运行以及在 VS Code 中运行的 Agent 会话都共享相同的底层协议。要了解其具体用法,请阅读关于如何通过全新的连接式 Copilot 云体验随时随地工作的介绍。
使用 Agent Host 协议
AHP 旨在让客户端和服务器端易于使用。Agent Host Protocol 库已提供 Rust、TypeScript、Kotlin、Swift、.NET 和 Go 版本,开发者只需少量提示即可构建客户端和服务器。我的桌面上放着一个宏键盘,它能实时反映我的 Agent 的状态,而其他人则基于该协议构建了从智能手表应用到看板式任务管理工具等各种应用。无论你希望为自己的 Agent 开发配套应用、将 Agent 会话集成到团队工具中,还是希望在编辑器或 Agent 中支持 AHP,该协议都开放供你构建使用。
你可以在 Copilot 应用中连接到你自己实现的 Agent 主机(启用“Experimental > Direct Connections”,然后前往“Environments > Add Agent Host Protocol Host”),也可以在 VS Code 中通过“Agents”窗口中的“Add Remote Agent Host”进行连接。你可以在终端中运行 code agent host 来启动 VS Code Agent 主机的独立版本,或者运行 code agent endpoints 查看编辑器中该主机的端点,示例代码可帮助你和你的 Agent 快速上手。
Agent Host 协议是一项开放标准,欢迎在 GitHub 上提出问题和建议。
祝编码愉快!
作者
首席软件工程师
首席软件工程师
Models are now good enough to work for hours or even days on their own. You don’t have to watch over every thing they do, but you still need to be able to check in, no matter where you are. An agent can’t live only inside one application. The work should continue even If you close a window or switch devices.
In GitHub Copilot you can start an agent session in one place and pick it up in another. This session continuity runs on the Agent Host Protocol (AHP), an open standard built first in VS Code and adopted across GitHub. Here’s how it works, what we learned building it, and how you can use it to bring your agents into your own apps and workflows.
Why one integration per client stopped working
GitHub Copilot was first built in VS Code as an extension that bundled its own harness. This gave you access to your agents in VS Code, but it tied their lifetime to the editor. Extensions are attached to a single VS Code window. Close that window, and the agent is gone. Update VS Code, and every agent stops as the application restarts. Connect to a remote machine, and you get an entirely new extension host commit-locked against the version of the VS Code workbench you have.
At the same time, the Copilot app was being developed, alongside the existing GitHub mobile apps for iOS and Android. Each product was doing its own distinct integration with cloud-based agents to work towards delivering session continuity.
Each of these integrations solved the problem for one product, but developers also still want to be able to pull their agents into their own workflows–whether that’s an editor, a terminal, a phone, or a tool they built themselves–and they can’t do that if every client needs its own one-off integration. That’s why developers needed a protocol: a standard, independently versioned language across versions of VS Code, the GitHub Copilot app, mobile apps, and any other client that might host an agent. A shared protocol means every client sees the same agents, history, and state without bespoke integrations, and you aren’t tied to one app’s idea of what an agent session is.
Designing a protocol for agents on every client
The protocol needed to allow multiple clients to interact with the same set of agents seamlessly. Start a session in the cloud from your phone, for example, then continue it from your laptop. It should tolerate network interruptions, reconnections, and concurrent client mutations. And it needed to be full-featured enough for you to do real work from each of your clients.
At the same time, the protocol needed to stay out of agent behavior . Unlike the domains that produced the Language Server Protocol and Debug Adapter Protocol , the world of agents is evolving quickly. That’s why AHP avoids encoding how agents work, and instead focuses on how you want to interact with them.
You also need the protocol to be simple enough to implement on your own client or server. While the full feature set would necessarily be extensive, the core protocol needed to be minimal.
The result of these requirements is the Agent Host Protocol (AHP). It is oriented around URI-identified “channels”, which are the coarsest unit of functionality in the protocol. Every server must implement the root, session, and chat channels, but can also implement more channels that provide terminal support, MCP additions, or OTel reporting, for example.
Within each channel is a reducer-based state object, which drives most of the logic for clients. The server is the arbiter of the state, and each client sends a sequence of actions that either mutate the state or trigger side effects, like sending a chat message. This provides a few very nice properties. Reconnection and replay in poor network conditions are easy: a client sends all queued actions, presents the right ‘loading’ state, and waits for the server to reconcile and acknowledge the actions before confirming them. Clients and servers are straightforward to debug. And reducer-based state also plays nicely with popular UI frameworks like React.
Shipping five clients and two hosts
Adopting the Agent Host Protocol in VS Code required building a new harness and agentic stack underneath it. The Copilot Chat extension, which used to provide all of VS Code’s AI and agentic capabilities, had been growing for over three years, reaching over 400,000 lines of TypeScript, not counting tests. But, as a VS Code extension, it was structured around the lifecycle of a VS Code window and depended entirely on the VS Code extension API. Neither that lifetime nor those APIs would be available in a standalone agent host process.
As we started building the Agent Host Protocol in early 2026, the Copilot SDK was also being developed, and it made sense to leverage it as the foundation for the new agentic stack. This was a big transition. It’s easy to build a harness implementation that says hello and can edit files—we were using the agent host to develop the agent host after the first couple weeks—but it’s another thing to build one that covers the long tail of features developers had come to expect from Copilot Chat.
GitHub has had Copilot cloud agents for a couple of years, allowing developers to run tasks in the cloud from any device. While VS Code was quietly developing the Agent Host Protocol, GitHub was looking to expand that capability to coordinate sessions running on your own devices via the Copilot app, or in cloud sandboxes. This was exactly the N:M problem that AHP was built to solve, so adopting the same technology made perfect sense.
From the outset, the GitHub Agent Host had different requirements than VS Code’s implementation. VS Code runs the host locally and can drop its host on other compute over SSH, containers, WSL, or Dev Tunnels, and it is actually included as part of the VS Code Server bundle. The GitHub Agent Host needed to run in the cloud and across a much wider variety of infrastructure, environments, and security constraints.
Those differing requirements are why they’re separate implementations written in different languages: VS Code’s in TypeScript and GitHub’s in Rust. For now, having two agent hosts has been a good acid-test for the protocol itself. How well does it work when two entirely different teams and sets of agents implement the same protocol independently?
Pretty well, it turns out. Like MCP, the Agent Host Protocol provides escape hatches via custom methods and _meta data on objects that consumers can use for out-of-band signaling. After several months heads-down on our respective implementations, our first task as we worked toward unification was inventorying the ways each implementation had extended the protocol. Many of these extensions reasonably stay GitHub-specific, such as the GitHub Agent Host using metadata to link to project boards. In other cases, variance was a sign of a gap in the protocol; early versions, for example, could not accurately represent shell-type tool output that wasn’t backed by a PTY. And some were bad assumptions, like VS Code’s client assuming a particular structure for the session URIs it received from the agent host. A protocol with only one implementation isn’t truly portable; as we taught our clients and servers to talk to each other, AHP became portable in practice, not just in theory.
Today, the Agent Host Protocol provides that same continuity across all VS Code and GitHub surfaces. Agent sessions running locally in the GitHub Copilot app, in cloud sandboxes, and in VS Code all share the same underlying protocol. To see how it’s used, read about how you can work from anywhere with the new connected Copilot cloud experience .
Using the Agent Host Protocol
AHP was designed to be easy to use in clients and servers. Agent Host Protocol libraries are available in Rust, TypeScript, Kotlin, Swift, .NET, and Go, and agents are able to build clients and servers with little prompting. I have a macropad sitting on my desk that reflects my agent’s state in real time, and others have built everything from smart watch apps to Kanban-style task management tools against the protocol. Whether you want a companion app for your own agents, a way to bring agent sessions into your team’s tools, or AHP support in your own editor or agent, the protocol is open for you to build on.
You can connect to an agent host you implement in the Copilot app (enable Experimental > Direct Connections , then go to Environments > Add Agent Host Protocol Host ) and in VS Code (via Add Remote Agent Host in the Agents window). You can spawn a standalone version of VS Code’s agent host by running code agent host in your terminal, or see the endpoints for the one in your editor by running code agent endpoints , and samples can help you and your agent get started.
The Agent Host Protocol is an open standard, and questions and suggestions are welcome on GitHub .
Happy coding!
Written by
Principal Software Engineer
Principal Software Engineer
| 刊期 | 得分 | 排名 | 结果 |
|---|---|---|---|
| 2026-11-30 | 7.4 | 28 | 未入选 |
| 2026-11-29 | 7.4 | 35 | 未入选 |
| 2026-11-28 | 7.4 | 48 | 未入选 |
| 2026-11-27 | 7.4 | 52 | 未入选 |
| 2026-11-26 | 7.4 | 58 | 未入选 |
| 2026-11-18 | 9.77 | 25 | 入选 |