Skip to main content

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.

Model classes are responsible for formatting messages, calling the LLM API, parsing tool calls from the response, and reporting cost. Every model follows the same interface: a query(messages) -> dict method that returns a message dict with an "extra" key containing parsed actions, cost, and the raw API response. The recommended entry point is the get_model() helper, which selects the right class and applies sensible defaults (such as automatic cache control for Anthropic models). You can also instantiate any model class directly for full control.

get_model()

from minisweagent.models import get_model

model = get_model("anthropic/claude-opus-4-5")
get_model(input_model_name, config) resolves the model name and class with the following precedence:
  1. input_model_name argument (if provided)
  2. model_name key inside config dict
  3. MSWEA_MODEL_NAME environment variable
  4. Raises ValueError if none of the above are set
The model class is selected via get_model_class(model_name, model_class):
  • If config["model_class"] is set (either a shortcut key such as "litellm_response" or a full dotted import path), that class is used.
  • Otherwise, LitellmModel is used as the default.
After selecting the class, get_model() automatically sets set_cache_control: "default_end" for any model whose name contains anthropic, sonnet, opus, or claude, unless set_cache_control is already present in the config. Model class shortcut keys
ShortcutClass
litellmLitellmModel
litellm_textbasedLitellmTextbasedModel
litellm_responseLitellmResponseModel
openrouterOpenRouterModel
openrouter_textbasedOpenRouterTextbasedModel
openrouter_responseOpenRouterResponseModel
portkeyPortkeyModel
portkey_responsePortkeyResponseAPIModel
requestyRequestyModel

LitellmModel

The primary model class. Uses LiteLLM to call any supported provider with native tool calling (the bash tool is passed via the tools parameter).
from minisweagent.models.litellm_model import LitellmModel
model_name
str
required
LiteLLM model identifier. Include the provider prefix for unambiguous routing, e.g. anthropic/claude-opus-4-5-20250929 or openai/gpt-4o.
model_kwargs
dict
default:"{}"
Additional keyword arguments forwarded verbatim to litellm.completion(). Use this to pass temperature, max_tokens, reasoning_effort, and any other provider-specific parameters.
litellm_model_registry
Path | str | None
default:"None"
Path to a JSON file containing a LiteLLM model registry, used to register custom or local models for cost tracking. Defaults to the LITELLM_MODEL_REGISTRY_PATH environment variable.
set_cache_control
"default_end" | None
default:"None"
When set to "default_end", adds Anthropic-compatible cache_control markers to the last eligible message in each request. Set automatically by get_model() for Anthropic model names.
cost_tracking
"default" | "ignore_errors"
default:"\"default\""
How to handle cost calculation errors. "default" raises a RuntimeError when cost cannot be determined (e.g. an unregistered local model). "ignore_errors" silently sets cost to 0.0. Override globally with the MSWEA_COST_TRACKING environment variable.
format_error_template
str
default:"\"{{ error }}\""
Jinja2 template rendered when the model response cannot be parsed (e.g. no tool call found). The result is fed back to the model as an error message.
observation_template
str
Jinja2 template used to format the output of each executed command before it is returned to the model. Has access to output.output, output.returncode, and output.exception_info.
multimodal_regex
str
default:"\"\""
Regular expression used to extract multimodal content (images, etc.) from message text. An empty string disables multimodal processing.
Example
from minisweagent.models.litellm_model import LitellmModel

model = LitellmModel(
    model_name="anthropic/claude-opus-4-5-20250929",
    model_kwargs={"temperature": 0.0, "max_tokens": 8192},
    cost_tracking="ignore_errors",
)

LitellmResponseModel

Targets the /responses endpoint (OpenAI Responses API) via litellm.responses() instead of litellm.completion(). Useful for models that expose extended thinking or stateless conversation APIs. Inherits all config fields from LitellmModel.
from minisweagent.models.litellm_response_model import LitellmResponseModel
The key behavioural difference from LitellmModel is in message preparation: response objects (messages with "object": "response") are flattened into their output items before each API call, making every request self-contained. Example
from minisweagent.models.litellm_response_model import LitellmResponseModel

model = LitellmResponseModel(
    model_name="openai/o3",
    model_kwargs={"reasoning": {"effort": "high"}},
)

LitellmTextbasedModel

A text-only variant of LitellmModel that does not use tool calling. Instead it parses the bash command from the model’s text output using a regular expression. Suitable for models that do not support tool use.
from minisweagent.models.litellm_textbased_model import LitellmTextbasedModel
Inherits all LitellmModel config fields, plus:
action_regex
str
Regular expression (with re.DOTALL) used to extract exactly one bash command from the model’s text response. The first capture group is treated as the command.
format_error_template
str
Override of the base default. Rendered when the number of matched actions is not exactly one. Default message: "Please always provide EXACTLY ONE action in triple backticks, found {{actions|length}} actions."
Example
from minisweagent.models.litellm_textbased_model import LitellmTextbasedModel

model = LitellmTextbasedModel(
    model_name="ollama/qwen2.5-coder:32b",
    cost_tracking="ignore_errors",
)

OpenRouterModel

