Skip to content

Commit cce2314

Browse files
authored
Add chat participant detection in extension guide (#7685)
* Add chat participant detection in extension guide * Update after review * Minor edits
1 parent d12b9c4 commit cce2314

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

api/extension-guides/chat.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ The `isSticky` property controls whether the chat participant is persistent, whi
9494

9595
We suggest using a lowercase `name` and using title case for the `fullName` to align with existing chat participants. Get more info about the [naming conventions for chat participants](#chat-participant-naming-conventions).
9696

97-
> **Note**: Some participant names are reserved, and in case you use a reserved name VS Code will display the fully qualified name of your participant (including the extension ID).
97+
> [!NOTE]
98+
> Some participant names are reserved, and in case you use a reserved name VS Code will display the fully qualified name of your participant (including the extension ID).
9899
99100
Up-front registration of participants and [commands](#register-commands) in `package.json` is required, so that VS Code can activate your extension at the right time, and not before it is needed.
100101

@@ -267,7 +268,59 @@ cat.followupProvider = {
267268
};
268269
```
269270

270-
> **Tip:** Follow-ups should be written as questions or directions, not just concise commands.
271+
> [!TIP]
272+
> Follow-ups should be written as questions or directions, not just concise commands.
273+
274+
### Implement participant detection
275+
276+
To make it easier to use chat participants with natural language, you can implement participant detection. Participant detection is a way to automatically route the user's question to a suitable participant, without having to explicitly mention the participant in the prompt. For example, if the user asks "How do I add a login page to my project?", the question would be automatically routed to the `@workspace` participant because it can answer questions about the user's project.
277+
278+
VS Code uses the chat participant description and examples to determine which participant to route a chat prompt to. You can specify this information in the `disambiguation` property in the extension `package.json` file. The `disambiguation` property contains a list of detection categories, each with a description and examples.
279+
280+
| Property | Description | Examples |
281+
|----------|-------------|----------|
282+
| `category` | The detection category. If the participant serves different purposes, you can have a category for each. | <ul><li>`cat`</li><li>`workspace_questions`</li><li>`web_questions`</li></ul> |
283+
| `description` | A detailed description of the kinds of questions that are suitable for this participant. | <ul><li>`The user wants to learn a specific computer science topic in an informal way.`</li><li>`The user just wants to relax and see the cat play.`</li></ul> |
284+
| `examples` | A list of representative example questions. | <ul><li>`Teach me C++ pointers using metaphors`</li><li>`Explain to me what is a linked list in a simple way`</li><li>`Can you show me a cat playing with a laser pointer?`</li></ul> |
285+
286+
You can define participant detection for the overall chat participant, for specific commands, or a combination of both.
287+
288+
The following code snippet shows how to implement participant detection at the participant level.
289+
290+
```json
291+
"contributes": {
292+
"chatParticipants": [
293+
"id": "chat-sample.cat",
294+
"fullName": "Cat",
295+
"name": "cat",
296+
"description": "Meow! What can I teach you?",
297+
298+
"disambiguation": [
299+
{
300+
"category": "cat",
301+
"description": "The user wants to learn a specific computer science topic in an informal way.",
302+
"examples": [
303+
"Teach me C++ pointers using metaphors",
304+
"Explain to me what is a linked list in a simple way",
305+
"Can you explain to me what is a function in programming?"
306+
]
307+
}
308+
]
309+
]
310+
}
311+
```
312+
313+
Similarly, you can also configure participant detection at the command level by adding a `disambiguation` property for one or more items in the `commands` property.
314+
315+
Apply the following guidelines to improve the accuracy of participant detection for your extension:
316+
317+
- **Be specific**: The description and examples should be as specific as possible to avoid conflicts with other participants. Avoid using generic terminology in the participant and command information.
318+
- **Use examples**: The examples should be representative of the kinds of questions that are suitable for the participant. Use synonyms and variations to cover a wide range of user queries.
319+
- **Use natural language**: The description and examples should be written in natural language, as if you were explaining the participant to a user.
320+
- **Test the detection**: Test the participant detection with a variation of example questions and verify there's no conflict with built-in chat participants.
321+
322+
> [!NOTE]
323+
> Built-in chat participants take precedence for participant detection. For example, a chat participant that operates on workspace files might conflict with the built-in `@workspace` participant.
271324
272325
## Supported chat response output types
273326

@@ -414,7 +467,8 @@ The following list provides the output types for a chat response in the Chat vie
414467

415468
## Variables
416469

417-
> **Note:** The Variables API is still in a proposed state and we are actively working on it.
470+
> [!NOTE]
471+
> The Variables API is still in a proposed state and we are actively working on it.
418472

419473
Chat extensions can also contribute chat *variables*, which provide context about the extension's domain. For example, a C++ extension might contribute a variable `#cpp` that would get resolved based on the state of the language service - what C++ version is used and what C++ programming approach is preferred.
420474

0 commit comments

Comments
 (0)