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]

Fix: Initialization ReviewLoop without BinaryReview

Kilian Lieret40969a5f6e9f
diff --git a/config/default_retry.yaml b/config/default_retry.yaml
index 94e458c5..f18bc4c8 100644
--- a/config/default_retry.yaml
+++ b/config/default_retry.yaml
@@ -109,8 +109,9 @@ parse_command: ParseCommandDetailed
history_processor: Last5Observations
demonstrations:
- trajectories/demonstrations/replay__marshmallow-code__marshmallow-1867__default_sys-env_window100__t-0.20__p-0.95__c-2.00__install-1/marshmallow-code__marshmallow-1867.traj
-review_loop_classname: ReviewLoop
review_loop_config:
+ review_loop_classname: ReviewLoop
+ reviewer_classname: Reviewer
reviewer_config:
system_template: |
You are checking whether a problem in a code base has been resolved.
@@ -138,6 +139,7 @@ review_loop_config:
```
{edited_files70}
```
+ binary_reviewer_classname: BinaryReviewer
binary_reviewer_config:
system_template: |
You are comparing two attempts to fix a problem in a code base to determine which one resolves the problem better.
diff --git a/sweagent/agent/reviewer.py b/sweagent/agent/reviewer.py
index 2d78b68e..0f084c35 100644
--- a/sweagent/agent/reviewer.py
+++ b/sweagent/agent/reviewer.py
@@ -153,12 +153,12 @@ class GTCConfig(FrozenSerializable):
class ReviewLoopConfig(FrozenSerializable):
"""The configuration for the review loop"""
- reviewer_config: ReviewerConfig
- binary_reviewer_config: BinaryReviewerConfig
+ reviewer_config: ReviewerConfig | None = None
+ binary_reviewer_config: BinaryReviewerConfig | None = None
gtc_config: GTCConfig | None = None
- review_loop_classname: str = "ReviewLoop"
- reviewer_classname: str = "Reviewer"
- binary_reviewer_classname: str = "BinaryReviewer"
+ review_loop_classname: str | None = None
+ reviewer_classname: str | None = None
+ binary_reviewer_classname: str | None = None
gtc_classname: str = ""
max_samples: int = 2
min_draws: int = 1
@@ -346,9 +346,12 @@ class ReviewLoop(AbstractReviewLoop):
self._model = model
self._instance = instance
self._reviewer: AbstractReviewer = globals()[loop_config.reviewer_classname](loop_config.reviewer_config, model)
- self._breviewer: AbstractBinaryReviewer = globals()[loop_config.binary_reviewer_classname](
- loop_config.binary_reviewer_config, model
- )
+ if loop_config.binary_reviewer_classname is not None:
+ self._breviewer: AbstractBinaryReviewer | None = globals()[loop_config.binary_reviewer_classname](
+ loop_config.binary_reviewer_config, model
+ )
+ else:
+ self._breviewer = None
self._gtc: AbstractGraveToCradle | None = None
if loop_config.gtc_classname:
self._gtc = globals()[loop_config.gtc_classname](loop_config.gtc_config, model)
@@ -394,6 +397,9 @@ class ReviewLoop(AbstractReviewLoop):
return review.accept
def _compare(self) -> None:
+ if self._breviewer is None:
+ self._best_idx = self._n_samples - 1
+ return
if self._n_samples < 2:
return
if self._reviews[self._best_idx].accept and not self._reviews[-1].accept:
@@ -429,7 +435,8 @@ class ReviewLoop(AbstractReviewLoop):
return True
def get_best(self) -> int:
- assert len(self._reviews) == len(self._submissions)
+ if self._breviewer is not None:
+ assert len(self._reviews) == len(self._submissions)
return self._best_idx
def get_forwarded_vars(self) -> dict[str, Any]:
diff --git a/tests/test_data/config_files/default_retry_no_breviewer.yaml b/tests/test_data/config_files/default_retry_no_breviewer.yaml
new file mode 100644
index 00000000..a2afbc79
--- /dev/null
+++ b/tests/test_data/config_files/default_retry_no_breviewer.yaml
@@ -0,0 +1,145 @@
+system_template: |-
+ 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.
+
+ COMMANDS:
+ {command_docs}
+
+ 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> $
+
+ You need to format your output using two fields; discussion and command.
+ Your output should always include _one_ discussion and _one_ command field EXACTLY as in the following example:
+ DISCUSSION
+ First I'll start by using ls to see what files are in the current directory. Then maybe we can look at some relevant files to see what they look like.
+ ```
+ ls -a
+ ```
+
+ 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.
+instance_template: |-
+ We're currently solving the following issue within our repository. Here's the issue text:
+ ISSUE:
+ {issue}
+
+ 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.
+ 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 ABOUT THE EDIT COMMAND: Indentation really matters! When editing a file, make sure to insert appropriate indentation before each line!
+
+ IMPORTANT TIPS:
+ 1. Always start by trying to replicate the bug that the issues discusses.
+ If the issue includes code for reproducing the bug, we recommend that you re-implement that in your environment, and run it to make sure you can reproduce the bug.
+ Then start trying to fix it.
+ When you think you've fixed the bug, re-run the bug reproduction script to make sure that the bug has indeed been fixed.
+
+ If the bug reproduction script does not print anything when it successfully runs, we recommend adding a print("Script completed successfully, no errors.") command at the end of the file,
+ so that you can be sure that the script indeed ran fine all the way through.
+
+ 2. If you run a command and it doesn't work, try running a different command. A command that did not work once will not work the second time unless you modify it!
+
+ 3. If you open a file and need to get to an area around a specific line that is not in the first 100 lines, say line 583, don't just use the scroll_down command multiple times. Instead, use the goto 583 command. It's much quicker.
+
+ 4. If the bug reproduction script requires inputting/reading a specific file, such as buggy-input.png, and you'd like to understand how to input that file, conduct a search in the existing repo code, to see whether someone else has already done that. Do this by running the command: find_file "buggy-input.png" If that doesn't work, use the linux 'find' command.
+
+ 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.
+
+ {failed_verdicts_with_submissions}
+
+ (Open file: {open_file})
+ (Current directory: {working_dir})
+ bash-$
+next_step_template: |-
+ {observation}
+ (Open file: {open_file})
+ (Current directory: {working_dir})
+ bash-$
+next_step_no_output_template: |-
+ Your command ran successfully and did not produce any output.
+ (Open file: {open_file})
+ (Current directory: {working_dir})
+ bash-$
+demonstration_template: |
+ Here is a demonstration of how to correctly accomplish this task.
+ It is included to show you how to correctly use the interface.
+ You do not need to follow exactly what is done in the demonstration.
+ --- DEMONSTRATION ---
+ {demonstration}
+ --- END OF DEMONSTRATION ---
+state_command:
+ name: state
+ code: |
+ state() {
+ local working_dir="$PWD";
+ if [ -z $CURRENT_FILE ]; then
+ echo '{"open_file": "n/a", "working_dir": "'$working_dir'"}';
+ else
+ echo '{"open_file": "'$(realpath $CURRENT_FILE)'", "working_dir": "'$working_dir'"}';
+ fi
+ };
+parse_function: ThoughtActionParser
+env_variables:
+ WINDOW: 100
+ OVERLAP: 2
+ CURRENT_LINE: 0
+ CURRENT_FILE: ''
+ SEARCH_RESULTS: ()
+ SEARCH_FILES: ()
+ SEARCH_INDEX: 0
+command_files:
+- config/commands/defaults.sh
+- config/commands/search.sh
+- config/commands/edit_linting.sh
+- config/commands/_split_string.py
+parse_command: ParseCommandDetailed
+history_processor: Last5Observations
+demonstrations:
+- trajectories/demonstrations/replay__marshmallow-code__marshmallow-1867__default_sys-env_window100__t-0.20__p-0.95__c-2.00__install-1/marshmallow-code__marshmallow-1867.traj
+review_loop_config:
+ review_loop_classname: ReviewLoop
+ reviewer_classname: Reviewer
+ reviewer_config:
+ system_template: |
+ You are checking whether a problem in a code base has been resolved.
+
+ You will be presented with
+
+ INPUTS
+
+ **INPUT 1**: Problem statement: A GitHub issue that describes an issue
+ **INPUT 2**: Code: Relevant lines from a file
+
+ TASK
+
+ Determine if the problem persists.
+
+ If you believe the problem has been resolved, answer "success". If you believe the problem persists, answer "fail".
+ instance_template: |
+ INPUT 1: Problem statement
+
+ {issue}
+
+
+ INPUT 2: Code
+
+ ```
+ {edited_files70}
+ ```
+ max_samples: 10
+ min_draws: 100
+ max_accepted_draws: 2
+ gtc_classname: GraveToCradle
diff --git a/tests/test_run.py b/tests/test_run.py
index 541968ac..e132cfaa 100644
--- a/tests/test_run.py
+++ b/tests/test_run.py
@@ -5,6 +5,7 @@ import json
import logging
import os
import subprocess
+from dataclasses import replace
from pathlib import Path
from typing import Any
@@ -115,10 +116,6 @@ def test_script_args():
agent=AgentArguments(
model=ModelArguments(
model_name="instant_empty_submit",
- total_cost_limit=0.0,
- per_instance_cost_limit=3.0,
- temperature=0.0,
- top_p=0.95,
),
config_file=Path("config/default.yaml"),
),
@@ -137,6 +134,25 @@ def test_exception_raised(test_script_args: ScriptArguments):
main.main()
+ "config_file_name", ["config/default_retry.yaml", "tests/test_data/config_files/default_retry_no_breviewer.yaml"]
+)
+def test_retry_from_config(test_script_args: ScriptArguments, config_file_name):
+ agent = AgentArguments(
+ model=ModelArguments(
+ model_name="instant_empty_submit",
+ ),
+ config_file=config_file_name,
+ )
+ assert agent.config is not None
+ assert agent.config.review_loop_config is not None
+ # Note: Not enough to just replace `config_file`
+ test_script_args = replace(test_script_args, agent=agent)
+ main = Main(test_script_args)
+ main.main()
+
+
@pytest.mark.slow()
class CreateFakeLogFile(MainHook):
"""Testing the skip functionality"""