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: Improve typing; add architecture to doc (#649)
Kilian Lieretcae17bad8818
diff --git a/docs/assets/architecture.png b/docs/assets/architecture.pngnew file mode 100644index 00000000..ccbfa922Binary files /dev/null and b/docs/assets/architecture.png differdiff --git a/docs/background/architecture.md b/docs/background/architecture.mdnew file mode 100644index 00000000..e4f59a29--- /dev/null+++ b/docs/background/architecture.md@@ -0,0 +1,15 @@+# Architecture++This page walks you through the general architecture of the SWE-agent package. Want to just run it? Jump ahead to the [installation](../installation/index.md) or [usage](../usage/index.md) sections.++++The central entry point to SWE-agent is the `run.py` script (1). It initializes the [`SWEEnv`](../reference/env.md) instance (2) that manages the environment. Upon initialization (and by default for every new instance), it starts a docker container together with a shell session (3). This shell session will be kept alive throughout the task. All installation commands and actions from the model will be executed therein.++`SWEEnv` then installs the dependencies of the repository to which the task instance belongs into a new conda environment (4).++The second class that is initialized by `run.py` is the [`Agent`](../reference/agent.md) class (5). It can be configured with a yaml file (see [config](../config/config.md)). It's most important method is `forward()` which prompts the model and executes its action.++To prompt the model, the history (all prompts to the model together with actions and outputs) need to be sent to the LM. In order to make the best use of the context window of the model, the history gets compressed by a `HistoryFormatter` (7). The model output (8) is then interpreted by the `Agent` class and executed in the Shell session via `SWEEnv`.++The [ACI](aci.md) elements are implemented as custom commands (9) that are available to the shell session.\ No newline at end of filediff --git a/docs/usage/inspector.md b/docs/usage/inspector.mdindex 28071030..134ae966 100644--- a/docs/usage/inspector.md+++ b/docs/usage/inspector.md@@ -25,4 +25,7 @@ The inspector will then be launched in the browser:-{% include-markdown "../_footer.md" %}\ No newline at end of file+If you do not see evaluation results, make sure that the SWE-bench output+is called `results.json` and is in the same directory as the trajectories.++{% include-markdown "../_footer.md" %}diff --git a/mkdocs.yml b/mkdocs.ymlindex 8436046d..2cb4db80 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -51,6 +51,7 @@ nav:- "background/index.md"- "Overview": "background/overview.md"- "ACI": "background/aci.md"+ - "Architecture": "background/architecture.md"- Installation:- "installation/index.md"- "Use in-browser": "installation/codespaces.md"diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 06e8dd14..b1fa78d8 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -770,9 +770,13 @@ class SWEEnv(gym.Env):self.returncode = int(exit_code)return buffer- def _check_syntax(self, input: str):+ def _check_syntax(self, input: str) -> tuple[str, bool]:"""- Saves environment variables to file+ Check syntax of command.++ Returns:+ output: Output of the command+ success: whether the exit code was 0"""output = self._communicate(f"/bin/bash -n <<'EOF'\n{input}\nEOF\n")return output, self.returncode == 0@@ -809,7 +813,7 @@ class SWEEnv(gym.Env):self.communicate_output = ""return ""- def communicate_with_handling(self, input: str, error_msg: str, timeout_duration=25) -> str:+ def communicate_with_handling(self, input: str, error_msg: str, timeout_duration: int = 25) -> str:"""Wrapper for communicate function that raises error if return code is non-zero@@ -837,7 +841,7 @@ class SWEEnv(gym.Env):"""return []- def get_pids(self, all_pids=False) -> list[str]:+ def get_pids(self, all_pids: bool = False) -> list[str]:"""Gets list of processes running inside docker container@@ -1112,7 +1116,7 @@ class SWEEnv(gym.Env):msg = f"Invalid command type: {command['type']}"raise ValueError(msg)- def interrupt(self):+ def interrupt(self) -> None:"""Send interrupt signal to container and exhaust stdout buffer with a communicate call"""@@ -1133,7 +1137,7 @@ class SWEEnv(gym.Env):msg = "Failed to interrupt container"raise RuntimeError(msg)- def open_pr(self, *, trajectory, _dry_run: bool = False):+ def open_pr(self, *, trajectory, _dry_run: bool = False) -> None:"""Create PR to repositoryArgs: