Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/codebaseAgentPrompt.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*--------------------------------------------------------------------------------------------*/45import { PromptElement, PromptSizing } from '@vscode/prompt-tsx';6import { IWorkspaceChunkSearchService } from '../../../../platform/workspaceChunkSearch/node/workspaceChunkSearchService';7import { GenericBasePromptElementProps } from '../../../context/node/resolvers/genericPanelIntentInvocation';8import { ToolName } from '../../../tools/common/toolNames';9import { CopilotToolMode } from '../../../tools/common/toolsRegistry';10import { InstructionMessage } from '../base/instructionMessage';11import { Tag } from '../base/tag';12import { ChatVariablesAndQuery } from './chatVariables';13import { HistoryWithInstructions } from './conversationHistory';14import { ChatToolCalls } from './toolCalling';15import { WorkspaceFoldersHint } from './workspace/workspaceFoldersHint';16import { MultirootWorkspaceStructure } from './workspace/workspaceStructure';1718export class CodebaseAgentPrompt extends PromptElement<GenericBasePromptElementProps> {19constructor(20props: GenericBasePromptElementProps,21@IWorkspaceChunkSearchService private readonly workspaceChunkSearch: IWorkspaceChunkSearchService,22) {23super(props);24}2526async render(state: void, sizing: PromptSizing) {27const { query, chatVariables, history, toolCallRounds, toolCallResults } = this.props.promptContext;28const hasSemanticSearch = await this.workspaceChunkSearch.isAvailable();29return (30<>31<HistoryWithInstructions flexGrow={1} passPriority historyPriority={700} history={history}>32<InstructionMessage>33<Tag name='context'>34<WorkspaceFoldersHint />35<MultirootWorkspaceStructure maxSize={2000} excludeDotFiles={true} /><br />36This view of the workspace structure may be truncated. You can use tools to collect more context if needed.37</Tag>38<Tag name='instructions'>39You are a code search expert.<br />40A developer needs to find some code in their codebase so that they can resolve a question or complete a task. You have full access to their codebase and can run tools to find code in it. Their request may contain hints for some of the files needed. It may require just one tool or many tools to collect the full context required.<br />41First, analyze the developer's request to determine how complicated their task is. Keep your search focused on the developer's request, and don't run extra tools if the developer's request clearly can be satisfied by just one.<br />42If the developer wants to implement a feature and they have not specified the relevant files, first break down the developer's request into smaller concepts and think about the kinds of files you need to grasp each concept.<br />43If you cannot infer the project type (languages, frameworks, and libraries) from the developer's request or the context that you have, run the `{ToolName.ReadProjectStructure}` tool to get the lay of the land and read additional files to understand the project setup.<br />44If you aren't sure which tool is relevant, you can call multiple tools. You can call tools repeatedly to take actions or gather as much context as needed.<br />45Don't make assumptions about the situation. Gather enough context to address the developer's request without going overboard.<br />46Your only task is to help the developer find context. Do not write code for the developer's request.<br />47Your response will be read by your colleague who is an expert in editing files, not the developer, so do not offer to edit files or perform additional follow up actions at the end of your response.48</Tag>49<Tag name='toolUseInstructions'>50Remember that you can call multiple tools in one response.<br />51If you think running multiple tools can answer the user's question, prefer calling them in parallel whenever possible{hasSemanticSearch && ` but do not call \`${ToolName.Codebase}\` in parallel`}.<br />52{hasSemanticSearch && `Use \`${ToolName.Codebase}\` to search for high level concepts or descriptions of functionality in the user's question.`}<br />53Prefer `{ToolName.SearchWorkspaceSymbols}` over `{ToolName.FindTextInFiles}` when you have precise code identifiers to search for.<br />54Prefer `{ToolName.FindTextInFiles}` over `{ToolName.Codebase}` when you have precise keywords to search for.<br />55When using a tool, follow the JSON schema very carefully and make sure to include all required fields.<br />56If a tool exists to do a task, use the tool instead of asking the developer to manually take an action.<br />57If you say that you will take an action, then go ahead and use the tool to do it.<br />58The tools `{ToolName.FindFiles}`, `{ToolName.FindTextInFiles}`, and `{ToolName.GetScmChanges}` are deterministic and comprehensive, so do not repeatedly invoke them with the same arguments.<br />59Never use multi_tool_use.parallel or any tool that does not exist. Use tools using the proper procedure. DO NOT write out a JSON codeblock with the tool inputs.60</Tag>61</InstructionMessage>62</HistoryWithInstructions>63<ChatToolCalls priority={899} flexGrow={3} promptContext={this.props.promptContext} toolCallRounds={toolCallRounds} toolCallResults={toolCallResults} toolCallMode={CopilotToolMode.FullContext} />64<ChatVariablesAndQuery flexGrow={2} priority={900} chatVariables={chatVariables} query={`The developer's request is: ${query}\n\nFind all code in the workspace relevant to the following request.`} includeFilepath={true} embeddedInsideUserMessage={false} />65</>66);67}68}697071