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: PatchFormatter path relative to repo root

Kilian Lieret82773617bfaa
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index 2e446443..5c116bd0 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -686,7 +686,16 @@ class Agent:
"""Get the edited files with context from the patch"""
assert self._env is not None
try:
- pf = PatchFormatter(patch, read_method=self._env.read_file) if patch else None
+ if self._env.repo is None:
+ pf = None
+ else:
+ pf = (
+ PatchFormatter(
+ patch, read_method=lambda path: self._env.read_file(Path("/") / self._env.repo.repo_name / path)
+ )
+ if patch
+ else None
+ )
except UnidiffParseError:
self.logger.error("Failed to parse patch with unidiff. Some variables will be empty.")
pf = None