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]

Fix: Cannot extract all env vars (because of PS1)

Kilian Lieret8f122498b1fc
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 1fc1b75a..d642ffad 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -223,17 +223,6 @@ class SWEEnv:
path_in_container = f"/{self.repo.repo_name}/{path}"
return self.communicate(f"cat {str(path_in_container)}")
- def get_env_vars(self) -> dict[str, str]:
- """Get all environment variables set in the environment."""
- env_output = self.communicate("env", check=True).strip()
- if not env_output:
- return {}
- try:
- return dict(line.split("=", 1) for line in env_output.splitlines() if line.strip())
- except ValueError:
- self.logger.error(f"Env output: {env_output!r}")
- raise
-
def set_env_variables(self, env_variables: dict[str, str]) -> None:
"""Set environment variables in the environment."""
_env_setters = [f"export {k}={v}" for k, v in env_variables.items()]
diff --git a/sweagent/tools/tools.py b/sweagent/tools/tools.py
index d32c9d7e..0768bc61 100644
--- a/sweagent/tools/tools.py
+++ b/sweagent/tools/tools.py
@@ -235,8 +235,8 @@ class ToolHandler:
timeout=self.config.install_timeout,
)
env.communicate(f"cd {cwd}", check=True)
- env_vars = env.get_env_vars()
- asyncio.run(self._check_available_commands(env, env_vars))
+ path = env.communicate("echo $PATH", check=True).strip()
+ asyncio.run(self._check_available_commands(env, {"PATH": path}))
# Getting state
# -------------