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 proper _state command to anthropic tools

Kilian Lieretd4c2d6daa333
diff --git a/config/function_calling_anthropic_openhands.yaml b/config/function_calling_anthropic_openhands.yaml
index ea8a05e3..7bbfbaf3 100644
--- a/config/function_calling_anthropic_openhands.yaml
+++ b/config/function_calling_anthropic_openhands.yaml
@@ -63,33 +63,20 @@ agent:
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.
- (Open file: {{open_file}})
(Current directory: {{working_dir}})
bash-$
next_step_template: |-
{{observation}}
- (Open file: {{open_file}})
(Current directory: {{working_dir}})
bash-$
next_step_no_output_template: |-
Your command ran successfully and did not produce any output.
- (Open file: {{open_file}})
(Current directory: {{working_dir}})
bash-$
- demonstration_template: |
- Here is a demonstration of how to correctly accomplish this task.
- It is included to show you how to correctly use the interface.
- You do not need to follow exactly what is done in the demonstration.
- --- DEMONSTRATION ---
- {{demonstration}}
- --- END OF DEMONSTRATION ---
demonstrations:
- trajectories/demonstrations/function_calling_simple.traj
put_demos_in_history: true
tools:
- env_variables:
- WINDOW: 100
- OVERLAP: 2
bundles:
- path: tools/edit_anthropic
- path: tools/submit
diff --git a/tools/edit_anthropic/bin/_state_anthropic b/tools/edit_anthropic/bin/_state_anthropic
new file mode 100644
index 00000000..ac0f2eca
--- /dev/null
+++ b/tools/edit_anthropic/bin/_state_anthropic
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+echo "{\"working_dir\": \"$(pwd)\"}"
diff --git a/tools/edit_anthropic/bin/str_replace_editor b/tools/edit_anthropic/bin/str_replace_editor
index e6c900c9..3cd12d2a 100644
--- a/tools/edit_anthropic/bin/str_replace_editor
+++ b/tools/edit_anthropic/bin/str_replace_editor
@@ -2,17 +2,17 @@
"""This is an adaptation of the Anthropic Text Editor tool from
https://github.com/anthropics/anthropic-quickstarts/blob/main/computer-use-demo/computer_use_demo/tools/edit.py
-However, we made it python 3.6 compatible.
+However, we made it python 3.6 compatible and stateless (all state is saved in a json file)
"""
import argparse
+import json
+import os
import subprocess
import sys
from collections import defaultdict
from pathlib import Path
-from typing import List, Optional, Any
-import json
-import os
+from typing import Any, List, Optional
TRUNCATED_MESSAGE: str = "<response clipped><NOTE>To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with `grep -n` in order to find the line numbers of what you are looking for.</NOTE>"
MAX_RESPONSE_LEN: int = 16000
diff --git a/tools/edit_anthropic/config.yaml b/tools/edit_anthropic/config.yaml
index 2d91f712..d68fa98c 100644
--- a/tools/edit_anthropic/config.yaml
+++ b/tools/edit_anthropic/config.yaml
@@ -40,3 +40,4 @@ tools:
description: "Required for `insert`: Line number to insert text after."
required: false
argument_format: "--insert_line {value}"
+state_command: "_state_anthropic"
\ No newline at end of file