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: aDocumentation 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.
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()
get_model(input_model_name, config) resolves the model name and class with the following precedence:
input_model_nameargument (if provided)model_namekey insideconfigdictMSWEA_MODEL_NAMEenvironment variable- Raises
ValueErrorif none of the above are set
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,
LitellmModelis used as the default.
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
| Shortcut | Class |
|---|---|
litellm | LitellmModel |
litellm_textbased | LitellmTextbasedModel |
litellm_response | LitellmResponseModel |
openrouter | OpenRouterModel |
openrouter_textbased | OpenRouterTextbasedModel |
openrouter_response | OpenRouterResponseModel |
portkey | PortkeyModel |
portkey_response | PortkeyResponseAPIModel |
requesty | RequestyModel |
LitellmModel
The primary model class. Uses LiteLLM to call any supported provider with native tool calling (thebash tool is passed via the tools parameter).
LiteLLM model identifier. Include the provider prefix for unambiguous routing,
e.g.
anthropic/claude-opus-4-5-20250929 or openai/gpt-4o.Additional keyword arguments forwarded verbatim to
litellm.completion().
Use this to pass temperature, max_tokens, reasoning_effort, and
any other provider-specific parameters.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.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.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.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.
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.Regular expression used to extract multimodal content (images, etc.) from
message text. An empty string disables multimodal processing.
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.
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
LitellmTextbasedModel
A text-only variant ofLitellmModel 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.
LitellmModel config fields, plus:
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.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."OpenRouterModel
Calls the OpenRouter chat completions API directly viarequests, bypassing LiteLLM. Uses native tool calling. Reads the API key from the OPENROUTER_API_KEY environment variable.
LitellmModel except litellm_model_registry (not present). Key fields:
OpenRouter model identifier, e.g.
anthropic/claude-opus-4-5.Extra parameters merged into the JSON request body.
Adds Anthropic-compatible cache control markers when set to
"default_end".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".OpenRouterResponseModel
OpenRouter variant targeting the/responses endpoint. Stateless — each request includes the full conversation history. Inherits config from OpenRouterModel.
OpenRouterTextbasedModel
Text-only OpenRouter variant that parses commands with a regex instead of tool calls. Inherits config fromOpenRouterModel, plus action_regex and a custom format_error_template (same fields as LitellmTextbasedModel).
PortkeyModel
Calls any LLM provider through a Portkey gateway using theportkey-ai SDK. Requires pip install portkey-ai. Reads credentials from the PORTKEY_API_KEY (required) and PORTKEY_VIRTUAL_KEY (optional) environment variables.
Model identifier passed to the Portkey API.
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.Extra parameters forwarded to the chat completions request.
Path to a LiteLLM model registry JSON file used for cost calculation.
Override the model name used when calculating cost via LiteLLM. Useful when
the Portkey model name differs from the LiteLLM name.
Adds Anthropic-compatible cache control markers.
Cost tracking behaviour.
PortkeyResponseAPIModel
Portkey variant that targets the Responses API endpoint viaclient.responses.create. Stateless — full history is sent with every request. Requires pip install portkey-ai.
PortkeyModel (without provider and set_cache_control, which are not present in PortkeyResponseAPIModelConfig).
Example
RequestyModel
Calls the Requesty router API directly viarequests. Uses native tool calling. Reads the API key from the REQUESTY_API_KEY environment variable.
Requesty model identifier.
Extra parameters merged into the JSON request body.
Adds Anthropic-compatible cache control markers when set.
Template rendered on action parse failures.
Template for formatting command output returned to the model.
Regex for multimodal content extraction. Empty string disables it.
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
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:
| Variable | Effect |
|---|---|
MSWEA_GLOBAL_COST_LIMIT | Raise RuntimeError when total accumulated cost exceeds this value (USD, float). 0 disables. |
MSWEA_GLOBAL_CALL_LIMIT | Raise RuntimeError when total API call count exceeds this value (int). 0 disables. |