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]

Convert tool installation steps to communicate

carlosejimenezc20153ff4382
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 53408d86..a3c4b8e4 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -6,7 +6,7 @@ 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.deployment.config import DeploymentConfig, DockerDeploymentConfig, get_deployment
from swerex.runtime.abstract import BashAction, CreateBashSessionRequest
from sweagent.environment.config.repo import Repo, RepoConfig
@@ -56,7 +56,7 @@ class SWEEnv:
@classmethod
def from_config(cls, config: EnvironmentConfig) -> Self:
return cls(
- deployment=config.deployment.get_deployment(),
+ deployment=get_deployment(config.deployment),
repo=config.repo,
startup_commands=config.startup_commands,
)
diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.py
index 685ca9d9..5752c934 100644
--- a/sweagent/run/batch_instances.py
+++ b/sweagent/run/batch_instances.py
@@ -6,7 +6,12 @@ from typing import Any, Literal, Self
import yaml
from pydantic import BaseModel, Field
-from swerex.deployment.config import DeploymentConfig, DockerDeploymentConfig
+from swerex.deployment.config import (
+ DeploymentConfig,
+ DockerDeploymentConfig,
+ DummyDeploymentConfig,
+ LocalDeploymentConfig,
+)
from sweagent.environment.config.problem_statement import ProblemStatementConfig, TextProblemStatement
from sweagent.environment.config.repo import PreExistingRepo
@@ -109,14 +114,14 @@ class SimpleBatchInstance(BaseModel):
repo = PreExistingRepo(repo_name=self.repo_name, base_commit=self.base_commit)
else:
repo = None
- if deployment.type == "local":
+ if isinstance(deployment, LocalDeploymentConfig):
if self.image_name:
- msg = "Local deployment does not support image name"
+ msg = "Local deployment does not support image_name"
raise ValueError(msg)
return BatchInstance(
env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
)
- if deployment.type == "dummy":
+ if isinstance(deployment, DummyDeploymentConfig):
return BatchInstance(
env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
)
diff --git a/sweagent/run/run_replay.py b/sweagent/run/run_replay.py
index 2b4ce8a2..eba0d574 100644
--- a/sweagent/run/run_replay.py
+++ b/sweagent/run/run_replay.py
@@ -11,7 +11,7 @@ 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 swerex.deployment.config import DeploymentConfig, DockerDeploymentConfig, get_deployment
from sweagent import CONFIG_DIR
from sweagent.agent.agents import Agent, AgentConfig
@@ -75,7 +75,7 @@ class RunReplay:
return cls(
traj_path=config.traj_path,
config_path=config.config_path,
- deployment=config.deployment.get_deployment(),
+ deployment=get_deployment(config.deployment),
repo=config.repo,
output_dir=config.output_dir,
**kwargs,
diff --git a/sweagent/tools/tools.py b/sweagent/tools/tools.py
index 3fb12b56..393fdbbe 100644
--- a/sweagent/tools/tools.py
+++ b/sweagent/tools/tools.py
@@ -179,26 +179,14 @@ class ToolHandler:
)
)
)
- asyncio.run(
- env.deployment.runtime.execute(
- RexCommand(command=f"export PATH=$PATH:/root/tools/{bundle.name}/bin", shell=True, check=True)
- )
- )
+ env.communicate(f"export PATH=$PATH:/root/tools/{bundle.name}/bin", check=True)
asyncio.run(
env.deployment.runtime.execute(
RexCommand(command=f"chmod +x /root/tools/{bundle.name}/bin/*", shell=True, check=False)
)
) # check false because bin might not exist
if (bundle / "install.sh").exists():
- asyncio.run(
- env.deployment.runtime.execute(
- RexCommand(
- command=f"cd /root/tools/{bundle.name}; bash install.sh",
- shell=True,
- check=True,
- )
- )
- )
+ env.communicate(f"cd /root/tools/{bundle.name}; bash install.sh", check=True)
# always make all files in bin executable
asyncio.run(
env.deployment.runtime.execute(
@@ -213,9 +201,7 @@ class ToolHandler:
missing_tools = []
for command in self.config.commands:
try:
- asyncio.run(
- env.deployment.runtime.execute(RexCommand(command=f"which {command.name}", shell=True, check=True))
- )
+ env.communicate(f"which {command.name}", check=True)
except Exception:
missing_tools.append(command.name)
if missing_tools: