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]

Handle human mode 'exit' command

Kilian Lieret9e5ae7cd5c0e
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index 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 None
self._chook.on_action_started(step=step)
execution_t0 = time.perf_counter()
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 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: ignore
r = asyncio.run(self.deployment.runtime.run_in_session(BashAction(command=input, timeout=timeout)))
output = r.output
diff --git a/sweagent/tools/tools.py b/sweagent/tools/tools.py
index 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.py
index 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_path
assert a.info["exit_status"] == "submitted" # type: ignore
assert a.info["submission"] == "test" # type: ignore
assert 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"