Repository navigation
implement vscode_askQuestions tool in core - #296135
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements the vscode_askQuestions tool in VS Code core, moving it from extension-based implementation. The tool allows agents to ask structured clarifying questions (single-select, multi-select, or freeform) before proceeding with tasks. This addresses tight coupling issues with the UI and "stream" concept mentioned in issue #291349.
Changes:
- Added
AskQuestionsToolimplementation with support for question carousels, answer conversion, validation, and telemetry - Extended
IChatServicewithfindRequestByIdmethod to locate requests across sessions - Updated UI components to recognize both the new
vscode_askQuestionsand legacycopilot_askQuestionstool IDs for backward compatibility
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/common/tools/builtinTools/askQuestionsTool.ts | Core implementation of the AskQuestionsTool with schema definition, question carousel conversion, answer parsing logic, and telemetry |
| src/vs/workbench/contrib/chat/test/common/tools/builtinTools/askQuestionsTool.test.ts | Comprehensive unit tests for the answer conversion logic covering all question types and edge cases |
| src/vs/workbench/contrib/chat/common/tools/builtinTools/tools.ts | Registration of AskQuestionsTool with the language model tools service and agent tool set |
| src/vs/workbench/contrib/chat/common/tools/builtinTools/runSubagentTool.ts | Exclusion of both old and new ask questions tool IDs from subagent mode tools |
| src/vs/workbench/contrib/chat/common/chatService/chatService.ts | Added findRequestById interface method for locating requests by ID across sessions |
| src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts | Implementation of findRequestById that searches all session models |
| src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts | Added mock implementations of findRequestById and getLatestRequest for tests |
| src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts | Added mock implementations of findRequestById and getLatestRequest for tests |
| src/vs/workbench/contrib/chat/browser/widget/chatListRenderer.ts | Updated to check for both old and new tool IDs when determining whether to pin tool invocations |
| src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolProgressPart.ts | Updated to check for both old and new tool IDs when rendering progress content |
Comments suppressed due to low confidence (4)
src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts:115
- The
getLatestRequestmethod appears to be unused and is not part of theIChatServiceinterface. This method should be removed from the mock service unless it's needed for a specific test case. If it was used during development but is no longer needed, it should be cleaned up.
getLatestRequest(): IChatRequestModel | undefined {
return undefined;
}
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolProgressPart.ts:108
- Consider importing and using the AskQuestionsToolId constant from askQuestionsTool.ts instead of using the string literal 'vscode_askQuestions'. This would improve maintainability by having a single source of truth for the tool ID. The old 'copilot_askQuestions' ID should continue to use a string literal for backward compatibility with serialized data, but the new ID should use the constant.
const isAskQuestionsTool = this.toolInvocation.toolId === 'copilot_askQuestions' || this.toolInvocation.toolId === 'vscode_askQuestions';
src/vs/workbench/contrib/chat/browser/widget/chatListRenderer.ts:1473
- Consider importing and using the AskQuestionsToolId constant from askQuestionsTool.ts instead of using the string literal 'vscode_askQuestions'. This would improve maintainability by having a single source of truth for the tool ID. The old 'copilot_askQuestions' ID should continue to use a string literal for backward compatibility with serialized data, but the new ID should use the constant.
const isAskQuestionsTool = (part.kind === 'toolInvocation' || part.kind === 'toolInvocationSerialized') && (part.toolId === 'copilot_askQuestions' || part.toolId === 'vscode_askQuestions');
src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts:55
- The
getLatestRequestmethod appears to be unused and is not part of theIChatServiceinterface. This method should be removed from the mock service unless it's needed for a specific test case. If it was used during development but is no longer needed, it should be cleaned up.
getLatestRequest(): IChatRequestModel | undefined {
return undefined;
}
417b447 to
e2f6ac8
Compare
…unnecessary event
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (6)
src/vs/workbench/contrib/chat/common/tools/builtinTools/askQuestionsTool.ts:193
- The schema/documentation requires
headerto be unique, but the implementation doesn’t validate this. Duplicate headers will overwrite entries inanswersand can cause incorrect results. Add a validation step (ideally inprepareToolInvocation) that rejects duplicateheadervalues.
for (const question of questions) {
if (question.options && question.options.length === 1) {
throw new Error(localize('askQuestionsTool.invalidOptions', 'Question "{0}" must have at least two options, or none for free text input.', question.header));
}
}
src/vs/workbench/contrib/chat/common/tools/builtinTools/askQuestionsTool.ts:276
answersis built as a plain object and indexed byquestion.header, which is tool input. Using special keys like__proto__/constructorcan lead to prototype pollution or surprising behavior. Consider usingObject.create(null)(or aMap) foranswers/skippedAnswersto avoid prototype-key issues before stringifying.
protected convertCarouselAnswers(questions: IQuestion[], carouselAnswers: Record<string, unknown> | undefined): IAnswerResult {
const result: IAnswerResult = { answers: {} };
if (carouselAnswers) {
src/vs/workbench/contrib/chat/test/common/tools/builtinTools/askQuestionsTool.test.ts:33
- This test suite already uses
ensureNoDisposablesAreLeakedInTestSuite()and registerstoolin that store, which disposes it automatically in the suite teardown. The explicittool?.dispose()inteardownis redundant and can be removed to reduce noise.
teardown(() => {
tool?.dispose();
});
src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts:52
- This mock generally throws for unimplemented
IChatServicemethods; returningundefinedhere can hide unexpected calls and make failures harder to diagnose. Consider throwingnew Error('Method not implemented.')(or implementing it) to keep mock behavior consistent and fail fast if the method is used.
getLatestRequest(): IChatRequestModel | undefined {
return undefined;
}
src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts:111
- This is a stub implementation that always returns
undefined. IfgetLatestRequestis expected to be used by the code under test, consider either implementing it to return the latest request fromsessionsor throwing to fail fast when called unexpectedly.
getLatestRequest(): IChatRequestModel | undefined {
return undefined;
}
src/vs/workbench/contrib/chat/common/tools/builtinTools/askQuestionsTool.ts:293
convertCarouselAnswerslogs the raw answer value for each question (including freeform text) withtrace. This may capture sensitive user input in logs. Please remove/redact answer values in logs (e.g. log only the question header and the answer shape or whether it was skipped).
const answer = carouselAnswers[question.header];
this.logService.trace(`[AskQuestionsTool] Processing question "${question.header}", raw answer: ${JSON.stringify(answer)}, type: ${typeof answer}`);
…stionsTool.ts Co-authored-by: Copilot <[email protected]>
roblourens
left a comment
There was a problem hiding this comment.
Looks good, thanks for the edits
fixes #291349
Tested by setting
github.copilot.chat.askQuestions.enabled: falseFollow-ups here #296134 as some things in chat depend upon it
cc Karthik Nadig (@karthiknadig)