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]

Doc: Port more content from readme to docs/ (#427)

Kilian Lieretf05fd25c078f
diff --git a/docs/config/demonstrations.md b/docs/config/demonstrations.md
index 021f52b9..5a652f88 100644
--- a/docs/config/demonstrations.md
+++ b/docs/config/demonstrations.md
@@ -1,12 +1,30 @@
# Changing the demonstrations
-If you'd like to modify the example demonstration that we feed the model at the start of each run, first generate a trajectory manually by running the agent with ```--model_name human```
-and then convert that trajectory into a demonstration by following the guide [here](https://github.com/princeton-nlp/SWE-agent/tree/main/make_demos).
+An important way to show LMs how to use commands and interact with the environment is through providing a demonstration - which is basically a completed [trajectory](../usage/trajectories.md) that the LM can learn from.
-To edit text in ```human``` mode:
+For simplicity we only ingest demonstrations in the from of a trajectory file. However, since trajectory files are usually JSON, you can convert them to yaml using the `make_demos/convert_traj_to_demo.py` script to be more human-readable and easier to edit.
-1. Run the command ```edit edit_start_line:edit_end_line```
+Demo (yaml) files are stored in the `make_demos/demos` directory by default and consist primarily of the sequence of actions that an LM would need to take to complete a task. It's important that your demo have the proper format to be parsed by SWE-agent and your config.
+
+## Converting an existing demonstration
+
+Here's how you can make a demo:
+
+1. Find a basic trajectory that you already like and want to use as the basis for your demo.
+ For instance, consider the `.traj` files in the [`trajectories/demonstrations/` folder](https://github.com/princeton-nlp/SWE-agent/tree/main/trajectories/demonstrations).
+2. Run `python convert_traj_to_demo.py <path to trajectory file.traj>` to convert the trajectory to a demo.
+ This demo will be saved as a readable yaml file in the `make_demos/demos` directory.
+3. Edit the demo by hand to make it work for your particular use case and configuration.
+4. Run `python run_replay.py --traj_path <path to demo> --config_file <path to config file>` to execute the actions of the demo, have the system generate the execution output, and ensure that it works as expected.
+5. Inspect the resulting trajectory to ensure it was executed correctly.
+
+## Manually creating a custom trajectory <a name="manual"></a>
+
+You can also manually generate a trajectory by running the agent with `--model_name human` (which allows you to enter the commands that would usually be suggested by the LM) and then convert that trajectory into a demonstration as above.
+To edit text in `human` mode:
+
+1. Run the command `edit edit_start_line:edit_end_line`
2. Write the text you want to insert. Feel free to write the text across multiple lines.
-3. Press ```return``` then write ```end_of_edit``` and then press ```return``` again to submit the edit.
+3. Press `return` then write `end_of_edit` and then press `return` again to submit the edit.
{% include-markdown "../_footer.md" %}
\ No newline at end of file
diff --git a/docs/usage/benchmarking.md b/docs/usage/benchmarking.md
index 97e05247..14738f67 100644
--- a/docs/usage/benchmarking.md
+++ b/docs/usage/benchmarking.md
@@ -6,9 +6,8 @@ There are two steps to the SWE-agent pipeline. First SWE-agent takes an input Gi
At this moment, there are known issues with a small number of repositories that don't install properly for `arm64` / `aarch64` architecture computers. We're working on a fix, but if you'd like to run and evaluate on the entirety of SWE-bench, the easiest way is by using an `x86` machine.
## πŸ‘©β€πŸ’» Inference <a name="inference"></a>
-**Inference on *any* GitHub Issue**: See [the command line tutorial](cl_tutorial.md).
-**Inference on SWE-bench**: Run SWE-agent on [SWE-bench Lite](https://www.swebench.com/lite.html) and generate patches.
+Run SWE-agent on [SWE-bench Lite](https://www.swebench.com/lite.html) and generate patches.
```bash
python run.py --model_name gpt4 \
@@ -23,12 +22,90 @@ python run.py --model_name gpt4 \
```
## πŸ§ͺ Evaluation <a name="evaluation"></a>
-This step is only available for issues from the SWE-bench set. To evaluate generated pull requests:
+
+The `evaluation/` folder provides SWE-agent compatible scripts for running [SWE-bench style evaluation](https://github.com/princeton-nlp/SWE-bench/blob/main/tutorials/evaluation.md) on model patch predictions. In addition, we also include additional scripts to quantify model performance on "subtasks" within the SWE-bench task, such as identifying the right file(s) to edit.
+
+### πŸ‡ Quick Start <a name="quick"></a>
+You can run evaluations on SWE-bench by passing in the predictions generated by SWE-agent (usually named `all_preds.jsonl`). Simply run the following script:
+
```bash
-cd evaluation/
-./run_eval.sh <predictions_path>
+./run_eval.sh <path to predictions>
+```
+
+The `<predictions_path>` arguments should look like
+
+```
+../trajectories/<username>/<model>-<dataset>-<hyperparams>/all_preds.jsonl
+```
+
+Depending on the number of task instances and how long setting up the execution environment takes, the evaluation could take a couple minutes or to 7 hours for the entirety of the SWE-bench test split.
+
+When evaluation finishes, you should see an output similar to the following:
+```bash
+2024-03-31 16:47:00,263 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Installing with command: . /n/fs/p-swe-bench/testbed/ba397fe0d6/pvlib__pvlib-python/0.8/tmpom22t9na/miniconda3/bin/activate pvlib__pvlib-python__0.8 && echo 'activate successful' && pip install -e .[all]
+2024-03-31 16:47:10,602 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Installation successful
+2024-03-31 16:47:10,619 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Apply patch successful (test)
+2024-03-31 16:47:10,635 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Apply patch successful (pred)
+2024-03-31 16:47:13,453 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Test script run successful
+==================================
+Log directory for evaluation run: /n/fs/p-swe-bench/results/gpt-4-1106-preview__swe-bench-dev-40-seed24__default_sys-env_window100-detailed_cmd_format-full_history-1_demos__t-0.20__p-0.95__c-4.00__install-1__sweep-01-run-4
+== Evaluation Report ==
+{'# Not Generated': 1, '# Generated': 36, '# Applied': 34, '# Resolved': 5}
+- Wrote per-instance scorecards to /<path to SWE-agent>/trajectories/carlosejimenez/gpt-4-1106-preview__swe-bench-dev-40-seed24__default_sys-env_window100-detailed_cmd_format-full_history-1_demos__t-0.20__p-0.95__c-4.00__install-1__sweep-01-run-4/scorecards.json
+- Wrote summary of run to /<path to SWE-agent>/trajectories/carlosejimenez/gpt-4-1106-preview__swe-bench-dev-40-seed24__default_sys-env_window100-detailed_cmd_format-full_history-1_demos__t-0.20__p-0.95__c-4.00__install-1__sweep-01-run-4/results.json
+Reference Report:
+{'# Not Generated': 1, '# Generated': 36, '# Applied': 34, '# Resolved': 5}
+```
+
+### πŸͺ‘ SWE-bench Evaluation <a name="eval"></a>
+
+`evaluation.py`: This script contains the logic for SWE-bench evaluation adapted for the SWE-agent setting. Given a set of predictions (e.g. `trajectories/<user>/<experiment>/all_preds.jsonl`), we...
+
+1. Filter + analyze predictions.
+2. Run SWE-bench style execution based evaluation.
+3. Save outcomes to `results.json` and `scorecards.json` files with info about task-specific and overall performance.
+
+!!! tip "Examples"
+ `run_eval.sh` (see above) is provided as an example of how to run `evaluation.py`
+
+Arguments:
+
+* `--predictions_path (required)`: The path to the file containing predictions (.jsonl format). This file includes the predictions that need to be evaluated against the benchmark tasks.
+* `--log_dir (required)`: The directory path where log files related to the evaluation process will be stored. It's used for saving logs that are generated during the evaluation.
+* `--swe_bench_tasks (required)`: The path to the file containing the SWE-bench task instances. This file includes the details of the tasks against which the predictions will be evaluated.
+* `--testbed (required)`: The directory path for the testbed, which is likely used for setting up the environment or context for the evaluations.
+* `--skip_existing (optional)`: If specified, the script will skip over log files that already exist, preventing re-evaluation of those tasks.
+* `--timeout (optional)`: Specifies the timeout in seconds for the evaluation process (default is 900 seconds). This helps in controlling the duration of each evaluation task to avoid excessively long running times.
+* `--verbose (optional)`: Enables verbose mode, which will provide more detailed output during the script execution. This is useful for debugging or getting more insight into the process.
+* `--conda_link (optional)`: Allows specifying a URL to a Conda installation that should be used for the evaluation environment. This can be necessary if the evaluation requires a specific software environment.
+* `--log_suffix (optional)`: An additional parameter to specify a suffix for log files. This can be used for organizing logs more effectively, especially when running multiple evaluations in parallel or under different configurations.
+
+### πŸ“ˆ Viewing Results <a name="viewer"></a>
+
+`aggregate_results.py`: This script aggregates and displays experiment results from the `trajectories/` folder.
+
+* Experiments are grouped by `(Model, Dataset, Config File, Temp., Top P, Cost, Install)`.
+* The following statistics for each experiment run are shown:
+ * `Not Generated`: # of task instances with no patch generated
+ * `Generated`: # of task instances with patch
+ * `Applied`: # of patches that applied successfully
+ * `Resolved`: # of task instances resolved
+ * `Costs [Success|Failed|Overall]`: Cost of [successful|failed|any] run
+* If there are multiple runs of an experiment (distinguished by `--suffix run<i>`), the above statistics are aggregate as totals or means.
+
+Usage:
+
```
-Replace `<predictions_path>` with the path to the model's predictions, which should be generated from the *Inference* step. The `<predictions_path>` arguments should look like `../trajectories/<username>/<model>-<dataset>-<hyperparams>/all_preds.jsonl`
-* See the [`evaluation/`](https://github.com/princeton-nlp/SWE-agent/tree/main/evaluation/) folder for details about how evaluation works.
+python aggregate_results.py
+```
+
+Arguments:
+
+* `--folder (type: str, default: ../trajectories)`: Specifies the folder containing the experiment * results. This is where the script will look to gather data.
+* `--model (type: str, nargs: '+')`: Filters the results by model(s). Only results corresponding to the * specified model(s) will be included.
+* `--dataset (type: str, nargs: '+')`: Filters the results by dataset(s). Only results for the specified * dataset(s) will be analyzed.
+* `--setup (type: str, nargs: '+')`: Filters the results by setup(s). This allows focusing on specific * experiment configurations.
+* `--runs_min (type: int)`: The minimum number of runs an experiment should have to be included in the * analysis. Helps exclude experiments with insufficient data.
+* `--runs_max (type: int)`: The maximum number of runs to consider for each experiment. This can limit the data to the most relevant runs.
{% include-markdown "../_footer.md" %}
\ No newline at end of file
diff --git a/docs/usage/faq.md b/docs/usage/faq.md
index f316d859..ec256d90 100644
--- a/docs/usage/faq.md
+++ b/docs/usage/faq.md
@@ -31,7 +31,7 @@ python run.py --model_name ollama:deepseek-coder:6.7b-instruct \
We also provide models for testing SWE-agent without spending any credits
-* `HumanModel` and `HumandThoughtModel` will prompt for input from the user that stands in for the output of the LM
+* `HumanModel` and `HumandThoughtModel` will prompt for input from the user that stands in for the output of the LM. This can be used to create new [demonstrations](../config/demonstrations.md#manual).
* `ReplayModel` takes a trajectory as input and "replays it"
* `InstantEmptySubmitTestModel` will create an empty `reproduce.py` and then submit
diff --git a/evaluation/README.md b/evaluation/README.md
index 4b584fca..28ed6683 100644
--- a/evaluation/README.md
+++ b/evaluation/README.md
@@ -1,79 +1,6 @@
-# Evaluation
+πŸ”— For more information on the trajectory inspector, visit [our documentation website][docs].
-The `evaluation/` folder provides SWE-agent compatible scripts for running [SWE-bench style evaluation](https://github.com/princeton-nlp/SWE-bench/blob/main/tutorials/evaluation.md) on model patch predictions. In addition, we also include additional scripts to quantify model performance on "subtasks" within the SWE-bench task, such as identifying the right file(s) to edit.
+You can also find the corresponding markdown files in the [`docs/` folder][source].
-## πŸ“– Table of Contents
-- [Evaluation](#evaluation)
- - [πŸ“– Table of Contents](#-table-of-contents)
- - [πŸ‡ Quick Start ](#-quick-start-)
- - [πŸͺ‘ SWE-bench Evaluation ](#-swe-bench-evaluation-)
- - [πŸ“ˆ Viewing Results ](#-viewing-results-)
-
-## πŸ‡ Quick Start <a name="quick"></a>
-You can run evaluations on SWE-bench by passing in the predictions generated by SWE-agent (usually named `all_preds.jsonl`). Simply run the following script:
-
-```bash
-./run_eval.sh <path to predictions>
-```
-
-Then run `./run_eval.sh`. Depending on the # of task instances and how long setting up the execution environment takes, the evaluation could take a couple minutes or to 7 hours for the entirety of the SWE-bench test split.
-
-When evaluation finishes, you should see an output similar to the following:
-```bash
-2024-03-31 16:47:00,263 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Installing with command: . /n/fs/p-swe-bench/testbed/ba397fe0d6/pvlib__pvlib-python/0.8/tmpom22t9na/miniconda3/bin/activate pvlib__pvlib-python__0.8 && echo 'activate successful' && pip install -e .[all]
-2024-03-31 16:47:10,602 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Installation successful
-2024-03-31 16:47:10,619 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Apply patch successful (test)
-2024-03-31 16:47:10,635 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Apply patch successful (pred)
-2024-03-31 16:47:13,453 - taskenv_context_manager - INFO - [pvlib__pvlib-python__0.8] [pvlib__pvlib-python-1395] Test script run successful
-==================================
-Log directory for evaluation run: /n/fs/p-swe-bench/results/gpt-4-1106-preview__swe-bench-dev-40-seed24__default_sys-env_window100-detailed_cmd_format-full_history-1_demos__t-0.20__p-0.95__c-4.00__install-1__sweep-01-run-4
-== Evaluation Report ==
-{'# Not Generated': 1, '# Generated': 36, '# Applied': 34, '# Resolved': 5}
-- Wrote per-instance scorecards to /<path to SWE-agent>/trajectories/carlosejimenez/gpt-4-1106-preview__swe-bench-dev-40-seed24__default_sys-env_window100-detailed_cmd_format-full_history-1_demos__t-0.20__p-0.95__c-4.00__install-1__sweep-01-run-4/scorecards.json
-- Wrote summary of run to /<path to SWE-agent>/trajectories/carlosejimenez/gpt-4-1106-preview__swe-bench-dev-40-seed24__default_sys-env_window100-detailed_cmd_format-full_history-1_demos__t-0.20__p-0.95__c-4.00__install-1__sweep-01-run-4/results.json
-Reference Report:
-{'# Not Generated': 1, '# Generated': 36, '# Applied': 34, '# Resolved': 5}
-```
-
-## πŸͺ‘ SWE-bench Evaluation <a name="eval"></a>
-`evaluation.py`: This script contains the logic for SWE-bench evaluation adapted for the SWE-agent setting. Given a set of predictions (e.g. `trajectories/<user>/<experiment>/all_preds.jsonl`), we...
-1. Filter + analyze predictions.
-2. Run SWE-bench style execution based evaluation.
-3. Save outcomes to `results.json` and `scorecards.json` files with info about task-specific and overall performance.
-
-> `run_eval.sh` is provided as an example of how to run `evaluation.py`
-
-Arguments:
-* `--predictions_path (required)`: The path to the file containing predictions (.jsonl format). This file includes the predictions that need to be evaluated against the benchmark tasks.
-* `--log_dir (required)`: The directory path where log files related to the evaluation process will be stored. It's used for saving logs that are generated during the evaluation.
-* `--swe_bench_tasks (required)`: The path to the file containing the SWE-bench task instances. This file includes the details of the tasks against which the predictions will be evaluated.
-* `--testbed (required)`: The directory path for the testbed, which is likely used for setting up the environment or context for the evaluations.
-* `--skip_existing (optional)`: If specified, the script will skip over log files that already exist, preventing re-evaluation of those tasks.
-* `--timeout (optional)`: Specifies the timeout in seconds for the evaluation process (default is 900 seconds). This helps in controlling the duration of each evaluation task to avoid excessively long running times.
-* `--verbose (optional)`: Enables verbose mode, which will provide more detailed output during the script execution. This is useful for debugging or getting more insight into the process.
-* `--conda_link (optional)`: Allows specifying a URL to a Conda installation that should be used for the evaluation environment. This can be necessary if the evaluation requires a specific software environment.
-* `--log_suffix (optional)`: An additional parameter to specify a suffix for log files. This can be used for organizing logs more effectively, especially when running multiple evaluations in parallel or under different configurations.
-
-## πŸ“ˆ Viewing Results <a name="viewer"></a>
-`aggregate_results.py`: This script aggregates and displays experiment results from the `trajectories/` folder.
-* Experiments are grouped by `(Model, Dataset, Config File, Temp., Top P, Cost, Install)`.
-* The following statistics for each experiment run are shown:
- * `Not Generated`: # of task instances with no patch generated
- * `Generated`: # of task instances with patch
- * `Applied`: # of patches that applied successfully
- * `Resolved`: # of task instances resolved
- * `Costs [Success|Failed|Overall]`: Cost of [successful|failed|any] run
-* If there are multiple runs of an experiment (distinguished by `--suffix run<i>`), the above statistics are aggregate as totals or means.
-
-Usage:
-```
-python aggregate_results.py
-```
-
-Arguments:
-* `--folder (type: str, default: ../trajectories)`: Specifies the folder containing the experiment * results. This is where the script will look to gather data.
-* `--model (type: str, nargs: '+')`: Filters the results by model(s). Only results corresponding to the * specified model(s) will be included.
-* `--dataset (type: str, nargs: '+')`: Filters the results by dataset(s). Only results for the specified * dataset(s) will be analyzed.
-* `--setup (type: str, nargs: '+')`: Filters the results by setup(s). This allows focusing on specific * experiment configurations.
-* `--runs_min (type: int)`: The minimum number of runs an experiment should have to be included in the * analysis. Helps exclude experiments with insufficient data.
-* `--runs_max (type: int)`: The maximum number of runs to consider for each experiment. This can limit the data to the most relevant runs.
\ No newline at end of file
+[docs]: https://princeton-nlp.github.io/SWE-agent/usage/benchmarking/
+[source]: https://github.com/princeton-nlp/SWE-agent/tree/main/docs
diff --git a/make_demos/README.md b/make_demos/README.md
index bf341411..7f63b9e4 100644
--- a/make_demos/README.md
+++ b/make_demos/README.md
@@ -1,16 +1,6 @@
-# Make demos
-An important way to show LMs how to use commands and interact with the environment is through providing a demonstration - which is basically a completed trajectory that the LM can learn from.
+πŸ”— For more information on the trajectory inspector, visit [our documentation website][docs].
-For simplicity we just ingest demonstrations in the from of a trajectory file. However, since trajectory files are usually JSON, you can convert them to yaml using the `convert_traj_to_demo.py` script to be more human-readable and easier to edit.
+You can also find the corresponding markdown files in the [`docs/` folder][source].
-Demo (yaml) files are stored in the `make_demos/demos` directory by default and consist primarily of the sequence of actions that an LM would need to take to complete a task. It's important that your demo have the proper format to be parsed by SWE-agent and your config.
-
-Here's how you can make a demo:
-1. Find a basic trajectory that you already like and want to use as the basis for your demo.
- - For instance, consider the `trajectories/demonstrations/replay__marshmallow-code__marshmallow-1867__default_sys-env_window100__t-0.20__p-0.95__c-2.00__install-1/marshmallow-code__marshmallow-1867.traj` trajectory for reference.
-2. Run `python convert_traj_to_demo.py <path to trajectory file>` to convert the trajectory to a demo.
- - This demo will be saved as a readable yaml file in the `make_demos/demos` directory.
-3. Edit the demo by hand to make it work for your particular use case and configuration.
-4. Run `python run_replay.py --traj_path <path to demo> --config_file <path to config file>` to execute the actions of the demo, have the system generate the execution output, and ensure that it works as expected.
- - Protip: you can use `sweagent.run` with `--model_name human` to manually execute actions in the environment - useful for debugging.
-5. Inspect the resulting trajectory to ensure it was executed correctly.
\ No newline at end of file
+[docs]: https://princeton-nlp.github.io/SWE-agent/config/demonstrations/
+[source]: https://github.com/princeton-nlp/SWE-agent/tree/main/docs
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 5b7579b3..7ba9e56d 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -325,6 +325,7 @@ class SWEEnv(gym.Env):
"""
Apply test patch for oracle setting
"""
+ assert self.record is not None
path_to_patch = "test.patch"
with open(path_to_patch, "w") as f:
f.write(self.record["test_patch"])