Path: blob/main/extensions/copilot/src/extension/prompts/node/agent/searchSubagentPrompt.tsx
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/456import { PromptElement, PromptSizing, SystemMessage, UserMessage } from '@vscode/prompt-tsx';7import { GenericBasePromptElementProps } from '../../../context/node/resolvers/genericPanelIntentInvocation';8import { CopilotToolMode } from '../../../tools/common/toolsRegistry';9import { ChatToolCalls } from '../panel/toolCalling';1011export interface SearchSubagentPromptProps extends GenericBasePromptElementProps {12readonly maxSearchTurns: number;13/** Thoroughness level requested by the caller. Influences the speed vs. thoroughness guidance in the system prompt. */14readonly thoroughness?: 'normal' | 'deep';15}1617const THOROUGHNESS_GUIDANCE: Record<NonNullable<SearchSubagentPromptProps['thoroughness']>, string> = {18normal: 'Use a balanced approach: parallelize where possible and stop when you have sufficient context.',19deep: 'Go broad to narrow: start with semantic or glob search to discover relevant areas, then narrow with text search. Parallelize tool calls. Read files when you need full context.',20};2122/**23* Prompt for the search subagent that uses custom search instructions24* instead of the default agent system prompt.25*/26export class SearchSubagentPrompt extends PromptElement<SearchSubagentPromptProps> {27async render(state: void, sizing: PromptSizing) {28const { conversation, toolCallRounds, toolCallResults } = this.props.promptContext;2930// Render the search instruction from the conversation31const searchInstruction = conversation?.turns[0]?.request.message;3233// Check if we're at the last turn (to align with training where we coax final answer)34const currentTurn = toolCallRounds?.length ?? 0;35const isLastTurn = currentTurn >= this.props.maxSearchTurns - 1;3637const thoroughnessGuidance = this.props.thoroughness ? THOROUGHNESS_GUIDANCE[this.props.thoroughness] : undefined;3839return (40<>41<SystemMessage priority={1000}>42You are an AI coding research assistant that uses search tools to gather information. You can call tools to search for information and read files across a codebase.<br />43<br />44{thoroughnessGuidance && (<>{thoroughnessGuidance}<br /><br /></>)}45Once you have searched the repository, return a message with ONLY: the <final_answer> tag to provide paths and line ranges of relevant code snippets.<br />46<br />47Example:<br />48<br />49<final_answer><br />50/absolute/path/to/file.py:10-20<br />51/absolute/path/to/another/file.cc:100-120<br />52</final_answer>53</SystemMessage>54<UserMessage priority={900}>{searchInstruction}</UserMessage>55<ChatToolCalls56priority={899}57flexGrow={2}58promptContext={this.props.promptContext}59toolCallRounds={toolCallRounds}60toolCallResults={toolCallResults}61toolCallMode={CopilotToolMode.FullContext}62/>63{isLastTurn && (64<UserMessage priority={900}>65OK, your allotted iterations are finished -- you must produce a list of code references as the final answer, starting and ending with <final_answer>.66</UserMessage>67)}68</>69);70}71}727374