Skip to main content

エージェントのコンテキストの受け渡し

Copilot agent でコンテキストの受け渡しを使う方法について説明します。

コンテキストの受け渡しについて

コンテキストの受け渡しを使うと、GitHub Copilot Extensions から特定のコンテキスト情報にアクセスできます。 コンテキストの受け渡しにより、エージェントは、ユーザーの現在のファイル、選択されたテキスト、リポジトリに関する関連情報を受け取ることができます。 これは、拡張機能を操作するときに自動的に行われますが、organization が所有するリポジトリで使うためには、ユーザーが GitHub App のアクセス許可を通じて明示的に認可する必要があります。

GitHub Copilot Chat in Visual Studio Code、Visual Studio、GitHub などのさまざまなクライアントは、それぞれ異なる参照型を介してコンテキストを提供します。 たとえば、IDE はファイルの内容や選択内容などの情報を送信しますが、Copilot Chat in GitHub は、表示されているページの現在の URL を含めます。

前提条件

GitHub と通信するように Copilot agent を構成する前に、Copilot agent が Copilot プラットフォームと通信する方法を理解しておく必要があります。 「Copilot プラットフォームと通信するように Copilot エージェントを構成する」を参照してください。

コンテキストの受け渡しの概要

コンテキストの受け渡しにより、エージェントはユーザーのアクティブなワークスペースに関する情報を受け取ることができます。 エージェントは、ユーザーからのメッセージの一覧とユーザーの現在の環境への参照を含むサーバー送信イベント (SSE) を受け取ります。 クライアントに応じて、さまざまなコンテキストが提供されます。

次の表は、使っているクライアントまたは IDE に基づいて GitHub Copilot Extensions に渡される参照型を示しています。

クライアントまたは IDEclient.fileclient.selectiongithub.repositorygithub.current-urlその他のコンテキスト
Visual Studio Codeはいはいはいいいえリポジトリの所有者とブランチ
Visual Studioはいはいはいいいえリポジトリの所有者とブランチ
GitHub.comいいえ番号はいはいリポジトリの情報とその他の GitHub リソース

IDE の Copilot Chat 用の参照型

次の参照型は、IDE からエージェントに渡すことができます。

  • client.file: IDE で現在アクティブなファイルの内容全体を表します。
  • client.selection: アクティブなファイル内でユーザーが選んだテキストの選択部分を表します。
  • github.repository: アクティブなリポジトリに関する情報を提供します。

Copilot Chat in GitHub の参照型

次の参照型は、GitHub からエージェントに渡すことができます。

  • github.current-url: ユーザーが表示している現在の GitHub ページの URL を表します。
  • github.repository: アクティブなリポジトリに関する情報を提供します。

参照の例

次に示すコードは、client.file のオブジェクト例です。

{
    // The reference type.
    "type": "client.file",
    "data": {
        // The full content of the active file. 
        "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
        "language": "plaintext"
    },
    "id": "relative-path/to/file",
    // `is_implicit` indicates whether the reference was automatically provided by the client (true) or manually attached by the user (false).
    "is_implicit": true,
    "metadata": {
        "display_name": "https://github.com/example-user/example-repository",
        "display_icon": "",
        "display_url": ""
    }
}

次に示すコードは、client.selection のオブジェクト例です。

{
    // The reference type.
    "type": "client.selection",
    "data": {
        // The currently selected portion of text.
        "content": "<current selection>",
        "end": {
            "col": 80,
            "line": 10
        },
        "start": {
            "col": 0,
            "line": 0
        }
    },
    "id": "relative-path/to/file",
    // `is_implicit` indicates whether the reference was automatically provided by the client (true) or manually attached by the user (false).
    "is_implicit": true,
    "metadata": {
        "display_name": "https://github.com/example-user/example-repository",
        "display_icon": "",
        "display_url": ""
    }
}

次に示すコードは、github.repository のオブジェクト例です。

{
    // The reference type.
    "type": "github.repository",
    "data": {
        "type": "repository",
        "id": "abc-123",
        "name": "example-repository",
        "ownerLogin": "example-user",
        "ownerType": "",
        "readmePath": "",
        "description": "",
        "commitOID": "",
        "ref": "",
        "refInfo": {
            "name": "",
            "type": ""
        },
        "visibility": "",
        "languages": null
    },
    "id": "example-user/example-repository",
    // `is_implicit` is always false for github.repository.
    "is_implicit": false,
    "metadata": {
        "display_name": "https://github.com/example-user/example-repository",
        "display_icon": "",
        "display_url": ""
    }
}

次に示すコードは、github.current-url のオブジェクト例です。

