Rust SDK for interacting with the GitHub Copilot CLI agent runtime (JSON-RPC over stdio or TCP).
This is a Rust port of the upstream SDKs and is currently in technical preview.
- Rust 1.85+ (Edition 2024)
- GitHub Copilot CLI installed and authenticated
copilotavailable inPATH, or setCOPILOT_CLI_PATHto the CLI executable/script
Once published, add:
[dependencies]
copilot-sdk = "0.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }For development from this repository:
[dependencies]
copilot-sdk = { path = "." }use copilot_sdk::{Client, SessionConfig};
#[tokio::main]
async fn main() -> copilot_sdk::Result<()> {
let client = Client::builder().build()?;
client.start().await?;
let session = client.create_session(SessionConfig::default()).await?;
let response = session.send_and_wait("Hello!").await?;
println!("{}", response);
client.stop().await?;
Ok(())
}Automatic context window management that compacts conversation history when approaching token limits:
let config = SessionConfig {
infinite_sessions: Some(InfiniteSessionConfig::enabled()),
..Default::default()
};Register tools that the assistant can invoke:
session.register_tool_with_handler(
Tool::builder("get_weather", "Get current weather")
.string_param("city", "City name", true)
.build(),
|invocation| async move {
let city: String = invocation.arg("city")?;
Ok(ToolResult::text(format!("Weather in {}: Sunny, 72°F", city)))
},
).await;let status = client.get_status().await?; // CLI version info
let auth = client.get_auth_status().await?; // Authentication state
let models = client.list_models().await?; // Available modelsUse your own API keys with compatible providers:
let config = SessionConfig {
provider: Some(ProviderConfig {
base_url: Some("https://api.openai.com/v1".into()),
api_key: Some("sk-...".into()),
..Default::default()
}),
..Default::default()
};cargo run --example basic_chat
cargo run --example tool_usage
cargo run --example streamingEnable pre-commit hooks to catch formatting/linting issues before push:
git config core.hooksPath .githookscargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo testE2E tests (real Copilot CLI):
cargo test --features e2e -- --test-threads=1Snapshot conformance tests (optional, against upstream YAML snapshots):
cargo test --features snapshots --test snapshot_conformanceSet COPILOT_SDK_RUST_SNAPSHOT_DIR or UPSTREAM_SNAPSHOTS to point at copilot-sdk/test/snapshots if it cannot be auto-detected.
- Supports stdio (spawned CLI) and TCP (spawned or external server).
MIT License - see LICENSE.
- Upstream SDKs: https://github.com/github/copilot-sdk