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]

Resample: Better handling of format errors

Kilian Lieretf8e64ce1f306
diff --git a/sweagent/agent/best_response_picker.py b/sweagent/agent/best_response_picker.py
index 7b269129..472beb9d 100644
--- a/sweagent/agent/best_response_picker.py
+++ b/sweagent/agent/best_response_picker.py
@@ -173,7 +173,17 @@ class BinaryTrajectoryComparison(AbstractBestActionPicker):
history: list[dict[str, Any]],
completions: list[dict[str, Any]],
) -> GetActionOutput:
- parsed_completions = [self._tools.parse_actions(a) for a in completions]
+ parsed_completions = []
+ for completion in completions:
+ try:
+ thought, action = self._tools.parse_actions(completion)
+ except FormatError:
+ logger.warning("Could not parse completion %s, skipping.", completion)
+ continue
+ parsed_completions.append((thought, action))
+ if len(parsed_completions) == 0:
+ msg = "No completions could be parsed."
+ raise FormatError(msg)
thoughts: list[str] = [h[0] for h in parsed_completions]
actions: list[str] = [h[1] for h in parsed_completions]
assert len(thoughts) == len(actions)