Skip to content

Commit 360bf09

Browse files
authored
Change tool paramters to input and make sure parameters stills works to keep backwards compatibility (microsoft#232248)
fixes microsoft#232143
1 parent c0f2791 commit 360bf09

File tree

7 files changed

+71
-34
lines changed

7 files changed

+71
-34
lines changed

src/vs/workbench/api/common/extHostLanguageModelTools.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import { IPreparedToolInvocation, isToolInvocationContext, IToolInvocation, IToo
1515
import { ExtHostLanguageModelToolsShape, IMainContext, IToolDataDto, MainContext, MainThreadLanguageModelToolsShape } from './extHost.protocol.js';
1616
import * as typeConvert from './extHostTypeConverters.js';
1717

18+
/**
19+
* @deprecated
20+
*/
21+
type CompatLanguageModelToolInvocationOptions<T = any> = vscode.LanguageModelToolInvocationOptions<T> & { parameters?: any };
22+
23+
/**
24+
* @deprecated
25+
*/
26+
type CompactLanguageModelToolInvocationPrepareOptions<T> = vscode.LanguageModelToolInvocationPrepareOptions<T> & { parameters: any };
27+
1828
export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape {
1929
/** A map of tools that were registered in this EH */
2030
private readonly _registeredTools = new Map<string, { extension: IExtensionDescription; tool: vscode.LanguageModelTool<Object> }>();
@@ -43,7 +53,7 @@ export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape
4353
return await fn(input, token);
4454
}
4555

46-
async invokeTool(toolId: string, options: vscode.LanguageModelToolInvocationOptions<any>, token?: CancellationToken): Promise<vscode.LanguageModelToolResult> {
56+
async invokeTool(toolId: string, options: CompatLanguageModelToolInvocationOptions<any>, token?: CancellationToken): Promise<vscode.LanguageModelToolResult> {
4757
const callId = generateUuid();
4858
if (options.tokenizationOptions) {
4959
this._tokenCountFuncs.set(callId, options.tokenizationOptions.countTokens);
@@ -58,7 +68,7 @@ export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape
5868
const result = await this._proxy.$invokeTool({
5969
toolId,
6070
callId,
61-
parameters: options.parameters,
71+
parameters: options.input ?? options.parameters,
6272
tokenBudget: options.tokenizationOptions?.tokenBudget,
6373
context: options.toolInvocationToken as IToolInvocationContext | undefined,
6474
}, token);
@@ -86,7 +96,7 @@ export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape
8696
throw new Error(`Unknown tool ${dto.toolId}`);
8797
}
8898

89-
const options: vscode.LanguageModelToolInvocationOptions<Object> = { parameters: dto.parameters, toolInvocationToken: dto.context as vscode.ChatParticipantToolToken | undefined };
99+
const options: CompatLanguageModelToolInvocationOptions<Object> = { input: dto.parameters, parameters: dto.parameters, toolInvocationToken: dto.context as vscode.ChatParticipantToolToken | undefined };
90100
if (dto.tokenBudget !== undefined) {
91101
options.tokenizationOptions = {
92102
tokenBudget: dto.tokenBudget,
@@ -113,7 +123,8 @@ export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape
113123
return undefined;
114124
}
115125

116-
const result = await item.tool.prepareInvocation({ parameters }, token);
126+
const options: CompactLanguageModelToolInvocationPrepareOptions<any> = { parameters, input: parameters };
127+
const result = await item.tool.prepareInvocation(options, token);
117128
if (!result) {
118129
return undefined;
119130
}

src/vs/workbench/api/common/extHostLanguageModels.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class ExtHostLanguageModels implements ExtHostLanguageModelsShape {
206206

207207
let part: IChatResponsePart | undefined;
208208
if (fragment.part instanceof extHostTypes.LanguageModelToolCallPart) {
209-
part = { type: 'tool_use', name: fragment.part.name, parameters: fragment.part.parameters, toolCallId: fragment.part.callId };
209+
part = { type: 'tool_use', name: fragment.part.name, parameters: fragment.part.input ?? fragment.part.parameters, toolCallId: fragment.part.callId };
210210
} else if (fragment.part instanceof extHostTypes.LanguageModelTextPart) {
211211
part = { type: 'text', value: fragment.part.value };
212212
}
@@ -382,6 +382,19 @@ export class ExtHostLanguageModels implements ExtHostLanguageModelsShape {
382382
}
383383
}
384384

385+
if (options.tools) {
386+
// TODO@API backwards compat, remove
387+
// when getting tools passed massage them to have inputSchema set
388+
type OldChatTool = vscode.LanguageModelChatTool & { parametersSchema?: object };
389+
options.tools = options.tools.map((tool: OldChatTool) => {
390+
return {
391+
...tool,
392+
inputSchema: tool.inputSchema ?? tool.parametersSchema,
393+
parametersSchema: tool.inputSchema ?? tool.parametersSchema,
394+
};
395+
});
396+
}
397+
385398
try {
386399
const requestId = (Math.random() * 1e6) | 0;
387400
const res = new LanguageModelResponse();

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@ export namespace LanguageModelChatMessage {
24072407
type: 'tool_use',
24082408
toolCallId: c.callId,
24092409
name: c.name,
2410-
parameters: c.parameters
2410+
parameters: c.input ?? c.parameters
24112411
};
24122412
} else if (c instanceof types.LanguageModelTextPart) {
24132413
return {
@@ -2973,12 +2973,13 @@ export namespace DebugTreeItem {
29732973
}
29742974

29752975
export namespace LanguageModelToolDescription {
2976-
export function to(item: IToolData): vscode.LanguageModelToolInformation {
2976+
export function to(item: IToolData): vscode.LanguageModelToolInformation & { parametersSchema: any } {
29772977
return {
29782978
// Note- the reason this is a unique 'name' is just to avoid confusion with the toolCallId
29792979
name: item.id,
29802980
description: item.modelDescription,
2981-
parametersSchema: item.parametersSchema,
2981+
inputSchema: item.inputSchema,
2982+
parametersSchema: item.inputSchema, // TODO@API backwards compat, remove
29822983
tags: item.tags ?? [],
29832984
};
29842985
}

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,9 +4657,12 @@ export class LanguageModelChatMessage implements vscode.LanguageModelChatMessage
46574657
export class LanguageModelToolCallPart implements vscode.LanguageModelToolCallPart {
46584658
callId: string;
46594659
name: string;
4660+
input: any;
4661+
4662+
/** @deprecated */
46604663
parameters: any;
46614664

4662-
constructor(callId: string, name: string, parameters: any) {
4665+
constructor(callId: string, name: string, input: any) {
46634666
// TODO TEMP- swapped the order of these two arguments, trying to preserve the behavior for a build or two
46644667
if (name.startsWith('call_')) {
46654668
this.name = callId;
@@ -4669,7 +4672,9 @@ export class LanguageModelToolCallPart implements vscode.LanguageModelToolCallPa
46694672
this.name = name;
46704673
}
46714674

4672-
this.parameters = parameters;
4675+
this.input = input;
4676+
// TODO@API backwards compat, remove
4677+
this.parameters = input;
46734678
}
46744679
}
46754680

src/vs/workbench/contrib/chat/common/languageModelToolsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface IToolData {
2222
displayName: string;
2323
userDescription?: string;
2424
modelDescription: string;
25-
parametersSchema?: IJSONSchema;
25+
inputSchema?: IJSONSchema;
2626
canBeReferencedInPrompt?: boolean;
2727
}
2828

src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export interface IRawToolContribution {
2626
when?: string;
2727
tags?: string[];
2828
userDescription?: string;
29+
inputSchema?: IJSONSchema;
30+
31+
/**
32+
* TODO@API backwards compat, remove
33+
* @deprecated
34+
*/
2935
parametersSchema?: IJSONSchema;
3036
canBeReferencedInPrompt?: boolean;
3137
}
@@ -47,10 +53,10 @@ const languageModelToolsExtensionPoint = extensionsRegistry.ExtensionsRegistry.r
4753
body: {
4854
name: '${1}',
4955
modelDescription: '${2}',
50-
parametersSchema: {
56+
inputSchema: {
5157
type: 'object',
5258
properties: {
53-
'${3:paramName}': {
59+
'${3:name}': {
5460
type: 'string',
5561
description: '${4:description}'
5662
}
@@ -83,8 +89,8 @@ const languageModelToolsExtensionPoint = extensionsRegistry.ExtensionsRegistry.r
8389
description: localize('toolModelDescription', "A description of this tool that may be used by a language model to select it."),
8490
type: 'string'
8591
},
86-
parametersSchema: {
87-
description: localize('parametersSchema', "A JSON schema for the parameters this tool accepts. The parameters must be an object at the top level. A particular language model may not support all JSON schema features. See the documentation for the language model family you are using for more information."),
92+
inputSchema: {
93+
description: localize('parametersSchema', "A JSON schema for the input this tool accepts. The input must be an object at the top level. A particular language model may not support all JSON schema features. See the documentation for the language model family you are using for more information."),
8894
$ref: toolsParametersSchemaSchemaId,
8995
},
9096
canBeReferencedInPrompt: {
@@ -173,6 +179,7 @@ export class LanguageModelToolsExtensionPointHandler implements IWorkbenchContri
173179

174180
const tool: IToolData = {
175181
...rawTool,
182+
inputSchema: rawTool.inputSchema ?? rawTool.parametersSchema, // BACKWARDS compatibility
176183
id: rawTool.name,
177184
icon,
178185
when: rawTool.when ? ContextKeyExpr.deserialize(rawTool.when) : undefined,

src/vscode-dts/vscode.d.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19096,7 +19096,7 @@ declare module 'vscode' {
1909619096
* The list of tools that the user attached to their request.
1909719097
*
1909819098
* When a tool reference is present, the chat participant should make a chat request using
19099-
* {@link LanguageModelChatToolMode.Required} to force the language model to generate parameters for the tool. Then, the
19099+
* {@link LanguageModelChatToolMode.Required} to force the language model to generate input for the tool. Then, the
1910019100
* participant can use {@link lm.invokeTool} to use the tool attach the result to its request for the user's prompt. The
1910119101
* tool may contribute useful extra context for the user's request.
1910219102
*/
@@ -19703,12 +19703,12 @@ declare module 'vscode' {
1970319703

1970419704
/**
1970519705
* A list of all available tools that were registered by all extensions using {@link lm.registerTool}. They can be called
19706-
* with {@link lm.invokeTool} with a set of parameters that match their declared `parametersSchema`.
19706+
* with {@link lm.invokeTool} with input that match their declared `inputSchema`.
1970719707
*/
1970819708
export const tools: readonly LanguageModelToolInformation[];
1970919709

1971019710
/**
19711-
* Invoke a tool listed in {@link lm.tools} by name with the given parameters. The parameters will be validated against
19711+
* Invoke a tool listed in {@link lm.tools} by name with the given input. The input will be validated against
1971219712
* the schema declared by the tool
1971319713
*
1971419714
* A tool can be invoked by a chat participant, in the context of handling a chat request, or globally by any extension in
@@ -19774,9 +19774,9 @@ declare module 'vscode' {
1977419774
description: string;
1977519775

1977619776
/**
19777-
* A JSON schema for the parameters this tool accepts.
19777+
* A JSON schema for the input this tool accepts.
1977819778
*/
19779-
parametersSchema?: object;
19779+
inputSchema?: object;
1978019780
}
1978119781

1978219782
/**
@@ -19811,18 +19811,18 @@ declare module 'vscode' {
1981119811
name: string;
1981219812

1981319813
/**
19814-
* The parameters with which to call the tool.
19814+
* The input with which to call the tool.
1981519815
*/
19816-
parameters: object;
19816+
input: object;
1981719817

1981819818
/**
1981919819
* Create a new LanguageModelToolCallPart.
1982019820
*
1982119821
* @param callId The ID of the tool call.
1982219822
* @param name The name of the tool to call.
19823-
* @param parameters The parameters with which to call the tool.
19823+
* @param input The input with which to call the tool.
1982419824
*/
19825-
constructor(callId: string, name: string, parameters: object);
19825+
constructor(callId: string, name: string, input: object);
1982619826
}
1982719827

1982819828
/**
@@ -19924,10 +19924,10 @@ declare module 'vscode' {
1992419924
toolInvocationToken: ChatParticipantToolToken | undefined;
1992519925

1992619926
/**
19927-
* The parameters with which to invoke the tool. The parameters must match the schema defined in
19928-
* {@link LanguageModelToolInformation.parametersSchema}
19927+
* The input with which to invoke the tool. The input must match the schema defined in
19928+
* {@link LanguageModelToolInformation.inputSchema}
1992919929
*/
19930-
parameters: T;
19930+
input: T;
1993119931

1993219932
/**
1993319933
* Options to hint at how many tokens the tool should return in its response, and enable the tool to count tokens
@@ -19969,9 +19969,9 @@ declare module 'vscode' {
1996919969
readonly description: string;
1997019970

1997119971
/**
19972-
* A JSON schema for the parameters this tool accepts.
19972+
* A JSON schema for the input this tool accepts.
1997319973
*/
19974-
readonly parametersSchema: object | undefined;
19974+
readonly inputSchema: object | undefined;
1997519975

1997619976
/**
1997719977
* A set of tags, declared by the tool, that roughly describe the tool's capabilities. A tool user may use these to filter
@@ -19985,25 +19985,25 @@ declare module 'vscode' {
1998519985
*/
1998619986
export interface LanguageModelToolInvocationPrepareOptions<T> {
1998719987
/**
19988-
* The parameters that the tool is being invoked with.
19988+
* The input that the tool is being invoked with.
1998919989
*/
19990-
parameters: T;
19990+
input: T;
1999119991
}
1999219992

1999319993
/**
1999419994
* A tool that can be invoked by a call to a {@link LanguageModelChat}.
1999519995
*/
1999619996
export interface LanguageModelTool<T> {
1999719997
/**
19998-
* Invoke the tool with the given parameters and return a result.
19998+
* Invoke the tool with the given input and return a result.
1999919999
*
20000-
* The provided {@link LanguageModelToolInvocationOptions.parameters} have been validated against the declared schema.
20000+
* The provided {@link LanguageModelToolInvocationOptions.input} has been validated against the declared schema.
2000120001
*/
2000220002
invoke(options: LanguageModelToolInvocationOptions<T>, token: CancellationToken): ProviderResult<LanguageModelToolResult>;
2000320003

2000420004
/**
2000520005
* Called once before a tool is invoked. It's recommended to implement this to customize the progress message that appears
20006-
* while the tool is running, and to provide a more useful message with context from the invocation parameters. Can also
20006+
* while the tool is running, and to provide a more useful message with context from the invocation input. Can also
2000720007
* signal that a tool needs user confirmation before running, if appropriate.
2000820008
*
2000920009
* * *Note 1:* Must be free of side-effects.

0 commit comments

Comments
 (0)