Local
Mini run script
Full source code
#!/usr/bin/env python3
"""Run mini-SWE-agent in your local environment. This is the default executable `mini`."""
# Read this first: https://mini-swe-agent.com/latest/usage/mini/ (usage)
import os
from pathlib import Path
from typing import Any
import typer
from rich.console import Console
from minisweagent import global_config_dir
from minisweagent.agents import get_agent
from minisweagent.agents.utils.prompt_user import _multiline_prompt
from minisweagent.config import builtin_config_dir, get_config_from_spec
from minisweagent.environments import get_environment
from minisweagent.models import get_model
from minisweagent.run.utilities.config import configure_if_first_time
from minisweagent.utils.serialize import UNSET, recursive_merge
DEFAULT_CONFIG_FILE = Path(os.getenv("MSWEA_MINI_CONFIG_PATH", builtin_config_dir / "mini.yaml"))
DEFAULT_OUTPUT_FILE = global_config_dir / "last_mini_run.traj.json"
_HELP_TEXT = """Run mini-SWE-agent in your local environment.
[not dim]
More information about the usage: [bold green]https://mini-swe-agent.com/latest/usage/mini/[/bold green]
[/not dim]
"""
_CONFIG_SPEC_HELP_TEXT = """Path to config files, filenames, or key-value pairs.
[bold red]IMPORTANT:[/bold red] [red]If you set this option, the default config file will not be used.[/red]
So you need to explicitly set it e.g., with [bold green]-c mini.yaml <other options>[/bold green]
Multiple configs will be recursively merged.
Examples:
[bold red]-c model.model_kwargs.temperature=0[/bold red] [red]You forgot to add the default config file! See above.[/red]
[bold green]-c mini.yaml -c model.model_kwargs.temperature=0.5[/bold green]
[bold green]-c swebench.yaml agent.mode=yolo[/bold green]
"""
console = Console(highlight=False)
app = typer.Typer(rich_markup_mode="rich")
# fmt: off
@app.command(help=_HELP_TEXT)
def main(
model_name: str | None = typer.Option(None, "-m", "--model", help="Model to use",),
model_class: str | None = typer.Option(None, "--model-class", help="Model class to use (e.g., 'litellm' or 'minisweagent.models.litellm_model.LitellmModel')", rich_help_panel="Advanced"),
agent_class: str | None = typer.Option(None, "--agent-class", help="Agent class to use (e.g., 'interactive' or 'minisweagent.agents.interactive.InteractiveAgent')", rich_help_panel="Advanced"),
environment_class: str | None = typer.Option(None, "--environment-class", help="Environment class to use (e.g., 'local' or 'minisweagent.environments.local.LocalEnvironment')", rich_help_panel="Advanced"),
task: str | None = typer.Option(None, "-t", "--task", help="Task/problem statement", show_default=False),
yolo: bool = typer.Option(False, "-y", "--yolo", help="Run without confirmation"),
cost_limit: float | None = typer.Option(None, "-l", "--cost-limit", help="Cost limit. Set to 0 to disable."),
config_spec: list[str] = typer.Option([str(DEFAULT_CONFIG_FILE)], "-c", "--config", help=_CONFIG_SPEC_HELP_TEXT),
output: Path | None = typer.Option(DEFAULT_OUTPUT_FILE, "-o", "--output", help="Output trajectory file"),
exit_immediately: bool = typer.Option(False, "--exit-immediately", help="Exit immediately when the agent wants to finish instead of prompting.", rich_help_panel="Advanced"),
) -> Any:
# fmt: on
configure_if_first_time()
# Build the config from the command line arguments
console.print(f"Building agent config from specs: [bold green]{config_spec}[/bold green]")
configs = [get_config_from_spec(spec) for spec in config_spec]
configs.append({
"run": {
"task": task or UNSET,
},
"agent": {
"agent_class": agent_class or UNSET,
"mode": "yolo" if yolo else UNSET,
"cost_limit": cost_limit or UNSET,
"confirm_exit": False if exit_immediately else UNSET,
"output_path": output or UNSET,
},
"model": {
"model_class": model_class or UNSET,
"model_name": model_name or UNSET,
},
"environment": {
"environment_class": environment_class or UNSET,
},
})
config = recursive_merge(*configs)
if (run_task := config.get("run", {}).get("task", UNSET)) is UNSET:
console.print("[bold yellow]What do you want to do?")
run_task = _multiline_prompt()
console.print("[bold green]Got that, thanks![/bold green]")
model = get_model(config=config.get("model", {}))
env = get_environment(config.get("environment", {}), default_type="local")
agent = get_agent(model, env, config.get("agent", {}), default_type="interactive")
agent.run(run_task)
if (output_path := config.get("agent", {}).get("output_path")):
console.print(f"Saved trajectory to [bold green]'{output_path}'[/bold green]")
return agent
if __name__ == "__main__":
app()
minisweagent.run.mini
Run mini-SWE-agent in your local environment. This is the default executable mini.
DEFAULT_CONFIG_FILE
module-attribute
DEFAULT_CONFIG_FILE = Path(
getenv(
"MSWEA_MINI_CONFIG_PATH",
builtin_config_dir / "mini.yaml",
)
)
DEFAULT_OUTPUT_FILE
module-attribute
DEFAULT_OUTPUT_FILE = (
global_config_dir / "last_mini_run.traj.json"
)
console
module-attribute
console = Console(highlight=False)
app
module-attribute
app = Typer(rich_markup_mode='rich')
main
main(
model_name: str | None = Option(
None, "-m", "--model", help="Model to use"
),
model_class: str | None = Option(
None,
"--model-class",
help="Model class to use (e.g., 'litellm' or 'minisweagent.models.litellm_model.LitellmModel')",
rich_help_panel="Advanced",
),
agent_class: str | None = Option(
None,
"--agent-class",
help="Agent class to use (e.g., 'interactive' or 'minisweagent.agents.interactive.InteractiveAgent')",
rich_help_panel="Advanced",
),
environment_class: str | None = Option(
None,
"--environment-class",
help="Environment class to use (e.g., 'local' or 'minisweagent.environments.local.LocalEnvironment')",
rich_help_panel="Advanced",
),
task: str | None = Option(
None,
"-t",
"--task",
help="Task/problem statement",
show_default=False,
),
yolo: bool = Option(
False,
"-y",
"--yolo",
help="Run without confirmation",
),
cost_limit: float | None = Option(
None,
"-l",
"--cost-limit",
help="Cost limit. Set to 0 to disable.",
),
config_spec: list[str] = Option(
[str(DEFAULT_CONFIG_FILE)],
"-c",
"--config",
help=_CONFIG_SPEC_HELP_TEXT,
),
output: Path | None = Option(
DEFAULT_OUTPUT_FILE,
"-o",
"--output",
help="Output trajectory file",
),
exit_immediately: bool = Option(
False,
"--exit-immediately",
help="Exit immediately when the agent wants to finish instead of prompting.",
rich_help_panel="Advanced",
),
) -> Any
Source code in src/minisweagent/run/mini.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |