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 nonsensical trajectory formatting for PRs (#647)
Kilian Lieret7c0c82585728
diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex 27d9e27b..3a15bae9 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -852,14 +852,6 @@ def remove_triple_backticks(text: str) -> str:return "\n".join(line.removeprefix("```") for line in text.splitlines())-_MARKDOWN_TRAJECTORY_EMOJI_MAPPING = {- "observation": "π",- "response": "οΈπ§βπ",- "state": "π§ ",- "thought": "π‘",-}--def format_trajectory_markdown(trajectory: list[dict[str, str]]):"""Format a trajectory as a markdown string for use in gh PR description."""prefix = [@@ -870,18 +862,14 @@ def format_trajectory_markdown(trajectory: list[dict[str, str]]):]steps = []for i, step in enumerate(trajectory):- step_strs = []- for key, value in step.items():- emoji = _MARKDOWN_TRAJECTORY_EMOJI_MAPPING.get(key, "")- if emoji:- emoji += " "- step_strs.append(f"**{emoji}{key.capitalize()} ({i})**:")- if key in ["observation", "state", "action"]:- step_strs.append("```")- step_strs.append(remove_triple_backticks(value).strip())- step_strs.append("```")- else:- step_strs.append(value.strip())+ step_strs = [+ f"**π§βπ Response ({i})**: ",+ f"{step['response'].strip()}",+ f"**πβ Observation ({i})**:",+ "```",+ f"{remove_triple_backticks(step['observation']).strip()}",+ "```",+ ]steps.append("\n".join(step_strs))suffix = ["",diff --git a/tests/test_env_utils.py b/tests/test_env_utils.pyindex 6fb29805..a4da24b8 100644--- a/tests/test_env_utils.py+++ b/tests/test_env_utils.py@@ -7,7 +7,6 @@ import subprocessimport pytestfrom sweagent.environment.utils import (- _MARKDOWN_TRAJECTORY_EMOJI_MAPPING,InvalidGithubURL,format_trajectory_markdown,get_associated_commit_urls,@@ -26,8 +25,6 @@ def test_format_trajectory_markdown(test_trajectory):formatted = format_trajectory_markdown(test_trajectory["trajectory"])assert formatted.startswith("<details>")assert formatted.endswith("</details>")- for emoji in _MARKDOWN_TRAJECTORY_EMOJI_MAPPING.values():- assert emoji in formatteddef test_remove_triple_backticks():