Calls the OpenRouter chat completions API directly via requests, bypassing LiteLLM. Uses native tool calling. Reads the API key from the OPENROUTER_API_KEY environment variable.
from minisweagent.models.openrouter_model import OpenRouterModel
Shares all config fields with LitellmModel except litellm_model_registry (not present). Key fields:
model_name
str
required
OpenRouter model identifier, e.g. anthropic/claude-opus-4-5.
model_kwargs
dict
default:"{}"
Extra parameters merged into the JSON request body.
set_cache_control
"default_end" | None
default:"None"
Adds Anthropic-compatible cache control markers when set to "default_end".
cost_tracking
"default" | "ignore_errors"
default:"\"default\""
Cost information is read from response["usage"]["cost"] returned by the OpenRouter API. Free or local models may return 0, which triggers a RuntimeError unless set to "ignore_errors".
Example
from minisweagent.models.openrouter_model import OpenRouterModel

model = OpenRouterModel(model_name="anthropic/claude-opus-4-5")

OpenRouterResponseModel

OpenRouter variant targeting the /responses endpoint. Stateless — each request includes the full conversation history. Inherits config from OpenRouterModel.
from minisweagent.models.openrouter_response_model import OpenRouterResponseModel
Example
from minisweagent.models.openrouter_response_model import OpenRouterResponseModel

model = OpenRouterResponseModel(model_name="openai/o3")

OpenRouterTextbasedModel

Text-only OpenRouter variant that parses commands with a regex instead of tool calls. Inherits config from OpenRouterModel, plus action_regex and a custom format_error_template (same fields as LitellmTextbasedModel).
from minisweagent.models.openrouter_textbased_model import OpenRouterTextbasedModel

PortkeyModel

Calls any LLM provider through a Portkey gateway using the portkey-ai SDK. Requires pip install portkey-ai. Reads credentials from the PORTKEY_API_KEY (required) and PORTKEY_VIRTUAL_KEY (optional) environment variables.
from minisweagent.models.portkey_model import PortkeyModel
model_name
str
required
Model identifier passed to the Portkey API.
provider
str
default:"\"\""
LLM provider name (e.g. "openai", "anthropic", "google"). Required by Portkey when not using a virtual key. Auto-detected from model_name when left empty.
model_kwargs
dict
default:"{}"
Extra parameters forwarded to the chat completions request.
litellm_model_registry
Path | str | None
default:"None"
Path to a LiteLLM model registry JSON file used for cost calculation.
litellm_model_name_override
str
default:"\"\""
Override the model name used when calculating cost via LiteLLM. Useful when the Portkey model name differs from the LiteLLM name.
set_cache_control
"default_end" | None
default:"None"
Adds Anthropic-compatible cache control markers.
cost_tracking
"default" | "ignore_errors"
default:"\"default\""
Cost tracking behaviour.
Example
from minisweagent.models.portkey_model import PortkeyModel

model = PortkeyModel(
    model_name="claude-opus-4-5-20250929",
    provider="anthropic",
)

PortkeyResponseAPIModel

Portkey variant that targets the Responses API endpoint via client.responses.create. Stateless — full history is sent with every request. Requires pip install portkey-ai.
from minisweagent.models.portkey_response_model import PortkeyResponseAPIModel
Config fields are the same as PortkeyModel (without provider and set_cache_control, which are not present in PortkeyResponseAPIModelConfig). Example
from minisweagent.models.portkey_response_model import PortkeyResponseAPIModel

model = PortkeyResponseAPIModel(model_name="gpt-4o", cost_tracking="ignore_errors")

RequestyModel

Calls the Requesty router API directly via requests. Uses native tool calling. Reads the API key from the REQUESTY_API_KEY environment variable.
from minisweagent.models.requesty_model import RequestyModel
model_name
str
required
Requesty model identifier.
model_kwargs
dict
default:"{}"
Extra parameters merged into the JSON request body.
set_cache_control
"default_end" | None
default:"None"
Adds Anthropic-compatible cache control markers when set.
format_error_template
str
default:"\"{{ error }}\""
Template rendered on action parse failures.
observation_template
str
Template for formatting command output returned to the model.
multimodal_regex
str
default:"\"\""
Regex for multimodal content extraction. Empty string disables it.
Note: RequestyModel always requires a non-zero cost value from the API response. There is no cost_tracking field; a missing cost always raises RequestyAPIError. Example
from minisweagent.models.requesty_model import RequestyModel

model = RequestyModel(model_name="anthropic/claude-opus-4-5")

Global model statistics

minisweagent.models maintains a process-level GLOBAL_MODEL_STATS tracker that accumulates cost and call count across all model instances. You can set hard limits via environment variables:
VariableEffect
MSWEA_GLOBAL_COST_LIMITRaise RuntimeError when total accumulated cost exceeds this value (USD, float). 0 disables.
MSWEA_GLOBAL_CALL_LIMITRaise RuntimeError when total API call count exceeds this value (int). 0 disables.
from minisweagent.models import GLOBAL_MODEL_STATS

print(f"Total cost: ${GLOBAL_MODEL_STATS.cost:.4f}")
print(f"Total calls: {GLOBAL_MODEL_STATS.n_calls}")

Build docs developers (and LLMs) love