# API를 통해 Copilot 클라우드 에이전트 사용

REST API를 사용하여 프로그래밍 방식으로 작업을 시작하고 관리할 Copilot cloud agent 수 있습니다.

에이전트 작업 API를 사용하여 고유한 도구 및 워크플로에 통합 cloud agent 할 수 있습니다. 예를 들어 새 작업을 시작하거나, 기존 작업을 나열하거나, 작업의 상태를 확인할 수 있습니다.

또한 이슈에 대한 REST 및 GraphQL API를 사용하여 이슈를 Copilot에 할당할 수 있습니다.

## 에이전트 작업 API 사용

> \[!NOTE]
> 에이전트 작업 API는 공개 미리 보기 상태에 있으며 변경될 수 있습니다.

### 인증

에이전트 작업 API는 사용자-서버 토큰만 지원합니다.
personal access token를 사용하거나, OAuth app 토큰 또는 GitHub App 사용자-서버 토큰을 사용하여 인증할 수 있습니다.

설치 액세스 토큰과 같은 GitHub App 서버-서버 토큰은 지원되지 않습니다.

### API를 통해 작업 시작

새로운 cloud agent 작업을 시작하려면 `POST`에 `/agents/repos/{owner}/{repo}/tasks` 요청을 보냅니다. 유일한 필수 매개 변수는 `prompt`에이전트에 대한 프롬프트인 매개 변수입니다.

```shell copy
curl -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  -H "Authorization: Bearer YOUR-TOKEN" \
  https://api.github.com/agents/repos/OWNER/REPO/tasks \
  -d '{
    "prompt": "Fix the login button on the homepage",
    "base_ref": "main"
  }'
```

다음 자리 표시자 값을 바꿉다.

* `YOUR-TOKEN`: personal access token 또는 GitHub App 사용자-서버 토큰입니다.
* `OWNER`: 리포지토리의 계정 소유자입니다.
* `REPO`: 리포지토리의 이름입니다.

요청 본문에 다음 선택적 매개 변수를 포함할 수도 있습니다.

* `base_ref`: 새 브랜치 및 풀 리퀘스트에 대한 기본 브랜치입니다.
* `model`: 작업에 사용할 AI 모델입니다. 생략하면 auto model selection 사용됩니다. 지원되는 모델에 대한 자세한 내용은 [에이전트 작업에 대한 REST API 엔드포인트](/ko/rest/agent-tasks/agent-tasks)을 참조하세요.
* `create_pull_request`: 작업에 대한 끌어오기 요청을 생성할지 여부를 결정하는 불리언입니다.

### 작업 목록

특정 리포지토리 또는 액세스 권한이 있는 모든 리포지토리에 대한 작업을 나열할 수 있습니다.

특정 리포지토리에 대한 작업을 나열하려면 다음을 수행합니다.

```shell copy
curl -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  -H "Authorization: Bearer YOUR-TOKEN" \
  https://api.github.com/agents/repos/OWNER/REPO/tasks
```

모든 리포지토리에서 작업을 나열하려면 다음을 수행합니다.

```shell copy
curl -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  -H "Authorization: Bearer YOUR-TOKEN" \
  https://api.github.com/agents/tasks
```

### 작업의 상태 확인

특정 작업의 상태를 확인하려면 작업 ID를 사용하여 `GET` 요청을 보냅니다.

```shell copy
curl -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  -H "Authorization: Bearer YOUR-TOKEN" \
  https://api.github.com/agents/repos/OWNER/REPO/tasks/TASK-ID
```

`TASK-ID`를 확인할 작업의 ID로 바꿉니다. 작업을 만들거나 작업을 나열할 때 응답에서 이 ID를 가져올 수 있습니다. 응답에는 작업의 현재 `state`항목이 포함되며, `queued``in_progress``completed``failed``idle``waiting_for_user``timed_out`다음 중 `cancelled`하나일 수 있습니다.

## 이슈 API 사용하기

> \[!NOTE]
> 이 기능은 공개 미리 보기에서 사용 중이며 변경될 수 있습니다.

GraphQL API 또는 REST API를 사용하여 Copilot에 문제를 할당할 수 있습니다. 두 API 모두 선택적 에이전트 할당 입력을 지원하여 작업을 사용자 지정합니다.

| GraphQL 매개 변수        | REST 매개 변수            | Description          |
| -------------------- | --------------------- | -------------------- |
| `targetRepositoryId` | `target_repo`         |                      |
| Copilot가 작동할 리포지토리   |                       |                      |
| `baseRef`            | `base_branch`         | Copilot가 분기될 지점      |
| `customInstructions` | `custom_instructions` |                      |
| Copilot에 대한 추가 지침    |                       |                      |
| `customAgent`        | `custom_agent`        | 작업에 사용할 custom agent |
| `model`              | `model`               | 사용할 모델 Copilot       |

### GraphQL API 사용

> \[!NOTE]
> `GraphQL-Features` 헤더에 값 `issues_copilot_assignment_api_support` 및 `coding_agent_model_selection`을 포함해야 합니다.

다음 GraphQL 변형을 사용하여 문제를 할당할 Copilot수 있습니다.

* [`updateIssue`](/ko/graphql/reference/issues#mutation-updateissue)
* [`createIssue`](/ko/graphql/reference/issues#mutation-createissue)
* [`addAssigneesToAssignable`](/ko/graphql/reference/issues#mutation-addassigneestoassignable)
* [`replaceActorsForAssignable`](/ko/graphql/reference/issues#mutation-replaceactorsforassignable)

#### 새 이슈 만들기 및 할당

1. 사용자 토큰(예: 사용자-서버 토큰)을 사용하여 API personal access tokenGitHub App 로 인증하고 있는지 확인합니다.

   > \[!NOTE]
   > 사용하는 fine-grained personal access token가 있는 경우, Copilot을(를) 문제에 할당하려면 다음 권한이 필요합니다.
   >
   > * 메타데이터에 대한 읽기 액세스
   > * 작업, 콘텐츠, 문제 및 끌어오기 요청에 대한 읽기 및 쓰기 접근 권한.
   >
   > 만약 personal access token (classic)를 사용하려면 문제에 `repo`를 할당하기 위해 Copilot 범위가 필요합니다.

2. 리포지토리의 Copilot cloud agent가 GraphQL API에 `suggestedActors`를 포함하는지 확인하여 리포지토리에서 Copilot가 사용 설정되어 있는지 검증하십시오.
   `octo-org` 를 리포지토리 소유자로, `octo-repo` 를 리포지토리 이름으로 변경합니다.

   ```graphql copy
   query {
     repository(owner: "octo-org", name: "octo-repo") {
       suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
         nodes {
           login
           __typename

           ... on Bot {
             id
           }

           ... on User {
             id
           }
         }
       }
     }
   }
   ```

   리포지토리 및 사용자에 대해 Copilot cloud agent가 사용 설정되어 있는 경우, 쿼리에서 반환된 첫 번째 노드는 `login` 값으로 `copilot-swe-agent`를 가집니다.

3. 이 로그인에 대한 `id` 값을 기록해 둡니다.

4. 이슈를 생성하려는 리포지토리의 GraphQL 전역 ID를 가져온 다음, `octo-org` 를 리포지토리 소유자로, `octo-repo` 를 리포지토리 이름으로 변경합니다.

   ```graphql copy
   query {
     repository(owner: "octo-org", name: "octo-repo") {
       id
     }
   }
   ```

5. `createIssue` 변형을 통해 이슈를 생성합니다.
   `REPOSITORY_ID`는 이전 단계에서 반환된 ID로, `BOT_ID`는 그보다 앞 단계에서 반한된 ID로 바꿉니다. 필요에 따라 입력을 `agentAssignment` 포함하여 작업을 사용자 지정할 수 있습니다.

   ```shell copy
   gh api graphql -f query='mutation {
     createIssue(input: {
       repositoryId: "REPOSITORY_ID",
       title: "Implement comprehensive unit tests",
       body: "DETAILS",
       assigneeIds: ["BOT_ID"],
       agentAssignment: {
         targetRepositoryId: "REPOSITORY_ID",
         baseRef: "main",
         customInstructions: "Add comprehensive test coverage",
         customAgent: "",
         model: ""
       }
     }) {
       issue {
         id
         title
         assignees(first: 10) {
           nodes {
             login
           }
         }
       }
     }
   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
   ```

#### 기존 이슈 할당

1. 사용자 토큰(예: 사용자-서버 토큰)을 사용하여 API personal access tokenGitHub App 로 인증하고 있는지 확인합니다.

2. 리포지토리의 Copilot cloud agent가 GraphQL API에 `suggestedActors`를 포함하는지 확인하여 리포지토리에서 Copilot가 사용 설정되어 있는지 검증하십시오.
   `octo-org` 를 리포지토리 소유자로, `octo-repo` 를 리포지토리 이름으로 변경합니다.

   ```graphql copy
   query {
     repository(owner: "monalisa", name: "octocat") {
       suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
         nodes {
           login
           __typename

           ... on Bot {
             id
           }

           ... on User {
             id
           }
         }
       }
     }
   }
   ```

   리포지토리 및 사용자에 대해 Copilot cloud agent가 사용 설정되어 있는 경우, 쿼리에서 반환된 첫 번째 노드는 `login` 값으로 `copilot-swe-agent`를 가집니다.

3. 할당하려는 문제의 GraphQL 전역 ID를 가져와 Copilot를 리포지토리 소유자로, `monalisa`를 이름으로, `octocat`를 문제 번호로 바꾸세요.

   ```graphql copy
   query {
     repository(owner: "monalisa", name: "octocat") {
       issue(number: 9000) {
         id
         title
       }
     }
   }
   ```

4. 기존 문제를 Copilot에게 `replaceActorsForAssignable` 변형을 사용하여 할당합니다. 이전 단계에서 반환된 ID로 `ISSUE_ID`을(를), 그 전 단계에서 반환된 ID로 `BOT_ID`을(를), 리포지토리 ID로 `REPOSITORY_ID`을(를) 바꿉니다. 필요에 따라 입력을 `agentAssignment` 포함하여 작업을 사용자 지정할 수 있습니다.

   ```shell copy
   gh api graphql -f query='mutation {
     replaceActorsForAssignable(input: {
       assignableId: "ISSUE_ID",
       actorIds: ["BOT_ID"],
       agentAssignment: {
         targetRepositoryId: "REPOSITORY_ID",
         baseRef: "main",
         customInstructions: "Fix the reported bug",
         customAgent: "",
         model: ""
       }
     }) {
       assignable {
         ... on Issue {
           id
           title
           assignees(first: 10) {
             nodes {
               login
             }
           }
         }
       }
     }
   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
   ```

5. 또는 `updateIssue` 변경 메서드를 사용하여 기존 문제를 업데이트하고 Copilot에 할당할 수 있습니다. 문제 ID로 `ISSUE_ID`를 바꾸고, 봇 ID로 `BOT_ID`를 바꾸십시오.

   ```shell copy
   gh api graphql -f query='mutation {
     updateIssue(input: {
       id: "ISSUE_ID",
       assigneeIds: ["BOT_ID"],
       agentAssignment: {
         targetRepositoryId: "REPOSITORY_ID",
         baseRef: "main",
         customInstructions: "Update feature implementation",
         customAgent: "",
         model: ""
       }
     }) {
       issue {
         id
         title
         assignees(first: 10) {
           nodes {
             login
           }
         }
       }
     }
   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
   ```

6. 기존 문제에 다른 담당자를 유지하면서 `addAssigneesToAssignable` 변경을 사용하여 Copilot를 추가할 수도 있습니다. 문제 ID로 `ISSUE_ID`를 바꾸고, 봇 ID로 `BOT_ID`를 바꾸십시오.

   ```shell copy
   gh api graphql -f query='mutation {
     addAssigneesToAssignable(input: {
       assignableId: "ISSUE_ID",
       assigneeIds: ["BOT_ID"],
       agentAssignment: {
         targetRepositoryId: "REPOSITORY_ID",
         baseRef: "main",
         customInstructions: "Collaborate on this task",
         customAgent: "",
         model: ""
       }
     }) {
       assignable {
         ... on Issue {
           id
           title
           assignees(first: 10) {
             nodes {
               login
             }
           }
         }
       }
     }
   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
   ```

### REST API 사용

다음 REST API 엔드포인트를 사용하여 문제를 할당할 Copilot수 있습니다.

* [문제에 할당자 추가](/ko/rest/issues/assignees#add-assignees-to-an-issue)
* [문제 만들기](/ko/rest/issues/issues#create-an-issue)
* [문제 업데이트](/ko/rest/issues/issues#update-an-issue)

#### 기존 문제에 담당자 추가

```shell copy
gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/OWNER/REPO/issues/ISSUE_NUMBER/assignees \
  --input - <<< '{
  "assignees": ["copilot-swe-agent[bot]"],
  "agent_assignment": {
    "target_repo": "OWNER/REPO",
    "base_branch": "main",
    "custom_instructions": "",
    "custom_agent": "",
    "model": ""
  }
}'
```

#### 새 문제 만들기

```shell copy
gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/OWNER/REPO/issues \
  --input - <<< '{
  "title": "Issue title",
  "body": "Issue description.",
  "assignees": ["copilot-swe-agent[bot]"],
  "agent_assignment": {
    "target_repo": "OWNER/REPO",
    "base_branch": "main",
    "custom_instructions": "",
    "custom_agent": "",
    "model": ""
  }
}'
```

#### 기존 문제 업데이트

```shell copy
gh api \
  --method PATCH \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/OWNER/REPO/issues/ISSUE_NUMBER \
  --input - <<< '{
  "assignees": ["copilot-swe-agent[bot]"],
  "agent_assignment": {
    "target_repo": "OWNER/REPO",
    "base_branch": "main",
    "custom_instructions": "",
    "custom_agent": "",
    "model": ""
  }
}'
```

## 추가 읽기

* [에이전트 작업에 대한 REST API 엔드포인트](/ko/rest/agent-tasks/agent-tasks)
* [GitHub Copilot 클라우드 에이전트 정보](/ko/copilot/concepts/agents/cloud-agent/about-cloud-agent)
* [GitHub Copilot 세션 시작](/ko/copilot/how-tos/use-copilot-agents/cloud-agent/start-copilot-sessions)