mini_swe_agent
diapason.agents.hybrid.mini_swe_agent
¶
MiniSWEAgent — vendored, ~330-line port of mini-SWE-agent v2.
Single-LLM agent loop with a bash tool, run inside a per-task git
clone. The model iterates: read files, grep, run tests, edit, retry —
the environment-interaction loop that turns SWE-bench from "predict the
patch blind" (~0.30) into "actually fix the bug" (~0.77 for frontier
models).
Two ways to use this module:
- Standalone agent — :class:
MiniSWEAgentregistered asmini_swe_agent. Use it directly as the agent for a cell. - As a worker subroutine inside another paradigm — call
:func:
run_swe_agent_loop(task, ...). Returns a dict with the final patch, token totals, cost, etc. This is how Minions / Conductor / Advisors / SkillOrchestra / ToolOrchestra / Archon swap their one-shot worker call for a real agent loop when running SWE-bench.
Differences vs. the upstream (https://github.com/swe-agent/mini-swe-agent):
- No Docker sandbox. We clone the SWE-bench repo into a tempdir and
exec bash there. Network is available (pip etc.). Treat outputs as
untrusted — model can run
rm -rfagainst its own workdir, but the workdir is disposable. Don't run this on a host with secrets in the CWD. - One tool,
bash. No separatesubmit— the loop ends when the model produces a turn with no tool calls. We extract the patch fromgit diffin the workdir at that point. - Trace events captured via the LocalCloudAgent thread-local trace
buffer so every bash invocation + result lands in
experiments/<cell>/logs/<task_id>.json.
MiniSWEAgent
¶
Bases: LocalCloudAgent
Single-model bash-loop agent for SWE-bench-shaped tasks.
Configurable knobs via cfg:
backbone(str, default"cloud"):"cloud"or"local".max_turns(int, default 30): hard cap on tool turns.bash_timeout_s(int, default 120): per-command timeout.output_cap(int, default 10_000): per-command stdout/stderr cap.turn_max_tokens(int, default 4096): max_tokens per LLM turn.
run_swe_agent_loop(task, *, backbone, backbone_model, cloud_endpoint='anthropic', local_endpoint=None, initial_prompt=None, max_turns=30, bash_timeout=120, bash_timeout_s=None, output_cap=10000, turn_max_tokens=4096, trace_prefix='mini_swe', workdir=None, compact_at_tokens=24000, compact_keep_last=4)
¶
Run a mini-SWE-agent loop for one SWE-bench task. Returns:
.. code-block:: python
{
"answer": str, # final framed answer with ```diff fence
"patch": str, # raw unified diff from git diff
"final_summary": str, # the no-tool-call assistant text (may be empty)
"tokens_in": int,
"tokens_out": int,
"tokens_local": int, # bookkeeping split for paradigms
"tokens_cloud": int,
"cost_usd": float,
"turns": int,
"max_turns_hit": bool,
"workdir": str,
}
Captures every bash invocation + LLM turn into the active trace buffer
via :func:_record_event from the LocalCloudAgent base, so callers
don't have to do their own per-call instrumentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Dict[str, Any]
|
SWE-bench-shaped dict with |
required |
backbone
|
str
|
|
required |
backbone_model
|
str
|
model id for the loop's backbone. |
required |
cloud_endpoint / local_endpoint
|
SDK targets. |
required | |
initial_prompt
|
Optional[str]
|
if set, used as the first user message (paradigms embed orchestrator context in here). If None, falls back to the task's problem_statement. |
None
|
workdir
|
Optional[Path]
|
pre-cloned repo path. If None, this function clones the repo into a tempdir and cleans it up at the end. Paradigms that want to chain multiple subloops over the same working tree can manage their own workdir. |
None
|