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]
Feat(agent): Write registry values directly
Kilian Liereta1866b7692cb
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 6c275fc0..25cd7a79 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -7,7 +7,13 @@ from typing import Literal, Selffrom pydantic import BaseModel, ConfigDict, Fieldfrom swerex.deployment.abstract import AbstractDeploymentfrom swerex.deployment.config import DeploymentConfig, DockerDeploymentConfig, get_deployment-from swerex.runtime.abstract import BashAction, BashInterruptAction, CreateBashSessionRequest, ReadFileRequest+from swerex.runtime.abstract import (+ BashAction,+ BashInterruptAction,+ CreateBashSessionRequest,+ ReadFileRequest,+ WriteFileRequest,+)from swerex.runtime.abstract import Command as RexCommandfrom sweagent.environment.hooks.abstract import CombinedEnvHooks, EnvHook@@ -222,6 +228,10 @@ class SWEEnv:r = asyncio.run(self.deployment.runtime.read_file(ReadFileRequest(path=str(path))))return r.content+ def write_file(self, path: str | PurePath, content: str) -> None:+ """Write content to file in container"""+ asyncio.run(self.deployment.runtime.write_file(WriteFileRequest(path=str(path), content=content)))+def set_env_variables(self, env_variables: dict[str, str]) -> None:"""Set environment variables in the environment."""_env_setters = [f"export {k}={shlex.quote(str(v))}" for k, v in env_variables.items()]diff --git a/sweagent/tools/tools.py b/sweagent/tools/tools.pyindex 0d725575..b4f46aff 100644--- a/sweagent/tools/tools.py+++ b/sweagent/tools/tools.py@@ -66,6 +66,9 @@ class ToolConfig(BaseModel):equivalent to adding `export VARNAME=value` to the `reset_commands`."""+ registry_variables: dict[str, Any] = {}+ """Populate the registry with these variables. Will be written out as json in the registry file."""+submit_command: str = "submit"parse_function: ParseFunction = Field(default_factory=FunctionCallingParser)@@ -194,6 +197,7 @@ class ToolHandler:def reset(self, env: SWEEnv) -> None:self.logger.info("Resetting tools")env.set_env_variables(self.config.env_variables)+ env.write_file("/root/.swe-agent-env", json.dumps(self.config.registry_variables))env.communicate(" && ".join(self._reset_commands), check="raise", timeout=self.config.install_timeout)async def _upload_bundles(self, env: SWEEnv) -> None: