Comprehensive knowledge of GitHub Copilot SDK for embedding Copilot's agentic workflows in Python, TypeScript, Go, and .NET applications...
The GitHub Copilot SDK enables developers to embed Copilot's agentic workflows programmatically in their applications. It exposes the same engine behind Copilot CLI as a production-tested agent runtime you can invoke from code.
Use the Copilot SDK when:
Don't use when:
| SDK | Installation |
|---|---|
| Node.js/TypeScript | npm install @github/copilot-sdk |
| Python | pip install github-copilot-sdk |
| Go | go get github.com/github/copilot-sdk/go |
| .NET | dotnet add package GitHub.Copilot.SDK |
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient();
const session = await client.createSession({ model: "gpt-4.1" });
const response = await session.sendAndWait({ prompt: "What is 2 + 2?" });
console.log(response?.data.content);
await client.stop();
import asyncio
from copilot import CopilotClient
async def main():
client = CopilotClient()
await client.start()
session = await client.create_session({"model": "gpt-4.1"})
response = await session.send_and_wait({"prompt": "What is 2 + 2?"})
print(response.data.content)
await client.stop()
asyncio.run(main())
const session = await client.createSession({
model: "gpt-4.1",
streaming: true,
});
session.on((event) => {
if (event.type === "assistant.message_delta") {
process.stdout.write(event.data.deltaContent);
}
});
await session.sendAndWait({ prompt: "Tell me a joke" });
import { defineTool } from "@github/copilot-sdk";
const getWeather = defineTool("get_weather", {
description: "Get weather for a city",
parameters: {
type: "object",
properties: {
city: { type: "string", description: "City name" },
},
required: ["city"],
},
handler: async ({ city }) => ({
city,
temperature: `${Math.floor(Math.random() * 30) + 50}°F`,
condition: "sunny",
}),
});
const session = await client.createSession({
model: "gpt-4.1",
tools: [getWeather],
});
Your Application → SDK Client → JSON-RPC → Copilot CLI (server mode)
The SDK manages the CLI process lifecycle automatically or connects to an external CLI server.
const session = await client.createSession({
model: "gpt-4.1", // Model to use
streaming: true, // Enable streaming
tools: [myTool], // Custom tools
mcpServers: {
// MCP server connections
github: {
type: "http",
url: "https://api.githubcopilot.com/mcp/",
},
},
systemMessage: {
// Custom system prompt
content: "You are a helpful assistant.",
},
customAgents: [
{
// Custom agent personas
name: "code-reviewer",
displayName: "Code Reviewer",
description: "Reviews code for best practices",
prompt: "Focus on security and performance.",
},
],
});
reference.md - Read when you need:
examples.md - Read when you need:
patterns.md - Read when you need:
drift-detection.md - Read when you need:
| Event Type (TS/Go) | Python Enum |
|---|---|
assistant.message_delta |
SessionEventType.ASSISTANT_MESSAGE_DELTA |
session.idle |
SessionEventType.SESSION_IDLE |
tool.invocation |
SessionEventType.TOOL_EXECUTION_START |
tool.result |
SessionEventType.TOOL_EXECUTION_COMPLETE |
Python: Import
from copilot.generated.session_events import SessionEventType
The SDK operates in --allow-all mode by default, enabling:
Use the Copilot SDK to build custom agents within amplihack:
# Create Copilot-powered agent for specific domain
from copilot import CopilotClient
async def create_code_review_agent():
client = CopilotClient()
await client.start()
session = await client.create_session({
"model": "gpt-4.1",
"streaming": True,
"systemMessage": {
"content": "You are an expert code reviewer."
}
})
return session
For complete API details, see reference.md.
For working code in all languages, see examples.md.
For production patterns, see patterns.md.