Path: blob/main/extensions/copilot/src/extension/prompts/node/agent/executionSubagentPrompt.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, SystemMessage, UserMessage } from '@vscode/prompt-tsx';6import { GenericBasePromptElementProps } from '../../../context/node/resolvers/genericPanelIntentInvocation';7import { ToolName } from '../../../tools/common/toolNames';8import { CopilotToolMode } from '../../../tools/common/toolsRegistry';9import { SafetyRules } from '../base/safetyRules';10import { TerminalStatePromptElement } from '../base/terminalState';11import { ChatToolCalls } from '../panel/toolCalling';1213export interface ExecutionSubagentPromptProps extends GenericBasePromptElementProps {14readonly maxExecutionTurns: number;15/** True if a previous {@link ToolName.CoreRunInTerminal} call timed out or was16* invoked in async/background mode; the model is told to stop calling tools17* and emit its `<final_answer>`. */18readonly hasBackgroundCommand?: boolean;19}2021/**22* Prompt for the execution subagent that uses custom execution instructions23* instead of the default agent system prompt.24*/25export class ExecutionSubagentPrompt extends PromptElement<ExecutionSubagentPromptProps> {26async render(state: void, sizing: PromptSizing) {27const { conversation, toolCallRounds, toolCallResults } = this.props.promptContext;2829// Render the execution instruction from the conversation30const executionInstruction = conversation?.turns[0]?.request.message;3132// Check if we're at the last turn (to align with training where we coax final answer)33const currentTurn = toolCallRounds?.length ?? 0;34const isLastTurn = currentTurn >= this.props.maxExecutionTurns - 1;3536return (37<>38<SystemMessage priority={1000}>39You are an AI coding research assistant that runs a series of terminal commands to perform a small execution-focused task.<br />40You will be given a description of a task, and potentially some commands to run, but you can adapt the commands as necessary to complete the task.<br />41For example, if you are asked to `make` a project but there is no Makefile, you might instead run "cmake . && make" to successfully build the code. <br />42<br />43<SafetyRules />44<br />45When calling {ToolName.CoreRunInTerminal}, you MUST follow these rules:<br />46- Always use mode="sync".<br />47- Always include "timeout" in milliseconds. Use timeout=30000 for short commands, or timeout=120000 for builds and test suites.<br />48- Only call {ToolName.CoreRunInTerminal} once per turn. Do NOT call it in parallel.<br />49- If a command may prompt for confirmation, use flags like --yes, -y, or pipe from `yes` to auto-confirm.<br />50<br />51Once you have finished, return a message with ONLY: the <final_answer> tag to provide a compact summary of each command that was run.<br />52<br />53Example:<br />54<br />55[Call {ToolName.CoreRunInTerminal} with {'{'}"command": "make", "explanation": "Build the project", "goal": "Build the project", "mode": "sync", "timeout": 30000{'}'}]<br />56<br />57[Result: No Makefile found.]<br />58<br />59[Call {ToolName.CoreRunInTerminal} with {'{'}"command": "cmake . && make", "explanation": "Build with cmake", "goal": "Build the project", "mode": "sync", "timeout": 120000{'}'}]<br />60<br />61[Result: Build unsuccessful with errors.]<br />62<br />63<final_answer><br />64Command: make<br />65Summary: No Makefile found. <br />6667Command: cmake . && make<br />68Summary: Build unsuccessful. Excerpt of build log showing the error:<br />69...<br />70</final_answer><br />71</SystemMessage>72<UserMessage priority={800}>73<TerminalStatePromptElement sessionId={conversation?.sessionId} />74</UserMessage>75<UserMessage priority={900}>{executionInstruction}</UserMessage>76<ChatToolCalls77priority={899}78flexGrow={2}79promptContext={this.props.promptContext}80toolCallRounds={toolCallRounds}81toolCallResults={toolCallResults}82toolCallMode={CopilotToolMode.FullContext}83/>84{isLastTurn && (85<UserMessage priority={900}>86OK, your allotted iterations are finished. Show the <final_answer>.87</UserMessage>88)}89{!isLastTurn && this.props.hasBackgroundCommand && (90<UserMessage priority={900}>91One or more commands are running in the background. You do not have the ability to monitor them. Show the <final_answer>.92</UserMessage>93)}94</>95);96}97}9899