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]
Take deployment config objects directly from Swe-rex
Kilian Lieret36293bb98d6e
diff --git a/sweagent/environment/config/deployment.py b/sweagent/environment/config/deployment.pydeleted file mode 100644index 9fdfd1eb..00000000--- a/sweagent/environment/config/deployment.py+++ /dev/null@@ -1,73 +0,0 @@-from typing import Literal--from pydantic import BaseModel, ConfigDict-from swerex.deployment import get_deployment-from swerex.deployment.abstract import AbstractDeployment---def _get_deployment(config) -> AbstractDeployment:- dtype = config.type- config_dict = config.model_dump()- del config_dict["type"]- return get_deployment(dtype, **config_dict)---class DummyDeploymentConfig(BaseModel):- """This deployment does nothing. Used for testing purposes."""-- type: Literal["dummy"] = "dummy"- """Discriminator for (de)serialization/CLI. Do not change."""-- model_config = ConfigDict(extra="forbid")-- def get_deployment(self) -> AbstractDeployment:- return _get_deployment(self)---class LocalDeploymentConfig(BaseModel):- type: Literal["local"] = "local"- """Discriminator for (de)serialization/CLI. Do not change."""-- model_config = ConfigDict(extra="forbid")-- def get_deployment(self) -> AbstractDeployment:- return _get_deployment(self)---class DockerDeploymentConfig(BaseModel):- """Configuration for the deployment of the environment"""-- image: str = "sweagent/swe-agent:latest"-- startup_timeout: float = 60.0- """Timeout for the startup of the docker container.- This can take a while especially if swe-rex isn't installed yet.- """-- type: Literal["docker"] = "docker"- """Discriminator for (de)serialization/CLI. Do not change."""-- model_config = ConfigDict(extra="forbid")-- def get_deployment(self) -> AbstractDeployment:- return _get_deployment(self)---class ModalDeploymentConfig(BaseModel):- image: str = "sweagent/swe-agent:latest"-- startup_timeout: float = 200.0- """Timeout for the startup of the modal app.- This can take a while especially if swe-rex isn't installed yet.- """-- type: Literal["modal"] = "modal"- """Discriminator for (de)serialization/CLI. Do not change."""-- model_config = ConfigDict(extra="forbid")-- def get_deployment(self) -> AbstractDeployment:- return _get_deployment(self)---DeploymentConfig = DockerDeploymentConfig | ModalDeploymentConfig | LocalDeploymentConfig | DummyDeploymentConfigdiff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex efab3e77..53408d86 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -1,5 +1,3 @@-from __future__ import annotations-import asyncioimport loggingimport shlex@@ -8,9 +6,9 @@ from typing import Selffrom pydantic import BaseModel, ConfigDict, Fieldfrom swerex.deployment.abstract import AbstractDeployment+from swerex.deployment.config import DeploymentConfig, DockerDeploymentConfigfrom swerex.runtime.abstract import BashAction, CreateBashSessionRequest-from sweagent.environment.config.deployment import DeploymentConfig, DockerDeploymentConfigfrom sweagent.environment.config.repo import Repo, RepoConfigfrom sweagent.environment.hooks.abstract import CombinedEnvHooks, EnvHookfrom sweagent.utils.log import get_logger@@ -19,7 +17,9 @@ from sweagent.utils.log import get_loggerclass EnvironmentConfig(BaseModel):"""Configure data sources and setup instructions for the environment in which we solve the tasks."""- deployment: DeploymentConfig = Field(default_factory=DockerDeploymentConfig)+ deployment: DeploymentConfig = Field(+ default_factory=lambda: DockerDeploymentConfig(image="sweagent/swe-agent:latest")+ )repo: RepoConfig | None = None# fixme: Actually run thesestartup_commands: list[str] = []diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.pyindex eaf67f93..685ca9d9 100644--- a/sweagent/run/batch_instances.py+++ b/sweagent/run/batch_instances.py@@ -6,8 +6,8 @@ from typing import Any, Literal, Selfimport yamlfrom pydantic import BaseModel, Field+from swerex.deployment.config import DeploymentConfig, DockerDeploymentConfig-from sweagent.environment.config.deployment import DeploymentConfig, DockerDeploymentConfigfrom sweagent.environment.config.problem_statement import ProblemStatementConfig, TextProblemStatementfrom sweagent.environment.config.repo import PreExistingRepofrom sweagent.environment.swe_env import EnvironmentConfig@@ -120,7 +120,7 @@ class SimpleBatchInstance(BaseModel):return BatchInstance(env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement)- deployment.image = self.image_name+ deployment.image = self.image_name # type: ignorereturn BatchInstance(env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement)@@ -153,7 +153,9 @@ class InstancesFromFile(BaseModel, AbstractInstanceSource):(i.e., it behaves exactly like python's list slicing `list[slice]`)."""- deployment: DeploymentConfig = Field(default_factory=DockerDeploymentConfig)+ deployment: DeploymentConfig = Field(+ default_factory=lambda: DockerDeploymentConfig(image="sweagent/swe-agent:latest")+ )"""Note that the image_name option is overwritten by the images specified in the task instances."""simple: Literal[True] = True@@ -186,7 +188,9 @@ class InstancesFromHuggingFace(BaseModel, AbstractInstanceSource):(i.e., it behaves exactly like python's list slicing `list[slice]`)."""- deployment: DeploymentConfig = Field(default_factory=DockerDeploymentConfig)+ deployment: DeploymentConfig = Field(+ default_factory=lambda: DockerDeploymentConfig(image="sweagent/swe-agent:latest")+ )"""Deployment configuration. Note that the image_name option is overwritten by the images specified in the task instances."""type: Literal["huggingface"] = "huggingface"@@ -212,7 +216,9 @@ class SWEBenchInstances(BaseModel, AbstractInstanceSource):split: Literal["dev", "test"] = "dev"- deployment: DeploymentConfig = Field(default_factory=DockerDeploymentConfig)+ deployment: DeploymentConfig = Field(+ default_factory=lambda: DockerDeploymentConfig(image="sweagent/swe-agent:latest")+ )"""Deployment configuration. Note that the image_name option is overwritten by the images specified in the task instances."""diff --git a/sweagent/run/run_replay.py b/sweagent/run/run_replay.pyindex 734d017f..2b4ce8a2 100644--- a/sweagent/run/run_replay.py+++ b/sweagent/run/run_replay.py@@ -11,11 +11,11 @@ import yamlfrom pydantic import Fieldfrom pydantic_settings import BaseSettingsfrom swerex.deployment.abstract import AbstractDeployment+from swerex.deployment.config import DeploymentConfig, DockerDeploymentConfigfrom sweagent import CONFIG_DIRfrom sweagent.agent.agents import Agent, AgentConfigfrom sweagent.agent.models import ReplayModelConfig-from sweagent.environment.config.deployment import DeploymentConfig, DockerDeploymentConfigfrom sweagent.environment.config.problem_statement import EmptyProblemStatementfrom sweagent.environment.config.repo import RepoConfigfrom sweagent.environment.swe_env import SWEEnvdiff --git a/tests/conftest.py b/tests/conftest.pyindex 9beb85fd..09970cc8 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -9,8 +9,8 @@ from contextlib import contextmanagerfrom pathlib import Pathimport pytest+from swerex.deployment.config import DockerDeploymentConfig, DummyDeploymentConfig-from sweagent.environment.config.deployment import DockerDeploymentConfig, DummyDeploymentConfigfrom sweagent.environment.config.repo import LocalRepoConfigfrom sweagent.environment.swe_env import EnvironmentConfig, SWEEnv@@ -83,7 +83,7 @@ def test_env_args(subprocess.run(clone_cmd, check=True)test_env_args = EnvironmentConfig(deployment=DockerDeploymentConfig(image="sweagent/swe-agent:latest"),- repo=LocalRepoConfig(path=str(local_repo_path)),+ repo=LocalRepoConfig(path=local_repo_path),)yield test_env_argsshutil.rmtree(local_repo_path)diff --git a/tests/test_batch_instance.py b/tests/test_batch_instance.pyindex 6236b1ce..1046762c 100644--- a/tests/test_batch_instance.py+++ b/tests/test_batch_instance.py@@ -1,8 +1,8 @@import jsonimport pytest+from swerex.deployment.config import DockerDeploymentConfig-from sweagent.environment.config.deployment import DockerDeploymentConfigfrom sweagent.environment.config.problem_statement import TextProblemStatementfrom sweagent.environment.config.repo import PreExistingRepofrom sweagent.run.batch_instances import BatchInstance, SimpleBatchInstance, SWEBenchInstances, _slice_spec_to_slice@@ -10,7 +10,9 @@ from sweagent.run.batch_instances import BatchInstance, SimpleBatchInstance, SWEdef test_simple_batch_from_swe_bench_to_full_batch_instance(test_data_sources_path):sb_instance = json.loads((test_data_sources_path / "swe-bench-dev-easy.json").read_text())[0]- instance = SimpleBatchInstance.from_swe_bench(sb_instance).to_full_batch_instance(DockerDeploymentConfig())+ instance = SimpleBatchInstance.from_swe_bench(sb_instance).to_full_batch_instance(+ DockerDeploymentConfig(image="sweagent/swe-agent:latest")+ )assert isinstance(instance.env.repo, PreExistingRepo)assert instance.env.repo.repo_name == "testbed"assert isinstance(instance.env.deployment, DockerDeploymentConfig)diff --git a/tests/test_data/data_sources/expert_instances.yaml b/tests/test_data/data_sources/expert_instances.yamlindex 7615fc0b..ef2b14b6 100644--- a/tests/test_data/data_sources/expert_instances.yaml+++ b/tests/test_data/data_sources/expert_instances.yaml@@ -1,6 +1,7 @@- env:deployment:type: docker+ image: sweagent/swe-agent:latestproblem_statement:type: texttext: "A simple test problem"@@ -8,6 +9,7 @@- env:deployment:type: docker+ image: sweagent/swe-agent:latestproblem_statement:type: texttext: "A simple test problem 2"diff --git a/tests/test_run_replay.py b/tests/test_run_replay.pyindex 2401813f..e63d1375 100644--- a/tests/test_run_replay.py+++ b/tests/test_run_replay.py@@ -3,9 +3,9 @@ from __future__ import annotationsimport subprocessimport pytest+from swerex.deployment.config import DockerDeploymentConfigfrom sweagent import CONFIG_DIR-from sweagent.environment.config.deployment import DockerDeploymentConfigfrom sweagent.environment.config.repo import LocalRepoConfigfrom sweagent.run.run_replay import RunReplay, RunReplayConfig@@ -15,7 +15,7 @@ def rr_config(swe_agent_test_repo_traj, tmp_path, swe_agent_test_repo_clone):return RunReplayConfig(traj_path=swe_agent_test_repo_traj,config_path=CONFIG_DIR / "default_from_url.yaml",- deployment=DockerDeploymentConfig(),+ deployment=DockerDeploymentConfig(image="sweagent/swe-agent:latest"),output_dir=tmp_path,repo=LocalRepoConfig(path=swe_agent_test_repo_clone),)