copilot-sdk
Build agentic applications with GitHub Copilot SDK. Use when embedding AI agents in apps, creating custom tools, implementing streaming responses, managing sessions, connecting to MCP servers, or creating custom agents. Triggers on Copilot SDK, GitHub SDK, agentic app, embed Copilot, programmable ag
By github · 9,425 installs
npx skills add github/awesome-copilot --skill copilot-sdk
Source repository · Upstream listing
GitHub Copilot SDK
Embed Copilot's agentic workflows in any application using Python, TypeScript, Go, or .NET.
Overview
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.
Prerequisites
1. GitHub Copilot access and an authenticated environment
2. Language runtime : Node.js ^20.19.0 or =22.12.0, Python 3.11+, Go 1.24+, or a .NET Standard 2.0 compatible implementation
3. Go : GitHub Copilot CLI installed and authenticated ([Installation guide](https://docs.github.com/en/copilot/how tos/set up/install copilot cli))
The TypeScript, Python, and .NET packages use a bundled Copilot runtime by default, so they do not need a separate CLI installation.
Installation
Node.js/TypeScript
Python
Published Python wheels include a pinned runtime version. The pre download command caches that runtime locally; if skipped, the SDK attempts to download it automatically on first use.
Go
.NET
Quick Start
TypeScript
Run: npx tsx index.ts
Python
Go
.NET (C )
Run: dotnet run
Streaming Responses
Enable real time output for better UX:
TypeScript
Python
Go
.NET
Custom Tools
Define tools that Copilot can invoke during reasoning. When you define a tool, you tell Copilot:
1. What the tool does (description)
2. What parameters it needs (schema)
3. What code to run (handler)
TypeScript (JSON Schema)
Python (Pydantic)
Go
.NET (Microsoft.Extensions.AI)
How Tools Work
When Copilot decides to call your tool:
1. Copilot sends a tool call request with the parameters
2. The SDK runs your handler function
3. The result is sent back to Copilot
4. Copilot incorporates the result into its response
Copilot decides when to call your tool based on the user's question and your tool's description.
Interactive CLI Assistant
Build a complete interactive assistant:
TypeScript
Python
MCP Server Integration
Connect to MCP (Model Context Protocol) servers for pre built tools. Connect to GitHub's MCP server for repository, issue, and PR access:
TypeScript
Python
Go
.NET
Custom Agents
Define specialized AI personas for specific tasks:
TypeScript
Python
System Message
Customize the AI's behavior and personality:
TypeScript
Python
External CLI Server
Run the CLI in server mode separately and connect the SDK to it. Useful for debugging, resource sharing, or custom environments.
Start CLI in Server Mode
Connect SDK to External Server
TypeScript
Python
Go
.NET
Note: When configured to use an external server, the SDK manages only its connection and does not manage the external process.
Event Types
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
Client Configuration
Option Description Default
cliPath Path to Copilot CLI executable System PATH
cliUrl Connect to existing server (e.g., "localhost:4321") 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
Session Configuration
Option Description
model LLM to use ("gpt 4.1", "claude sonnet 4.5", etc.)
sessionId Custom session identifier
tools Custom tool definitions
mcpServers MCP server connections
customAgents Custom agent personas
systemMessage Override default system prompt
streaming Enable incremental response chunks
availableTools Whitelist of permitted tools
excludedTools Blacklist of disabled tools
Session Persistence
Save and resume conversations across restarts:
Create with Custom ID
Resume Session
List and Delete Sessions
Error Handling
Graceful Shutdown
Common Patterns
Multi turn Conversation
File Attachments
Abort Long Operations
Available Models
Query available models at runtime:
Best Practices
1. Always clean up : Use language native context managers or disposal, or explicitly disconnect sessions and stop clients
2. Set timeouts : Use sendAndWait with timeout for long operations
3. Handle events : Subscribe to error events for robust error handling
4. Use streaming : Enable streaming for better UX on long responses
5. Persist sessions : Use custom session IDs for multi turn conversations
6. Define clear tools : Write descriptive tool names and descriptions
Architecture
The SDK manages the CLI process lifecycle automatically. All communication happens via JSON RPC over stdio or TCP.
Resources
GitHub Repository : https://github.com/github/copilot sdk
Getting Started Tutorial : https://github.com/github/copilot sdk/blob/main/docs/tutorials/first app.md
GitHub MCP Server : https://github.com/github/github mcp server
MCP Servers Directory : https://github.com/modelcontextprotocol/servers
Cookbook : https://github.com/github/copilot sdk/tree/main/cookbook
Samples : https://github.com/github/copilot sdk/tree/main/samples
Status
This SDK is in Technical Preview and may have breaking changes. Not recommended for production use yet.