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]
Handle human mode 'exit' command
Kilian Lieret9e5ae7cd5c0e
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 6be42a43..1b0f2115 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -492,6 +492,13 @@ class Agent:if self.tools.should_block_action(step.action):raise BlockedActionError()+ if step.action.strip() == "exit":+ self.logger.info("Exiting agent")+ step.done = True+ step.observation = "Exited"+ step.exit_status = "exit_command"+ return step+assert self._env is not Noneself._chook.on_action_started(step=step)execution_t0 = time.perf_counter()diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 23802f26..efab3e77 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -162,10 +162,6 @@ class SWEEnv:Returns:output: output from container"""- if input.strip() == "exit":- asyncio.run(self.deployment.stop())- return ""-self.logger.log(logging.TRACE, "Input:\n%s", input) # type: ignorer = asyncio.run(self.deployment.runtime.run_in_session(BashAction(command=input, timeout=timeout)))output = r.outputdiff --git a/sweagent/tools/tools.py b/sweagent/tools/tools.pyindex 8b78c130..6af83bc4 100644--- a/sweagent/tools/tools.py+++ b/sweagent/tools/tools.py@@ -33,7 +33,6 @@ class ToolFilterConfig(BaseModel):"ipython","bash","sh",- "exit","/bin/bash","/bin/sh","nohup",diff --git a/tests/test_agent.py b/tests/test_agent.pyindex 61d85b63..1b6fa37a 100644--- a/tests/test_agent.py+++ b/tests/test_agent.py@@ -183,3 +183,13 @@ def test_successful_submission(dummy_env: SWEEnv, default_agent: Agent, tmp_pathassert a.info["exit_status"] == "submitted" # type: ignoreassert a.info["submission"] == "test" # type: ignoreassert a.trajectory[-1]["observation"] == "test"+++def test_human_exit(dummy_env: SWEEnv, default_agent: Agent, tmp_path):+ a = default_agent+ a.model = PredeterminedTestModel(["```\nexit\n```"]) # type: ignore+ a.setup(dummy_env, EmptyProblemStatement())+ r = a.step()+ assert r.done+ assert r.exit_status == "exit_command"+ assert r.action.strip() == "exit"