Skip to content

Commit 9dd29dc

Browse files
authored
tools: ensure groups of referenced tools are expanded by default (#525)
Closes microsoft/vscode#257379
1 parent 1ef1ab7 commit 9dd29dc

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/extension/prompt/node/defaultIntentRequestHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ class DefaultToolCallingLoop extends ToolCallingLoop<IDefaultToolLoopOptions> {
697697
this.toolGrouping.tools = tools;
698698
} else {
699699
this.toolGrouping = this.toolGroupingService.create(this.options.conversation.sessionId, tools);
700+
for (const ref of this.options.request.toolReferences) {
701+
this.toolGrouping.ensureExpanded(ref.name);
702+
}
700703
}
701704

702705
if (!this.toolGrouping.isEnabled) {

src/extension/tools/common/virtualTools/toolGrouping.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class ToolGrouping implements IToolGrouping {
3232
private _didToolsChange = true;
3333
private _turnNo = 0;
3434
private _trimOnNextCompute = false;
35+
private _expandOnNext?: Set<string>;
3536

3637
public get tools(): readonly LanguageModelToolInformation[] {
3738
return this._tools;
@@ -116,6 +117,11 @@ export class ToolGrouping implements IToolGrouping {
116117
this._trimOnNextCompute = true;
117118
}
118119

120+
ensureExpanded(toolName: string): void {
121+
this._expandOnNext ??= new Set();
122+
this._expandOnNext.add(toolName);
123+
}
124+
119125
async compute(token: CancellationToken): Promise<LanguageModelToolInformation[]> {
120126
await this._doCompute(token);
121127
return [...this._root.tools()];
@@ -132,6 +138,16 @@ export class ToolGrouping implements IToolGrouping {
132138
this._didToolsChange = false;
133139
}
134140

141+
if (this._expandOnNext) {
142+
for (const toolName of this._expandOnNext) {
143+
this._root.find(toolName)?.path.forEach(p => {
144+
p.isExpanded = true;
145+
p.lastUsedOnTurn = this._turnNo;
146+
});
147+
}
148+
this._expandOnNext = undefined;
149+
}
150+
135151
let trimDownTo = HARD_TOOL_LIMIT;
136152

137153
if (this._trimOnNextCompute) {

src/extension/tools/common/virtualTools/virtualToolTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export interface IToolGrouping {
4444
*/
4545
getContainerFor(toolName: string): VirtualTool | undefined;
4646

47+
/**
48+
* Ensures the given tool is available in the next call to `compute`.
49+
*/
50+
ensureExpanded(toolName: string): void;
51+
4752
/**
4853
* Returns a list of tools that should be used for the given request.
4954
* Internally re-reads the request and conversation state.

0 commit comments

Comments
 (0)