Expand description
§agent-framework-github-copilot
A GitHub Copilot chat client for
agent-framework-rs.
GitHub Copilot’s chat endpoint is OpenAI Chat-Completions-compatible
(POST {base_url}/chat/completions, default base URL
https://api.githubcopilot.com), so request/response conversion is reused
from [agent_framework_openai::convert] rather than duplicated — the same
streaming approach used by agent-framework-ollama and
agent-framework-foundry-local (see convert for the small,
Copilot-specific streaming-delta parser that is implemented locally).
Unlike those two clients, Copilot’s endpoint is not directly reachable
with a plain API key: callers supply a long-lived GitHub OAuth token or
personal access token (the github_token), and before every request this
client transparently exchanges it for a short-lived Copilot API bearer
token via GET https://api.github.com/copilot_internal/v2/token
(Authorization: token <github_token>). The exchanged token is cached in
the client and only re-fetched once it is missing or within about 60
seconds of its expires_at. Every /chat/completions request also
carries two headers the Copilot API requires beyond the OpenAI-compatible
shape: Editor-Version and Copilot-Integration-Id; requests missing
them are rejected by the real service.
use agent_framework_github_copilot::GitHubCopilotChatClient;
use agent_framework_core::prelude::*;
let client = GitHubCopilotChatClient::new("gho_examplegithubtoken", "gpt-4o");
let agent = Agent::builder(client)
.instructions("You are concise.")
.build();
let reply = agent.run_once("Say hi").await?;
println!("{}", reply.text());Pointing at a non-default (e.g. enterprise or proxied) endpoint:
use agent_framework_github_copilot::GitHubCopilotChatClient;
let client = GitHubCopilotChatClient::new("gho_examplegithubtoken", "gpt-4o")
.with_base_url("https://copilot-proxy.example.internal");Modules§
- convert
- Conversion between framework types and GitHub Copilot’s OpenAI-compatible
/chat/completionswire format.
Structs§
- GitHub
Copilot Chat Client - A GitHub Copilot chat client (
POST {base_url}/chat/completions).