Skip to content

Commit ec7cc2d

Browse files
sunbryeCopilot
andauthored
Manual sync of Copilot SDK docs (#61250)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 849f661 commit ec7cc2d

17 files changed

Lines changed: 556 additions & 201 deletions
32.2 KB
Loading
53.8 KB
Loading
17.4 KB
Loading
12.2 KB
Loading
-72.4 KB
Loading

content/copilot/how-tos/copilot-sdk/authenticate-copilot-sdk/authenticate-copilot-sdk.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ Use an OAuth {% data variables.product.github %} App to authenticate users throu
5656
**How it works:**
5757
1. User authorizes your OAuth {% data variables.product.github %} App.
5858
1. Your app receives a user access token (`gho_` or `ghu_` prefix).
59-
1. Pass the token to the SDK via the `githubToken` option.
59+
1. Pass the token to the SDK via the `gitHubToken` option.
6060

6161
**SDK configuration:**
6262

6363
```typescript
6464
import { CopilotClient } from "@github/copilot-sdk";
6565

6666
const client = new CopilotClient({
67-
githubToken: userAccessToken, // Token from OAuth flow
67+
gitHubToken: userAccessToken, // Token from OAuth flow
6868
useLoggedInUser: false, // Don't use stored CLI credentials
6969
});
7070
```
@@ -130,7 +130,7 @@ For complete setup instructions, including provider configuration options, limit
130130

131131
When multiple authentication methods are available, the SDK uses them in this priority order:
132132

133-
1. **Explicit `githubToken`** — Token passed directly to the SDK constructor
133+
1. **Explicit `gitHubToken`** — Token passed directly to the SDK constructor
134134
1. **Direct API token**`GITHUB_COPILOT_API_TOKEN` with `COPILOT_API_URL`
135135
1. **Environment variable tokens**`COPILOT_GITHUB_TOKEN``GH_TOKEN``GITHUB_TOKEN`
136136
1. **Stored OAuth credentials** — From previous `copilot` CLI sign-in

content/copilot/how-tos/copilot-sdk/integrations/microsoft-agent-framework.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The Microsoft Agent Framework is the unified successor to Semantic Kernel and Au
2424
| A2A protocol | Agent-to-Agent communication standard supported by the framework |
2525

2626
> [!NOTE]
27-
> MAF integration packages are available for .NET and Python. For TypeScript and Go, use the {% data variables.copilot.copilot_sdk_short %} directly—the standard SDK APIs provide tool calling, streaming, and custom agents.
27+
> MAF integration packages are available for .NET and Python. For TypeScript, Go, and Java, use the {% data variables.copilot.copilot_sdk_short %} directly—the standard SDK APIs provide tool calling, streaming, and custom agents.
2828
2929
## Prerequisites
3030

@@ -317,5 +317,7 @@ catch (AgentException ex)
317317
## Further reading
318318

319319
* [AUTOTITLE](/copilot/how-tos/copilot-sdk/sdk-getting-started)
320+
* [AUTOTITLE](/copilot/how-tos/copilot-sdk/use-copilot-sdk/custom-agents)
321+
* [AUTOTITLE](/copilot/how-tos/copilot-sdk/use-copilot-sdk/custom-skills)
320322
* [Microsoft Agent Framework documentation](https://learn.microsoft.com/en-us/agent-framework/agents/providers/github-copilot)
321323
* [Blog: Build AI Agents with GitHub Copilot SDK and Microsoft Agent Framework](https://devblogs.microsoft.com/semantic-kernel/build-ai-agents-with-github-copilot-sdk-and-microsoft-agent-framework/)

content/copilot/how-tos/copilot-sdk/sdk-getting-started.md

Lines changed: 182 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,185 @@ unsubscribeIdle();
144144
145145
## Next steps
146146
147-
To continue getting started with {% data variables.copilot.copilot_sdk_short %}, see [Build Your First Copilot-Powered App](https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md#step-4-add-a-custom-tool) in the `github/copilot-sdk` repository.
147+
### Add a custom tool
148+
149+
Give {% data variables.product.prodname_copilot_short %} the ability to call your code by defining a custom tool. Here's a weather lookup tool:
150+
151+
```typescript copy
152+
import { CopilotClient, defineTool } from "@github/copilot-sdk";
153+
154+
// Define a tool that Copilot can call
155+
const getWeather = defineTool("get_weather", {
156+
description: "Get the current weather for a city",
157+
parameters: {
158+
type: "object",
159+
properties: {
160+
city: { type: "string", description: "The city name" },
161+
},
162+
required: ["city"],
163+
},
164+
handler: async (args: { city: string }) => {
165+
const { city } = args;
166+
// In a real app, you'd call a weather API here
167+
const conditions = ["sunny", "cloudy", "rainy", "partly cloudy"];
168+
const temp = Math.floor(Math.random() * 30) + 50;
169+
const condition = conditions[Math.floor(Math.random() * conditions.length)];
170+
return { city, temperature: `${temp}°F`, condition };
171+
},
172+
});
173+
174+
const client = new CopilotClient();
175+
const session = await client.createSession({
176+
model: "gpt-4.1",
177+
streaming: true,
178+
tools: [getWeather],
179+
});
180+
181+
session.on("assistant.message_delta", (event) => {
182+
process.stdout.write(event.data.deltaContent);
183+
});
184+
185+
session.on("session.idle", () => {
186+
console.log(); // New line when done
187+
});
188+
189+
await session.sendAndWait({
190+
prompt: "What's the weather like in Seattle and Tokyo?",
191+
});
192+
193+
await client.stop();
194+
process.exit(0);
195+
```
196+
197+
For examples in Python, Go, .NET, and Rust, see [Getting started](https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md#step-4-add-a-custom-tool) in the `github/copilot-sdk` repository. {% data reusables.copilot.copilot-sdk.java-sdk-link %}
198+
199+
When you define a tool, you're telling {% data variables.product.prodname_copilot_short %}:
200+
201+
1. **What the tool does** (description)
202+
1. **What parameters it needs** (schema)
203+
1. **What code to run** (handler)
204+
205+
{% data variables.product.prodname_copilot_short %} decides when to call your tool based on the user's question. When it does, the {% data variables.copilot.copilot_sdk_short %} runs your handler function and sends the result back to {% data variables.product.prodname_copilot_short %}, which incorporates it into the response.
206+
207+
### Build an interactive assistant
208+
209+
Combine everything into an interactive chat assistant:
210+
211+
```typescript copy
212+
import { CopilotClient, defineTool } from "@github/copilot-sdk";
213+
import * as readline from "readline";
214+
215+
const getWeather = defineTool("get_weather", {
216+
description: "Get the current weather for a city",
217+
parameters: {
218+
type: "object",
219+
properties: {
220+
city: { type: "string", description: "The city name" },
221+
},
222+
required: ["city"],
223+
},
224+
handler: async ({ city }) => {
225+
const conditions = ["sunny", "cloudy", "rainy", "partly cloudy"];
226+
const temp = Math.floor(Math.random() * 30) + 50;
227+
const condition = conditions[Math.floor(Math.random() * conditions.length)];
228+
return { city, temperature: `${temp}°F`, condition };
229+
},
230+
});
231+
232+
const client = new CopilotClient();
233+
const session = await client.createSession({
234+
model: "gpt-4.1",
235+
streaming: true,
236+
tools: [getWeather],
237+
});
238+
239+
session.on("assistant.message_delta", (event) => {
240+
process.stdout.write(event.data.deltaContent);
241+
});
242+
243+
const rl = readline.createInterface({
244+
input: process.stdin,
245+
output: process.stdout,
246+
});
247+
248+
console.log("Weather Assistant (type 'exit' to quit)");
249+
console.log(" Try: 'What's the weather in Paris?'\n");
250+
251+
const prompt = () => {
252+
rl.question("You: ", async (input) => {
253+
if (input.toLowerCase() === "exit") {
254+
await client.stop();
255+
rl.close();
256+
return;
257+
}
258+
259+
process.stdout.write("Assistant: ");
260+
await session.sendAndWait({ prompt: input });
261+
console.log("\n");
262+
prompt();
263+
});
264+
};
265+
266+
prompt();
267+
```
268+
269+
Run with:
270+
271+
```bash copy
272+
npx tsx weather-assistant.ts
273+
```
274+
275+
For examples in Python, Go, .NET, and Rust, see [Getting started](https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md#step-5-build-an-interactive-assistant) in the `github/copilot-sdk` repository. {% data reusables.copilot.copilot-sdk.java-sdk-link %}
276+
277+
### Connect to MCP servers
278+
279+
MCP (Model Context Protocol) servers provide pre-built tools. Connect to {% data variables.product.github %}'s MCP server to give {% data variables.product.prodname_copilot_short %} access to repositories, issues, and pull requests:
280+
281+
```typescript copy
282+
const session = await client.createSession({
283+
mcpServers: {
284+
github: {
285+
type: "http",
286+
url: "https://api.githubcopilot.com/mcp/",
287+
},
288+
},
289+
});
290+
```
291+
292+
For more information, see [AUTOTITLE](/copilot/how-tos/copilot-sdk/use-copilot-sdk/mcp-servers).
293+
294+
### Create custom agents
295+
296+
Define specialized AI personas for specific tasks:
297+
298+
```typescript copy
299+
const session = await client.createSession({
300+
customAgents: [{
301+
name: "pr-reviewer",
302+
displayName: "PR Reviewer",
303+
description: "Reviews pull requests for best practices",
304+
prompt: "You are an expert code reviewer. Focus on security, performance, and maintainability.",
305+
}],
306+
});
307+
```
308+
309+
For more information, see [AUTOTITLE](/copilot/how-tos/copilot-sdk/use-copilot-sdk/custom-agents).
310+
311+
### Customize the system message
312+
313+
Control the AI's behavior and personality by appending instructions:
314+
315+
```typescript copy
316+
const session = await client.createSession({
317+
systemMessage: {
318+
content: "You are a helpful assistant for our engineering team. Always be concise.",
319+
},
320+
});
321+
```
322+
323+
### Further reading
324+
325+
* [AUTOTITLE](/copilot/how-tos/copilot-sdk/set-up-copilot-sdk/choosing-a-setup-path)
326+
* [AUTOTITLE](/copilot/how-tos/copilot-sdk/use-copilot-sdk/agent-loop)
327+
* [Connecting to an external CLI server](https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md#connecting-to-an-external-cli-server) in the `github/copilot-sdk` repository
328+
* [Telemetry and observability](https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md#telemetry-and-observability) in the `github/copilot-sdk` repository

0 commit comments

Comments
 (0)