-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Search Subagent support #2736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Search Subagent support #2736
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
a5a8b5d
search subagent tool added
f89f525
cleaning up description of search subagent
5251e9a
additional changes
d29fff9
update linting issue
6541477
Exit early on search subagent call
7e6e0f1
search subagent tool added
258978d
cleaning up description of search subagent
d64f8e5
additional changes
88b1b4c
update linting issue
17c5395
Add fixes for subagent
ccef095
describe read file tool in its prompt
4c5caff
update prompt class type
7031d5f
Merge branch 'main' into anisha/search_subagent
ea48829
fixing copilot cli issues?
4f04523
resolved merge conflicts with main
d78875a
resolve merge conflicts with main
2fbff7d
explicit any pt 2
5b567cd
update explicit any to unknown
3b2a339
demo
zhichli e59c5de
merge main
24anisha 0b9438e
updating prompt to include description
24anisha 1c61c9e
fixing newline bug
24anisha b17d06d
added correct input params for subagent
24anisha d72da66
Merge branch 'main' into anisha/search_subagent
24anisha 337ce2e
update to add final turn warning injection
24anisha 5a18cde
code snippet hydration
24anisha 8836814
adding details to toolMetadata (untested)
24anisha b14528d
Merge branch 'main' into anisha/search_subagent
24anisha 0bf515e
commented out until testing
24anisha 9e02d6e
Merge branch 'main' into anisha/search_subagent
24anisha 1c9797f
Merge pull request #2 from vritant24/dev/vrbhardw/exitEarlyOnSearchSu…
24anisha 54e16da
Merge branch 'anisha/search_subagent' of https://github.com/24anisha/…
24anisha 77dae9a
remove exit from main PR
24anisha 9f068a6
actuallly terminate loop
vritant24 8b7ffee
Merge pull request #3 from vritant24/dev/vrbhardw/terminateToolLoop
24anisha 0d38b5b
end loop after round is added and run
vritant24 e00481d
Merge pull request #4 from vritant24/dev/vrbhardw/endToolCall
24anisha e6b1199
add search subagent to package nls
24anisha cc487fa
remove early exit handling
24anisha bbbc0ed
add experiment flags
24anisha 46041cd
Merge branch 'main' into anisha/flight_searchagent
24anisha 076da01
update code to check for exp + auto mode
24anisha c6a1b3f
update to only use gpt 5 mini for search subagent
24anisha efd7486
Merge branch 'main' into anisha/flight_searchagent
24anisha 3c0d8f7
Update src/extension/prompts/node/agent/searchSubagentPrompt.tsx
24anisha 9349052
Update docs/tools.md
24anisha b5df7d2
Update package.nls.json
24anisha 5c51cef
update tests to handle new prompts
24anisha 4c8ab2e
Merge branch 'main' into anisha/flight_searchagent
24anisha a6a2bf2
Apply suggestion from @Copilot
24anisha 683bf3c
deleting vestigial file
24anisha 563ecee
Merge branch 'anisha/flight_searchagent' of https://github.com/24anis…
24anisha 526d379
fix merge conflict
24anisha 3def81f
update to default to using the main agent model as fallback for subag…
24anisha a241f80
remove extra whitespace
24anisha 91abd0d
Merge branch 'main' into anisha/flight_searchagent
24anisha dfa6cd1
Merge branch 'main' into anisha/flight_searchagent
24anisha f01c2f4
remove runSubagent from package.json and update prompt for final snip…
24anisha 9d4a4b2
Merge branch 'anisha/flight_searchagent' of https://github.com/24anis…
24anisha 9e4c248
reset default to false
24anisha f28e5fd
add clearer injection prompt
24anisha c819574
Merge branch 'main' into anisha/flight_searchagent
24anisha 3e4998e
updating to work with main branch changes
24anisha 4695ab0
rewrite search subagent to have its own tool calling loop file + ensu…
24anisha 0e4bb5b
remove copilot-added search subagent doc
24anisha c94cd57
update toolResultMessage
24anisha 367e292
handle exp configuration for search subagent in the right place
24anisha 5929a6e
Merge branch 'main' into anisha/flight_searchagent
24anisha 4ffd863
merge with main
24anisha beece09
use searchSubagentLoop instead of subagentLoop
24anisha 55dc699
update to be in line with main
24anisha f463d21
remove CCA agents
24anisha bf4c5cf
Some minor cleanup
bhavyaus d540c5f
Merge branch 'main' into anisha/flight_searchagent
bhavyaus 84a6ea0
Merge branch 'main' into anisha/flight_searchagent
bhavyaus 5c2950e
Update import for ChatToolInvocationPart in SearchSubagentTool
bhavyaus ce57383
Merge branch 'main' into anisha/flight_searchagent
bhavyaus 9eb218e
Merge branch 'main' into anisha/flight_searchagent
bhavyaus 6a9a14d
Replace inSubAgent flag with subAgentInvocationId for tool calling lo…
bhavyaus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/extension/prompt/node/searchSubagentToolCallingLoop.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { randomUUID } from 'crypto'; | ||
| import type { CancellationToken, ChatRequest, ChatResponseStream, LanguageModelToolInformation, Progress } from 'vscode'; | ||
| import { IAuthenticationChatUpgradeService } from '../../../platform/authentication/common/authenticationUpgrade'; | ||
| import { ChatLocation, ChatResponse } from '../../../platform/chat/common/commonTypes'; | ||
| import { IConfigurationService } from '../../../platform/configuration/common/configurationService'; | ||
| import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider'; | ||
| import { ILogService } from '../../../platform/log/common/logService'; | ||
| import { IRequestLogger } from '../../../platform/requestLogger/node/requestLogger'; | ||
| import { IExperimentationService } from '../../../platform/telemetry/common/nullExperimentationService'; | ||
| import { ITelemetryService } from '../../../platform/telemetry/common/telemetry'; | ||
| import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation'; | ||
| import { ChatResponseProgressPart, ChatResponseReferencePart } from '../../../vscodeTypes'; | ||
| import { IToolCallingLoopOptions, ToolCallingLoop, ToolCallingLoopFetchOptions } from '../../intents/node/toolCallingLoop'; | ||
| import { SearchSubagentPrompt } from '../../prompts/node/agent/searchSubagentPrompt'; | ||
| import { PromptRenderer } from '../../prompts/node/base/promptRenderer'; | ||
| import { ToolName } from '../../tools/common/toolNames'; | ||
| import { IToolsService } from '../../tools/common/toolsService'; | ||
| import { IBuildPromptContext } from '../common/intents'; | ||
| import { IBuildPromptResult } from './intents'; | ||
|
|
||
| export interface ISearchSubagentToolCallingLoopOptions extends IToolCallingLoopOptions { | ||
| request: ChatRequest; | ||
| location: ChatLocation; | ||
| promptText: string; | ||
| } | ||
|
|
||
| export class SearchSubagentToolCallingLoop extends ToolCallingLoop<ISearchSubagentToolCallingLoopOptions> { | ||
|
|
||
| public static readonly ID = 'searchSubagentTool'; | ||
|
|
||
| constructor( | ||
| options: ISearchSubagentToolCallingLoopOptions, | ||
| @IInstantiationService private readonly instantiationService: IInstantiationService, | ||
| @ILogService logService: ILogService, | ||
| @IRequestLogger requestLogger: IRequestLogger, | ||
| @IEndpointProvider private readonly endpointProvider: IEndpointProvider, | ||
| @IToolsService private readonly toolsService: IToolsService, | ||
| @IAuthenticationChatUpgradeService authenticationChatUpgradeService: IAuthenticationChatUpgradeService, | ||
| @ITelemetryService telemetryService: ITelemetryService, | ||
| @IConfigurationService configurationService: IConfigurationService, | ||
| @IExperimentationService experimentationService: IExperimentationService, | ||
| ) { | ||
| super(options, instantiationService, endpointProvider, logService, requestLogger, authenticationChatUpgradeService, telemetryService, configurationService, experimentationService); | ||
| } | ||
|
|
||
| protected override createPromptContext(availableTools: LanguageModelToolInformation[], outputStream: ChatResponseStream | undefined): IBuildPromptContext { | ||
| const context = super.createPromptContext(availableTools, outputStream); | ||
| if (context.tools) { | ||
| context.tools = { | ||
| ...context.tools, | ||
| toolReferences: [], | ||
| subAgentInvocationId: randomUUID() | ||
| }; | ||
| } | ||
| context.query = this.options.promptText; | ||
| return context; | ||
| } | ||
|
|
||
| private async getEndpoint(request: ChatRequest) { | ||
| let endpoint = await this.endpointProvider.getChatEndpoint(this.options.request); | ||
| if (!endpoint.supportsToolCalls) { | ||
| endpoint = await this.endpointProvider.getChatEndpoint('gpt-4.1'); | ||
| } | ||
| return endpoint; | ||
| } | ||
|
|
||
| protected async buildPrompt(buildPromptContext: IBuildPromptContext, progress: Progress<ChatResponseReferencePart | ChatResponseProgressPart>, token: CancellationToken): Promise<IBuildPromptResult> { | ||
| const endpoint = await this.getEndpoint(this.options.request); | ||
| const renderer = PromptRenderer.create( | ||
| this.instantiationService, | ||
| endpoint, | ||
| SearchSubagentPrompt, | ||
| { | ||
| promptContext: buildPromptContext | ||
| } | ||
| ); | ||
| return await renderer.render(progress, token); | ||
| } | ||
|
|
||
| protected async getAvailableTools(): Promise<LanguageModelToolInformation[]> { | ||
| const endpoint = await this.getEndpoint(this.options.request); | ||
| const allTools = this.toolsService.getEnabledTools(this.options.request, endpoint); | ||
|
|
||
| // Only include tools relevant for search operations. | ||
| // We include semantic_search (Codebase) and the basic search primitives. | ||
| // The Codebase tool checks for inSubAgent context to prevent nested tool calling loops. | ||
| const allowedSearchTools = new Set([ | ||
| ToolName.Codebase, // Semantic search | ||
| ToolName.FindFiles, | ||
| ToolName.FindTextInFiles, | ||
| ToolName.ReadFile | ||
| ]); | ||
|
|
||
| return allTools.filter(tool => allowedSearchTools.has(tool.name as ToolName)); | ||
| } | ||
|
|
||
| protected async fetch({ messages, finishedCb, requestOptions }: ToolCallingLoopFetchOptions, token: CancellationToken): Promise<ChatResponse> { | ||
| const endpoint = await this.getEndpoint(this.options.request); | ||
| return endpoint.makeChatRequest2({ | ||
| debugName: SearchSubagentToolCallingLoop.ID, | ||
| messages, | ||
| finishedCb, | ||
| location: this.options.location, | ||
| requestOptions: { | ||
| ...requestOptions, | ||
| temperature: 0 | ||
| }, | ||
| // This loop is inside a tool called from another request, so never user initiated | ||
| userInitiatedRequest: false, | ||
| telemetryProperties: { | ||
| messageId: randomUUID(), | ||
| messageSource: SearchSubagentToolCallingLoop.ID | ||
| }, | ||
| }, token); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.