|
| 1 | +--- |
| 2 | +title: Context passing for your agent |
| 3 | +intro: 'Learn how to use context passing with your {% data variables.product.prodname_copilot_agent_short %}.' |
| 4 | +versions: |
| 5 | + feature: copilot-extensions |
| 6 | +topics: |
| 7 | + - Copilot |
| 8 | +shortTitle: Context passing |
| 9 | +type: how_to |
| 10 | +--- |
| 11 | + |
| 12 | +## About context passing |
| 13 | + |
| 14 | +{% data variables.product.prodname_copilot_extensions %} can access certain contextual information using context passing. |
| 15 | +Context passing allows agents to receive relevant details about a user’s current file, selected text, and repository. |
| 16 | +It happens automatically when you interact with an extension, but requires your explicit authorization through {% data variables.product.prodname_github_app %} permissions for use in any organization-owned repositories. |
| 17 | + |
| 18 | +Different clients, such as {% data variables.product.prodname_copilot_chat %} in {% data variables.product.prodname_vscode %}, {% data variables.product.prodname_vs %}, and {% data variables.product.github %}, provide context through different reference types. |
| 19 | +For example, IDEs send information such as file contents and selections, while {% data variables.product.prodname_copilot_chat_dotcom_short %} includes the current URL for the page being viewed. |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +{% data reusables.copilot.copilot-extensions.agents-copilot-platform-prerequisites %} |
| 24 | + |
| 25 | +## Understanding context passing |
| 26 | + |
| 27 | +Context passing enables agents to receive information about the user’s active workspace. |
| 28 | +Your agent receives server-sent events (SSEs) that contain a list of messages from the user as well as references to the user’s current environment. |
| 29 | +Depending on the client, different types of context are provided. |
| 30 | + |
| 31 | +The following table shows the reference types that are passed to {% data variables.product.prodname_copilot_extensions %} based on the client or IDE you are using. |
| 32 | + |
| 33 | +{% rowheaders %} |
| 34 | + |
| 35 | +| Client or IDE | client.file | client.selection | github.repository | github.current-url | Additional contexts | |
| 36 | +| ------------------ | ----------- | ---------------- | ----------------- | ------------------ | ------------------------------------------------- | |
| 37 | +| {% data variables.product.prodname_vscode %} | Yes | Yes | Yes | No | Repository owner and branch | |
| 38 | +| {% data variables.product.prodname_vs %} | Yes | Yes | Yes | No | Repository owner and branch | |
| 39 | +| {% data variables.product.prodname_dotcom_the_website %} | No | No | Yes | Yes | Repository information and other {% data variables.product.github %} resources | |
| 40 | + |
| 41 | +{% endrowheaders %} |
| 42 | + |
| 43 | +### Reference types for {% data variables.product.prodname_copilot_chat_short %} in IDEs |
| 44 | + |
| 45 | +The following reference types can be passed to your agent from an IDE: |
| 46 | +* `client.file`: Represents the full content of the currently active file in the IDE. |
| 47 | +* `client.selection`: Represents the selected portion of text the user highlighted in the active file. |
| 48 | +* `github.repository`: Provides information about the active repository. |
| 49 | + |
| 50 | +### Reference types for {% data variables.product.prodname_copilot_chat_dotcom_short %} |
| 51 | + |
| 52 | +The following reference types can be passed to your agent from {% data variables.product.github %}: |
| 53 | +* `github.current-url`: Represents the URL of the current {% data variables.product.github %} page the user is viewing. |
| 54 | +* `github.repository`: Provides information about the active repository. |
| 55 | + |
| 56 | +## Example references |
| 57 | + |
| 58 | +The following code shows an example object for `client.file`: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + // The reference type. |
| 63 | + "type": "client.file", |
| 64 | + "data": { |
| 65 | + // The full content of the active file. |
| 66 | + "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit", |
| 67 | + "language": "plaintext" |
| 68 | + }, |
| 69 | + "id": "relative-path/to/file", |
| 70 | + // `is_implicit` indicates whether the reference was automatically provided by the client (true) or manually attached by the user (false). |
| 71 | + "is_implicit": true, |
| 72 | + "metadata": { |
| 73 | + "display_name": "https://github.com/example-user/example-repository", |
| 74 | + "display_icon": "", |
| 75 | + "display_url": "" |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +The following code shows an example object for `client.selection`: |
| 81 | + |
| 82 | +```json |
| 83 | +{ |
| 84 | + // The reference type. |
| 85 | + "type": "client.selection", |
| 86 | + "data": { |
| 87 | + // The currently selected portion of text. |
| 88 | + "content": "<current selection>", |
| 89 | + "end": { |
| 90 | + "col": 80, |
| 91 | + "line": 10 |
| 92 | + }, |
| 93 | + "start": { |
| 94 | + "col": 0, |
| 95 | + "line": 0 |
| 96 | + } |
| 97 | + }, |
| 98 | + "id": "relative-path/to/file", |
| 99 | + // `is_implicit` indicates whether the reference was automatically provided by the client (true) or manually attached by the user (false). |
| 100 | + "is_implicit": true, |
| 101 | + "metadata": { |
| 102 | + "display_name": "https://github.com/example-user/example-repository", |
| 103 | + "display_icon": "", |
| 104 | + "display_url": "" |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +The following code shows an example object for `github.repository`: |
| 110 | + |
| 111 | +```json |
| 112 | +{ |
| 113 | + // The reference type. |
| 114 | + "type": "github.repository", |
| 115 | + "data": { |
| 116 | + "type": "repository", |
| 117 | + "id": "abc-123", |
| 118 | + "name": "example-repository", |
| 119 | + "ownerLogin": "example-user", |
| 120 | + "ownerType": "", |
| 121 | + "readmePath": "", |
| 122 | + "description": "", |
| 123 | + "commitOID": "", |
| 124 | + "ref": "", |
| 125 | + "refInfo": { |
| 126 | + "name": "", |
| 127 | + "type": "" |
| 128 | + }, |
| 129 | + "visibility": "", |
| 130 | + "languages": null |
| 131 | + }, |
| 132 | + "id": "example-user/example-repository", |
| 133 | + // `is_implicit` is always false for github.repository. |
| 134 | + "is_implicit": false, |
| 135 | + "metadata": { |
| 136 | + "display_name": "https://github.com/example-user/example-repository", |
| 137 | + "display_icon": "", |
| 138 | + "display_url": "" |
| 139 | + } |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +The following code shows an example object for `github.current-url`: |
| 144 | + |
| 145 | +```json |
| 146 | +{ |
| 147 | + // The reference type. |
| 148 | + "type": "github.current-url", |
| 149 | + "data": { |
| 150 | + // The GitHub URL the user was on while chatting with the agent. |
| 151 | + "url": "https://github.com/example-user/example-repository" |
| 152 | + }, |
| 153 | + "id": "https://github.com/example-user/example-repository", |
| 154 | + // `is_implicit` is always true for github.current-url. |
| 155 | + "is_implicit": true, |
| 156 | + "metadata": { |
| 157 | + "display_name": "https://github.com/example-user/example-repository", |
| 158 | + "display_icon": "", |
| 159 | + "display_url": "" |
| 160 | + } |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +## Setting up context passing |
| 165 | + |
| 166 | +To enable context passing through an IDE client, the **{% data variables.product.prodname_copilot_short %} Editor Context** permission must be configured for your agent. |
| 167 | +This permission only controls access for the `client.file` and `client.selection` reference types. |
| 168 | +Users that install and use the agent will be clearly informed that the agent has read access to {% data variables.product.prodname_copilot_short %} Editor Context which includes content such as active file and current selection. |
| 169 | + |
| 170 | +`github.current-url` and `github.repository` are unaffected by the {% data variables.product.prodname_copilot_short %} Editor Context. These reference types rely on authorization filtering to ensure third party agents only receive references they have access to. For information on managing the privacy of `github.current-url` and `github.repository`, see [Privacy controls](#privacy-controls). |
| 171 | + |
| 172 | +Follow these steps to set the necessary permissions for context passing from IDEs to your agent: |
| 173 | + |
| 174 | +{% data reusables.apps.settings-step-personal-orgs %} |
| 175 | +{% data reusables.user-settings.developer_settings %} |
| 176 | +{% data reusables.user-settings.github_apps %} |
| 177 | +1. In the list of {% data variables.product.prodname_github_apps %}, click the {% data variables.product.prodname_github_app %} you want to configure for context passing. |
| 178 | +1. In the navigation menu on the left, select **Permissions & events**. |
| 179 | +1. Under **Account Permissions**, select **Read-only** access for **{% data variables.product.prodname_copilot_short %} Editor Context**. |
| 180 | + |
| 181 | +## Privacy controls |
| 182 | + |
| 183 | +In cases where you don't want to share certain context details with the agent, you can redact and remove reference types in multiple ways. |
| 184 | + |
| 185 | +### Chat in IDEs |
| 186 | + |
| 187 | +* If an agent doesn't have the {% data variables.product.prodname_copilot_short %} Editor Context read-access permission, all `client.*` references are removed. |
| 188 | +* If an agent doesn't have read access to a repository, all `client.*` references are removed and the `github.repository` reference is redacted. |
| 189 | +> [!NOTE] {% data variables.product.prodname_vs %} and {% data variables.product.prodname_vscode %} provides an option to exclude content from the current file. The `client.*` reference types are removed if the user has excluded content from the current file. |
| 190 | +
|
| 191 | +### Chat in {% data variables.product.github %} |
| 192 | + |
| 193 | +* If an agent doesn't have read access to the repository associated with the current {% data variables.product.github %} URL, the `github.current-url` and `github.repository` references are redacted. |
| 194 | +* If repository information cannot be extracted from the current {% data variables.product.github %} URL, `github.current-url` is redacted. |
| 195 | + |
| 196 | +### Redacted references |
| 197 | + |
| 198 | +When a reference is redacted due to insufficient permissions, it is replaced with a placeholder indicating the type of information that was excluded. |
| 199 | +In the following example, the `type` field indicates that the reference has been redacted and the `data.type` field reveals the original reference type. |
| 200 | + |
| 201 | +```json |
| 202 | +{ |
| 203 | + "role": "user", |
| 204 | + "content": "Current Date and Time (UTC): 2024-10-22 00:43:14\nCurrent User's Login: monalisa\n", |
| 205 | + "name": "_session", |
| 206 | + "copilot_references": [ |
| 207 | + { |
| 208 | + "type": "github.redacted", |
| 209 | + "data": { |
| 210 | + "type": "github.current-url" |
| 211 | + }, |
| 212 | + "id": "example-id", |
| 213 | + "is_implicit": true, |
| 214 | + "metadata": { |
| 215 | + "display_name": "", |
| 216 | + "display_icon": "", |
| 217 | + "display_url": "" |
| 218 | + } |
| 219 | + } |
| 220 | + ], |
| 221 | + "copilot_confirmations": null |
| 222 | +} |
| 223 | +``` |
| 224 | + |
| 225 | +### Context Exclusions |
| 226 | + |
| 227 | +To safeguard sensitive information, certain scenarios automatically prevent the passing of context to agents. |
| 228 | +If an organization has set content exclusion rules for {% data variables.product.prodname_copilot_short %}, files that fall under these rules will not be included in the context passed to agents. |
| 229 | + |
| 230 | +For more information on content exlusion rules, see [AUTOTITLE](/copilot/managing-copilot/configuring-and-auditing-content-exclusion/excluding-content-from-github-copilot). |
| 231 | + |
| 232 | +#### Large Files |
| 233 | + |
| 234 | +Files exceeding the size limit set by the client will not be sent. The reference will include metadata indicating that the file was too large to process. |
| 235 | + |
| 236 | +#### Hidden Files |
| 237 | + |
| 238 | +Files beginning with a dot, such as `.env` and `.config`, are excluded by default to prevent unintentional sharing of sensitive configurations. In {% data variables.product.prodname_vscode_shortname %}, you can specify files or directories in a `.copilotignore` file to prevent them from being sent to {% data variables.product.prodname_copilot_short %} agents. This client-side mechanism offers granular control over which files are excluded. |
0 commit comments