Quickstart: Build with Copilot SDK

Embed GitHub Copilot’s agentic engine into any application. Multi-language from day one.

The SDK wraps the Copilot CLI server process and communicates via JSON-RPC. Core abstractions: CopilotClient (manages the server connection) and CopilotSession (a conversation with model, tools, and skills).

Prerequisites

The Copilot SDK is in technical preview (launched Jan 2026). Check github/copilot-sdk for current status.

# Node.js
npm install @github/copilot-sdk

# Python
pip install copilot-sdk

# Go
go get github.com/github/copilot-sdk

# .NET
dotnet add package GitHub.Copilot.SDK

Minimal Agent (Node.js)

import { CopilotAgent, Tool } from "@github/copilot-sdk";

const agent = new CopilotAgent({
  model: "gpt-4.1",
  instructions: "You are a helpful coding assistant.",
});

const result = await agent.run("Explain what a closure is in JavaScript");
console.log(result.output);

With Custom Tools

import { CopilotAgent, defineTool } from "@github/copilot-sdk";

const readFile = defineTool({
  name: "read_file",
  description: "Read a file from the filesystem",
  parameters: {
    type: "object",
    properties: {
      path: { type: "string", description: "File path to read" },
    },
    required: ["path"],
  },
  execute: async ({ path }) => {
    const fs = await import("fs/promises");
    return fs.readFile(path, "utf-8");
  },
});

const runTests = defineTool({
  name: "run_tests",
  description: "Run the project's test suite",
  parameters: {
    type: "object",
    properties: {
      filter: { type: "string", description: "Test name filter" },
    },
  },
  execute: async ({ filter }) => {
    const { execSync } = await import("child_process");
    const cmd = filter ? `npm test -- --filter ${filter}` : "npm test";
    return execSync(cmd, { encoding: "utf-8" });
  },
});

const agent = new CopilotAgent({
  model: "gpt-4.1",
  tools: [readFile, runTests],
  instructions: "You are a coding assistant. Read files and run tests as needed.",
});

const result = await agent.run("Find and fix any failing tests");
console.log(result.output);

With MCP Servers

Connect to any MCP server for extended capabilities:

import { CopilotAgent, MCPServer } from "@github/copilot-sdk";

const agent = new CopilotAgent({
  model: "gpt-4.1",
  mcpServers: [
    new MCPServer({
      name: "github",
      command: "npx",
      args: ["@modelcontextprotocol/server-github"],
    }),
    new MCPServer({
      name: "postgres",
      command: "npx",
      args: ["@modelcontextprotocol/server-postgres"],
      env: { DATABASE_URL: process.env.DATABASE_URL },
    }),
  ],
  instructions: "You have access to GitHub and the project database.",
});

With Streaming

const agent = new CopilotAgent({
  model: "gpt-4.1",
  tools: [readFile, editFile],
});

for await (const event of agent.stream("Refactor the auth module")) {
  switch (event.type) {
    case "text":
      process.stdout.write(event.text);
      break;
    case "tool_call":
      console.log(`\n[Calling ${event.toolName}...]`);
      break;
    case "tool_result":
      console.log(`[${event.toolName} completed]`);
      break;
  }
}

Go Example

package main

import (
    "context"
    "fmt"
    copilot "github.com/github/copilot-sdk"
)

func main() {
    agent := copilot.NewAgent(copilot.AgentConfig{
        Model:        "gpt-4.1",
        Instructions: "You are a helpful coding assistant.",
        Tools: []copilot.Tool{
            {
                Name:        "read_file",
                Description: "Read a file",
                Parameters:  readFileSchema,
                Execute:     readFileHandler,
            },
        },
    })

    result, err := agent.Run(context.Background(), "What does main.go do?")
    if err != nil {
        panic(err)
    }
    fmt.Println(result.Output)
}

Python Example

from copilot_sdk import CopilotAgent, tool

@tool
def read_file(path: str) -> str:
    """Read a file from the filesystem."""
    with open(path) as f:
        return f.read()

agent = CopilotAgent(
    model="gpt-4.1",
    tools=[read_file],
    instructions="You are a helpful coding assistant.",
)

result = agent.run("Summarize the project structure")
print(result.output)

Multi-Model Routing

Use different models for different tasks:

const agent = new CopilotAgent({
  model: "gpt-4.1",  // default for complex reasoning
  modelRouter: {
    // Use cheaper model for simple tasks
    "summarize": "gpt-5-mini",
    "format": "gpt-5-mini",
    // Use premium model for code generation
    "generate_code": "gpt-4.1",
    "review_code": "gpt-4.1",
  },
  tools: [readFile, editFile, runTests],
});

Copilot Extensions (Server-Side)

Build agents that integrate into GitHub Copilot Chat:

// Skillset approach (lightweight)
// Define API endpoints that Copilot can call
const skillset = {
  skills: [
    {
      name: "lookup_deployment",
      description: "Look up deployment status",
      endpoint: "/api/deployments",
      parameters: {
        env: { type: "string", enum: ["staging", "production"] }
      }
    }
  ]
};

// Agent approach (full control)
// Handle the full request/response cycle
app.post("/agent", async (req, res) => {
  const { messages } = req.body;
  // Process with your own logic, call your own LLMs
  // Return SSE stream of responses
});

What’s Next