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]

Refactor open-PR config and add override to skip if referenced

Kilian Lieret0c70263bcd2f
diff --git a/run.py b/run.py
index 9697a0cb..7e717c2b 100644
--- a/run.py
+++ b/run.py
@@ -34,14 +34,24 @@ logger.propagate = False
logging.getLogger("simple_parsing").setLevel(logging.WARNING)
+@dataclass(frozen=True)
+class ActionsArguments(FlattenedAccess, FrozenSerializable):
+ """Run real-life actions (opening PRs, etc.) if we can solve the issue."""
+ open_pr: bool = False # Open a PR with the patch if we can solve the issue
+ # Skip action if there are already commits claiming to fix the issue. Please only
+ # set this to False if you are sure the commits are not fixes or if this is your
+ # own repository!
+ skip_if_commits_reference_issue: bool = True
+
+
@dataclass(frozen=True)
class ScriptArguments(FlattenedAccess, FrozenSerializable):
environment: EnvironmentArguments
agent: AgentArguments
+ actions: ActionsArguments
instance_filter: str = ".*" # Only run instances that completely match this regex
skip_existing: bool = True # Skip instances with existing trajectories
suffix: str = ""
- open_pr: bool = False # Open a PR with the patch if we can solve the issue
@property
def run_name(self):
@@ -118,7 +128,7 @@ def main(args: ScriptArguments):
return_type="info",
)
save_predictions(traj_dir, instance_id, info)
- if should_open_pr(args, info, token=env.token):
+ if args.actions.open_pr and should_open_pr(args, info, token=env.token):
env.open_pr()
except KeyboardInterrupt:
@@ -156,7 +166,7 @@ def should_open_pr(args, info: Dict[str, Any], *, token: str="") -> bool:
return False
org, repo, issue_number = parse_gh_issue_url(args.environment.data_path)
associated_commits = get_associated_commit_urls(org, repo, issue_number, token=token)
- if associated_commits:
+ if args.actions.skip_if_commits_reference_issue and associated_commits:
commit_url_strs = ", ".join(associated_commits)
logger.info(f"Issue already has associated commits (see {commit_url_strs}). Skipping PR creation.")
return False
@@ -243,6 +253,7 @@ if __name__ == "__main__":
),
config_file="config/default.yaml",
),
+ actions=ActionsArguments(open_pr=False, skip_if_commits_reference_issue=True),
)
# Nicer yaml dumping of multiline strings
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index c1dbe80d..7596782a 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -678,9 +678,9 @@ class SWEEnv(gym.Env):
logger.info("Opening PR")
# todo: have better way of handling this
# Adding random string suffix to avoid name conflicts if we had a previously failed run
+ issue_url = self.args.data_path
issue = get_gh_issue_data(issue_url, token=self.token)
branch_name = f"swe-agent-fix-#{issue.number}-" + str(random.random())[2:10]
- issue_url = self.args.data_path
self.communicate_with_handling(
input=f"rm model.patch",