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