hermes - 💡(How to fix) Fix Feature Request: Named terminal backend pool for per-call container selection

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

terminal:
  backend: docker

  backends:
    default:                                          # 必选,未指定时落到这里
      image: nikolaik/python-nodejs:python3.11-nodejs20
      workdir: /workspace
      # 可选
      extra_mounts: []
      env: {}

    analytics:                                        # 数据分析专用
      image: hermes-sandbox-plus
      workdir: /workspace

    browser:                                          # 浏览器自动化
      image: hermes-chromium
      extra_mounts:
        - ~/.hermes/cache/chromium:/root/.cache/chromium
      env:
        CHROMIUM_FLAGS: "--no-sandbox --disable-gpu"

  # 保留以兼容旧配置
  docker_image: nikolaik/python-nodejs:python3.11-nodejs20

---

terminal(command, timeout, workdir, background, pty,
          backend="default")    # 新增 per-call 后端选择

---

terminal("...", backend="analytics") → backends.analytics.image
terminal("...")                      → backends.default.image
                                     → terminal.docker_image (旧字段兼容)

---

# 轻量查询 — default
terminal("curl -s https://api.github.com/repos/numpy/numpy")

# 数据分析 — analytics(numpy/pandas 已预装,无需 pip install)
terminal("python3 /workspace/analyze.py", backend="analytics")

---

terminal("pip install numpy", image="python:3.11")  # → 容器 A(装好了)
terminal("import numpy", image="python:3.11")        # → 容器 B(空的!numpy 没了)
RAW_BUFFERClick to expand / collapse

问题

当前 terminal.backend: docker 模式下,所有 terminal() 调用共用全局唯一镜像terminal.docker_image)。无法按任务类型选择合适的运行环境。

具体痛点:

  • 数据分析任务需要 numpy/pandas 全家桶 → 镜像臃肿 2-3 GB
  • 一次性轻量脚本(curl / jq)→ 也跑同一个重镜像,浪费启动时间
  • 需要临时用带 Chromium 的容器 → 必须全局切镜像,影响其他 session
  • pip 包在容器重建后丢失 → 重型任务每次冷启动都要重装依赖

方案:命名后端池

terminal() 像 profiles 一样支持多个命名后端,per-call 切换,容器复用。

config.yaml schema

terminal:
  backend: docker

  backends:
    default:                                          # 必选,未指定时落到这里
      image: nikolaik/python-nodejs:python3.11-nodejs20
      workdir: /workspace
      # 可选
      extra_mounts: []
      env: {}

    analytics:                                        # 数据分析专用
      image: hermes-sandbox-plus
      workdir: /workspace

    browser:                                          # 浏览器自动化
      image: hermes-chromium
      extra_mounts:
        - ~/.hermes/cache/chromium:/root/.cache/chromium
      env:
        CHROMIUM_FLAGS: "--no-sandbox --disable-gpu"

  # 保留以兼容旧配置
  docker_image: nikolaik/python-nodejs:python3.11-nodejs20

terminal() 工具签名

terminal(command, timeout, workdir, background, pty,
          backend="default")    # 新增 per-call 后端选择

优先级

terminal("...", backend="analytics") → backends.analytics.image
terminal("...")                      → backends.default.image
                                     → terminal.docker_image (旧字段兼容)

容器生命周期 & 镜像拉取

  • 同名 backend → 同一容器(常驻复用,状态保持)
  • 首次引用 → docker run(镜像不存在则 docker pull,显示 spinner;拉取失败则回退到 default 并告警)
  • 后续引用 → docker exec
  • session 内闲置超过 TTL(可配,默认 30 分钟)→ 自动 stop 回收内存
  • session 结束 → 全部销毁

风险缓解

风险缓解
并发容器占内存max_backends_per_session(可配,默认 5)
冷启动拉镜像慢首次拉取显示进度;fallback 到 default
用户写了不存在的后端名报错 "backend 'xxx' not found. Available: default, analytics" + 回退 default
后端容器启动失败回退到 default 执行,输出中追加 warning

使用示例

# 轻量查询 — default
terminal("curl -s https://api.github.com/repos/numpy/numpy")

# 数据分析 — analytics(numpy/pandas 已预装,无需 pip install)
terminal("python3 /workspace/analyze.py", backend="analytics")

实现规模

主要改动在 tools/terminal_tool.py,容器管理从单容器改为 dict[str, Container]。预计 200-400 行 Python。

兼容性

  • terminal.backend: local / ssh → 不受影响
  • terminal.docker_image → 作为 fallback,完全兼容
  • profiles → 不同 profile 可定义不同的后端池
  • cron jobs → 可扩展为 per-job 指定后端

为什么不直接用 per-call image 参数

terminal("pip install numpy", image="python:3.11")  # → 容器 A(装好了)
terminal("import numpy", image="python:3.11")        # → 容器 B(空的!numpy 没了)

每次换 image 都起新容器。用命名 backend 作为容器锚点,同名 = 同容器 = 状态保持。


来自 Hermes 用户的实际使用反馈,需要在大规模数据和轻量脚本之间频繁切换。

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING