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]
Enh: Need to explicitly make agent interruptable
Kilian Lieret09b2d276607b
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 4f3e97d6..6463932a 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -1227,7 +1227,9 @@ class DefaultAgent(AbstractAgent):self,env: SWEEnv,problem_statement: ProblemStatement | ProblemStatementConfig,+ *,output_dir: Path = Path("."),+ interactive: bool = False,) -> AgentRunResult:"""Run the agent on a problem instance. This method contains themain loop that repeatedly calls `self._step` until the problem is solved.@@ -1236,6 +1238,7 @@ class DefaultAgent(AbstractAgent):setup_args: Arguments to pass to the agent's setup method.env: The environment to run the agent on.traj_dir: Directory to save the trajectory to+ interruptible: Whether the human can jump in by pressing ^C"""self.setup(env=env, problem_statement=problem_statement, output_dir=output_dir)@@ -1247,11 +1250,13 @@ class DefaultAgent(AbstractAgent):step_output = self.step()self.save_trajectory()except KeyboardInterrupt:- if not isinstance(self.model, HumanModel):+ if interactive and not isinstance(self.model, HumanModel):self.human_step_in()continueraiseexcept EOFError:+ if not interactive:+ raise# Can only happen if we have a human model, so switch backself.logger.info("Detected ^D - switching back to AI mode")self.human_step_out()@@ -1287,7 +1292,7 @@ class DefaultAgent(AbstractAgent):returnself.model = self._original_model- self.tools.config.parse_function = self._original_parser+ self.tools.config.parse_function = self._original_parser # type: ignoreself._original_model = Noneself._original_parser = Nonediff --git a/sweagent/run/run_single.py b/sweagent/run/run_single.pyindex 8ba4f77b..dfcdc43c 100644--- a/sweagent/run/run_single.py+++ b/sweagent/run/run_single.py@@ -78,6 +78,9 @@ class RunSingleConfig(BaseSettings, cli_implicit_flags=False):env_var_path: Path | None = None"""Path to a .env file to load environment variables from."""+ interactive: bool = False+ """Whether to make the agent interactive (i.e., allow the human to jump in by pressing ^C)."""+# pydantic configmodel_config = SettingsConfigDict(extra="forbid", env_prefix="SWE_AGENT_")@@ -127,6 +130,7 @@ class RunSingle:output_dir: Path = Path("."),hooks: list[RunHook] | None = None,actions: RunSingleActionConfig | None = None,+ interactive: bool = False,):"""Note: When initializing this class, make sure to add the hooks that are required by your actions.See `from_config` for an example.@@ -151,6 +155,7 @@ class RunSingle:self.problem_statement = problem_statementfor hook in hooks or []:self.add_hook(hook)+ self.interactive = interactive@propertydef hooks(self) -> list[RunHook]:@@ -169,6 +174,7 @@ class RunSingle:problem_statement=config.problem_statement,output_dir=config.output_dir,actions=config.actions,+ interactive=config.interactive,)self.add_hook(SaveApplyPatchHook(apply_patch_locally=config.actions.apply_patch_locally))if config.actions.open_pr:@@ -194,6 +200,7 @@ class RunSingle:problem_statement=self.problem_statement,env=self.env,output_dir=output_dir,+ interactive=self.interactive,)self._chooks.on_instance_completed(result=result)self.logger.info("Done")