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]
Remove some tool-related things from Env
Kilian Lieretd960c99cc035
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 313833b7..c1e5b020 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -66,6 +66,7 @@ class AgentConfig(BaseModel):model: ModelConfig = ModelConfig(name="gpt4")+# todo: Move parse function to tools# todo: separate out from_config. In particular separate out model (as a class, etc.). Agent should only take templates, tools, history processor and model.# slight problem: get_model needs commands....# todo: Can this class be split up into separate responsibilities?@@ -213,6 +214,7 @@ class Agent:def add_demonstrations_to_history(self) -> None:"""Add demonstrations to history"""+ # todo: Extract loop body into a method?for demonstration_path in self.config.templates.demonstrations:if self.config.templates.demonstration_template is None and not self.config.templates.put_demos_in_history:msg = "Cannot use demonstrations without a demonstration template or put_demos_in_history=True"@@ -291,13 +293,12 @@ class Agent:assert self.traj_path is not Noneself.traj_path.write_text(json.dumps(data, indent=2))- def forward(self, observation: str, available_actions: list[str], state: dict[str, str]) -> tuple[str, str, str]:+ def forward(self, observation: str, state: dict[str, str]) -> tuple[str, str, str]:"""Forwards the model, i.e., queries the model with the current trajectory and observation.This is identical to `self.forward_with_error_check`, but adds the output to the trajectory.Args:observation: Observation- available_actions: Currently not usedstate:Returns:@@ -489,7 +490,7 @@ class Agent:self._chook.on_step_start()assert self._tool_handler is not Nonestate = self._tool_handler.get_state()- thought, raw_action, output = self.forward(observation, self._env.get_available_actions(), state)+ thought, raw_action, output = self.forward(observation, state)self._chook.on_actions_generated(thought=thought, action=raw_action, output=output)run_action: str = self._tool_handler.guard_multiline_input(raw_action)diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex bd1c8412..80e356d9 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -82,7 +82,6 @@ class SWEEnv:def start(self) -> None:"""Start the environment"""self._init_deployment()- self._init_scripts()def _copy_repo(self) -> None:"""Clone/copy repository/codebase in container"""@@ -116,8 +115,7 @@ class SWEEnv:self.communicate(input="cd /")self._copy_repo()self._reset_repository()- self._reset_environment_variables()- self.on_environment_startup()+ self._chook.on_environment_startup()return None, infodef _reset_repository(self) -> None:@@ -141,19 +139,6 @@ class SWEEnv:error_msg="Failed to clean repository",)- # todo: This is part of our commands, not the environment- def _reset_environment_variables(self) -> None:- """Reset environment variables (`CURRENT_FILE`) etc. within container"""- cmd = [- 'export CURRENT_FILE=""',- "export CURRENT_LINE=0",- ]- self.communicate(- input=" && ".join(cmd),- check=True,- error_msg="Failed to reset environment variables",- )-# todo: Shouldn't this be the same as reset meanwhile?def reset_for_new_attempt(self,@@ -162,7 +147,6 @@ class SWEEnv:this prepares the container for taking another shot at the same instance."""self._reset_repository()- self._reset_environment_variables()def _get_edited_files_with_context(self, patch: str) -> dict[str, str]:"""Get the edited files with context from the patch"""@@ -271,7 +255,6 @@ class SWEEnv:def reset_container(self) -> None:self.close()self._init_deployment()- self._init_scripts()def _init_deployment(self,@@ -283,25 +266,6 @@ class SWEEnv:asyncio.run(self.deployment.runtime.create_session(CreateBashSessionRequest(startup_source=["/root/.bashrc"])))self.logger.info("Environment Initialized")- # todo: this part is part of our commands, not the environment- def _init_scripts(self):- """Initialize custom commands within container"""- self.communicate(- "mkdir -p /root/commands",- check=True,- error_msg="Failed to create commands directory",- )- self.communicate(- "touch /root/commands/__init__.py",- check=True,- error_msg="Failed to create __init__.py",- )- self.communicate(- "export PATH=$PATH:/root/commands",- check=True,- error_msg="Failed to add commands directory to PATH",- )-def communicate(self,input: str,@@ -346,13 +310,7 @@ class SWEEnv:r = asyncio.run(self.deployment.runtime.run_in_session(BashAction(command=input, timeout=1)))return output- def get_available_actions(self) -> list[str]:- """Returns list of available actions in current environment state-- Currently not in use.- """- return []-+ # todo: Move to tools?def get_submission(self, output: str) -> str | None:"""Function for extracting diff patch submission at the end of an episode.@@ -368,13 +326,6 @@ class SWEEnv:return Nonereturn match.group(1)- def on_environment_startup(self) -> None:- """Creates conda environment and installs third party dependencies to allow code execution"""- self._chook.on_environment_startup()-- def add_commands(self, commands: list[dict]) -> None:- """Adds custom commands to container"""-# todo: Use the runtime for this insteaddef read_file(self, path: str | PurePath) -> str:"""Read file contents from container