数据截至 (上游 commit 25941c89cfbc)
第 2 章 · 执行环境与“无 shell 会话”
本章讲清楚:环境层(
environments/local.py、environments/docker.py)如何执行一条命令;为什么“每条命令开新进程、没有持久 shell”是 mini 的一个关键赌注;以及 agent 怎么靠一个哨兵字符串自己宣告完成。
2.1 环境的契约小得惊人
一个环境只需实现三个方法(Environment Protocol,src/minisweagent/__init__.py:61-70):execute(action)、get_template_vars()、serialize()。真正干活的就 execute——输入一个 {"command": ...},输出一个 {"output", "returncode", "exception_info"}。就这么简单。
正因为契约这么小,项目里塞得下七种环境(environments/__init__.py 的 _ENVIRONMENT_MAPPING):local、docker、singularity、swerex_docker、swerex_modal、bubblewrap、contree。