Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/agent/searchSubagentPrompt.tsx
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
7
import { PromptElement, PromptSizing, SystemMessage, UserMessage } from '@vscode/prompt-tsx';
8
import { GenericBasePromptElementProps } from '../../../context/node/resolvers/genericPanelIntentInvocation';
9
import { CopilotToolMode } from '../../../tools/common/toolsRegistry';
10
import { ChatToolCalls } from '../panel/toolCalling';
11
12
export interface SearchSubagentPromptProps extends GenericBasePromptElementProps {
13
readonly maxSearchTurns: number;
14
/** Thoroughness level requested by the caller. Influences the speed vs. thoroughness guidance in the system prompt. */
15
readonly thoroughness?: 'normal' | 'deep';
16
}
17
18
const THOROUGHNESS_GUIDANCE: Record<NonNullable<SearchSubagentPromptProps['thoroughness']>, string> = {
19
normal: 'Use a balanced approach: parallelize where possible and stop when you have sufficient context.',
20
deep: '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.',
21
};
22
23
/**
24
* Prompt for the search subagent that uses custom search instructions
25
* instead of the default agent system prompt.
26
*/
27
export class SearchSubagentPrompt extends PromptElement<SearchSubagentPromptProps> {
28
async render(state: void, sizing: PromptSizing) {
29
const { conversation, toolCallRounds, toolCallResults } = this.props.promptContext;
30
31
// Render the search instruction from the conversation
32
const searchInstruction = conversation?.turns[0]?.request.message;
33
34
// Check if we're at the last turn (to align with training where we coax final answer)
35
const currentTurn = toolCallRounds?.length ?? 0;
36
const isLastTurn = currentTurn >= this.props.maxSearchTurns - 1;
37
38
const thoroughnessGuidance = this.props.thoroughness ? THOROUGHNESS_GUIDANCE[this.props.thoroughness] : undefined;
39
40
return (
41
<>
42
<SystemMessage priority={1000}>
43
You 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 />
44
<br />
45
{thoroughnessGuidance && (<>{thoroughnessGuidance}<br /><br /></>)}
46
Once you have searched the repository, return a message with ONLY: the &lt;final_answer&gt; tag to provide paths and line ranges of relevant code snippets.<br />
47
<br />
48
Example:<br />
49
<br />
50
&lt;final_answer&gt;<br />
51
/absolute/path/to/file.py:10-20<br />
52
/absolute/path/to/another/file.cc:100-120<br />
53
&lt;/final_answer&gt;
54
</SystemMessage>
55
<UserMessage priority={900}>{searchInstruction}</UserMessage>
56
<ChatToolCalls
57
priority={899}
58
flexGrow={2}
59
promptContext={this.props.promptContext}
60
toolCallRounds={toolCallRounds}
61
toolCallResults={toolCallResults}
62
toolCallMode={CopilotToolMode.FullContext}
63
/>
64
{isLastTurn && (
65
<UserMessage priority={900}>
66
OK, your allotted iterations are finished -- you must produce a list of code references as the final answer, starting and ending with &lt;final_answer&gt;.
67
</UserMessage>
68
)}
69
</>
70
);
71
}
72
}
73
74