一个尽量对齐 mini-swe-agent 主使用面的 Rust 版复刻。
它提供了一个完整的本地 CLI agent 工作流:模型调用、bash action 执行、benchmark 批量运行、trajectory 保存与回放,以及本地 / 容器 / ConTree 兼容环境。
flowchart LR
CLI["CLI (`mini` / `bench` / `inspector`)"] --> Config["Config Loader"]
Config --> Agent["Agent Loop"]
Agent --> Model["Model Backend"]
Agent --> Env["Execution Environment"]
Model --> Agent
Env --> Agent
Agent --> Traj["Trajectory Store"]
Traj --> Inspector["TUI Inspector"]
Bench["Benchmark Runner"] --> Agent
mini、bench、bench-single、inspector、config- OpenAI 兼容
/chat/completions和/responses - 单一
bashtool 调用与 text-based bash code block 回退 human/confirm/yolo模式- 本地、Docker、Singularity、Bubblewrap、ConTree 兼容环境
- trajectory 持久化、TUI inspector、benchmark 输出和状态汇总
- 本地 JSON/JSONL、远程 JSON/JSONL、Hugging Face dataset repo
先准备 API Key:
export OPENAI_API_KEY=your_key运行一个最小任务:
cargo run -- mini -m gpt-4.1-mini -t "Inspect the repository and finish immediately"默认输出 trajectory:
~/.config/rust-mini-swe-agent/last_run.traj.json
直接运行:
cargo run -- mini -m gpt-4.1-mini -t "Create a hello world file and finish the task"或者从 stdin 读任务:
printf 'Inspect the repository and then finish immediately' | cargo run -- mini -m gpt-4.1-mini输出的 trajectory 默认保存在:
~/.config/rust-mini-swe-agent/last_run.traj.json
支持通过 -c config.yaml 载入配置,配置结构示例:
agent:
system_template: "You are a helpful assistant that can interact with a computer."
instance_template: "Please solve this issue: {{task}}"
step_limit: 0
cost_limit: 3.0
output_path: "./run.traj.json"
mode: "confirm"
whitelist_actions: ["^pwd$", "^ls"]
confirm_exit: true
environment:
environment_class: "local"
cwd: "."
timeout_secs: 30
image: null
model:
model_name: "gpt-4.1-mini"
base_url: "https://api.openai.com/v1"
api_key_env: "OPENAI_API_KEY"
temperature: 0.2
run:
task: null
env_startup_command: null仓库里也附带了现成示例:
cargo run -- mini -c config.example.yaml -t "Inspect the repository and then finish immediately"如果要跑 contree,可以在配置里这样写:
environment:
environment_class: "contree"
image: "docker://docker.io/swebench/sweb.eval.x86_64.demo:latest"
cwd: "/testbed"
interpreter: ["bash", "-c"]
contree_config:
base_url: "https://your-contree-endpoint"
token: "your-contree-token"仓库里也带了现成模板:
cargo run -- mini -c contree -t "Inspect the repository and finish immediately"也支持和原项目类似的多层配置覆盖:
cargo run -- mini -c mini -c model.temperature=0.0 -t "Inspect the repo"启动时会自动加载全局配置文件:
~/.config/rust-mini-swe-agent/.env
数据集可以来自三类来源:
- 本地
json或jsonl - 远程
http(s)JSON/JSONL - Hugging Face dataset repo id,例如
princeton-nlp/SWE-Bench_Lite
本地记录至少需要:
{"instance_id":"demo-1","problem_statement":"Fix the bug"}批量运行:
cargo run -- bench --dataset ./instances.json --output-dir ./runs -w 4直接读取 Hugging Face 数据集:
cargo run -- bench --dataset princeton-nlp/SWE-Bench_Lite --split dev --output-dir ./runs -w 4单例运行:
cargo run -- bench-single --dataset ./instances.json --instance demo-1cargo run -- inspector ./runs
cargo run -- inspector ./runs --step 2cargo run -- config setup
cargo run -- config show
cargo run -- config set OPENAI_API_KEY sk-xxx已实现:
- 多子命令 CLI
- 交互模式
- 多
-c配置和key=value覆盖 - 自动加载全局
.env - 内置
mini.yaml、default.yaml和contree.yaml - bash tool call 校验
- text-based bash code block 解析回退
openrouter/openrouter_responserequestyportkey/portkey_responselitellm_response风格/responses兼容- 远程
http(s)数据集读取 - Hugging Face dataset repo 读取
MSWEA_SWEBENCH_DATASET_BASE_URL/MSWEA_SWEBENCH_DATASET_DIR数据集解析MSWEA_HF_DATASET_CONFIG自定义 Hugging Face dataset configcost_tracking/multimodal_regex配置字段兼容- 本地和 docker 环境
singularity/bubblewrap/contree环境入口- 更接近原版的 docker 持久容器和 singularity sandbox 生命周期
- 提交哨兵
COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT - trajectory 持久化
- benchmark runner
- TUI trajectory inspector
已知差距:
- 不是逐 provider 的原生 SDK 全量复刻,部分 provider 仍以兼容层方式实现
contree已支持 REST/API 与兼容执行路径,但不是 Pythoncontree_sdk的原生 session 实现- inspector 是
ratatuiTUI,不是 Python Textual UI - 仍有少量环境高级参数和边界行为未与 Python 版逐项对齐