File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed
tools/common/virtualTools Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -697,6 +697,9 @@ class DefaultToolCallingLoop extends ToolCallingLoop<IDefaultToolLoopOptions> {
697
697
this . toolGrouping . tools = tools ;
698
698
} else {
699
699
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
+ }
700
703
}
701
704
702
705
if ( ! this . toolGrouping . isEnabled ) {
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export class ToolGrouping implements IToolGrouping {
32
32
private _didToolsChange = true ;
33
33
private _turnNo = 0 ;
34
34
private _trimOnNextCompute = false ;
35
+ private _expandOnNext ?: Set < string > ;
35
36
36
37
public get tools ( ) : readonly LanguageModelToolInformation [ ] {
37
38
return this . _tools ;
@@ -116,6 +117,11 @@ export class ToolGrouping implements IToolGrouping {
116
117
this . _trimOnNextCompute = true ;
117
118
}
118
119
120
+ ensureExpanded ( toolName : string ) : void {
121
+ this . _expandOnNext ??= new Set ( ) ;
122
+ this . _expandOnNext . add ( toolName ) ;
123
+ }
124
+
119
125
async compute ( token : CancellationToken ) : Promise < LanguageModelToolInformation [ ] > {
120
126
await this . _doCompute ( token ) ;
121
127
return [ ...this . _root . tools ( ) ] ;
@@ -132,6 +138,16 @@ export class ToolGrouping implements IToolGrouping {
132
138
this . _didToolsChange = false ;
133
139
}
134
140
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
+
135
151
let trimDownTo = HARD_TOOL_LIMIT ;
136
152
137
153
if ( this . _trimOnNextCompute ) {
Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ export interface IToolGrouping {
44
44
*/
45
45
getContainerFor ( toolName : string ) : VirtualTool | undefined ;
46
46
47
+ /**
48
+ * Ensures the given tool is available in the next call to `compute`.
49
+ */
50
+ ensureExpanded ( toolName : string ) : void ;
51
+
47
52
/**
48
53
* Returns a list of tools that should be used for the given request.
49
54
* Internally re-reads the request and conversation state.
You can’t perform that action at this time.
0 commit comments