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]

Add SWE-ReX versions to output

Kilian Lieret3414cbc2b52d
diff --git a/sweagent/__init__.py b/sweagent/__init__.py
index 28fd3fab..d9210ffa 100644
--- a/sweagent/__init__.py
+++ b/sweagent/__init__.py
@@ -35,16 +35,40 @@ assert TRAJECTORY_DIR.is_dir()
def get_agent_commit_hash() -> str:
- repo = Repo(REPO_ROOT, search_parent_directories=True)
+ """Get the commit hash of the current SWE-agent commit.
+
+ If we cannot get the hash, we return an empty string.
+ """
+ try:
+ repo = Repo(REPO_ROOT, search_parent_directories=False)
+ except Exception:
+ return ""
return repo.head.object.hexsha
-def get_agent_version_info() -> str:
+def get_rex_commit_hash() -> str:
+ import swerex
+
+ print(swerex.__file__)
+
try:
- hash = get_agent_commit_hash()
+ repo = Repo(Path(swerex.__file__).resolve().parent.parent.parent, search_parent_directories=False)
except Exception:
- hash = "unknown"
- return f"This is SWE-agent version {__version__} with commit hash {hash}."
+ return ""
+ return repo.head.object.hexsha
+
+
+def get_rex_version() -> str:
+ from swerex import __version__ as rex_version
+
+ return rex_version
+
+
+def get_agent_version_info() -> str:
+ hash = get_agent_commit_hash()
+ rex_hash = get_rex_commit_hash()
+ rex_version = get_rex_version()
+ return f"This is SWE-agent version {__version__} ({hash}) with SWE-ReX {rex_version} ({rex_hash})."
get_logger("swe-agent", emoji="👋").info(get_agent_version_info())
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index a6284074..d254b2ad 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -14,7 +14,7 @@ from swerex.exceptions import BashIncorrectSyntaxError, CommandTimeoutError, Swe
from tenacity import RetryError
from typing_extensions import Self
-from sweagent import __version__, get_agent_commit_hash
+from sweagent import __version__, get_agent_commit_hash, get_rex_commit_hash, get_rex_version
from sweagent.agent.history_processors import DefaultHistoryProcessor, HistoryProcessor
from sweagent.agent.hooks.abstract import AbstractAgentHook, CombinedAgentHook
from sweagent.agent.models import (
@@ -294,6 +294,8 @@ class Agent:
self.info = AgentInfo()
self.info["swe_agent_hash"] = get_agent_commit_hash()
self.info["swe_agent_version"] = __version__
+ self.info["swe_rex_version"] = get_rex_version()
+ self.info["swe_rex_hash"] = get_rex_commit_hash()
self.traj_path = output_dir / (self._problem_statement.id + ".traj")
self.logger.info("Trajectory will be saved to %s", self.traj_path)