빌드할 내용:
You: What's the weather like in Seattle?
Copilot: Let me check the weather for Seattle...
Currently 62°F and cloudy with a chance of rain.
Typical Seattle weather!
You: How about Tokyo?
Copilot: In Tokyo it's 75°F and sunny. Great day to be outside!
사전 요구 사항
시작하기 전에 다음을 확인합니다.
- GitHub Copilot CLI 설치 및 인증(설치 가이드)
- 기본 설정 언어 런타임:
- Node.js 20 이상 또는 Python 3.11 이상 또는 Go 1.24 이상 또는 > Rust 1.94 이상 또는 Java 17 이상 또는 .NET 8.0 이상
CLI가 작동하는지 확인합니다.
copilot --version
1단계: SDK 설치
먼저 새 디렉터리를 만들고 프로젝트를 초기화합니다.
mkdir copilot-demo && cd copilot-demo
npm init -y --init-type module
그런 다음, SDK 및 TypeScript 실행기를 설치합니다.
npm install @github/copilot-sdk tsx
pip install github-copilot-sdk
먼저 새 디렉터리를 만들고 모듈을 초기화합니다.
mkdir copilot-demo && cd copilot-demo
go mod init copilot-demo
그런 다음, SDK를 설치합니다.
go get github.com/github/copilot-sdk/go
먼저 새 이진 상자를 만듭니다.
cargo new copilot-demo && cd copilot-demo
그런 다음, 예제에서 사용하는 SDK 및 직접 종속성을 설치합니다.
cargo add github-copilot-sdk --features derive
# Used by #[tokio::main] and tokio::spawn
cargo add tokio --features rt-multi-thread,macros
# Used by custom-tool parameter derives later in this guide
cargo add serde --features derive
cargo add schemars
먼저 새 콘솔 프로젝트를 만듭니다.
dotnet new console -n CopilotDemo && cd CopilotDemo
그런 다음, SDK를 추가합니다.
dotnet add package GitHub.Copilot.SDK
먼저 새 디렉터리를 만들고 프로젝트를 초기화합니다.
Maven—pom.xml에 추가:
<dependency>
<groupId>com.github</groupId>
<artifactId>copilot-sdk-java</artifactId>
<version>${copilot.sdk.version}</version>
</dependency>
Gradle—build.gradle에 추가:
implementation 'com.github:copilot-sdk-java:${copilotSdkVersion}'
2단계: 첫 번째 메시지 보내기
새 파일을 만들고 다음 코드를 추가합니다. SDK를 사용하는 가장 간단한 방법인 약 5줄의 코드입니다.
index.ts을 만듭니다.
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();
process.exit(0);
다음을 실행합니다.
npx tsx index.ts
main.py을 만듭니다.
import asyncio
from copilot import CopilotClient
from copilot.session import PermissionHandler
async def main():
client = CopilotClient()
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-4.1")
response = await session.send_and_wait("What is 2 + 2?")
print(response.data.content)
await client.stop()
asyncio.run(main())
다음을 실행합니다.
python main.py
main.go을 만듭니다.
package main
import (
"context"
"fmt"
"log"
"os"
copilot "github.com/github/copilot-sdk/go"
)
func main() {
ctx := context.Background()
client := copilot.NewClient(nil)
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
session, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"})
if err != nil {
log.Fatal(err)
}
response, err := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "What is 2 + 2?"})
if err != nil {
log.Fatal(err)
}
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
os.Exit(0)
}
다음을 실행합니다.
go run main.go
src/main.rs을 만듭니다.
use std::sync::Arc;
use std::time::Duration;
use github_copilot_sdk::handler::ApproveAllHandler;
use github_copilot_sdk::{Client, ClientOptions, MessageOptions, SessionConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::start(ClientOptions::default()).await?;
let session = client
.create_session(SessionConfig::default().with_handler(Arc::new(ApproveAllHandler)))
.await?;
let response = session
.send_and_wait(
MessageOptions::new("What is 2 + 2?").with_wait_timeout(Duration::from_secs(120)),
)
.await?;
if let Some(event) = response {
if let Some(content) = event.data.get("content").and_then(|value| value.as_str()) {
println!("{content}");
}
}
session.disconnect().await?;
client.stop().await?;
Ok(())
}
다음을 실행합니다.
cargo run
새 콘솔 프로젝트를 만들고 다음을 추가합니다 Program.cs.
using GitHub.Copilot;
await using var client = new CopilotClient();
await using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-4.1",
OnPermissionRequest = PermissionHandler.ApproveAll
});
var response = await session.SendAndWaitAsync(new MessageOptions { Prompt = "What is 2 + 2?" });
Console.WriteLine(response?.Data.Content);
다음을 실행합니다.
dotnet run
HelloCopilot.java을 만듭니다.
import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
public class HelloCopilot {
public static void main(String[] args) throws Exception {
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(
new SessionConfig()
.setModel("gpt-4.1")
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
).get();
var response = session.sendAndWait(
new MessageOptions().setPrompt("What is 2 + 2?")
).get();
System.out.println(response.getData().content());
client.stop().get();
}
}
}
다음을 실행합니다.
javac -cp copilot-sdk.jar HelloCopilot.java && java -cp .:copilot-sdk.jar HelloCopilot
다음과 같이 표시됩니다:
4
축하합니다! 방금 첫 번째 Copilot 지원 앱을 빌드했습니다.
3단계: 스트리밍 응답 추가
지금, 당신은 아무것도 보기 전에 전체 응답을 기다립니다. 생성된 응답을 스트리밍하여 대화형으로 만들어 보겠습니다.
다음과 같이 index.ts를 업데이트합니다.
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient();
const session = await client.createSession({
model: "gpt-4.1",
streaming: true,
});
// Listen for response chunks
session.on("assistant.message_delta", (event) => {
process.stdout.write(event.data.deltaContent);
});
session.on("session.idle", () => {
console.log(); // New line when done
});
await session.sendAndWait({ prompt: "Tell me a short joke" });
await client.stop();
process.exit(0);
다음과 같이 main.py를 업데이트합니다.
import asyncio
import sys
from copilot import CopilotClient
from copilot.session import PermissionHandler
from copilot.generated.session_events import SessionEventType
async def main():
client = CopilotClient()
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-4.1", streaming=True)
# Listen for response chunks
def handle_event(event):
if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:
sys.stdout.write(event.data.delta_content)
sys.stdout.flush()
if event.type == SessionEventType.SESSION_IDLE:
print() # New line when done
session.on(handle_event)
await session.send_and_wait("Tell me a short joke")
await client.stop()
asyncio.run(main())
다음과 같이 main.go를 업데이트합니다.
package main
import (
"context"
"fmt"
"log"
"os"
copilot "github.com/github/copilot-sdk/go"
)
func main() {
ctx := context.Background()
client := copilot.NewClient(nil)
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
Model: "gpt-4.1",
Streaming: copilot.Bool(true),
})
if err != nil {
log.Fatal(err)
}
// Listen for response chunks
session.On(func(event copilot.SessionEvent) {
switch d := event.Data.(type) {
case *copilot.AssistantMessageDeltaData:
fmt.Print(d.DeltaContent)
case *copilot.SessionIdleData:
_ = d
fmt.Println()
}
})
_, err = session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Tell me a short joke"})
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}
다음과 같이 src/main.rs를 업데이트합니다.
use std::io::{self, Write};
use std::sync::Arc;
use std::time::Duration;
use github_copilot_sdk::handler::ApproveAllHandler;
use github_copilot_sdk::{Client, ClientOptions, MessageOptions, SessionConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::start(ClientOptions::default()).await?;
let mut config = SessionConfig::default();
config.streaming = Some(true);
let session = client
.create_session(config.with_handler(Arc::new(ApproveAllHandler)))
.await?;
// Listen for response chunks
let mut events = session.subscribe();
tokio::spawn(async move {
while let Ok(event) = events.recv().await {
match event.event_type.as_str() {
"assistant.message_delta" => {
if let Some(text) =
event.data.get("deltaContent").and_then(|value| value.as_str())
{
print!("{text}");
io::stdout().flush().ok();
}
}
"assistant.message" => println!(),
_ => {}
}
}
});
session
.send_and_wait(
MessageOptions::new("Tell me a short joke")
.with_wait_timeout(Duration::from_secs(120)),
)
.await?;
session.disconnect().await?;
client.stop().await?;
Ok(())
}
다음과 같이 Program.cs를 업데이트합니다.
using GitHub.Copilot;
await using var client = new CopilotClient();
await using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-4.1",
OnPermissionRequest = PermissionHandler.ApproveAll,
Streaming = true,
});
// Listen for response chunks
session.On<SessionEvent>(ev =>
{
if (ev is AssistantMessageDeltaEvent deltaEvent)
{
Console.Write(deltaEvent.Data.DeltaContent);
}
if (ev is SessionIdleEvent)
{
Console.WriteLine();
}
});
await session.SendAndWaitAsync(new MessageOptions { Prompt = "Tell me a short joke" });
다음과 같이 HelloCopilot.java를 업데이트합니다.
import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
public class HelloCopilot {
public static void main(String[] args) throws Exception {
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(
new SessionConfig()
.setModel("gpt-4.1")
.setStreaming(true)
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
).get();
// Listen for response chunks
session.on(AssistantMessageDeltaEvent.class, delta -> {
System.out.print(delta.getData().deltaContent());
});
session.on(SessionIdleEvent.class, idle -> {
System.out.println(); // New line when done
});
session.sendAndWait(
new MessageOptions().setPrompt("Tell me a short joke")
).get();
client.stop().get();
}
}
}
코드를 다시 실행합니다. 응답이 단어별로 표시되는 것을 볼 수 있습니다.
이벤트 구독 방법
SDK는 세션 이벤트를 구독하는 메서드를 제공합니다.
| Method | Description |
|---|---|
on(handler) | 모든 이벤트를 구독합니다. 는 구독 취소 함수를 반환합니다. |
on(eventType, handler) | 특정 이벤트 유형(Node.js/TypeScript만 해당)을 구독합니다. 는 구독 취소 함수를 반환합니다. |
subscribe() | 모든 이벤트를 구독(Rust); event_type 기준으로 필터링 |
// Subscribe to all events
const unsubscribeAll = session.on((event) => {
console.log("Event:", event.type);
});
// Subscribe to specific event type
const unsubscribeIdle = session.on("session.idle", (event) => {
console.log("Session is idle");
});
// Later, to unsubscribe:
unsubscribeAll();
unsubscribeIdle();
from copilot import CopilotClient, PermissionDecisionApproveOnce
from copilot.generated.session_events import SessionEvent, SessionEventType
client = CopilotClient()
session = await client.create_session(on_permission_request=lambda req, inv: PermissionDecisionApproveOnce())
# Subscribe to all events
unsubscribe = session.on(lambda event: print(f"Event: {event.type}"))
# Filter by event type in your handler
def handle_event(event: SessionEvent) -> None:
if event.type == SessionEventType.SESSION_IDLE:
print("Session is idle")
elif event.type == SessionEventType.ASSISTANT_MESSAGE:
print(f"Message: {event.data.content}")
unsubscribe = session.on(handle_event)
# Later, to unsubscribe:
unsubscribe()
# Subscribe to all events
unsubscribe = session.on(lambda event: print(f"Event: {event.type}"))
# Filter by event type in your handler
def handle_event(event):
if event.type == SessionEventType.SESSION_IDLE:
print("Session is idle")
elif event.type == SessionEventType.ASSISTANT_MESSAGE:
print(f"Message: {event.data.content}")
unsubscribe = session.on(handle_event)
# Later, to unsubscribe:
unsubscribe()
package main
import (
"fmt"
copilot "github.com/github/copilot-sdk/go"
)
func main() {
session := &copilot.Session{}
// Subscribe to all events
unsubscribe := session.On(func(event copilot.SessionEvent) {
fmt.Println("Event:", event.Type)
})
// Filter by event type in your handler
session.On(func(event copilot.SessionEvent) {
switch d := event.Data.(type) {
case *copilot.SessionIdleData:
_ = d
fmt.Println("Session is idle")
case *copilot.AssistantMessageData:
fmt.Println("Message:", d.Content)
}
})
// Later, to unsubscribe:
unsubscribe()
}
// Subscribe to all events
unsubscribe := session.On(func(event copilot.SessionEvent) {
fmt.Println("Event:", event.Type)
})
// Filter by event type in your handler
session.On(func(event copilot.SessionEvent) {
switch d := event.Data.(type) {
case *copilot.SessionIdleData:
_ = d
fmt.Println("Session is idle")
case *copilot.AssistantMessageData:
fmt.Println("Message:", d.Content)
}
})
// Later, to unsubscribe:
unsubscribe()
let mut events = session.subscribe();
tokio::spawn(async move {
while let Ok(event) = events.recv().await {
println!("Event: {}", event.event_type);
match event.event_type.as_str() {
"session.idle" => println!("Session is idle"),
"assistant.message" => {
if let Some(content) = event.data.get("content").and_then(|value| value.as_str()) {
println!("Message: {content}");
}
}
_ => {}
}
}
});
using GitHub.Copilot;
public static class EventSubscriptionExample
{
public static void Example(CopilotSession session)
{
// Subscribe to all events
var unsubscribe = session.On<SessionEvent>(ev => Console.WriteLine($"Event: {ev.Type}"));
// Filter by event type using pattern matching
session.On<SessionEvent>(ev =>
{
switch (ev)
{
case SessionIdleEvent:
Console.WriteLine("Session is idle");
break;
case AssistantMessageEvent msg:
Console.WriteLine($"Message: {msg.Data.Content}");
break;
}
});
// Later, to unsubscribe:
unsubscribe.Dispose();
}
}
// Subscribe to all events
var unsubscribe = session.On<SessionEvent>(ev => Console.WriteLine($"Event: {ev.Type}"));
// Filter by event type using pattern matching
session.On<SessionEvent>(ev =>
{
switch (ev)
{
case SessionIdleEvent:
Console.WriteLine("Session is idle");
break;
case AssistantMessageEvent msg:
Console.WriteLine($"Message: {msg.Data.Content}");
break;
}
});
// Later, to unsubscribe:
unsubscribe.Dispose();
// Subscribe to all events
var unsubscribe = session.on(event -> {
System.out.println("Event: " + event.getType());
});
// Subscribe to a specific event type
session.on(AssistantMessageEvent.class, msg -> {
System.out.println("Message: " + msg.getData().content());
});
session.on(SessionIdleEvent.class, idle -> {
System.out.println("Session is idle");
});
// Later, to unsubscribe:
unsubscribe.close();
4단계: 사용자 지정 도구 추가
이제 강력한 기능을 살펴보겠습니다. Copilot 사용자 지정 도구를 정의하여 코드를 호출할 수 있는 기능을 제공해 보겠습니다. 간단한 날씨 조회 도구를 만듭니다.
다음과 같이 index.ts를 업데이트합니다.
import { CopilotClient, defineTool } from "@github/copilot-sdk";
// Define a tool that Copilot can call
const getWeather = defineTool("get_weather", {
description: "Get the current weather for a city",
parameters: {
type: "object",
properties: {
city: { type: "string", description: "The city name" },
},
required: ["city"],
},
handler: async (args: { city: string }) => {
const { city } = args;
// In a real app, you'd call a weather API here
const conditions = ["sunny", "cloudy", "rainy", "partly cloudy"];
const temp = Math.floor(Math.random() * 30) + 50;
const condition = conditions[Math.floor(Math.random() * conditions.length)];
return { city, temperature: `${temp}°F`, condition };
},
});
const client = new CopilotClient();
const session = await client.createSession({
model: "gpt-4.1",
streaming: true,
tools: [getWeather],
});
session.on("assistant.message_delta", (event) => {
process.stdout.write(event.data.deltaContent);
});
session.on("session.idle", () => {
console.log(); // New line when done
});
await session.sendAndWait({
prompt: "What's the weather like in Seattle and Tokyo?",
});
await client.stop();
process.exit(0);
다음과 같이 main.py를 업데이트합니다.
import asyncio
import random
import sys
from copilot import CopilotClient
from copilot.session import PermissionHandler
from copilot.tools import define_tool
from copilot.generated.session_events import SessionEventType
from pydantic import BaseModel, Field
# Define the parameters for the tool using Pydantic
class GetWeatherParams(BaseModel):
city: str = Field(description="The name of the city to get weather for")
# Define a tool that Copilot can call
@define_tool(description="Get the current weather for a city")
async def get_weather(params: GetWeatherParams) -> dict:
city = params.city
# In a real app, you'd call a weather API here
conditions = ["sunny", "cloudy", "rainy", "partly cloudy"]
temp = random.randint(50, 80)
condition = random.choice(conditions)
return {"city": city, "temperature": f"{temp}°F", "condition": condition}
async def main():
client = CopilotClient()
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-4.1", streaming=True, tools=[get_weather])
def handle_event(event):
if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:
sys.stdout.write(event.data.delta_content)
sys.stdout.flush()
if event.type == SessionEventType.SESSION_IDLE:
print()
session.on(handle_event)
await session.send_and_wait("What's the weather like in Seattle and Tokyo?")
await client.stop()
asyncio.run(main())
다음과 같이 main.go를 업데이트합니다.
package main
import (
"context"
"fmt"
"log"
"math/rand"
"os"
copilot "github.com/github/copilot-sdk/go"
)
// Define the parameter type
type WeatherParams struct {
City string `json:"city" jsonschema:"The city name"`
}
// Define the return type
type WeatherResult struct {
City string `json:"city"`
Temperature string `json:"temperature"`
Condition string `json:"condition"`
}
func main() {
ctx := context.Background()
// Define a tool that Copilot can call
getWeather := copilot.DefineTool(
"get_weather",
"Get the current weather for a city",
func(params WeatherParams, inv copilot.ToolInvocation) (WeatherResult, error) {
// In a real app, you'd call a weather API here
conditions := []string{"sunny", "cloudy", "rainy", "partly cloudy"}
temp := rand.Intn(30) + 50
condition := conditions[rand.Intn(len(conditions))]
return WeatherResult{
City: params.City,
Temperature: fmt.Sprintf("%d°F", temp),
Condition: condition,
}, nil
},
)
client := copilot.NewClient(nil)
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
Model: "gpt-4.1",
Streaming: copilot.Bool(true),
Tools: []copilot.Tool{getWeather},
})
if err != nil {
log.Fatal(err)
}
session.On(func(event copilot.SessionEvent) {
switch d := event.Data.(type) {
case *copilot.AssistantMessageDeltaData:
fmt.Print(d.DeltaContent)
case *copilot.SessionIdleData:
_ = d
fmt.Println()
}
})
_, err = session.SendAndWait(ctx, copilot.MessageOptions{
Prompt: "What's the weather like in Seattle and Tokyo?",
})
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}
다음과 같이 src/main.rs를 업데이트합니다.
use std::io::{self, Write};
use std::sync::Arc;
use std::time::Duration;
use github_copilot_sdk::handler::ApproveAllHandler;
use github_copilot_sdk::tool::{JsonSchema, ToolHandlerRouter, define_tool};
use github_copilot_sdk::{Client, ClientOptions, MessageOptions, SessionConfig, ToolResult};
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
struct GetWeatherParams {
city: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Define a tool that Copilot can call
let router = ToolHandlerRouter::new(
vec![define_tool(
"get_weather",
"Get the current weather for a city",
|_inv, params: GetWeatherParams| async move {
Ok(ToolResult::Text(format!(
"{}: 62°F and sunny",
params.city
)))
},
)],
Arc::new(ApproveAllHandler),
);
let tools = router.tools();
let client = Client::start(ClientOptions::default()).await?;
let mut config = SessionConfig::default();
config.streaming = Some(true);
config.tools = Some(tools);
let session = client.create_session(config.with_handler(Arc::new(router))).await?;
let mut events = session.subscribe();
tokio::spawn(async move {
while let Ok(event) = events.recv().await {
match event.event_type.as_str() {
"assistant.message_delta" => {
if let Some(text) =
event.data.get("deltaContent").and_then(|value| value.as_str())
{
print!("{text}");
io::stdout().flush().ok();
}
}
"assistant.message" => println!(),
_ => {}
}
}
});
session
.send_and_wait(
MessageOptions::new("What's the weather like in Seattle and Tokyo?")
.with_wait_timeout(Duration::from_secs(120)),
)
.await?;
session.disconnect().await?;
client.stop().await?;
Ok(())
}
다음과 같이 Program.cs를 업데이트합니다.
using GitHub.Copilot;
using Microsoft.Extensions.AI;
using System.ComponentModel;
await using var client = new CopilotClient();
// Define a tool that Copilot can call
var getWeather = CopilotTool.DefineTool(
([Description("The city name")] string city) =>
{
// In a real app, you'd call a weather API here
var conditions = new[] { "sunny", "cloudy", "rainy", "partly cloudy" };
var temp = Random.Shared.Next(50, 80);
var condition = conditions[Random.Shared.Next(conditions.Length)];
return new { city, temperature = $"{temp}°F", condition };
},
factoryOptions: new AIFunctionFactoryOptions
{
Name = "get_weather",
Description = "Get the current weather for a city",
}
);
await using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-4.1",
OnPermissionRequest = PermissionHandler.ApproveAll,
Streaming = true,
Tools = [getWeather],
});
session.On<SessionEvent>(ev =>
{
if (ev is AssistantMessageDeltaEvent deltaEvent)
{
Console.Write(deltaEvent.Data.DeltaContent);
}
if (ev is SessionIdleEvent)
{
Console.WriteLine();
}
});
await session.SendAndWaitAsync(new MessageOptions
{
Prompt = "What's the weather like in Seattle and Tokyo?",
});
다음과 같이 HelloCopilot.java를 업데이트합니다.
import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
public class HelloCopilot {
public static void main(String[] args) throws Exception {
var random = new Random();
var conditions = List.of("sunny", "cloudy", "rainy", "partly cloudy");
// Define a tool that Copilot can call
var getWeather = ToolDefinition.create(
"get_weather",
"Get the current weather for a city",
Map.of(
"type", "object",
"properties", Map.of(
"city", Map.of("type", "string", "description", "The city name")
),
"required", List.of("city")
),
invocation -> {
var city = (String) invocation.getArguments().get("city");
var temp = random.nextInt(30) + 50;
var condition = conditions.get(random.nextInt(conditions.size()));
return CompletableFuture.completedFuture(Map.of(
"city", city,
"temperature", temp + "°F",
"condition", condition
));
}
);
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(
new SessionConfig()
.setModel("gpt-4.1")
.setStreaming(true)
.setTools(List.of(getWeather))
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
).get();
session.on(AssistantMessageDeltaEvent.class, delta -> {
System.out.print(delta.getData().deltaContent());
});
session.on(SessionIdleEvent.class, idle -> {
System.out.println();
});
session.sendAndWait(
new MessageOptions().setPrompt("What's the weather like in Seattle and Tokyo?")
).get();
client.stop().get();
}
}
}
실행하면 Copilot 도구를 호출하여 날씨 데이터를 가져와서 결과로 응답하는 것을 볼 수 있습니다.
5단계: 대화형 도우미 빌드
이 모든 것을 유용한 대화형 도우미로 합시다.
import { CopilotClient, defineTool } from "@github/copilot-sdk";
import * as readline from "readline";
const getWeather = defineTool("get_weather", {
description: "Get the current weather for a city",
parameters: {
type: "object",
properties: {
city: { type: "string", description: "The city name" },
},
required: ["city"],
},
handler: async ({ city }) => {
const conditions = ["sunny", "cloudy", "rainy", "partly cloudy"];
const temp = Math.floor(Math.random() * 30) + 50;
const condition = conditions[Math.floor(Math.random() * conditions.length)];
return { city, temperature: `${temp}°F`, condition };
},
});
const client = new CopilotClient();
const session = await client.createSession({
model: "gpt-4.1",
streaming: true,
tools: [getWeather],
});
session.on("assistant.message_delta", (event) => {
process.stdout.write(event.data.deltaContent);
});
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
console.log("🌤️ Weather Assistant (type 'exit' to quit)");
console.log(" Try: 'What's the weather in Paris?'\n");
const prompt = () => {
rl.question("You: ", async (input) => {
if (input.toLowerCase() === "exit") {
await client.stop();
rl.close();
return;
}
process.stdout.write("Assistant: ");
await session.sendAndWait({ prompt: input });
console.log("\n");
prompt();
});
};
prompt();
다음을 사용하여 실행합니다.
npx tsx weather-assistant.ts
weather_assistant.py을 만듭니다.
import asyncio
import random
import sys
from copilot import CopilotClient
from copilot.session import PermissionHandler
from copilot.tools import define_tool
from copilot.generated.session_events import SessionEventType
from pydantic import BaseModel, Field
class GetWeatherParams(BaseModel):
city: str = Field(description="The name of the city to get weather for")
@define_tool(description="Get the current weather for a city")
async def get_weather(params: GetWeatherParams) -> dict:
city = params.city
conditions = ["sunny", "cloudy", "rainy", "partly cloudy"]
temp = random.randint(50, 80)
condition = random.choice(conditions)
return {"city": city, "temperature": f"{temp}°F", "condition": condition}
async def main():
client = CopilotClient()
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-4.1", streaming=True, tools=[get_weather])
def handle_event(event):
if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:
sys.stdout.write(event.data.delta_content)
sys.stdout.flush()
session.on(handle_event)
print("🌤️ Weather Assistant (type 'exit' to quit)")
print(" Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'\n")
while True:
try:
user_input = input("You: ")
except EOFError:
break
if user_input.lower() == "exit":
break
sys.stdout.write("Assistant: ")
await session.send_and_wait(user_input)
print("\n")
await client.stop()
asyncio.run(main())
다음을 사용하여 실행합니다.
python weather_assistant.py
weather-assistant.go을 만듭니다.
package main
import (
"bufio"
"context"
"fmt"
"log"
"math/rand"
"os"
"strings"
copilot "github.com/github/copilot-sdk/go"
)
type WeatherParams struct {
City string `json:"city" jsonschema:"The city name"`
}
type WeatherResult struct {
City string `json:"city"`
Temperature string `json:"temperature"`
Condition string `json:"condition"`
}
func main() {
ctx := context.Background()
getWeather := copilot.DefineTool(
"get_weather",
"Get the current weather for a city",
func(params WeatherParams, inv copilot.ToolInvocation) (WeatherResult, error) {
conditions := []string{"sunny", "cloudy", "rainy", "partly cloudy"}
temp := rand.Intn(30) + 50
condition := conditions[rand.Intn(len(conditions))]
return WeatherResult{
City: params.City,
Temperature: fmt.Sprintf("%d°F", temp),
Condition: condition,
}, nil
},
)
client := copilot.NewClient(nil)
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
Model: "gpt-4.1",
Streaming: copilot.Bool(true),
Tools: []copilot.Tool{getWeather},
})
if err != nil {
log.Fatal(err)
}
session.On(func(event copilot.SessionEvent) {
switch d := event.Data.(type) {
case *copilot.AssistantMessageDeltaData:
fmt.Print(d.DeltaContent)
case *copilot.SessionIdleData:
_ = d
fmt.Println()
}
})
fmt.Println("🌤️ Weather Assistant (type 'exit' to quit)")
fmt.Println(" Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'\n")
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Print("You: ")
if !scanner.Scan() {
break
}
input := scanner.Text()
if strings.ToLower(input) == "exit" {
break
}
fmt.Print("Assistant: ")
_, err = session.SendAndWait(ctx, copilot.MessageOptions{Prompt: input})
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
break
}
fmt.Println()
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Input error: %v\n", err)
}
}
다음을 사용하여 실행합니다.
go run weather-assistant.go
src/main.rs을 만듭니다.
use std::io::{self, BufRead, Write};
use std::sync::Arc;
use std::time::Duration;
use github_copilot_sdk::handler::ApproveAllHandler;
use github_copilot_sdk::tool::{JsonSchema, ToolHandlerRouter, define_tool};
use github_copilot_sdk::{Client, ClientOptions, MessageOptions, SessionConfig, ToolResult};
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
struct GetWeatherParams {
city: String,
}
fn read_line() -> Option<String> {
let stdin = io::stdin();
let mut line = String::new();
stdin.lock().read_line(&mut line).ok()?;
if line.is_empty() {
return None;
}
Some(line.trim_end_matches(&['\n', '\r'][..]).to_string())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let router = ToolHandlerRouter::new(
vec![define_tool(
"get_weather",
"Get the current weather for a city",
|_inv, params: GetWeatherParams| async move {
Ok(ToolResult::Text(format!(
"{}: 62°F and sunny",
params.city
)))
},
)],
Arc::new(ApproveAllHandler),
);
let tools = router.tools();
let client = Client::start(ClientOptions::default()).await?;
let mut config = SessionConfig::default();
config.streaming = Some(true);
config.tools = Some(tools);
let session = client.create_session(config.with_handler(Arc::new(router))).await?;
let mut events = session.subscribe();
tokio::spawn(async move {
while let Ok(event) = events.recv().await {
match event.event_type.as_str() {
"assistant.message_delta" => {
if let Some(text) =
event.data.get("deltaContent").and_then(|value| value.as_str())
{
print!("{text}");
io::stdout().flush().ok();
}
}
"assistant.message" => println!(),
_ => {}
}
}
});
println!("Weather Assistant (type 'exit' to quit)");
println!("Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'\n");
loop {
print!("You: ");
io::stdout().flush().ok();
let Some(input) = read_line() else { break };
if input.eq_ignore_ascii_case("exit") {
break;
}
print!("Assistant: ");
io::stdout().flush().ok();
session
.send_and_wait(MessageOptions::new(input).with_wait_timeout(Duration::from_secs(120)))
.await?;
println!();
}
session.disconnect().await?;
client.stop().await?;
Ok(())
}
다음을 사용하여 실행합니다.
cargo run
새 콘솔 프로젝트를 만들고 Program.cs을 업데이트합니다.
using GitHub.Copilot;
using Microsoft.Extensions.AI;
using System.ComponentModel;
// Define the weather tool
var getWeather = CopilotTool.DefineTool(
([Description("The city name")] string city) =>
{
var conditions = new[] { "sunny", "cloudy", "rainy", "partly cloudy" };
var temp = Random.Shared.Next(50, 80);
var condition = conditions[Random.Shared.Next(conditions.Length)];
return new { city, temperature = $"{temp}°F", condition };
},
factoryOptions: new AIFunctionFactoryOptions
{
Name = "get_weather",
Description = "Get the current weather for a city",
});
await using var client = new CopilotClient();
await using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-4.1",
OnPermissionRequest = PermissionHandler.ApproveAll,
Streaming = true,
Tools = [getWeather]
});
// Listen for response chunks
session.On<SessionEvent>(ev =>
{
if (ev is AssistantMessageDeltaEvent deltaEvent)
{
Console.Write(deltaEvent.Data.DeltaContent);
}
if (ev is SessionIdleEvent)
{
Console.WriteLine();
}
});
Console.WriteLine("🌤️ Weather Assistant (type 'exit' to quit)");
Console.WriteLine(" Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'\n");
while (true)
{
Console.Write("You: ");
var input = Console.ReadLine();
if (string.IsNullOrEmpty(input) || input.Equals("exit", StringComparison.OrdinalIgnoreCase))
{
break;
}
Console.Write("Assistant: ");
await session.SendAndWaitAsync(new MessageOptions { Prompt = input });
Console.WriteLine("\n");
}
다음을 사용하여 실행합니다.
dotnet run
WeatherAssistant.java을 만듭니다.
import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.CompletableFuture;
public class WeatherAssistant {
public static void main(String[] args) throws Exception {
var random = new Random();
var conditions = List.of("sunny", "cloudy", "rainy", "partly cloudy");
var getWeather = ToolDefinition.create(
"get_weather",
"Get the current weather for a city",
Map.of(
"type", "object",
"properties", Map.of(
"city", Map.of("type", "string", "description", "The city name")
),
"required", List.of("city")
),
invocation -> {
var city = (String) invocation.getArguments().get("city");
var temp = random.nextInt(30) + 50;
var condition = conditions.get(random.nextInt(conditions.size()));
return CompletableFuture.completedFuture(Map.of(
"city", city,
"temperature", temp + "°F",
"condition", condition
));
}
);
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(
new SessionConfig()
.setModel("gpt-4.1")
.setStreaming(true)
.setOnPermissionRequest(request ->
CompletableFuture.completedFuture(PermissionDecision.allow())
)
.setTools(List.of(getWeather))
).get();
session.on(AssistantMessageDeltaEvent.class, delta -> {
System.out.print(delta.getData().deltaContent());
});
session.on(SessionIdleEvent.class, idle -> {
System.out.println();
});
System.out.println("🌤️ Weather Assistant (type 'exit' to quit)");
System.out.println(" Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'\n");
var scanner = new Scanner(System.in);
while (true) {
System.out.print("You: ");
if (!scanner.hasNextLine()) break;
var input = scanner.nextLine();
if (input.equalsIgnoreCase("exit")) break;
System.out.print("Assistant: ");
session.sendAndWait(
new MessageOptions().setPrompt(input)
).get();
System.out.println("\n");
}
client.stop().get();
}
}
}
다음을 사용하여 실행합니다.
javac -cp copilot-sdk.jar WeatherAssistant.java && java -cp .:copilot-sdk.jar WeatherAssistant
세션 예제:
🌤️ Weather Assistant (type 'exit' to quit)
Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'
You: What's the weather in Seattle?
Assistant: Let me check the weather for Seattle...
It's currently 62°F and cloudy in Seattle.
You: How about Tokyo and London?
Assistant: I'll check both cities for you:
- Tokyo: 75°F and sunny
- London: 58°F and rainy
You: exit
Copilot 호출할 수 있는 사용자 지정 도구를 사용하여 도우미를 빌드했습니다.
도구 작동 방식
도구를 정의할 때 Copilot에 다음과 같이 알려주는 것입니다:
- 도구가 수행하는 작업 (설명)
- 필요한 매개 변수 (스키마)
- 실행할 코드 (처리기)
Copilot 사용자의 질문에 따라 도구를 호출할 시기를 결정합니다. 이 작업을 수행하는 경우:
- Copilot 매개 변수를 사용하여 도구 호출 요청을 보냅니다.
- SDK는 처리기 함수를 실행합니다.
- 결과는 Copilot 다시 전송됩니다.
- Copilot 결과를 응답에 통합합니다.
다음 단계는 무엇인가요?
이제 기본 사항을 살펴보았으므로 다음과 같은 더 강력한 기능을 살펴볼 수 있습니다.
MCP 서버에 연결
MCP(모델 컨텍스트 프로토콜) 서버는 미리 빌드된 도구를 제공합니다. GitHub MCP 서버에 연결하여 리포지토리, 문제 및 끌어오기 요청에 Copilot 액세스 권한을 부여합니다.
const session = await client.createSession({
mcpServers: {
github: {
type: "http",
url: "https://api.githubcopilot.com/mcp/",
},
},
});
📖 ** Using MCP servers with the GitHub Copilot SDK** - 로컬 서버와 원격 서버, 모든 구성 옵션 및 문제 해결에 대해 알아봅니다.
사용자 지정 에이전트 만들기
특정 작업에 대한 특수한 AI 페르소나를 정의합니다.
const session = await client.createSession({
customAgents: [{
name: "pr-reviewer",
displayName: "PR Reviewer",
description: "Reviews pull requests for best practices",
prompt: "You are an expert code reviewer. Focus on security, performance, and maintainability.",
}],
});
팁
세션 구성에서 이 에이전트를 처음부터 미리 선택하도록 설정할 agent: "pr-reviewer" 수도 있습니다. 자세한 내용은 사용자 정의 에이전트 및 하위 에이전트 오케스트레이션 을 참조하세요.
시스템 메시지 사용자 지정
지침을 추가하여 AI의 동작 및 성격을 제어합니다.
const session = await client.createSession({
systemMessage: {
content: "You are a helpful assistant for our engineering team. Always be concise.",
},
});
더 세밀하게 제어하려면 나머지 부분은 유지한 채 시스템 프롬프트의 개별 섹션을 재정의할 수 있도록 mode: "customize"을 사용하세요.
const session = await client.createSession({
systemMessage: {
mode: "customize",
sections: {
tone: { action: "replace", content: "Respond in a warm, professional tone. Be thorough in explanations." },
code_change_rules: { action: "remove" },
guidelines: { action: "append", content: "\n* Always cite data sources" },
},
content: "Focus on financial analysis and reporting.",
},
});
사용 가능한 섹션 ID: identity,, tone, tool_efficiency``environment_context, code_change_rules``guidelines, safety``tool_instructions, . custom_instructions``runtime_instructions``last_instructions
각 재정의는 네 가지 작업(replace, remove, append, prepend)을 지원합니다. 알 수 없는 섹션 ID는 문제없이 처리됩니다. 내용은 추가 지침에 덧붙여지고 경고가 발생합니다. 알 수 없는 섹션의 remove는 별도 경고 없이 무시됩니다.
TypeScript 예제는 언어별 SDK README를 참조하세요. Python, Go, Rust, Java 및 C#.
외부 CLI 서버에 연결
기본적으로 SDK는 필요에 따라 CLI를 시작하고 중지하여 Copilot CLI 프로세스 수명 주기를 자동으로 관리합니다. 그러나 서버 모드에서 별도로 CLI를 실행하고 SDK를 연결할 수도 있습니다. 이 기능은 다음과 같은 경우에 유용할 수 있습니다.
- 디버깅: 로그를 검사하기 위해 SDK 다시 시작 간에 CLI를 계속 실행합니다.
- 리소스 공유: 여러 SDK 클라이언트가 동일한 CLI 서버에 연결할 수 있습니다.
- 개발: 사용자 지정 설정 또는 다른 환경에서 CLI 실행
서버 모드에서 CLI 실행
플래그를 사용하여 서버 모드에서 CLI를 --headless 시작하고 필요에 따라 포트를 지정합니다.
copilot --headless --port 4321
포트를 지정하지 않으면 CLI에서 사용 가능한 임의 포트를 선택합니다.
기본적으로 헤드리스 서버는 루프백(127.0.0.1)의 연결만 허용하므로 SDK는 동일한 컴퓨터에서 실행되어야 합니다. 다른 호스트(예: 컨테이너 또는 별도의 서버에서 CLI를 실행하는 경우)의 연결을 허용하려면 다음을 사용하여 루프백이 아닌 주소 --host에 바인딩합니다.
# Listen on all interfaces
copilot --headless --host 0.0.0.0 --port 4321
경고
비 루프백 주소에 헤드리스 서버를 노출하면 해당 주소로 라우팅할 수 있는 모든 사용자가 연결할 수 있습니다. 네트워크 컨트롤(방화벽, 프라이빗 네트워크, 역방향 프록시) 및 사용자 환경에 적합한 인증과 페어링합니다.
외부 서버에 SDK 연결
CLI가 서버 모드에서 실행되면 "cli url" 옵션을 사용하여 연결하도록 SDK 클라이언트를 구성합니다.
import { CopilotClient, approveAll } from "@github/copilot-sdk";
const client = new CopilotClient({
cliUrl: "localhost:4321"
});
// Use the client normally
const session = await client.createSession({ onPermissionRequest: approveAll });
// ...
from copilot import CopilotClient, RuntimeConnection
from copilot.session import PermissionHandler
client = CopilotClient(connection=RuntimeConnection.for_uri("localhost:4321"))
await client.start()
# Use the client normally
session = await client.create_session(on_permission_request=PermissionHandler.approve_all)
# ...
package main
import (
"context"
"log"
copilot "github.com/github/copilot-sdk/go"
)
func main() {
ctx := context.Background()
client := copilot.NewClient(&copilot.ClientOptions{
Connection: copilot.UriConnection{URL: "localhost:4321"},
})
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
// Use the client normally
_, _ = client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
}
import copilot "github.com/github/copilot-sdk/go"
client := copilot.NewClient(&copilot.ClientOptions{
Connection: copilot.UriConnection{URL: "localhost:4321"},
})
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
// Use the client normally
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
// ...
use std::sync::Arc;
use github_copilot_sdk::handler::ApproveAllHandler;
use github_copilot_sdk::{Client, ClientOptions, SessionConfig, Transport};
let mut options = ClientOptions::default();
options.transport = Transport::External {
host: "localhost".to_string(),
port: 4321,
};
let client = Client::start(options).await?;
// Use the client normally
let session = client
.create_session(SessionConfig::default().with_handler(Arc::new(ApproveAllHandler)))
.await?;
// ...
using GitHub.Copilot;
using var client = new CopilotClient(new CopilotClientOptions
{
Connection = RuntimeConnection.ForUri("localhost:4321"),
});
// Use the client normally
await using var session = await client.CreateSessionAsync(new()
{
OnPermissionRequest = PermissionHandler.ApproveAll
});
// ...
import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.json.*;
var client = new CopilotClient(
new CopilotClientOptions().setCliUrl("localhost:4321")
);
client.start().get();
// Use the client normally
var session = client.createSession(
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
).get();
// ...
참고: /Go가 cli_url 제공되거나 Rust가 사용되는 / 경우cliUrl``UriConnection``Transport::ExternalSDK는 CLI 프로세스를 생성하거나 관리하지 않습니다. 지정된 URL의 기존 서버에만 연결됩니다.
원격 분석 및 관찰 가능성
Copilot SDK는 분산 추적을 위해 OpenTelemetry 지원합니다.
telemetry CLI 프로세스에서 추적 내보내기 및 SDK와 CLI 간의 자동 W3C 추적 컨텍스트 전파를 사용하도록 클라이언트에 구성을 제공합니다.
원격 분석 사용
클라이언트를 생성할 때 telemetry(또는 Telemetry) 구성 객체를 전달하세요. 이는 옵트인입니다. 별도의 "사용" 플래그가 필요하지 않습니다.
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient({
telemetry: {
otlpEndpoint: "http://localhost:4318",
},
});
선택적 피어 종속성: @opentelemetry/api
from copilot import CopilotClient, CopilotClientOptions
client = CopilotClient(CopilotClientOptions(
telemetry={
"otlp_endpoint": "http://localhost:4318",
},
))
원격 분석 추가 기능을 포함하여 설치: pip install copilot-sdk[telemetry] (opentelemetry-api 제공)
client, err := copilot.NewClient(copilot.ClientOptions{
Telemetry: &copilot.TelemetryConfig{
OTLPEndpoint: "http://localhost:4318",
},
})
종속성: go.opentelemetry.io/otel
use github_copilot_sdk::{Client, ClientOptions, OtelExporterType, TelemetryConfig};
let mut options = ClientOptions::default();
options.telemetry = Some(
TelemetryConfig::new()
.with_exporter_type(OtelExporterType::OtlpHttp)
.with_otlp_endpoint("http://localhost:4318"),
);
let client = Client::start(options).await?;
추가 종속성이 없습니다. SDK는 생성된 CLI 프로세스에 대한 원격 분석 환경 변수를 삽입합니다.
var client = new CopilotClient(new CopilotClientOptions
{
Telemetry = new TelemetryConfig
{
OtlpEndpoint = "http://localhost:4318",
},
});
추가 종속성이 없습니다. 기본 제공 System.Diagnostics.Activity을 사용합니다.
import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.json.*;
var client = new CopilotClient(new CopilotClientOptions()
.setTelemetry(new TelemetryConfig()
.setOtlpEndpoint("http://localhost:4318")));
종속성: io.opentelemetry:opentelemetry-api
'TelemetryConfig' 설정 옵션
| Option | Node.js | Python | Go | 러스트 | Java | .NET | Description |
|---|---|---|---|---|---|---|---|
| OTLP 엔드포인트 | otlpEndpoint | otlp_endpoint | OTLPEndpoint | otlp_endpoint | otlpEndpoint | OtlpEndpoint | OTLP HTTP 엔드포인트 URL |
| 파일 경로 | filePath | file_path | FilePath | file_path | filePath | FilePath | JSON 줄 추적 출력에 대한 파일 경로 |
| 내보내기 형식 | exporterType | exporter_type | ExporterType | exporter_type | exporterType | ExporterType | |
"otlp-http" 또는 "file" | |||||||
| 원본 이름 | sourceName | source_name | SourceName | source_name | sourceName | SourceName | 계측 범위 이름 |
| 콘텐츠 캡처 | captureContent | capture_content | CaptureContent | capture_content | captureContent | CaptureContent | 메시지 콘텐츠를 캡처할지 여부 |
파일 내보내기
OTLP 엔드포인트 대신 로컬 파일에 추적을 쓰려면 다음을 수행합니다.
const client = new CopilotClient({
telemetry: {
filePath: "./traces.jsonl",
exporterType: "file",
},
});
추적 컨텍스트 전파
추적 컨텍스트는 자동으로 전파되며 수동 계측이 필요하지 않습니다.
- SDK → CLI: 현재 span/activity의
traceparent및tracestate헤더가session.create,session.resume, 그리고session.sendRPC 호출에 포함됩니다. - CLI → SDK: CLI가 도구 처리기를 호출하면 CLI 범위의 추적 컨텍스트가 전파되므로 도구 코드가 올바른 부모 범위에서 실행됩니다.
📖 ** 코필로트 SDK용 OpenTelemetry 계측** - TelemetryConfig 옵션, 추적 컨텍스트 전파 및 언어별 종속성입니다.
자세히 알아보기
- 인증 - GitHub OAuth, 환경 변수 및 BYOK
- BYOK (bring your own key) - Azure AI Foundry, OpenAI 등에서 고유한 API 키를 사용합니다.
- Node.js SDK 참조
- Python SDK 참조
- Go SDK 참조
- Rust SDK 참조
- .NET SDK 참조
- Java SDK 참조
- Using MCP servers with the GitHub Copilot SDK - 모델 컨텍스트 프로토콜을 통해 외부 도구 통합
- GitHub MCP 서버 설명서
- MCP 서버 디렉터리 - 더 많은 MCP 서버 탐색
- 코필로트 SDK용 OpenTelemetry 계측 - TelemetryConfig, 추적 컨텍스트 전파 및 언어별 종속성
잘 했어요! GitHub Copilot SDK의 핵심 개념을 알아보았습니다.
- ✅ 클라이언트 및 세션 만들기
- ✅ 메시지 보내기 및 응답 받기
- ✅ 실시간 출력을 위한 스트리밍
- ✅ Copilot 호출할 수 있는 사용자 지정 도구 정의
이제 멋진 것을 만들어 보세요! 🚀