Skip to content

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]

Admonish to not break existing functionality

Kilian Lieret8917167e3eb2
diff --git a/config/function_calling_replace.yaml b/config/function_calling_replace.yaml
index 084f2fc6..c9c14be3 100644
--- a/config/function_calling_replace.yaml
+++ b/config/function_calling_replace.yaml
@@ -69,7 +69,9 @@ agent:
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.
- 7. Do not try to install any packages with `pip`, `conda`, or any other way. This will usually not work. If the environment is not set up correctly, try to fix the issue without executing python code or running any tests that require the package installed.
+ 7. When editing files, first explain the code you want to edit and why it is causing the problem. Then explain the edit you want to make and how it fixes the problem. Explain how the edit does not break existing functionality.
+
+ 8. Do not try to install any packages with `pip`, `conda`, or any other way. This will usually not work. If the environment is not set up correctly, try to fix the issue without executing python code or running any tests that require the package installed.
(Open file: {{open_file}})
(Current directory: {{working_dir}})
diff --git a/tools/edit_replace/bin/edit b/tools/edit_replace/bin/edit
index 22443168..317d8dca 100644
--- a/tools/edit_replace/bin/edit
+++ b/tools/edit_replace/bin/edit
@@ -38,11 +38,21 @@ Please make your search string more specific (for example, by including more lin
_NO_CHANGES_MADE_MSG = """Your search and replace strings are the same. No changes were made. Please modify your search or replace strings."""
-_SINGLE_EDIT_SUCCESS_MSG = """Text replaced. Please review the changes and make sure they are correct
-(correct indentation, no duplicate lines, etc). Edit the file again if necessary."""
+_SINGLE_EDIT_SUCCESS_MSG = """Text replaced. Please review the changes and make sure they are correct:
-_MULTIPLE_EDITS_SUCCESS_MSG = """Replaced {n_replacements} occurrences. Please review the changes and make sure they are correct
-(correct indentation, no duplicate lines, etc). Edit the file again if necessary."""
+1. The edited file is correctly indented
+2. The edited file does not contain duplicate lines
+3. The edit does not break existing functionality
+
+Edit the file again if necessary."""
+
+_MULTIPLE_EDITS_SUCCESS_MSG = """Replaced {n_replacements} occurrences. Please review the changes and make sure they are correct:
+
+1. The edited file is correctly indented
+2. The edited file does not contain duplicate lines
+3. The edit does not break existing functionality
+
+Edit the file again if necessary."""
_LINT_ERROR_TEMPLATE = """Your proposed edit has introduced new syntax error(s). Please read this error message carefully and then retry editing the file.
diff --git a/tools/edit_replace/config.yaml b/tools/edit_replace/config.yaml
index 93212882..8ad71ddd 100644
--- a/tools/edit_replace/config.yaml
+++ b/tools/edit_replace/config.yaml
@@ -4,7 +4,7 @@ tools:
edit <search> <replace> [<replace-all>]
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>.
+ If replace-all is True , replace all occurrences of <search> with <replace>.
For example, if you are looking at this file:
@@ -17,16 +17,20 @@ tools:
print("Hello")
print("world")
- you search string should be `Hello world` and your replace string should be `"Hello"\n print("world")`
+ you can search for `Hello world` and replace with `"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
+ 1. Always include proper whitespace/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.
+
+ Before every edit, please
+
+ 1. Explain the code you want to edit and why it is causing the problem
+ 2. Explain the edit you want to make and how it fixes the problem
+ 3. Explain how the edit does not break existing functionality
arguments:
- name: search
type: string
diff --git a/trajectories/demonstrations/replay__marshmallow-code__marshmallow-1867__function_calling_replace__install-1/marshmallow-code__marshmallow-1867.traj b/trajectories/demonstrations/replay__marshmallow-code__marshmallow-1867__function_calling_replace__install-1/marshmallow-code__marshmallow-1867.traj
index 52319a0d..e03387a0 100644
--- a/trajectories/demonstrations/replay__marshmallow-code__marshmallow-1867__function_calling_replace__install-1/marshmallow-code__marshmallow-1867.traj
+++ b/trajectories/demonstrations/replay__marshmallow-code__marshmallow-1867__function_calling_replace__install-1/marshmallow-code__marshmallow-1867.traj
@@ -301,8 +301,8 @@
{
"message_type": "action",
"role": "assistant",
- "content": "We are now looking at the relevant section of the `fields.py` file where the `TimeDelta` serialization occurs. The issue suggests that there is a rounding problem near line 1474. The current implementation uses integer division, which truncates the decimal part and can lead to incorrect rounding on line 1475. To fix this issue, we should ensure that the division results in a float, and then round the result to the nearest integer before converting it to an int. This should preserve the milliseconds precision as expected. Let's replace the return line with the right code.",
- "thought": "We are now looking at the relevant section of the `fields.py` file where the `TimeDelta` serialization occurs. The issue suggests that there is a rounding problem near line 1474. The current implementation uses integer division, which truncates the decimal part and can lead to incorrect rounding on line 1475. To fix this issue, we should ensure that the division results in a float, and then round the result to the nearest integer before converting it to an int. This should preserve the milliseconds precision as expected. Let's replace the return line with the right code.",
+ "content": "We are now looking at the relevant section of the `fields.py` file where the `TimeDelta` serialization occurs. The issue suggests that there is a rounding problem near line 1474. The current implementation uses integer division, which truncates the decimal part and can lead to incorrect rounding on line 1475. To fix this issue, we should ensure that the division results in a float, and then round the result to the nearest integer before converting it to an int. This should preserve the milliseconds precision as expected without breaking existing functionality. Let's replace the return line with the right code.",
+ "thought": "We are now looking at the relevant section of the `fields.py` file where the `TimeDelta` serialization occurs. The issue suggests that there is a rounding problem near line 1474. The current implementation uses integer division, which truncates the decimal part and can lead to incorrect rounding on line 1475. To fix this issue, we should ensure that the division results in a float, and then round the result to the nearest integer before converting it to an int. This should preserve the milliseconds precision as expected without breaking existing functionality. Let's replace the return line with the right code.",
"action": "edit 'return int(value.total_seconds() / base_unit.total_seconds())' '# round to nearest int\nreturn int(round(value.total_seconds() / base_unit.total_seconds()))'",
"agent": "main",
"tool_calls": [
@@ -355,8 +355,8 @@
{
"message_type": "action",
"role": "assistant",
- "content": "The code has been updated to use the `round` function, which should fix the rounding issue. Before submitting the changes, it would be prudent to run the reproduce.py code again to ensure that this change has the desired effect. I see that \"Current directory\" is still `/marshmallow-code__marshmallow`, so we can just run `reproduce.py` directly.",
- "thought": "The code has been updated to use the `round` function, which should fix the rounding issue. Before submitting the changes, it would be prudent to run the reproduce.py code again to ensure that this change has the desired effect. I see that \"Current directory\" is still `/marshmallow-code__marshmallow`, so we can just run `reproduce.py` directly.",
+ "content": "The code has been updated to use the `round` function, which should fix the rounding issue. The file is correctly indented and does not contain duplicate lines. The existing functionality is not broken, but we fixed the rounding issue. Before submitting the changes, it would be prudent to run the reproduce.py code again to ensure that this change has the desired effect. I see that \"Current directory\" is still `/marshmallow-code__marshmallow`, so we can just run `reproduce.py` directly.",
+ "thought": "The code has been updated to use the `round` function, which should fix the rounding issue. The file is correctly indented and does not contain duplicate lines. The existing functionality is not broken, but we fixed the rounding issue. Before submitting the changes, it would be prudent to run the reproduce.py code again to ensure that this change has the desired effect. I see that \"Current directory\" is still `/marshmallow-code__marshmallow`, so we can just run `reproduce.py` directly.",
"action": "python reproduce.py",
"agent": "main",
"tool_calls": [