Build agentic applications with GitHub Copilot SDK. Use when embedding AI agents in apps, creating custom tools, implementing streaming responses, managing sessions, or integrating with MCP servers. Triggers on Copilot SDK, GitHub SDK, agentic app, embed Copilot, programmable agent.
Embed Copilot's agentic workflows in any application using Python, TypeScript, Go, or .NET.
The 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.
Verify CLI: copilot --version
npm install @github/copilot-sdk
pip install github-copilot-sdk
go get github.com/github/copilot-sdk/go
dotnet add package GitHub.Copilot.SDK
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient();
await client.start();
const session = await client.createSession({
model: "gpt-5"
});
const response = await session.sendAndWait({
prompt: "What is 2+2?"
});
console.log(response);
await client.stop();
import asyncio
from copilot import CopilotClient
async def main():
client = CopilotClient()
await client.start()
session = await client.create_session({"model": "gpt-5"})
done = asyncio.Event()
def on_event(event):
if event.type.value == "assistant.message":
print(event.data.content)
elif event.type.value == "session.idle":
done.set()
session.on(on_event)
await session.send({"prompt": "What is 2+2?"})
await done.wait()
await session.destroy()
await client.stop()
asyncio.run(main())
package main
import (
"fmt"
"log"
copilot "github.com/github/copilot-sdk/go"
)
func main() {
client := copilot.NewClient(&copilot.ClientOptions{LogLevel: "error"})
if err := client.Start(); err != nil {
log.Fatal(err)
}
defer client.Stop()
session, _ := client.CreateSession(&copilot.SessionConfig{Model: "gpt-5"})
defer session.Destroy()
done := make(chan bool)
session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message" && event.Data.Content != nil {
fmt.Println(*event.Data.Content)
}
if event.Type == "session.idle" {
close(done)
}
})
session.Send(copilot.MessageOptions{Prompt: "What is 2+2?"})
<-done
}
await using var client = new CopilotClient();
await client.StartAsync();
await using var session = await client.CreateSessionAsync(new SessionConfig { Model = "gpt-5" });
var done = new TaskCompletionSource();
session.On(evt => {
if (evt is AssistantMessageEvent msg) Console.WriteLine(msg.Data.Content);
else if (evt is SessionIdleEvent) done.SetResult();
});
await session.SendAsync(new MessageOptions { Prompt = "What is 2+2?" });
await done.Task;
| Option | Description | Default |
|--------|-------------|---------|
| cliPath | Path to Copilot CLI executable | System PATH |
| cliUrl | Connect to existing server (e.g., "localhost:8080") | None |
| port | Server communication port | Random |
| useStdio | Use stdio transport instead of TCP | true |
| logLevel | Logging verbosity | "info" |
| autoStart | Launch server automatically | true |
| autoRestart | Restart on crashes | true |
| cwd | Working directory for CLI process | Inherited |
const client = new CopilotClient({
cliPath: "/custom/path/to/copilot",
port: 8080,
logLevel: "debug",
autoStart: true
});
| Option | Description |
|--------|-------------|
| model | LLM to use ("gpt-5", "claude-sonnet-4.5", etc.) |
| sessionId | Custom session identifier |
| tools | Custom tool definitions |
| systemMessage | Override default system prompt |
| streaming | Enable incremental response chunks |
| availableTools | Whitelist of permitted tools |
| excludedTools | Blacklist of disabled tools |
Enable real-time output by setting streaming: true:
const session = await client.createSession({
model: "gpt-5",
streaming: true
});
session.on("assistant.message_delta", (event) => {
process.stdout.write(event.data.deltaContent);
});
session.on("session.idle", () => {
console.log("\nDone!");
});
await session.send({ prompt: "Explain quantum computing" });
session = await client.create_session({
"model": "gpt-5",
"streaming": True
})
def on_event(event):
if event.type.value == "assistant.message_delta":
print(event.data.delta_content, end="", flush=True)
elif event.type.value == "session.idle":
print("\nDone!")
session.on(on_event)
await session.send({"prompt": "Explain quantum computing"})
| Event | Description |
|-------|-------------|
| user.message | User input added |
| assistant.message | Complete model response |
| assistant.message_delta | Streaming response chunk |
| assistant.reasoning | Model reasoning (model-dependent) |
| assistant.reasoning_delta | Streaming reasoning chunk |
| tool.execution_start | Tool invocation started |
| tool.execution_complete | Tool execution finished |
| session.idle | No active processing |
| session.error | Error occurred |
Define tools that Copilot can invoke during reasoning:
import { defineTool } from "@github/copilot-sdk";
import { z } from "zod";
const weatherTool = defineTool({
name: "get_weather",
description: "Get current weather for a city",
parameters: z.object({
city: z.string().describe("City name"),
units: z.enum(["celsius", "fahrenheit"]).default("celsius")
}),
handler: async ({ city, units }) => {
const weather = await fetchWeather(city);
return { temperature: weather.temp, conditions: weather.conditions };
}
});
const session = await client.createSession({
model: "gpt-5",
tools: [weatherTool]
});
from pydantic import BaseModel, Field
from copilot import CopilotClient, define_tool
class WeatherParams(BaseModel):
city: str = Field(description="City name")
units: str = Field(default="celsius", description="Temperature units")
@define_tool(description="Get current weather for a city")
async def get_weather(params: WeatherParams) -> dict:
weather = await fetch_weather(params.city)
return {"temperature": weather.temp, "conditions": weather.conditions}
session = await client.create_session({
"model": "gpt-5",
"tools": [get_weather]
})
type WeatherParams struct {
City string `json:"city" jsonschema:"City name"`
Units string `json:"units" jsonschema:"Temperature units"`
}
weatherTool := copilot.DefineTool("get_weather",
"Get current weather for a city",
func(params WeatherParams, inv copilot.ToolInvocation) (any, error) {
weather, err := fetchWeather(params.City)
if err != nil {
return nil, err
}
return map[string]any{
"temperature": weather.Temp,
"conditions": weather.Conditions,
}, nil
})
session, _ := client.CreateSession(&copilot.SessionConfig{
Model: "gpt-5",
Tools: []copilot.Tool{weatherTool},
})
using Microsoft.Extensions.AI;
using System.ComponentModel;
var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-5",
Tools = [
AIFunctionFactory.Create(
async ([Description("City name")] string city) => {
var weather = await FetchWeatherAsync(city);
return new { weather.Temp, weather.Conditions };
},
"get_weather",
"Get current weather for a city"),
]
});
Save and resume conversations across restarts:
const session = await client.createSession({
sessionId: "user-123-conversation",
model: "gpt-5"
});
const session = await client.resumeSession("user-123-conversation");
// Conversation context is restored
await session.send({ prompt: "What did we discuss earlier?" });
const sessions = await client.listSessions();
await client.deleteSession("old-session-id");
try {
await client.start();
const session = await client.createSession({ model: "gpt-5" });
const response = await session.sendAndWait(
{ prompt: "Hello!" },
30000 // timeout in ms
);
} catch (error) {
if (error.code === "ENOENT") {
console.error("Copilot CLI not installed");
} else if (error.code === "ECONNREFUSED") {
console.error("Cannot connect to Copilot server");
} else {
console.error("Error:", error.message);
}
} finally {
await client.stop();
}
process.on("SIGINT", async () => {
console.log("Shutting down...");
await client.stop();
process.exit(0);
});
Your Application
|
SDK Client
| JSON-RPC
Copilot CLI (server mode)
|
GitHub (models, auth)
The SDK manages the CLI process lifecycle automatically. All communication happens via JSON-RPC over stdio or TCP.
The SDK supports using your own API keys:
const session = await client.createSession({
model: "gpt-5",
provider: {
apiKey: process.env.OPENAI_API_KEY,
endpoint: "https://api.openai.com/v1"
}
});
Query available models at runtime:
const models = await client.listModels();
// Returns: ModelInfo[] with { id, name, capabilities, policy, billing }
// Extract model IDs: models.map(m => m.id)
try-finally or defer to ensure client.stop() is calledsendAndWait with timeout for long operationsconst session = await client.createSession({ model: "gpt-5" });
await session.sendAndWait({ prompt: "My name is Alice" });
await session.sendAndWait({ prompt: "What's my name?" });
// Response: "Your name is Alice"
await session.send({
prompt: "Analyze this file",
attachments: [{
type: "file",
path: "./data.csv",
displayName: "Sales Data"
}]
});
const timeoutId = setTimeout(() => {
session.abort();
}, 60000);
session.on("session.idle", () => {
clearTimeout(timeoutId);
});
This SDK is in Technical Preview and may have breaking changes. Not recommended for production use yet.
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer