mini-swe-agent ships two agent classes that share a common foundation.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/swe-agent/mini-swe-agent/llms.txt
Use this file to discover all available pages before exploring further.
DefaultAgent implements the fully-automated run loop — it initialises the conversation, calls the model in a loop, executes shell actions, and saves a trajectory file when done. InteractiveAgent extends DefaultAgent with a human-in-the-loop layer: it can confirm actions before running them, accept direct user commands, and let you steer the session at any point without restarting.
Both classes accept the same constructor signature. All configuration fields are passed as keyword arguments and validated by the underlying Pydantic config model.
DefaultAgent
Constructor
model and env are required positional arguments. All remaining keyword arguments are forwarded to config_class for validation. You can supply a custom config class (a AgentConfig subclass) via config_class if you need extra fields.
AgentConfig fields
AgentConfig is a Pydantic BaseModel. All fields may be set via keyword arguments to the constructor or through a YAML config file.
Jinja2 template string for the system message — the very first message in
the conversation. Template variables are populated via
get_template_vars(),
which merges config, environment, model, and runtime state (step count, cost,
elapsed time).Jinja2 template string for the first user message, which presents the task to
the model. The
task variable is available here (passed to run()).Maximum number of model calls the agent is allowed to make.
0 means no
limit. When the limit is reached the agent raises LimitsExceeded and exits
with exit_status: "LimitsExceeded".Stop the agent after its accumulated API cost exceeds this value (in USD).
Checked before every model call. Set to
0 to disable.Stop the agent after this many seconds of wall-clock time.
0 means no
limit. When exceeded the agent raises TimeExceeded and exits with
exit_status: "TimeExceeded".If set, the full trajectory (messages, config, cost stats) is written to this
path as JSON after every step. Parent directories are created automatically.
Public methods
| Method | Signature | Description |
|---|---|---|
run | run(task: str = "", **kwargs) -> dict | Initialise messages, then call step() in a loop until the last message has role == "exit". Returns the extra dict of that final message. |
step | step() -> list[dict] | Single agent step: calls query() then execute_actions(). Returns the list of new observation messages. |
query | query() -> dict | Check limits, call model.query(), accumulate cost. Returns the model’s message dict. |
execute_actions | execute_actions(message: dict) -> list[dict] | Run every action in message["extra"]["actions"] through the environment, format observations, and append them to self.messages. |
serialize | serialize(*extra_dicts) -> dict | Return a JSON-serialisable dict with messages, config, cost stats, and trajectory format version. Additional dicts are recursively merged in. |
save | save(path: Path | None, *extra_dicts) -> dict | Serialise and, if path is given, write to disk. Returns the serialised data. |
Return value of run()
run() returns the extra dict attached to the final exit message. It always contains at least:
Example usage
InteractiveAgent
InteractiveAgent is a direct subclass of DefaultAgent. It overrides add_messages, query, step, and execute_actions to print agent output to the terminal, optionally prompt the user before executing commands, and handle keyboard interruptions gracefully.
InteractiveAgentConfig fields
InteractiveAgentConfig extends AgentConfig with the following additional fields:
Controls how the agent handles action execution:
"confirm"— prompt the user before running any LM-issued command that is not on the whitelist."yolo"— run all LM-issued commands immediately without confirmation."human"— the user types commands directly; the LM does not issue its own commands until the mode is switched.
/c, /y, /u slash commands
in the terminal prompt.List of regular expression strings. Commands that match any pattern are
executed without prompting, even in
"confirm" mode.When
true, the agent asks the user for confirmation before submitting and
exiting. The user can type a follow-up task to continue the session instead
of quitting.Slash commands (runtime)
While the agent is running, the following slash commands are accepted at any prompt:| Command | Effect |
|---|---|
/y | Switch to yolo mode |
/c | Switch to confirm mode |
/u | Switch to human mode |
/m | Enter a multiline comment |
/h | Print available commands |