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]

Take deployment config objects directly from Swe-rex

Kilian Lieret36293bb98d6e
diff --git a/sweagent/environment/config/deployment.py b/sweagent/environment/config/deployment.py
deleted file mode 100644
index 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 | DummyDeploymentConfig
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index efab3e77..53408d86 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -1,5 +1,3 @@
-from __future__ import annotations
-
import asyncio
import logging
import shlex
@@ -8,9 +6,9 @@ from typing import Self
from pydantic import BaseModel, ConfigDict, Field
from swerex.deployment.abstract import AbstractDeployment
+from swerex.deployment.config import DeploymentConfig, DockerDeploymentConfig
from swerex.runtime.abstract import BashAction, CreateBashSessionRequest
-from sweagent.environment.config.deployment import DeploymentConfig, DockerDeploymentConfig
from sweagent.environment.config.repo import Repo, RepoConfig
from sweagent.environment.hooks.abstract import CombinedEnvHooks, EnvHook
from sweagent.utils.log import get_logger
@@ -19,7 +17,9 @@ from sweagent.utils.log import get_logger
class 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 these
startup_commands: list[str] = []
diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.py
index eaf67f93..685ca9d9 100644
--- a/sweagent/run/batch_instances.py
+++ b/sweagent/run/batch_instances.py
@@ -6,8 +6,8 @@ from typing import Any, Literal, Self
import yaml
from pydantic import BaseModel, Field
+from swerex.deployment.config import DeploymentConfig, DockerDeploymentConfig
-from sweagent.environment.config.deployment import DeploymentConfig, DockerDeploymentConfig
from sweagent.environment.config.problem_statement import ProblemStatementConfig, TextProblemStatement
from sweagent.environment.config.repo import PreExistingRepo
from 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: ignore
return 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.py
index 734d017f..2b4ce8a2 100644
--- a/sweagent/run/run_replay.py
+++ b/sweagent/run/run_replay.py
@@ -11,11 +11,11 @@ import yaml
from pydantic import Field
from pydantic_settings import BaseSettings
from swerex.deployment.abstract import AbstractDeployment
+from swerex.deployment.config import DeploymentConfig, DockerDeploymentConfig
from sweagent import CONFIG_DIR
from sweagent.agent.agents import Agent, AgentConfig
from sweagent.agent.models import ReplayModelConfig
-from sweagent.environment.config.deployment import DeploymentConfig, DockerDeploymentConfig
from sweagent.environment.config.problem_statement import EmptyProblemStatement
from sweagent.environment.config.repo import RepoConfig
from sweagent.environment.swe_env import SWEEnv
diff --git a/tests/conftest.py b/tests/conftest.py
index 9beb85fd..09970cc8 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -9,8 +9,8 @@ from contextlib import contextmanager
from pathlib import Path
import pytest
+from swerex.deployment.config import DockerDeploymentConfig, DummyDeploymentConfig
-from sweagent.environment.config.deployment import DockerDeploymentConfig, DummyDeploymentConfig
from sweagent.environment.config.repo import LocalRepoConfig
from 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_args
shutil.rmtree(local_repo_path)
diff --git a/tests/test_batch_instance.py b/tests/test_batch_instance.py
index 6236b1ce..1046762c 100644
--- a/tests/test_batch_instance.py
+++ b/tests/test_batch_instance.py
@@ -1,8 +1,8 @@
import json
import pytest
+from swerex.deployment.config import DockerDeploymentConfig
-from sweagent.environment.config.deployment import DockerDeploymentConfig
from sweagent.environment.config.problem_statement import TextProblemStatement
from sweagent.environment.config.repo import PreExistingRepo
from sweagent.run.batch_instances import BatchInstance, SimpleBatchInstance, SWEBenchInstances, _slice_spec_to_slice
@@ -10,7 +10,9 @@ from sweagent.run.batch_instances import BatchInstance, SimpleBatchInstance, SWE
def 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.yaml
index 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:latest
problem_statement:
type: text
text: "A simple test problem"
@@ -8,6 +9,7 @@
- env:
deployment:
type: docker
+ image: sweagent/swe-agent:latest
problem_statement:
type: text
text: "A simple test problem 2"
diff --git a/tests/test_run_replay.py b/tests/test_run_replay.py
index 2401813f..e63d1375 100644
--- a/tests/test_run_replay.py
+++ b/tests/test_run_replay.py
@@ -3,9 +3,9 @@ from __future__ import annotations
import subprocess
import pytest
+from swerex.deployment.config import DockerDeploymentConfig
from sweagent import CONFIG_DIR
-from sweagent.environment.config.deployment import DockerDeploymentConfig
from sweagent.environment.config.repo import LocalRepoConfig
from 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),
)