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]
First version of sampling with chooser
Kilian Lieret60c4139e52a2
diff --git a/config/function_calling_anthropic_openhands_sample_bc.yaml b/config/function_calling_anthropic_openhands_sample_bc.yamlnew file mode 100644index 00000000..8cc4402a--- /dev/null+++ b/config/function_calling_anthropic_openhands_sample_bc.yaml@@ -0,0 +1,48 @@+# This template is heavily inspired by anthropic and openhands+agent:+ templates:+ system_template: |-+ You are a helpful assistant that can interact with a computer to solve tasks.+ instance_template: |-+ <uploaded_files>+ {{working_dir}}+ </uploaded_files>+ I've uploaded a python code repository in the directory {{working_dir}}. Consider the following PR description:++ <pr_description>+ {{problem_statement}}+ </pr_description>++ Can you help me implement the necessary changes to the repository so that the requirements specified in the <pr_description> are met?+ I've already taken care of all changes to any of the test files described in the <pr_description>. This means you DON'T have to modify the testing logic or any of the tests in any way!+ Your task is to make the minimal changes to non-tests files in the {{working_dir}} directory to ensure the <pr_description> is satisfied.+ Follow these steps to resolve the issue:+ 1. As a first step, it might be a good idea to find and read code relevant to the <pr_description>+ 2. Create a script to reproduce the error and execute it with `python <filename.py>` using the bash tool, to confirm the error+ 3. Edit the sourcecode of the repo to resolve the issue+ 4. Rerun your reproduce script and confirm that the error is fixed!+ 5. Think about edgecases and make sure your fix handles them as well+ Your thinking should be thorough and so it's fine if it's very long.+ next_step_template: |-+ OBSERVATION:+ {{observation}}++ Please propose a new action. You must include _ONE_ function/tool call.+ next_step_no_output_template: |-+ Your command ran successfully and did not produce any output.++ Please propose a new action. You must include _ONE_ function/tool call.+ demonstrations:+ - trajectories/demonstrations/str_replace_anthropic_demo.yaml+ put_demos_in_history: true+ tools:+ bundles:+ - path: tools/registry+ - path: tools/edit_anthropic+ - path: tools/submit+ enable_bash_tool: true+ parse_function:+ type: function_calling+ history_processors: []+ best_response_picker:+ type: binary_trajectory_comparisondiff --git a/sweagent/agent/best_response_picker.py b/sweagent/agent/best_response_picker.pyindex f1a28c82..5a5e59a8 100644--- a/sweagent/agent/best_response_picker.py+++ b/sweagent/agent/best_response_picker.py@@ -1,4 +1,5 @@from abc import abstractmethod+from textwrap import dedentfrom typing import Any, Literalfrom jinja2 import Template@@ -86,8 +87,47 @@ class AskColleagues(AbstractBestActionPicker):class BinaryTrajectoryComparison(AbstractBestActionPicker):type: Literal["binary_trajectory_comparison"] = "binary_trajectory_comparison"- system_template: str- instance_template: str+ system_template: str = """<context>You are an expert software engineer overseeing junior developers. They suggest actions to take to solve a problem. You must choose the best action to take. </context>"""+ instance_template: str = dedent("""+ We're solving the following problem++ <problem_statement>+ {{problem_statement}}+ </problem_statement>++ So far, we've performed the following actions:++ <trajectory>+ {{traj}}+ </trajectory>++ Two junior developers suggested the following actions:++ <thought1>+ {{thought1}}+ </thought1>++ <action1>+ {{action1}}+ </action1>++ <thought2>+ {{thought2}}+ </thought2>++ <action2>+ {{action2}}+ </action2>++ Please compare the two actions in detail.++ Which action should we take?++ If you think the first action is better, respond with "first".+ If you think the second action is better, respond with "second".++ The last line of your response MUST be "first" or "second".+ """)def _format_trajectory(self, trajectory: Trajectory) -> str:steps = []@@ -116,6 +156,8 @@ class BinaryTrajectoryComparison(AbstractBestActionPicker):traj=self._format_trajectory(trajectory),action1=action1,action2=action2,+ thought1=thought1,+ thought2=thought2,)logger.debug(f"MODEL INPUT (user)\n{user_message}")return [@@ -136,7 +178,7 @@ class BinaryTrajectoryComparison(AbstractBestActionPicker):actions: list[str] = [h[1] for h in parsed_completions]assert len(thoughts) == len(actions)best_idx = 0- for i in range(len(actions)):+ for i in range(1, len(actions)):messages = self.format_messages(problem_statement=problem_statement,trajectory=trajectory,@@ -146,6 +188,7 @@ class BinaryTrajectoryComparison(AbstractBestActionPicker):action2=actions[i],)response = self._model.query(messages)["message"] # type: ignore+ logger.info(f"RESPONSE: {response}")idx = self.interpret(response)best_idx = i if idx == 1 else best_idx