{
    // The reference type.
    "type": "github.current-url",
    "data": {
        // The GitHub URL the user was on while chatting with the agent.
        "url": "https://github.com/example-user/example-repository"
    },
    "id": "https://github.com/example-user/example-repository",
    // `is_implicit` is always true for github.current-url.
    "is_implicit": true,
    "metadata": {
        "display_name": "https://github.com/example-user/example-repository",
        "display_icon": "",
        "display_url": ""
    }
}

コンテキストの受け渡しを設定する

IDE クライアントを介したコンテキストの受け渡しを有効にするには、エージェントに対して Copilot Editor Context アクセス許可を構成する必要があります。 このアクセス許可は、client.file および client.selection 参照型へのアクセスのみを制御します。 エージェントをインストールして使うユーザーには、アクティブなファイルや現在の選択内容などのコンテンツを含む Copilot エディター コンテキストへの読み取りアクセス権がエージェントにあることが明確に通知されます。

github.current-urlgithub.repository は、Copilot エディター コンテキストの影響を受けません。 これらの参照型は、認可フィルター処理を利用して、サード パーティのエージェントがアクセス権のある参照のみを確実に受け取ります。 github.current-urlgithub.repository のプライバシーの管理については、「プライバシーの制御」を参照してください。

IDE からエージェントにコンテキストを渡すために必要なアクセス許可を設定するには、次の手順を実行します。

  1. GitHub の任意のページの右上隅にある、自分のプロファイル写真をクリックします。
  2. アカウント設定にアクセスしてください。
    • 個人用アカウントが所有するアプリの場合は、[設定] をクリックします。
    • 組織が所有するアプリの場合:
      1. [自分の組織] をクリックします。
      2. 組織の右側にある [設定] をクリックします。
  3. 左側のサイドバーで [ 開発者設定] をクリックします。
  4. 左側のサイドバーで、 [GitHub Apps] をクリックします。
  5. GitHub Apps の一覧で、コンテキストの受け渡し用に構成する GitHub App をクリックします。
  6. 左側のナビゲーション メニューで、[Permissions & events] を選びます。
  7. [Account Permissions] で、Copilot エディター コンテキストに対して [Read-only] アクセスを選びます。

プライバシー制御

特定のコンテキストの詳細をエージェントと共有したくない場合は、複数の方法で参照型を編集および削除できます。

IDE でのチャット

  • エージェントに Copilot エディター コンテキストの読み取りアクセス許可がない場合、すべての client.* 参照が削除されます。
  • リポジトリに対する読み取りアクセス権がエージェントにない場合、すべての client.* 参照が削除され、github.repository 参照が編集されます。

Note

Visual Studio と Visual Studio Code には、現在のファイルからコンテンツを除外するオプションが用意されています。 ユーザーが現在のファイルからコンテンツを除外した場合、client.* 参照型は削除されます。

GitHub でチャットする

  • エージェントが現在の GitHub URL に関連付けられているリポジトリに対して読み取りアクセス権を持っていない場合、github.current-urlgithub.repository の参照は編集されます。
  • 現在の GitHub URL からリポジトリ情報を抽出できない場合、github.current-url は編集されます。

編集された参照

アクセス許可が不十分なために参照が編集されると、その参照は、除外された情報の種類を示すプレースホルダーに置き換えられます。 次の例では、type フィールドは参照が編集されていることを示し、data.type フィールドは元の参照型を示しています。

{
    "role": "user",
    "content": "Current Date and Time (UTC): 2024-10-22 00:43:14\nCurrent User's Login: monalisa\n",
    "name": "_session",
    "copilot_references": [
        {
            "type": "github.redacted",
            "data": {
                "type": "github.current-url"
            },
            "id": "example-id",
            "is_implicit": true,
            "metadata": {
                "display_name": "",
                "display_icon": "",
                "display_url": ""
            }
        }
    ],
    "copilot_confirmations": null
}

コンテキストの除外

機密情報を保護するために、特定のシナリオでは、エージェントへのコンテキストの受け渡しは自動的に禁止されます。 Organization が Copilot にコンテンツ除外規則を設定している場合、これらの規則に該当するファイルはエージェントに渡されるコンテキストに含まれません。

コンテンツ除外規則の詳細については、「GitHub Copilot からのコンテンツの除外」を参照してください。

大きいファイル

クライアントが設定したサイズ制限を超えるファイルは送信されません。 参照には、ファイルが大きすぎて処理できないことを示すメタデータが含まれます。

非表示のファイル

.env.config などのドットで始まるファイルは、機密性の高い構成が意図せず共有されないように、既定で除外されます。 VS Code では、.copilotignore ファイル内のファイルまたはディレクトリを指定して、それらが Copilot エージェントに送信されないようにすることができます。 このクライアント側のメカニズムにより、どのファイルを除外するかを詳細に制御できます。