Skip to content

Commit 244b63d

Browse files
committed
feat: Add installation instructions and examples for Python, Go, Node.js, and .NET SDKs
1 parent a794ef0 commit 244b63d

5 files changed

Lines changed: 212 additions & 86 deletions

File tree

.github/skills/copilot-sdk/SKILL.md

Lines changed: 37 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
---
23
name: copilot-sdk
34
description: >
@@ -12,6 +13,17 @@ description: >
1213
or querying the GitHub Copilot REST/metrics API.
1314
---
1415

16+
17+
18+
# Installation / Adding the Copilot SDK
19+
20+
The Copilot SDK must be installed or added to your project before use in any language. See the install instructions for your language:
21+
22+
- [Python: install & example](examples/python-basic.md)
23+
- [Go: install & example](examples/go-basic.md)
24+
- [Node.js: install & example](examples/nodejs-basic.md)
25+
- [.NET: install & example](examples/dotnet-basic.md)
26+
1527
# GitHub Copilot SDK — Scripting Guide
1628

1729
## When to Use the SDK
@@ -41,110 +53,49 @@ that is a syntax error on Python 3.9 and earlier.
4153

4254
Check your version:
4355
```bash
44-
python3 --version
45-
```
46-
47-
If you have Python 3.9 or earlier, install a newer version:
48-
```bash
49-
brew install python@3.12 # macOS
50-
```
51-
52-
## Installation
53-
54-
```bash
55-
pip install github-copilot-sdk
56-
```
57-
58-
> **Homebrew Python (macOS):** Homebrew Python 3.10+ enforces PEP 668 and will reject
59-
> `pip install --user`. Use a virtual environment:
60-
>
61-
> ```bash
62-
> python3.12 -m venv .venv
6356
> source .venv/bin/activate
6457
> pip install github-copilot-sdk
65-
> ```
58+
import asyncio
6659

67-
The importable package name is `copilot` (not `github-copilot-sdk`):
68-
```python
69-
from copilot import CopilotClient, PermissionHandler
70-
```
60+
# GitHub Copilot SDK — Scripting Guide
7161

72-
## Prerequisites
62+
## When to Use the SDK
7363

