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: getting env vars in tools

Kilian Lieretef8c83a67ddd
diff --git a/sweagent/tools/tools.py b/sweagent/tools/tools.py
index 36df3789..61cbc4f7 100644
--- a/sweagent/tools/tools.py
+++ b/sweagent/tools/tools.py
@@ -237,7 +237,10 @@ class ToolHandler:
asyncio.run(self._check_available_commands(env, env_vars))
def _get_env_vars(self, env: SWEEnv) -> dict[str, str]:
- return dict(line.split("=", 1) for line in env.communicate("env", check=True).strip().split("\n"))
+ env_output = env.communicate("env", check=True).strip()
+ if not env_output:
+ return {}
+ return dict(line.split("=", 1) for line in env_output.split("\n"))
def _set_env_variables(self, env: SWEEnv) -> None:
_env_setters = [f"export {k}={v}" for k, v in self.config.env_variables.items()]
diff --git a/tools/defaults/lib/default_utils.py b/tools/defaults/lib/default_utils.py
index f9353c32..b2b04f4d 100644
--- a/tools/defaults/lib/default_utils.py
+++ b/tools/defaults/lib/default_utils.py
@@ -85,12 +85,20 @@ class WindowedFile:
"""
Args:
+ path: Path to the file to open.
+ first_line: First line of the display window.
+ window: Number of lines to display.
exit_on_exception: If False, will raise exception.
If true, will print an error message and exit.
Will create file if not found.
- Internal convention: All line numbers are 0-indexed.
+ Internal convention/notes:
+
+ * All line numbers are 0-indexed.
+ * Previously, we used "current_line" for the internal state
+ of the window position, pointing to the middle of the window.
+ Now, we use `first_line` for this purpose (it's simpler this way).
"""
_path = registry.get_if_none(path, "CURRENT_FILE")
self._exit_on_exception = exit_on_exception
@@ -180,7 +188,7 @@ class WindowedFile:
return "\n".join(out_lines)
def set_window_text(self, new_text: str) -> None:
- """Set window text."""
+ """Replace the text in the current display window."""
text = self.text.splitlines()
start, stop = self.line_range
text[start : stop + 1] = new_text.splitlines()