Skip to content

Local

minisweagent.run.mini

Run mini-SWE-agent in your local environment.

[not dim] There are two different user interfaces:

[bold green]mini[/bold green] Simple REPL-style interface [bold green]mini -v[/bold green] Pager-style interface (Textual)

More information about the usage: [bold green]https://mini-swe-agent.com/latest/usage/mini/[/bold green][/not dim]

DEFAULT_CONFIG module-attribute

DEFAULT_CONFIG = Path(
    getenv(
        "MSWEA_MINI_CONFIG_PATH",
        builtin_config_dir / "mini.yaml",
    )
)

console module-attribute

console = Console(highlight=False)

app module-attribute

app = Typer(rich_markup_mode='rich')

prompt_session module-attribute

prompt_session = PromptSession(
    history=FileHistory(
        global_config_dir / "mini_task_history.txt"
    )
)

run_interactive

run_interactive(
    model: Model,
    env: Environment,
    agent_config: dict,
    task: str,
    output: Path | None = None,
) -> Any
Source code in src/minisweagent/run/mini.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def run_interactive(model: Model, env: Environment, agent_config: dict, task: str, output: Path | None = None) -> Any:
    agent = InteractiveAgent(
        model,
        env,
        **agent_config,
    )

    exit_status, result = None, None
    try:
        exit_status, result = agent.run(task)
    finally:
        if output:
            save_traj(agent, output, exit_status=exit_status, result=result)
    return agent

run_textual

run_textual(
    model: Model,
    env: Environment,
    agent_config: dict,
    task: str,
    output: Path | None = None,
) -> Any
Source code in src/minisweagent/run/mini.py
57
58
59
60
61
62
63
64
65
66
67
68
def run_textual(model: Model, env: Environment, agent_config: dict, task: str, output: Path | None = None) -> Any:
    agent_app = AgentApp(
        model,
        env,
        task,
        **agent_config,
    )
    try:
        agent_app.run()
    finally:
        if output:
            save_traj(agent_app.agent, output, exit_status=agent_app.exit_status, result=agent_app.result)

main

main(
    visual: bool = Option(
        False,
        "-v",
        "--visual",
        help="Use visual (pager-style) UI (Textual)",
    ),
    model_name: str | None = Option(
        None, "-m", "--model", help="Model to use"
    ),
    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: Path = Option(
        DEFAULT_CONFIG,
        "-c",
        "--config",
        help="Path to config file",
    ),
    output: Path | None = Option(
        None, "-o", "--output", help="Output file"
    ),
    exit_immediately: bool = Option(
        False,
        "--exit-immediately",
        help="Exit immediately when the agent wants to finish instead of prompting.",
    ),
) -> Any
Source code in src/minisweagent/run/mini.py
 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
106
107
108
109
110
111
112
113
114
115
116
@app.command(help=__doc__)
def main(
    visual: bool = typer.Option(False, "-v", "--visual", help="Use visual (pager-style) UI (Textual)"),
    model_name: str | None = typer.Option(
        None,
        "-m",
        "--model",
        help="Model to use",
    ),
    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: Path = typer.Option(DEFAULT_CONFIG, "-c", "--config", help="Path to config file"),
    output: Path | None = typer.Option(None, "-o", "--output", help="Output file"),
    exit_immediately: bool = typer.Option(
        False, "--exit-immediately", help="Exit immediately when the agent wants to finish instead of prompting."
    ),
) -> Any:
    configure_if_first_time()
    config = yaml.safe_load(get_config_path(config_spec).read_text())

    if not task:
        console.print("[bold yellow]What do you want to do?")
        task = prompt_session.prompt(
            "",
            multiline=True,
            bottom_toolbar=HTML(
                "Submit task: <b fg='yellow' bg='black'>Esc+Enter</b> | "
                "Navigate history: <b fg='yellow' bg='black'>Arrow Up/Down</b> | "
                "Search history: <b fg='yellow' bg='black'>Ctrl+R</b>"
            ),
        )
        console.print("[bold green]Got that, thanks![/bold green]")

    config["agent"]["mode"] = "confirm" if not yolo else "yolo"
    if cost_limit:
        config["agent"]["cost_limit"] = cost_limit
    if not visual and exit_immediately:
        config["agent"]["confirm_exit"] = False
    model = get_model(model_name, config.get("model", {}))
    env = LocalEnvironment(**config.get("env", {}))

    if visual:
        return run_textual(model, env, config["agent"], task, output)  # type: ignore[arg-type]
    else:
        return run_interactive(model, env, config["agent"], task, output)  # type: ignore[arg-type]