74-
> **The SDK calls the Copilot CLI — the CLI must be present and authenticated.**
75-
> The SDK spawns `copilot` as a subprocess; if the CLI is missing or unauthenticated
76-
> the SDK will fail to start.
64+
Use the Copilot SDK in any deterministic script that needs to delegate non-deterministic tasks (classification, extraction, summarization, evaluation, free-form generation) to an LLM. The SDK is available for Python, Go, .NET (C#), and Node.js (JavaScript/TypeScript).
7765

78-
```bash
79-
# Verify CLI is installed and authenticated
80-
gh copilot --version
81-
```
66+
> **CLI dependency:** The SDK does **not** make direct API calls. It spawns and drives the **GitHub Copilot CLI** as a subprocess. The CLI must be installed and authenticated before running any SDK script. See the [official installation guide](https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli).
8267

83-
Install the CLI: https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli
8468

85-
## Quick Start (Python)
69+
## Language Quick Start Examples
8670

87-
```python
88-
import asyncio
89-
from copilot import CopilotClient, PermissionHandler
71+
- [Python Example](examples/python-basic.md)
72+
- [Go Example](examples/go-basic.md)
73+
- [Node.js Example](examples/nodejs-basic.md)
74+
- [.NET (C#) Example](examples/dotnet-basic.md)
9075

91-
async def main():
92-
client = CopilotClient()
93-
await client.start()
94-
try:
95-
async with await client.create_session(
96-
on_permission_request=PermissionHandler.approve_all,
97-
infinite_sessions={"enabled": False},
98-
model="gpt-4.1",
99-
) as session:
100-
result_text: list[str] = []
101-
done = asyncio.Event()
76+
Each example demonstrates how to create a client, start a session, send a prompt, and handle the response. See the referenced files for details and advanced usage.
10277

103-
def on_event(event):
104-
if event.type.value == "assistant.message":
105-
result_text.append(event.data.content)
106-
done.set()
107-
elif event.type.value == "session.idle":
108-
done.set()
78+
## Documentation and Advanced Usage
10979

110-
session.on(on_event)
111-
await session.send("What is 2 + 2?")
112-
await done.wait()
80+
- [Python SDK README](https://raw.githubusercontent.com/github/copilot-sdk/refs/heads/main/python/README.md)
81+
- [Go SDK README](https://raw.githubusercontent.com/github/copilot-sdk/refs/heads/main/go/README.md)
82+
- [Node.js SDK README](https://raw.githubusercontent.com/github/copilot-sdk/refs/heads/main/nodejs/README.md)
83+
- [.NET SDK README](https://raw.githubusercontent.com/github/copilot-sdk/refs/heads/main/dotnet/README.md)
11384

114-
print(result_text[0] if result_text else "")
115-
finally:
116-
await client.stop()
85+
For .NET file-based scripting, see [Microsoft Learn: File-based programs in C#](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/tutorials/file-based-programs).
11786

118-
asyncio.run(main())
119-
```
120-
121-
## `create_session` API
122-
123-
**Important:** In SDK v0.2.0+, all `create_session` arguments are keyword-only.
124-
Do **not** pass a dict positionally — use `**config` or explicit kwargs.
87+
## Key Points
12588

126-
```python
127-
# ✅ Correct — keyword arguments
128-
session = await client.create_session(
129-
on_permission_request=PermissionHandler.approve_all,
130-
model="gpt-4.1",
131-
system_message={"content": "You are a helpful assistant."},
132-
infinite_sessions={"enabled": False},
133-
)
89+
- The SDK requires the Copilot CLI to be installed and authenticated.
90+
- Each language SDK provides async or event-driven APIs for session management and prompt handling.
91+
- Permission handlers are required for tool execution (see each language's example for details).
92+
- Advanced features (custom tools, streaming, system message customization, telemetry, etc.) are documented in the official SDK READMEs above.
13493
135-
# ✅ Correct — unpack a config dict
136-
config = {
137-
"on_permission_request": PermissionHandler.approve_all,
138-
"model": "gpt-4.1",
139-
"infinite_sessions": {"enabled": False},
140-
}
141-
session = await client.create_session(**config)
94+
## Example Directory
14295
143-
# ❌ Wrong — positional dict (fails in v0.2.0+)
144-
session = await client.create_session(config)
145-
```
96+
All code examples have been moved to the `examples/` subdirectory for clarity and multi-language support.
14697
147-
### All Session Parameters
98+
---
14899
149100
| Parameter | Type | Description |
150101
|-----------|------|-------------|
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// .NET (C#) — Install and Example
2+
3+
### Installation
4+
5+
**NuGet (project):**
6+
7+
```sh
8+
dotnet add package GitHub.Copilot.SDK
9+
```
10+
11+
**C# file-based script:**
12+
13+
```csharp
14+
#! /usr/bin/env dotnet-script
15+
#r "nuget: GitHub.Copilot.SDK"
16+
```
17+
18+
# Checking if Copilot CLI is installed
19+
20+
Before calling the Copilot CLI from .NET, you can check if it is available in the system path:
21+
22+
```csharp
23+
using System.Diagnostics;
24+
try {
25+
Process.Start(new ProcessStartInfo {
26+
FileName = "copilot",
27+
Arguments = "--version",
28+
RedirectStandardOutput = true,
29+
UseShellExecute = false,
30+
CreateNoWindow = true
31+
});
32+
} catch {
33+
throw new Exception("Copilot CLI is not installed or not in PATH");
34+
}
35+
```
36+
37+
# .NET (C#) Example: Basic Usage
38+
39+
```csharp
40+
using GitHub.Copilot.SDK;
41+
42+
await using var client = new CopilotClient();
43+
await using var session = await client.CreateSessionAsync(new SessionConfig { Model = "gpt-4.1" });
44+
var response = await session.SendAndWaitAsync(new MessageOptions { Prompt = "Hello" });
45+
Console.WriteLine(response?.Data.Content);
46+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Go — Install and Example
2+
3+
### Installation
4+
5+
```sh
6+
go get github.com/github/copilot-sdk-go
7+
```
8+
9+
# Checking if Copilot CLI is installed
10+
11+
Before calling the Copilot CLI from Go, you can check if it is available in the system path:
12+
13+
```go
14+
import (
15+
"log"
16+
"os/exec"
17+
)
18+
19+
func main() {
20+
if _, err := exec.LookPath("copilot"); err != nil {
21+
log.Fatal("Copilot CLI is not installed or not in PATH")
22+
}
23+
// ...existing code...
24+
}
25+
```
26+
27+
# Go Example: Basic Usage
28+
29+
```go
30+
package main
31+
32+
import (
33+
"fmt"
34+
copilot "github.com/github/copilot-sdk/go"
35+
)
36+
37+
func main() {
38+
client := copilot.NewClient(nil)
39+
client.Start()
40+
defer client.Stop()
41+
session, _ := client.CreateSession(&copilot.SessionConfig{Model: "gpt-4.1"})
42+
response, _ := session.SendAndWait(copilot.MessageOptions{Prompt: "Hello"}, 0)
43+
fmt.Println(*response.Data.Content)
44+
}
45+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Node.js — Install and Example
2+
3+
### Installation
4+
5+
```sh
6+
npm install @github/copilot-sdk
7+
```
8+
9+
# Checking if Copilot CLI is installed
10+
11+
Before calling the Copilot CLI from Node.js, you can check if it is available in the system path:
12+
13+
```js
14+
const { execSync } = require('child_process');
15+
try {
16+
execSync('copilot --version', { stdio: 'ignore' });
17+
} catch (e) {
18+
throw new Error('Copilot CLI is not installed or not in PATH');
19+
}
20+
```
21+
22+
# Node.js Example: Basic Usage
23+
24+
```typescript
25+
import { CopilotClient } from "@github/copilot-sdk";
26+
const client = new CopilotClient();
27+
const session = await client.createSession({ model: "gpt-4.1" });
28+
const response = await session.sendAndWait({ prompt: "Hello" });
29+
console.log(response?.data.content);
30+
await client.stop();
31+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Python — Install and Example
2+
3+
## Installation
4+
5+
```sh
6+
pip install copilot-sdk
7+
```
8+
9+
# Checking if Copilot CLI is installed
10+
11+
Before calling the Copilot CLI from Python, you can check if it is available in the system path:
12+
13+
```python
14+
import shutil
15+
if shutil.which("copilot") is None:
16+
raise RuntimeError("Copilot CLI is not installed or not in PATH")
17+
```
18+
19+
# Python Example: Basic Usage
20+
21+
```python
22+
import asyncio
23+
from copilot import CopilotClient, PermissionHandler
24+
25+
async def main():
26+
client = CopilotClient()
27+
await client.start()
28+
try:
29+
async with await client.create_session(
30+
on_permission_request=PermissionHandler.approve_all,
31+
infinite_sessions={"enabled": False},
32+
model="gpt-4.1",
33+
) as session:
34+
done = asyncio.Event()
35+
result: list[str] = []
36+
37+
def on_event(event):
38+
if event.type.value == "assistant.message":
39+
result.append(event.data.content)
40+
done.set()
41+
elif event.type.value == "session.idle":
42+
done.set()
43+
44+
session.on(on_event)
45+
await session.send("What is 2 + 2?")
46+
await done.wait()
47+
48+
print(result[0] if result else "")
49+
finally:
50+
await client.stop()
51+
52+
asyncio.run(main())
53+
```

0 commit comments

Comments
 (0)