chat: wip on model-specific tools

This is a rethinking of the initial API proposed in `languageModelToolSupportsModel.d.ts`.

1. This switches to `models?: LanguageModelChatSelector[];` to control enablement.
   definitely open to switching this out, but I think a synchronously-analyzable
   expression is important to retain the data flows in core without too many races.
2. The extension is able to define a tool at runtime via registerToolDefinition. This
   should let us have entirely service-driven tools from model providers without
   requiring a static definition for each one. We can also have model-specific
   variants of tools without a ton of package.json work for each variant of the tool
   (as initially proposed using `when` clauses)

This then propagates that down into the tools service. Currently I have this as just
compiling to a `when` expression once it reaches the main thread. Then, for the tools
service, it takes an IContextKeyService in cases where tools should be enumerated,
and the chat input sets the model keys in its scoped context key service. This allows
the tools to be filtered correctly in the tool picker.

I initially thought about allowing multiple definitions be registered for the same tool
name/id for model-specific variants of tools but I realized that gets really gnarly and
we already have a `toolReferenceName` that multiple tools can register into.

Todo for tomorrow morning:
- Tools don't make it to the ChatRequest yet, or something, still need to investigate
- Need to make sure tools in prompts/models all work. For a first pass I think we can
  let prompts/modes reference all tools by toolReferenceName.
- Validate that multiple tools actually can safely share a reference name (and do
  some priority ordering?)
- General further validation
- Some unit tests
This commit is contained in:
Connor Peet
2026-01-13 16:02:29 -08:00
parent d94a1fb7f5
commit 8d3270de42
29 changed files with 455 additions and 225 deletions

View File

@@ -1607,6 +1607,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
registerTool<T>(name: string, tool: vscode.LanguageModelTool<T>) {
return extHostLanguageModelTools.registerTool(extension, name, tool);
},
registerToolDefinition<T>(definition: vscode.LanguageModelToolDefinition, tool: vscode.LanguageModelTool<T>) {
return extHostLanguageModelTools.registerToolDefinition(extension, definition, tool);
},
invokeTool<T>(nameOrInfo: string | vscode.LanguageModelToolInformation, parameters: vscode.LanguageModelToolInvocationOptions<T>, token?: vscode.CancellationToken) {
if (typeof nameOrInfo !== 'string') {
checkProposedApiEnabled(extension, 'chatParticipantAdditions');