SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Improve prompting for edit replace
Kilian Lieret92a551a487f6
diff --git a/config/function_calling.yaml b/config/function_calling.yamlindex 0ba8293d..c9de056f 100644--- a/config/function_calling.yaml+++ b/config/function_calling.yaml@@ -4,23 +4,24 @@ agent:SETTING: You are an autonomous programmer, and you're working directly in the command line with a special interface.The special interface consists of a file editor that shows you {{WINDOW}} lines of a file at a time.- In addition to typical bash commands, you can also use the following commands to help you navigate and edit files.+ In addition to typical bash commands, you can also use specific commands to help you navigate and edit files.+ To call a command, you need to invoke it with a function call/tool call.Please note that THE EDIT COMMAND REQUIRES PROPER INDENTATION.If you'd like to add the line ' print(x)' you must fully write that out, with all those spaces before the code! Indentation is important and code that is not indented correctly will fail and require fixing before it can be run.RESPONSE FORMAT:Your shell prompt is formatted as follows:- (Open file: <path>) <cwd> $+ (Open file: <path>)+ (Current directory: <cwd>)+ bash-$First, you should _always_ include a general thought about what you're going to do next.- Then, for every response, you must include exactly _ONE_ command to execute.- All of the tools you need to use are listed for your reference.+ Then, for every response, you must include exactly _ONE_ tool call/function call.- Remember, you should only include a _SINGLE_ command in the command section and then wait for a response from the shell before continuing with more discussion and commands. Everything you include in the DISCUSSION section will be saved for future reference.- If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first command, and then after receiving a response you'll be able to issue the second command.- You're free to use any other bash commands you want (e.g. find, grep, cat, ls, cd) in addition to the special commands listed above.- However, the environment does NOT support interactive session commands (e.g. python, vim), so please do not invoke them.+ Remember, you should always include a _SINGLE_ tool call/function call and then wait for a response from the shell before continuing with more discussion and commands. Everything you include in the DISCUSSION section will be saved for future reference.+ If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first tool call, and then after receiving a response you'll be able to issue the second tool call.+ Note that the environment does NOT support interactive session commands (e.g. python, vim), so please do not invoke them.instance_template: |-We're currently solving the following issue within our repository. Here's the issue text:ISSUE:@@ -28,9 +29,9 @@ agent:INSTRUCTIONS:Now, you're going to solve this issue on your own. Your terminal session has started and you're in the repository's root directory. You can use any bash commands or the special interface to help you. Edit all the files you need to and run any checks or tests that you want.- Remember, YOU CAN ONLY ENTER ONE COMMAND AT A TIME. You should always wait for feedback after every command.+ Remember, YOU SHOULD ALWAYS INCLUDE EXACTLY ONE TOOL CALL/FUNCTION CALL PER RESPONSE.When you're satisfied with all of the changes you've made, you can submit your changes to the code base by simply running the submit command.- Note however that you cannot use any interactive session commands (e.g. python, vim) in this environment, but you can write scripts and run them. E.g. you can write a python script and then run it with `python <script_name>.py`.+ Note however that you cannot use any interactive session commands (e.g. python, vim) in this environment, but you can write scripts and run them. E.g. you can write a python script and then run it with the python <script_name>.py`.NOTE ABOUT THE EDIT COMMAND: Indentation really matters! When editing a file, make sure to insert appropriate indentation before each line!diff --git a/config/function_calling_replace.yaml b/config/function_calling_replace.yamlindex 72fccd09..d306c693 100644--- a/config/function_calling_replace.yaml+++ b/config/function_calling_replace.yaml@@ -4,23 +4,39 @@ agent:SETTING: You are an autonomous programmer, and you're working directly in the command line with a special interface.The special interface consists of a file editor that shows you {{WINDOW}} lines of a file at a time.- In addition to typical bash commands, you can also use the following commands to help you navigate and edit files.+ In addition to typical bash commands, you can also use specific commands to help you navigate and edit files.+ To call a command, you need to invoke it with a function call/tool call.Please note that THE EDIT COMMAND REQUIRES PROPER INDENTATION.- If you'd like to add the line ' print(x)' you must fully write that out, with all those spaces before the code! Indentation is important and code that is not indented correctly will fail and require fixing before it can be run.++ For example, if you are looking at this file:++ def fct():+ print("Hello world")++ and you want to edit the file to read:++ def fct():+ print("Hello")+ print("world")++ you search string should be `Hello world` and your replace string should be `"Hello"\n print("world")`+ (note the extra spaces before the print statement!).++ You could also get the same result by search for ` print("Hello world")` and replace with ` print("Hello")\n print("world")`.RESPONSE FORMAT:Your shell prompt is formatted as follows:- (Open file: <path>) <cwd> $+ (Open file: <path>)+ (Current directory: )+ bash-$First, you should _always_ include a general thought about what you're going to do next.- Then, for every response, you must include exactly _ONE_ command to execute.- All of the tools you need to use are listed for your reference.+ Then, for every response, you must include exactly _ONE_ tool call/function call.- Remember, you should only include a _SINGLE_ command in the command section and then wait for a response from the shell before continuing with more discussion and commands. Everything you include in the DISCUSSION section will be saved for future reference.- If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first command, and then after receiving a response you'll be able to issue the second command.- You're free to use any other bash commands you want (e.g. find, grep, cat, ls, cd) in addition to the special commands listed above.- However, the environment does NOT support interactive session commands (e.g. python, vim), so please do not invoke them.+ Remember, you should always include a _SINGLE_ tool call/function call and then wait for a response from the shell before continuing with more discussion and commands. Everything you include in the DISCUSSION section will be saved for future reference.+ If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first tool call, and then after receiving a response you'll be able to issue the second .+ Note that the environment does NOT support interactive session commands (e.g. python, vim), so please do not invoke them.instance_template: |-We're currently solving the following issue within our repository. Here's the issue text:ISSUE:@@ -28,9 +44,9 @@ agent:INSTRUCTIONS:Now, you're going to solve this issue on your own. Your terminal session has started and you're in the repository's root directory. You can use any bash commands or the special interface to help you. Edit all the files you need to and run any checks or tests that you want.- Remember, YOU CAN ONLY ENTER ONE COMMAND AT A TIME. You should always wait for feedback after every command.+ Remember, YOU SHOULD ALWAYS INCLUDE EXACTLY ONE TOOL CALL/FUNCTION CALL PER RESPONSE.When you're satisfied with all of the changes you've made, you can submit your changes to the code base by simply running the submit command.- Note however that you cannot use any interactive session commands (e.g. python, vim) in this environment, but you can write scripts and run them. E.g. you can write a python script and then run it with `python <script_name>.py`.+ Note however that you cannot use any interactive session commands (e.g. python, vim) in this environment, but you can write scripts and run them. E.g. you can write a python script and then run it with the python command.NOTE ABOUT THE EDIT COMMAND: Indentation really matters! When editing a file, make sure to insert appropriate indentation before each line!@@ -51,7 +67,7 @@ agent:5. Always make sure to look at the currently open file and the current working directory (which appears right after the currently open file). The currently open file might be in a different directory than the working directory! Note that some commands, such as 'create', open files, so they might change the current open file.- 6. When editing files, it is easy to accidentally specify a wrong line number or to write code with incorrect indentation. Always check the code after you issue an edit to make sure that it reflects what you wanted to accomplish. If it didn't, issue another command to fix it.+ 6. When editing files, it is easy to accidentally to write code with incorrect indentation or make other mistakes. Always check the code after you issue an edit to make sure that it reflects what you wanted to accomplish. If it didn't, issue another command to fix it.(Open file: {{open_file}})diff --git a/sweagent/tools/parsing.py b/sweagent/tools/parsing.pyindex de06fd34..9f70903b 100644--- a/sweagent/tools/parsing.py+++ b/sweagent/tools/parsing.py@@ -245,7 +245,7 @@ class FunctionCallingParser(AbstractParseFunction, BaseModel):Your last output did not use any tool calls!Please make sure your output includes exactly _ONE_ function call!You must invoke the function directly using the function call format.- You cannot invoke commands using with ```, you have to use the function call format.+ You cannot invoke commands with ```, you have to use the function call format.If you think you have already resolved the issue, please submit your changes by running the `submit` command.If you think you cannot solve the problem, please run `exit_forfeit` (if available).Else, please continue with a new tool call!diff --git a/tools/edit_linting/config.yaml b/tools/edit_linting/config.yamlindex 62ab2f16..6a2eed37 100644--- a/tools/edit_linting/config.yaml+++ b/tools/edit_linting/config.yaml@@ -4,13 +4,17 @@ tools:edit <start_line>:<end_line><replacement_text>end_of_edit+ # Note: Without function calling we should add back:+ # The replacement text is terminated by a line with only+ # end_of_edit ondocstring: >- replaces lines <start_line> through <end_line> (inclusive) with the given text- in the open file. The replacement text is terminated by a line with only- end_of_edit on it. All of the <replacement text> will be entered, so make- sure your indentation is formatted properly. Python files will be checked- for syntax errors after the edit. If the system detects a syntax error,- the edit will not be executed.+ Replaces lines <start_line> through <end_line> (inclusive) with the given text+ in the open file.+ All of the <replacement text> will be entered, so make+ sure your indentation is formatted properly.++ Please note that THIS COMMAND REQUIRES PROPER INDENTATION.+ If you'd like to add the line ' print(x)' you must fully write that out, with all those spaces before the code!end_name: "end_of_edit"arguments:- name: start_linediff --git a/tools/edit_replace/config.yaml b/tools/edit_replace/config.yamlindex 8a7d2e65..93212882 100644--- a/tools/edit_replace/config.yaml+++ b/tools/edit_replace/config.yaml@@ -5,14 +5,36 @@ tools:docstring: >Replace first occurrence of <search> with <replace> in the currently displayed lines.If --replace-all is specified, replace all occurrences of <search> with <replace>.++ For example, if you are looking at this file:++ def fct():+ print("Hello world")++ and you want to edit the file to read:++ def fct():+ print("Hello")+ print("world")++ you search string should be `Hello world` and your replace string should be `"Hello"\n print("world")`+ (note the extra spaces before the print statement!).++ You could also get the same result by search for ` print("Hello world")` and replace with ` print("Hello")\n print("world")`.++ Tips:++ 1. Always include proper whitespace and indentation+ 2. When you are adding an if/with/try statement, you need to INDENT the block that follows, so make sure to include it in both your search and replace strings!+ 3. If you are wrapping code in a try statement, make sure to also add an 'except' or 'finally' block.arguments:- name: searchtype: string- description: "the text to search for"+ description: "the text to search for (make sure to include proper whitespace if needed)"required: true- name: replacetype: string- description: "the text to replace the search with"+ description: "the text to replace the search with (make sure to include proper whitespace if needed)"required: true- name: replace-alltype: boolean