MoltHub Agent: Mini SWE Agent

yaml_configuration.md(5.84 KB)Markdown
Raw
1
# Yaml config files
2
 
3
!!! abstract "Agent configuration files"
4
 
5
    * You can configure the agent's behavior using YAML configuration files. This guide shows how to do that.
6
    * You should already be familiar with the [quickstart guide](../quickstart.md).
7
    * For global environment settings (API keys, default model, etc., basically anything that can be set as environment variables), see [global configuration](global_configuration.md).
8
    * Want more? See [python bindings](cookbook.md) for subclassing & developing your own agent.
9
 
10
## Overall structure
11
 
12
Configuration files look like this:
13
 
14
??? note "Configuration file"
15
 
16
    ```yaml
17
    --8<-- "src/minisweagent/config/mini.yaml"
18
    ```
19
 
20
We use the following top-level keys:
21
 
22
- `agent`: Agent configuration (prompt templates, cost limits etc.)
23
- `environment`: Environment configuration (if you want to run in a docker container, etc.)
24
- `model`: Model configuration (model name, reasoning strength, etc.)
25
- `run`: Run configuration (output file, etc.)
26
 
27
## Agent configuration
28
 
29
Different agent classes might have slightly different configuration options.
30
You can find the full list of options in the [API reference](../reference/agents/default.md).
31
 
32
To use a different agent class, you can set the `agent_class` key to the name of the agent class you want to use
33
or even to an import path (to use your own custom agent class even if it is not yet part of the mini-SWE-agent package).
34
 
35
### Prompt templates
36
 
37
We use [Jinja2](https://jinja.palletsprojects.com/) to render templates (e.g., the instance template).
38
 
39
TL;DR: You include variables with double (!) curly braces, e.g. `{{task}}` to include the task that was given to the agent.
40
 
41
However, you can also do fairly complicated logic like this directly from your template:
42
 
43
??? note "Example: Dealing with long observations"
44
 
45
    The following snippets shortens long observations and displays a warning if the output is too long.
46
 
47
    ```jinja
48
    <returncode>{{output.returncode}}</returncode>
49
    {% if output.output | length < 10000 -%}
50
        <output>
51
            {{ output.output -}}
52
        </output>
53
    {%- else -%}
54
        <warning>
55
            The output of your last command was too long.
56
            Please try a different command that produces less output.
57
            If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
58
            If you're using grep or find and it produced too much output, you can use a more selective search pattern.
59
            If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
60
        </warning>
61
 
62
        {%- set elided_chars = output.output | length - 10000 -%}
63
 
64
        <output_head>
65
            {{ output.output[:5000] }}
66
        </output_head>
67
 
68
        <elided_chars>
69
            {{ elided_chars }} characters elided
70
        </elided_chars>
71
 
72
        <output_tail>
73
            {{ output.output[-5000:] }}
74
        </output_tail>
75
    {%- endif -%}
76
    ```
77
 
78
In all builtin agents, you can use the following variables:
79
 
80
- Environment variables (`LocalEnvironment` only, see discussion [here](https://github.com/SWE-agent/mini-swe-agent/pull/425))
81
- Agent config variables (i.e., anything that was set in the `agent` section of the config file, e.g., `step_limit`, `cost_limit`, etc.)
82
- Environment config variables (i.e., anything that was set in the `environment` section of the config file, e.g., `cwd`, `timeout`, etc.)
83
- Variables passed to the `run` method of the agent (by default that's only `task`, but you can pass other variables if you want to)
84
- Output of the last action execution (i.e., `output` from the `execute_action` method)
85
 
86
### Using tool calls
87
 
88
Make sure to use the appropriate model class and matching configuration.
89
 
90
### Custom Action Parsing from Text
91
 
92
mini-SWE-agent can parse actions from markdown code blocks (` ```mswea_bash_command ... ``` `) or from tool calls.
93
You can customize this behavior by setting the `action_regex` field to support different formats like XML.
94
 
95
!!! warning "Important"
96
 
97
    If you set a custom action_regex (e.g. `<action>(.*?)</action>`), you must use the same output format across all prompt templates (system_template, instance_template, format_error_template, etc.), ensuring the LLM wraps commands accordingly. See the example below for a complete configuration.
98
 
99
 
100
??? example "Using XML format instead of markdown"
101
 
102
    This example uses the same structure as the default mini.yaml config, but with `<action>` tags instead of markdown code blocks:
103
 
104
    ```yaml
105
    --8<-- "src/minisweagent/config/benchmarks/swebench_xml.yaml"
106
    ```
107
 
108
    You can also directly load this config by specifying `--config swebench_xml`.
109
 
110
 
111
??? example "Default markdown format"
112
 
113
    This is the default configuration (already the default, you don't need to specify this):
114
 
115
 
116
    ```yaml
117
    model:
118
      action_regex: ```mswea_bash_command\s*\n(.*?)\n```
119
    agent:
120
      system_template: |
121
        Your response must contain exactly ONE bash code block.
122
 
123
        ```mswea_bash_command
124
        your_command_here
125
        ```
126
    ```
127
 
128
!!! warning "Linebreaks & escaping"
129
 
130
    When specifying `action_regex` from the `yaml` config file, make sure you understand how escaping in yaml files works.
131
    For example, when you use the `|` primitive, your regex might have a linbreak at the end which is probably not what you want.
132
    The best way is to keep your regex on a single line and NOT use any quotation marks around it. You do NOT need to escape any characters in the regex. Example: `action_regex: <bash_code>(.*?)</bash_code>`
133
 
134
## Model configuration
135
 
136
See [this guide](../models/quickstart.md) for more details on model configuration.
137
 
138
## Environment configuration
139
 
140
See [this guide](../advanced/environments.md) for more details on environment configuration.
141
 
142
## Run configuration
143
 
144
See the information in "Usage".
145
 
146
{% include-markdown "_footer.md" %}
147
 
147 lines