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: Add tool bundle config help (#910)

Kilian Lieretec5fdac48b4b
diff --git a/docs/config/tools.md b/docs/config/tools.md
index 8fdce95d..d9a638e6 100644
--- a/docs/config/tools.md
+++ b/docs/config/tools.md
@@ -1,4 +1,76 @@
# Configuring tools
-!!! warning "Under construction"
- This section is under construction.
+Tools are one one of the ways to configure and extend the agent.
+
+Typically, there is
+
+* The `bash` tool, allowing the agent to run shell commands (including invoking python scripts)
+* Specific tools for the agent to inspect the code (file viewer, etc)
+* Code editors (for example with search and replace or line range based methods)
+
+With SWE-agent, these tools are organized in _tool bundles_.
+
+Each tool bundle is a folder with the following structure:
+
+```
+bundle/
+├── bin/
+│ └── <tool executable>
+│ └── <state executable>
+├── config.yaml
+├── install.sh
+├── README.md
+└── pyproject.toml
+```
+
+The `bin/` folder contains the actual tool implementation as executables.
+
+Here's an example of a tool bundle config:
+
+```yaml
+tools:
+ filemap:
+ signature: "filemap <file_path>"
+ docstring: "Print the contents of a Python file, skipping lengthy function and method definitions."
+ arguments:
+ - name: file_path
+ type: string
+ description: The path to the file to be read
+ required: true
+```
+
+Another important key is the `state` field.
+The `state` command is a special command that is executed after every action and returns a json string that we parse.
+The resulting dictionary can be used to format prompt templates.
+For example, for the classical SWE-agent tools, we extract the working directory and the currently open file like so:
+
+```python title="tools/defaults/bin/_state"
+#!/usr/bin/env python3
+
+import json
+import os
+from pathlib import Path
+
+from registry import registry # type: ignore
+
+
+def main():
+ current_file = registry.get("CURRENT_FILE")
+ open_file = "n/a" if not current_file else str(Path(current_file).resolve())
+ state = {"open_file": open_file, "working_dir": os.getcwd()}
+
+ print(json.dumps(state))
+
+if __name__ == "__main__":
+ main()
+```
+
+TO use it, we set the following config key
+
+```yaml
+tools:
+ ...
+state_command: "_state"
+```
+
+To see the full specification of the state command, see the [tool config documentation](../reference/bundle_config.md).
\ No newline at end of file
diff --git a/docs/reference/bundle_config.md b/docs/reference/bundle_config.md
index b5452313..0fe0ad23 100644
--- a/docs/reference/bundle_config.md
+++ b/docs/reference/bundle_config.md
@@ -1,5 +1,9 @@
# Tool bundle configuration
+::: sweagent.tools.tools.ToolConfig
+
+::: sweagent.tools.tools.ToolFilterConfig
+
::: sweagent.tools.commands.Command
-::: sweagent.tools.commands.Argument
\ No newline at end of file
+::: sweagent.tools.commands.Argument
diff --git a/mkdocs.yml b/mkdocs.yml
index cb69c4a3..a3eef73f 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -85,6 +85,7 @@ nav:
- "Config files": "config/config.md"
- "Templates": "config/templates.md"
- "Demonstrations": "config/demonstrations.md"
+ - "Tools": "config/tools.md"
- "Environments": "config/environments.md"
- Development:
- "Contribution guide": "dev/contribute.md"