Command Configuration
In this document, we describe how to implement your own commands for the SWE-agent ACI.
To see examples of command implementations, open the .sh
and .py
files in the
config/commands
folder.
Scaffolding
Every command subscribes to the following skeleton code.
# @yaml
# signature: [command] [argument(s)]
# docstring: [Brief description of what your command does.]
# arguments:
# [argument 1 name]:
# type: [type (i.e. integer, string)]
# description: [Brief description of this argument]
# required: [true|false]
# [argument 2 name]:
# ...
[command]() {
# Implementation here
}
- If a command takes in arguments, reference them via positional parameters notation (i.e.
$1
). - If there are no arguments, omit the
arguments
section. - The implementation for your command is unconstrained. There are no limitations on the form of the underlying command code.
- The minimal documentation requirements are
signature
anddocstring
. - If you'd like multiple commands to make modifications to a similar body of functions, we recommend using global variables.
- For instance, in
config/commands/default.sh
, you'll see we define theCURRENT_LINE
variable for the file viewer. This variable is modified across multiple commands, includingopen
,goto
,scroll_up
,scroll_down
, andedit
. - You can also third-party libraries (check out how we enable linting in
config/commands/edit_linting.sh
).
- For instance, in
- To show effects of the command, print to standard output (i.e.
echo
). SWE-agent is implemented such that it does not look for a return value from these commands. - The following environment variables are used to persist information between commands:
CURRENT_FILE
: File that is currently openCURRENT_LINE
: First line of the window that is currently being shown/editedWINDOW
(start line to end line): Part of the file that is currently shown/editedSTART_CURSOR
,END_CURSOR
: Only used for thecursors_*
commands.
- You can also use environment variables to set parameters for your commands. For this, edit the
env_vars
section of the config. For example, theWINDOW
setting controls the number of context lines shown when editing a file.
Displaying the Command to SWE-agent
After you define a command, there are a small set of additional steps to making it available for the agent to use.
First, within your config file...
- Add
config/commands/<file name>.sh
file to thecommand_files
field. - Set the
parse_command
field toParseCommandBash
orParseCommandDetailed
. This key points to the functionality that generates how command documentation is shown to the agent. - Decide which template(s) you want to show the
{command_docs}
in.- We strongly recommend including
{command_docs}
in thesystem_template
, which is the first message shown to the agent for every task instance episode. - You might also consider adding
{command_docs}
to theformat_error_template
, which is shown if the response provided by a model is malformed.
- We strongly recommend including
- (Optional) Including a demonstration that uses a command is helpful to showcase proper use + increases the frequency with which the agent uses the command. If you'd like to add a demonstration...
- Create a demonstration manually (i.e.
python run.py --model human_thought ...
) or automatically (i.e.python run_replay --traj_path ...
) - Add/Update the demonstration to the
demonstrations
argument. - Update
demonstration_template
to control how the demonstration is displayed to the agent.
- Create a demonstration manually (i.e.
Config files
If you're not familiar with how SWE-agent configuration files work, we recommend checking out the config
documentation.
Next, run your configuration and see how your agent uses the commands!
python run.py --config_file config/[your config].yaml ...
-
Something broken? Report bug
-
Something unclear? Ask question