copilot-sdk

框架

github/copilot-sdk

多平台 SDK,用于将 GitHub Copilot 智能体集成到应用中。

项目简介

GitHub Copilot SDK 提供经过生产验证的智能体运行时,可将 Copilot 的自主工作流嵌入到您的应用程序中。支持 Python、TypeScript、Go、.NET、Java 和 Rust,通过 JSON-RPC 管理 Copilot CLI 进程。需要 GitHub Copilot 订阅或 BYOK。

README 预览

# GitHub Copilot CLI SDKs\n\n\n\n[](https://www.npmjs.com/package/@github/copilot-sdk)\n[](https://pypi.org/project/github-copilot-sdk/)\n[](https://www.nuget.org/packages/GitHub.Copilot.SDK)\n[](https://pkg.go.dev/github.com/github/copilot-sdk/go)\n[](https://crates.io/crates/github-copilot-sdk)\n[](https://central.sonatype.com/artifact/com.github/copilot-sdk-java)\n\nAgents for every app.\n\nEmbed Copilot's agentic workflows in your application with the GitHub Copilot SDK for Python, TypeScript, Go, .NET, Java, and Rust.\n\nThe GitHub Copilot SDK exposes the same engine behind Copilot CLI: a production-tested agent runtime you can invoke programmatically. No need to build your own orchestration—you define agent behavior, Copilot handles planning, tool invocation, file edits, and more.\n\n## Available SDKs\n\n| SDK                      | Location                                                                | Cookbook                                                                                              | Installation                                                                                                                                                                                                                               |\n| ------------------------ | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| **Node.js / TypeScript** | [`nodejs/`](./nodejs/)                                                  | [Cookbook](https://github.com/github/awesome-copilot/blob/main/cookbook/copilot-sdk/nodejs/README.md) | `npm install @github/copilot-sdk`                                                

常见问题 (4)

故障排除
如何阻止 Copilot SDK 将 127.0.0.1 或 localhost 请求通过 HTTP 代理进行路由?

在 NO_PROXY 中设置环回地址,使本地 BYOK 端点绕过代理:

export NO_PROXY="127.0.0.1,::1,localhost"
export no_proxy="127.0.0.1,::1,localhost"

在 Windows(PowerShell)上:

$env:NO_PROXY="127.0.0.1,::1,localhost"
$env:no_proxy="127.0.0.1,::1,localhost"

设置变量后重启 VS Code。Agent Host PR 中已加入一项永久性修复:在注入 HTTP_PROXY/HTTPS_PROXY 时会自动将环回主机追加到 NO_PROXY;请更新到包含该更改的 VS Code/Copilot SDK 版本。

来源 Issue #2766
故障排除
为什么在 Copilot SDK Rust 会话中,当派生的子代理失败或进入空闲状态时,`send_and_wait` 会提前解析并返回错误的结果?

这是 github/copilot-sdk Rust v1.0.14(搭配 CLI 运行时 1.0.84-5)中的一个 bug。CLI 会在父会话流上带着子代理的 agent_id 重新发送子代理事件,但 rust/src/session.rs 中的 handle_notification 会让每一个 session.idle、session.error 和 assistant.message 都完成父级的 send_and_wait waiter,而不检查 agent_id。

修复方法是升级到包含 PR fix(rust): only root-agent events complete send_and_wait 的发布版本。作为临时本地补丁,可将 waiter 的完成和最后一条消息的更新限制为仅针对根代理事件:

// In the send_and_wait waiter arm of handle_notification
let is_root_event = notification
    .agent_id
    .as_ref()
    .is_none_or(|id| id == &root_agent_id);

if is_root_event {
    match notification.method.as_str() {
        "session.idle" | "session.error" => {
            // resolve the waiter
        }
        "assistant.message" => {
            // update the waiter's last message
        }
        _ => {}
    }
}

带有子级标记的事件仍应转发给 on_event;它们只能被 send_and_wait waiter 忽略。请通过一个回归测试进行验证:一个正在进行中的父级等待在收到带有子级 agent_id 的 session.error 后仍保持挂起状态,然后仅在收到根级 session.idle 后才完成解析。

来源 Issue #2750
故障排除
为什么在 Copilot SDK 的 Rust crate 中绑定 SessionFsProvider 时,Client::create_session 会发生挂起?

死锁的发生是因为 session.create 在会话事件循环启动之前就被发送了。在创建过程中,CLI 会发送入站的 sessionFs.stat/sessionFs.writeFile 请求,但此时还没有任何东西来分发它们,因此 RPC 会无限期地等待。这个问题已在 PR fix(rust): start the session event loop before the session.create RPC 中修复,修复方式是在调用 session.create 之前启动事件循环,与现有的 session.resume 行为保持一致。请升级到包含该修复的版本。在 rust/v1.0.14 上,解决方法是修补 rust/src/session.rs 中的 start_prepared_create,使 spawn_event_loop 在 call_with_inline_callback 之前运行。

来源 Issue #2749
故障排除
如果 Rust 路由器通过在会话注册被替换之前克隆的 sender 将请求入队,这算是一个 bug 吗?

无需代码修复。这不是一个可观测的 bug。router 任务是每个 per-session channel 的唯一生产者,且 unbounded 发送不会阻塞。因此,通过在并发重新注册之前克隆的 sender 进行发送,等同于在查找时刻(即替换发生之前)将该发送线性化。在 enqueue 期间持有 router 锁不会改变任何可达的结果。Session-ID 重用、unknown-session 丢弃以及 wire protocol 均保持不变。

来源 Issue #2791