You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/agent-runtime/src/tools/definitions/tool/write-file.ts
+7-44Lines changed: 7 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -6,62 +6,23 @@ const toolName = 'write_file'
6
6
exportconstwriteFileTool={
7
7
toolName,
8
8
description: `
9
-
#### **IMPORTANT** Edit Snippet
9
+
Create or replace a file with the given content.
10
10
11
-
Format the \`content\` parameter as an edit snippet that describes how you would like to modify the provided existing code.
11
+
#### Edit Snippet
12
12
13
-
Edit snippets will be parsed by a less intelligent "fast-apply" model, so you MUST follow this format, otherwise the finetuned smaller model will not understand what to change. For example, do not include detailed instructions on how to apply code changes for the fast-apply model.
13
+
Format the \`content\` parameter with the entire content of the file or as an edit snippet that describes how you would like to modify the provided existing code.
14
14
15
-
Abbreviate any sections of the code in your response that will remain the same with placeholder comments: "// ... existing code ...". Be descriptive in the comment. You MUST to use these in order to **MINIMIZE** the number of characters in the \`content\` parameter.
15
+
You may abbreviate any sections of the code in your response that will remain the same with placeholder comments: "// ... existing code ...". Abbreviate as much as possible to save the user credits!
16
16
17
-
Make sure that you are abbreviating exactly where you believe the existing code will remain the same.
18
-
Indicate the location and nature of the modifications (additions and deletions) with comments and ellipses.
19
-
20
-
Make sure that you preserve the indentation and code structure of exactly how you believe the final code will look like (do not output lines that will not be in the final code after they are merged).
21
-
22
-
##### **IMPORTANT** Deletion Comments
23
-
24
-
**CRITICAL FOR DELETIONS** If you plan on deleting a section, you MUST provide a comment giving the relevant context such that the code is understood to be removed. This is REQUIRED for the fast-apply model to understand what to delete.
25
-
26
-
Examples:
27
-
28
-
If the initial code is:
29
-
\`\`\`Some code
30
-
Block 1
31
-
Block 2
32
-
Block 3
33
-
More code
34
-
\`\`\`
35
-
And if you want to delete code block 2, you MUST include a comment like:
36
-
\`\`\`// existing code
37
-
Block 1
38
-
// Delete Block 2
39
-
Block 3
40
-
// rest of code
41
-
\`\`\`
42
-
43
-
**YOU MUST ALWAYS INCLUDE DELETION COMMENTS** when removing **anything**: single lines, code blocks, functions, variables, or any other code elements. The fast-apply model cannot understand deletions without these explicit comments.
44
-
45
-
Merely omitting the code block may or may not work. In order to guarantee the deletion of the code, you must include a deletion comment.
17
+
If you don't use any placeholder comments, the entire file will be replaced. E.g. don't write out a single function without using placeholder comments unless you want to replace the entire file with that function.
46
18
47
19
#### Additional Info
48
20
49
21
Prefer str_replace to write_file for most edits, including small-to-medium edits to a file, for deletions, or for editing large files (>1000 lines). Otherwise, prefer write_file for major edits throughout a file, or for creating new files.
50
22
51
23
Do not use this tool to delete or rename a file. Instead run a terminal command for that.
52
24
53
-
Notes for editing a file:
54
-
- If you don't use any placeholder comments, the entire file will be replaced. E.g. don't write out a single function without using placeholder comments unless you want to replace the entire file with that function.
55
-
- When editing a file, try not to change any user code that doesn't need to be changed. In particular, you must preserve pre-existing user comments exactly as they are.
56
-
- You can also use this tool to create new files.
57
-
- After you have written out a write_file block, the changes will be applied immediately. You can assume that the changes went through as intended. However, note that there are sometimes mistakes in the process of applying the edits you described in the write_file block, e.g. sometimes large portions of the file are deleted. If you notice that the changes did not go through as intended, based on further updates to the file, you can write out a new write_file block to fix the mistake.
0 commit comments