{"meta":{"title":"API を使用してCopilotクラウドエージェントを利用する","intro":"REST API を使用して、 Copilot cloud agent タスクをプログラムで開始および管理できます。","product":"GitHub Copilot","breadcrumbs":[{"href":"/ja/copilot","title":"GitHub Copilot"},{"href":"/ja/copilot/how-tos","title":"方法"},{"href":"/ja/copilot/how-tos/use-copilot-agents","title":"Copilot エージェントを使用する"},{"href":"/ja/copilot/how-tos/use-copilot-agents/cloud-agent","title":"Cloud agent"},{"href":"/ja/copilot/how-tos/use-copilot-agents/cloud-agent/use-cloud-agent-via-the-api","title":"API を使用してクラウド エージェントを使用する"}],"documentType":"article"},"body":"# API を使用してCopilotクラウドエージェントを利用する\n\nREST API を使用して、 Copilot cloud agent タスクをプログラムで開始および管理できます。\n\nエージェント タスク API を使用して、 cloud agent を独自のツールとワークフローに統合できます。 たとえば、新しいタスクを開始したり、既存のタスクを一覧表示したり、タスクの状態を確認したりできます。\n\nさらに、REST API と GraphQL API を使用して問題を Copilotに割り当てることができます。\n\n## エージェント タスク API の使用\n\n> \\[!NOTE]\n> エージェント タスク API は パブリック プレビュー であり、変更される可能性があります。\n\n### 認証\n\nエージェント タスク API では、ユーザーからサーバーへのトークンのみがサポートされます。\npersonal access token、OAuth app トークン、またはGitHub Appユーザーからサーバーへのトークンを使用して認証できます。\n\nGitHub Appインストール アクセス トークンなどのサーバー間トークンはサポートされていません。\n\n### API を使用してタスクを開始する\n\n新しいcloud agent タスクを開始するには、`POST`に`/agents/repos/{owner}/{repo}/tasks`要求を送信します。 必須のパラメーターは `prompt` のみです。これはエージェントのプロンプトです。\n\n```shell copy\ncurl -X POST \\\n  -H \"Accept: application/vnd.github+json\" \\\n  -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n  -H \"Authorization: Bearer YOUR-TOKEN\" \\\n  https://api.github.com/agents/repos/OWNER/REPO/tasks \\\n  -d '{\n    \"prompt\": \"Fix the login button on the homepage\",\n    \"base_ref\": \"main\"\n  }'\n```\n\n次のプレースホルダー値を置き換えます。\n\n* `YOUR-TOKEN`: personal access token または GitHub App ユーザーからサーバーへのトークン。\n* `OWNER`: リポジトリのアカウント所有者。\n* `REPO`: リポジトリの名前。\n\n要求本文には、次の省略可能なパラメーターを含めることもできます。\n\n* ```\n            `base_ref`: 新しい分岐とプル要求のベース分岐。\n  ```\n* `model`: タスクに使用する AI モデル。 省略した場合、auto model selection が使われます。 サポートされているモデルの詳細については、 [AUTOTITLE を](/ja/rest/agent-tasks/agent-tasks)参照してください。\n* `create_pull_request`: タスクのプル要求を作成するかどうかを決定するブール値。\n\n### タスクの一覧表示\n\n特定のリポジトリまたはアクセス権を持つすべてのリポジトリのタスクを一覧表示できます。\n\n特定のリポジトリのタスクを一覧表示するには:\n\n```shell copy\ncurl -H \"Accept: application/vnd.github+json\" \\\n  -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n  -H \"Authorization: Bearer YOUR-TOKEN\" \\\n  https://api.github.com/agents/repos/OWNER/REPO/tasks\n```\n\nすべてのリポジトリのタスクを一覧表示するには:\n\n```shell copy\ncurl -H \"Accept: application/vnd.github+json\" \\\n  -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n  -H \"Authorization: Bearer YOUR-TOKEN\" \\\n  https://api.github.com/agents/tasks\n```\n\n### タスクの状態の確認\n\n特定のタスクの状態を確認するには、タスク ID を使用して `GET` 要求を送信します。\n\n```shell copy\ncurl -H \"Accept: application/vnd.github+json\" \\\n  -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n  -H \"Authorization: Bearer YOUR-TOKEN\" \\\n  https://api.github.com/agents/repos/OWNER/REPO/tasks/TASK-ID\n```\n\n`TASK-ID`を、確認するタスクの ID に置き換えます。 この ID は、タスクまたはリスト タスクを作成するときに応答から取得できます。 応答には、タスクの現在の `state` ( `queued`、 `in_progress`、 `completed`、 `failed`、 `idle`、 `waiting_for_user`、 `timed_out`、または `cancelled`のいずれか) が含まれます。\n\n## issues API の使用\n\n> \\[!NOTE]\n> この機能は パブリック プレビュー であり、変更される可能性があります。\n\nGraphQL API または REST API を使用して、 Copilot に問題を割り当てることができます。 どちらの API でも、タスクをカスタマイズするためのオプションのエージェント割り当て入力がサポートされています。\n\n| GraphQL パラメーター       | REST パラメーター           | Description            |\n| -------------------- | --------------------- | ---------------------- |\n| `targetRepositoryId` | `target_repo`         |                        |\n| Copilotが機能するリポジトリ    |                       |                        |\n| `baseRef`            | `base_branch`         |                        |\n| Copilotが分岐元となるブランチ   |                       |                        |\n| `customInstructions` | `custom_instructions` |                        |\n| Copilot に関する追加の手順    |                       |                        |\n| `customAgent`        | `custom_agent`        | タスクで使用する custom agent。 |\n| `model`              | `model`               | 使用する Copilot のモデル      |\n\n### GraphQL API を使用する\n\n> \\[!NOTE]\n> `GraphQL-Features`ヘッダーには、`issues_copilot_assignment_api_support`と`coding_agent_model_selection`の値を含める必要があります。\n\n次の GraphQL の変更を使用して、 Copilotに問題を割り当てることができます。\n\n* [`updateIssue`](/ja/graphql/reference/issues#mutation-updateissue)\n* [`createIssue`](/ja/graphql/reference/issues#mutation-createissue)\n* [`addAssigneesToAssignable`](/ja/graphql/reference/issues#mutation-addassigneestoassignable)\n* [`replaceActorsForAssignable`](/ja/graphql/reference/issues#mutation-replaceactorsforassignable)\n\n#### 新しい issue の作成と割り当て\n\n1. personal access tokenやGitHub Appユーザーからサーバーへのトークンなど、ユーザー トークンを使用して API を使用して認証していることを確認します。\n\n   > \\[!NOTE]\n   > fine-grained personal access tokenを使用する場合、問題にCopilotを割り当てるには、次のアクセス許可が必要です。\n   >\n   > * メタデータへの読み取りアクセス\n   > * アクション、コンテンツ、課題、プルリクエストへのアクセスの読み取りおよび書き込み\n   >\n   > personal access token (classic)を使用する場合は、問題に`repo`を割り当てるためにCopilotスコープが必要です。\n\n2. GraphQL API のリポジトリのCopilot cloud agentに`suggestedActors`が含まれているかどうかを確認して、リポジトリでCopilotが有効になっていることを確認します。\n   `octo-org` をリポジトリ所有者に置き換え、`octo-repo` をリポジトリ名に置き換えます。\n\n   ```graphql copy\n   query {\n     repository(owner: \"octo-org\", name: \"octo-repo\") {\n       suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {\n         nodes {\n           login\n           __typename\n\n           ... on Bot {\n             id\n           }\n\n           ... on User {\n             id\n           }\n         }\n       }\n     }\n   }\n   ```\n\n   ユーザーとリポジトリで Copilot cloud agent が有効になっている場合、クエリから返された最初のノードには `login` 値 `copilot-swe-agent`。\n\n3. このログインの `id` の値を記録しておきます。\n\n4. Issue を作成するリポジトリの GraphQL グローバル ID をフェッチし、`octo-org` をリポジトリ所有者に置き換え、`octo-repo` をリポジトリ名に置き換えます。\n\n   ```graphql copy\n   query {\n     repository(owner: \"octo-org\", name: \"octo-repo\") {\n       id\n     }\n   }\n   ```\n\n5. `createIssue` ミューテーションを使って issue を作成します。\n   `REPOSITORY_ID` を前のステップで返された ID に置き換え、`BOT_ID` をその前のステップで返された ID に置き換えます。 必要に応じて、 `agentAssignment` 入力を含め、タスクをカスタマイズできます。\n\n   ```shell copy\n   gh api graphql -f query='mutation {\n     createIssue(input: {\n       repositoryId: \"REPOSITORY_ID\",\n       title: \"Implement comprehensive unit tests\",\n       body: \"DETAILS\",\n       assigneeIds: [\"BOT_ID\"],\n       agentAssignment: {\n         targetRepositoryId: \"REPOSITORY_ID\",\n         baseRef: \"main\",\n         customInstructions: \"Add comprehensive test coverage\",\n         customAgent: \"\",\n         model: \"\"\n       }\n     }) {\n       issue {\n         id\n         title\n         assignees(first: 10) {\n           nodes {\n             login\n           }\n         }\n       }\n     }\n   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'\n   ```\n\n#### 既存の issue\n\n1. personal access tokenやGitHub Appユーザーからサーバーへのトークンなど、ユーザー トークンを使用して API を使用して認証していることを確認します。\n\n2. GraphQL API のリポジトリのCopilot cloud agentに`suggestedActors`が含まれているかどうかを確認して、リポジトリでCopilotが有効になっていることを確認します。\n   `octo-org` をリポジトリ所有者に置き換え、`octo-repo` をリポジトリ名に置き換えます。\n\n   ```graphql copy\n   query {\n     repository(owner: \"monalisa\", name: \"octocat\") {\n       suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {\n         nodes {\n           login\n           __typename\n\n           ... on Bot {\n             id\n           }\n\n           ... on User {\n             id\n           }\n         }\n       }\n     }\n   }\n   ```\n\n   ユーザーとリポジトリで Copilot cloud agent が有効になっている場合、クエリから返された最初のノードには `login` 値 `copilot-swe-agent`。\n\n3. Copilotに割り当てる問題の GraphQL グローバル ID を取得し、`monalisa`をリポジトリの所有者に置き換え、`octocat`名前に、`9000`を問題番号に置き換えます。\n\n   ```graphql copy\n   query {\n     repository(owner: \"monalisa\", name: \"octocat\") {\n       issue(number: 9000) {\n         id\n         title\n       }\n     }\n   }\n   ```\n\n4. Copilotの変更を使用して、既存の問題を`replaceActorsForAssignable`に割り当てます。\n   `ISSUE_ID`を前の手順から返された ID に置き換え、`BOT_ID`その前の手順から返された ID に置き換え、リポジトリ ID で`REPOSITORY_ID`します。 必要に応じて、 `agentAssignment` 入力を含め、タスクをカスタマイズできます。\n\n   ```shell copy\n   gh api graphql -f query='mutation {\n     replaceActorsForAssignable(input: {\n       assignableId: \"ISSUE_ID\",\n       actorIds: [\"BOT_ID\"],\n       agentAssignment: {\n         targetRepositoryId: \"REPOSITORY_ID\",\n         baseRef: \"main\",\n         customInstructions: \"Fix the reported bug\",\n         customAgent: \"\",\n         model: \"\"\n       }\n     }) {\n       assignable {\n         ... on Issue {\n           id\n           title\n           assignees(first: 10) {\n             nodes {\n               login\n             }\n           }\n         }\n       }\n     }\n   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'\n   ```\n\n5. または、 `updateIssue` の変更を使用して既存の問題を更新し、 Copilotに割り当てることができます。\n   `ISSUE_ID`を問題 ID に置き換え、`BOT_ID`をボット ID に置き換えます。\n\n   ```shell copy\n   gh api graphql -f query='mutation {\n     updateIssue(input: {\n       id: \"ISSUE_ID\",\n       assigneeIds: [\"BOT_ID\"],\n       agentAssignment: {\n         targetRepositoryId: \"REPOSITORY_ID\",\n         baseRef: \"main\",\n         customInstructions: \"Update feature implementation\",\n         customAgent: \"\",\n         model: \"\"\n       }\n     }) {\n       issue {\n         id\n         title\n         assignees(first: 10) {\n           nodes {\n             login\n           }\n         }\n       }\n     }\n   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'\n   ```\n\n6. また、 `addAssigneesToAssignable` の変更を使用して、他の担当者を維持しながら、既存の問題に Copilot を追加することもできます。\n   `ISSUE_ID`を問題 ID に置き換え、`BOT_ID`をボット ID に置き換えます。\n\n   ```shell copy\n   gh api graphql -f query='mutation {\n     addAssigneesToAssignable(input: {\n       assignableId: \"ISSUE_ID\",\n       assigneeIds: [\"BOT_ID\"],\n       agentAssignment: {\n         targetRepositoryId: \"REPOSITORY_ID\",\n         baseRef: \"main\",\n         customInstructions: \"Collaborate on this task\",\n         customAgent: \"\",\n         model: \"\"\n       }\n     }) {\n       assignable {\n         ... on Issue {\n           id\n           title\n           assignees(first: 10) {\n             nodes {\n               login\n             }\n           }\n         }\n       }\n     }\n   }' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'\n   ```\n\n### REST API の使用\n\n次の REST API エンドポイントを使用して、 Copilotに問題を割り当てることができます。\n\n* [課題に担当者を追加する](/ja/rest/issues/assignees#add-assignees-to-an-issue)\n* [問題を作成する](/ja/rest/issues/issues#create-an-issue)\n* [問題を更新する](/ja/rest/issues/issues#update-an-issue)\n\n#### 既存の問題への担当者の追加\n\n```shell copy\ngh api \\\n  --method POST \\\n  -H \"Accept: application/vnd.github+json\" \\\n  -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n  /repos/OWNER/REPO/issues/ISSUE_NUMBER/assignees \\\n  --input - <<< '{\n  \"assignees\": [\"copilot-swe-agent[bot]\"],\n  \"agent_assignment\": {\n    \"target_repo\": \"OWNER/REPO\",\n    \"base_branch\": \"main\",\n    \"custom_instructions\": \"\",\n    \"custom_agent\": \"\",\n    \"model\": \"\"\n  }\n}'\n```\n\n#### 新しい問題の作成\n\n```shell copy\ngh api \\\n  --method POST \\\n  -H \"Accept: application/vnd.github+json\" \\\n  -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n  /repos/OWNER/REPO/issues \\\n  --input - <<< '{\n  \"title\": \"Issue title\",\n  \"body\": \"Issue description.\",\n  \"assignees\": [\"copilot-swe-agent[bot]\"],\n  \"agent_assignment\": {\n    \"target_repo\": \"OWNER/REPO\",\n    \"base_branch\": \"main\",\n    \"custom_instructions\": \"\",\n    \"custom_agent\": \"\",\n    \"model\": \"\"\n  }\n}'\n```\n\n#### 既存の問題の更新\n\n```shell copy\ngh api \\\n  --method PATCH \\\n  -H \"Accept: application/vnd.github+json\" \\\n  -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n  /repos/OWNER/REPO/issues/ISSUE_NUMBER \\\n  --input - <<< '{\n  \"assignees\": [\"copilot-swe-agent[bot]\"],\n  \"agent_assignment\": {\n    \"target_repo\": \"OWNER/REPO\",\n    \"base_branch\": \"main\",\n    \"custom_instructions\": \"\",\n    \"custom_agent\": \"\",\n    \"model\": \"\"\n  }\n}'\n```\n\n## 詳細については、次を参照してください。\n\n* [エージェント タスクの REST API エンドポイント](/ja/rest/agent-tasks/agent-tasks)\n* [クラウド エージェントGitHub Copilotについて](/ja/copilot/concepts/agents/cloud-agent/about-cloud-agent)\n* [GitHub Copilot セッションの開始](/ja/copilot/how-tos/use-copilot-agents/cloud-agent/start-copilot-sessions)"}