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]
Code qual: Some one-off fixes
Kilian Lieret2a39aa168102
diff --git a/inspector/server.py b/inspector/server.pyindex 4fb55d83..fc1d1790 100644--- a/inspector/server.py+++ b/inspector/server.py@@ -181,7 +181,7 @@ def load_results(results_path: Path) -> dict[str, Any] | None:return results-# todo: shouldn't reload results fore very status+# TODO: shouldn't reload results fore very statusdef get_status(traj_path) -> str:"""Return results emoji for single trajectory"""results = load_results(Path(traj_path).parent / "results.json")diff --git a/pyproject.toml b/pyproject.tomlindex f868b35c..3d641860 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -147,18 +147,15 @@ select = [# bugbear"B006", # mutable default"B007", # unused loop var+ "B009", # getattr with constant# flake8-errmsg"EM",- # flake8-implicit-str-concat- "ISC001",# flake8-future-annotations"FA102",# flake8-return"RET",# RUF"RUF019", # unneded key in dict check- # other- "COM812", # use trailing commas# pytest"PT",# flake8-simplify (SIM)diff --git a/run.py b/run.pyindex cee1bd22..c79ee104 100644--- a/run.py+++ b/run.py@@ -130,8 +130,6 @@ class ScriptArguments(FlattenedAccess, FrozenSerializable):class _ContinueLoop(Exception):"""Used for internal control flow"""- ...-class MainHook:"""Hook structure for the web server or other addons to interface with"""@@ -146,29 +144,23 @@ class MainHook:def on_init(self, *, args: ScriptArguments, agent: Agent, env: SWEEnv, traj_dir: Path):"""Called when hook is initialized"""- ...def on_start(self):"""Called at the beginning of `Main.main`"""- ...def on_end(self):"""Called at the end of `Main.main`"""- ...def on_instance_start(self, *, index: int, instance: dict[str, Any]):"""Called at the beginning of each instance loop in `Main.run`"""- ...def on_instance_skipped(self,):"""Called when an instance is skipped in `Main.run`"""- ...def on_instance_completed(self, *, info, trajectory):"""Called when an instance is completed in `Main.run`"""- ...class SaveApplyPatchHook(MainHook):diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 9513b4c8..dde20eeb 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -180,7 +180,7 @@ class AgentArguments(FlattenedAccess, FrozenSerializable):object.__setattr__(self, "config", config)assert self.config is not None # mypyfor subroutine in getattr(self.config, "subroutines", {}).values():- model_args = getattr(subroutine, "model")+ model_args = subroutine.modelobject.__setattr__(model_args,"per_instance_cost_limit",@@ -218,7 +218,6 @@ class AgentHook:def on_model_query(self, *, query: str, agent: str):"""Actually query the model with the complete history."""- ...def on_query_message_added(self,@@ -300,7 +299,7 @@ class Agent:demo_history,is_demonstration=True,)- demonstration = self.config.demonstration_template.format(**{"demonstration": demo_message})+ demonstration = self.config.demonstration_template.format(demonstration=demo_message)self._append_history({"agent": self.name,diff --git a/sweagent/agent/commands.py b/sweagent/agent/commands.pyindex d8c3ffbb..1151e047 100644--- a/sweagent/agent/commands.py+++ b/sweagent/agent/commands.py@@ -133,13 +133,12 @@ class ParseCommandBash(ParseCommand):arguments = docs_dict.get("arguments", None)if "signature" in docs_dict:signature = docs_dict["signature"]- else:- if arguments is not None:- for param, settings in arguments.items():- if settings["required"]:- signature += f" <{param}>"- else:- signature += f" [<{param}>]"+ elif arguments is not None:+ for param, settings in arguments.items():+ if settings["required"]:+ signature += f" <{param}>"+ else:+ signature += f" [<{param}>]"command = Command.from_dict({"code": code,diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 6d6a75b9..03ced218 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -327,6 +327,7 @@ class SWEEnv(gym.Env):subprocess.run(f"docker cp {path_to_patch} {self.container_name}:/root/test.patch",shell=True,+ check=False,)self.communicate_with_handling(input="git apply /root/test.patch",@@ -876,7 +877,7 @@ class SWEEnv(gym.Env):_dry_run: Whether to actually push anything or just simulate it"""logger.info("Opening PR")- # todo: have better way of handling this+ # TODO: have better way of handling this# Adding random string suffix to avoid name conflicts if we had a previously failed runissue_url = self.args.data_pathtry:diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex ed267a8f..e949e990 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -57,7 +57,7 @@ def is_github_repo_url(data_path: str) -> bool:return GITHUB_REPO_URL_PATTERN.search(data_path) is not None-# todo: Why not just use copy_anything_to_container?+# TODO: Why not just use copy_anything_to_container?def copy_file_to_container(container, contents, container_path):"""Copies a given string into a Docker container at a specified path.@@ -575,7 +575,7 @@ class InstanceBuilder:self.args |= instance_dictdef set_missing_fields(self):- # todo: This field is only needed while swe_env is using some questionable logic+ # TODO: This field is only needed while swe_env is using some questionable logic# to determine whether to clone from a mirror or not. This should be removed in the future.# Values: 'swe-bench' (loaded from json/jsonl for swe-bench style inference),# 'online' (loaded from github issue or similar) or 'local' (loaded from local file)