Skip to content
lunkerchenPublic
forked from OnlyTerp/toolrush

About

Kill the tool-call tax: harness tool latency back below model TPS. Fast local lanes, persistent pools, session caches. Scratch lab turned real.

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

ToolRush — 終結工具呼叫稅

shipped and live v2.1.2 macOS / Linux / Windows Tests Passing

現代 AI Agent 模型串流輸出 Token 的速度,往往比宿主環境讀取一個檔案還要快。效能瓶頸早已不再是每秒生成多少 Token(TPS),而是工具呼叫稅(Tool-Call Tax):每一次呼叫 read_file、search_files 與 terminal,背後都在為原本只要幾微秒的操作承受反覆開關行程(Process Spawn)、Shell 往返跳轉、包裝層序列化與重複分發的沈重負擔。

ToolRush 徹底終結這項代價。 它是專為 Hermes Agent 打造的低開銷執行層:完全保留原生工具介面、相同的輸出規格與安全防禦邊界,同時提供極低延遲傳輸、真正的程式化批次並行能力,以及跨版本升級相容機制。

實測基準圖表:原生 Shell 與 ToolRush 於正式環境之對比

實測成果(於真實安裝之 Hermes 環境測量 — 無 Mock、無假數據)

1. macOS 實測數據(Apple Silicon M 系列 · Hermes Agent v0.21.0)

執行面向 原生 Hermes (Cold Spawn) ToolRush v2 (Warm Shell) 提速幅度
Terminal 呼叫延遲 (中位數) 45.57 ms 7.96 ms 5.72x (降低 82.5% 開銷)
底層 Raw Bash 執行 3.08 ms 1.07 ms 2.88x 提速
批次多目標搜尋 (search_files 4 目標) 230.50 ms 28.92 ms 7.97x (節省 87.5% 耗時)
行程管理與清理 頂層 PID 終止(易殘留孤兒) POSIX Process Group 連鎖回收 (killpg) 健全回收中斷與逾時子程序

2. Windows 實測數據(原作者基準)

執行面向 改造前 改造後 提速幅度
原生檔案讀取 255.23 ms 4.44 ms 57.5x
常駐暖 Shell (Persistent Bash) 285 ms 12.1 ms 23.6x
搜尋傳輸 (直連 rg) 183–455 ms 27–97 ms 4.7–6.8x
批次並行 RPC 108 ms (循序) 53 ms (批次) 2.1x (重疊度 3.3x)

以上皆為「工具實際執行耗時(Wall Time)」,並非包含模型思考的完整回合時間。這反映最真實的情況:在密集調用工具的回合能感受到極大提速,純對話回合則維持原狀。完整數據、p95 分布與測試方法請參閱 v2/README.md。


系統架構

五大核心面向:原生讀取、直連 rg、常駐暖 Shell、批次並行 RPC、更新存活

  1. 單一搜尋核心,極速傳輸:不以粗糙邏輯重寫搜尋。直連 rg 二進制檔,完整保留 .gitignore 規則、正則語法、Context 旗標與設定檔;原生檔案讀取完全復用 upstream 的邊界限制、安全守衛、二進制/文件路由與輸出組合器。
  2. 正確性先於速度:修復搜尋結果結尾損壞 JSON 的問題;分頁具備穩定排序與「更多結果」標記;正則反斜線與前置連字號維持字面量解析;統一處理換行(CRLF)與末行無換行的情況。
  3. 真正的程式化並行(目前僅 Windows):在 execute_code 中提供 from hermes_tools import parallel。單次 RPC 可並行分發 1–16 個唯讀操作至最多 4 個工作執行緒,嚴格維持輸入順序,並完整保持鑑權、白名單與呼叫配額限制。寫入與終端指令一律拒絕並行。
  4. 健全的串流常駐暖 Shell(Warm-Shell):維護單一持久化 bash,透過 OS pipe 串流傳輸,具備有限記憶體解析、原子快照提交、精確保留 Exit Code/CWD/環境變數。在 macOS/POSIX 上透過 os.setsid 與 os.killpg 乾淨終止取消與逾時的指令樹;在 Windows 上維持專屬行程管理。
  5. 強化調度准入防禦:靜態檢查拒絕隱式寫入(wget、curl -o、sed w、分支建立、環境包裝腳本、共用 CWD 異動)。准入不等於授權:被拒絕加速的操作依然會以安全標準循序流程執行。
  6. 更新存活機制:外掛於記憶體中動態掛載相容 patch,不修改 upstream 源碼。遇到未知變動時主動降級發出警告,絕不覆蓋新版官方程式碼。
  7. 完整診斷與回滾機制:提供 doctor.py --smoke、各面向獨立開關(TOOLRUSH_*=0)、主開關 toolrush.enabled: false,以及完整可重現的基準測試腳本。

一鍵安裝方式(推薦使用正式 Idempotent Installer)

macOS / Linux

先下載、檢查內容,確認無誤後再執行。請勿將 curl 直接管道給 bash。

# 將 TAG 換成你要安裝的釋出標籤(勿使用 main,以免安裝到未經審查的變更)
TAG=v2.1.2
curl -fsSL -o /tmp/toolrush-install.sh \
  "https://raw.githubusercontent.com/lunkerchen/toolrush/${TAG}/scripts/install.sh"

# 檢查校驗值與腳本內容
shasum -a 256 /tmp/toolrush-install.sh
less /tmp/toolrush-install.sh

# 確認無誤後才執行
bash /tmp/toolrush-install.sh
rm -f /tmp/toolrush-install.sh

或直接 clone 指定標籤後執行(同樣建議先檢視腳本):

git clone --depth=1 --branch v2.1.2 https://github.com/lunkerchen/toolrush.git /tmp/toolrush
less /tmp/toolrush/scripts/install.sh   # 先檢視
bash /tmp/toolrush/scripts/install.sh
rm -rf /tmp/toolrush

Windows (PowerShell)

同樣先下載並檢視,不要使用 irm ... | iex。

$Tag = 'v2.1.2'
Invoke-WebRequest -UseBasicParsing `
  -Uri "https://raw.githubusercontent.com/lunkerchen/toolrush/$Tag/scripts/install.ps1" `
  -OutFile "$env:TEMP\toolrush-install.ps1"

Get-FileHash "$env:TEMP\toolrush-install.ps1" -Algorithm SHA256
Get-Content "$env:TEMP\toolrush-install.ps1"   # 確認內容

powershell -ExecutionPolicy Bypass -File "$env:TEMP\toolrush-install.ps1"
Remove-Item "$env:TEMP\toolrush-install.ps1"

驗證安裝

# 用 Hermes 自己的 venv Python 執行,結果才具代表性
~/.hermes/hermes-agent/venv/bin/python ~/.hermes/plugins/toolrush/doctor.py --smoke

停用 / 移除

在 ~/.hermes/config.yaml 中將 toolrush 停用或執行:

hermes plugins disable toolrush

若需完全移除:

rm -rf ~/.hermes/plugins/toolrush

驗收與證據

Canonical tests passing 5 negative controls live activation verified

  • 通過 206 個歷史基準驗證案例(歷史記錄存檔於 v2/evidence/),當前版本正式回歸測試套件(tests/)全數通過。
  • 5 組對照反向測試(Negative Controls):當加速修復被還原時皆如預期觸發失敗,杜絕虛假通過。
  • 實機端到端驗證:已於實際運行的 execute_code 核心中成功驗證 parallel RPC,重啟後設定與憑證經 SHA-256 驗證位元組完全一致。
  • 完整合約判決、XML 證據與原始基準測試數據見 v2/evidence/。

專案結構

路徑 內容說明
v2/plugin/ 正式交付實作 — 完整報告、設計文件、MANIFEST (sha256)、外掛本體、安裝源碼快照、測試證據
scripts/ 正式安裝與驗證腳本:install.sh (macOS/POSIX) 與 install.ps1 (Windows)
tests/ 正式回歸測試套件:單元、整合、准入硬化與相容性測試
docs/ 技術文件:compatibility.md 相容性矩陣與架構資產
benchmarks/ 效能評測腳本 (scripts/) 與原始數據 (results/) 歸檔
legacy/ v1 實驗性原型與歷史驗證合約文件存檔
v2/evidence/ 歷史驗證數據與 XML 存證(Historical Validation Records)

核心守則

  • 先立合約再寫程式:無對照測試即視為未完成。
  • 實驗室絕不直改正式環境程式碼:先於原型驗證,再透過開關與外掛安全整合。
  • 與官方標準路徑維持位元組級結果一致:輸出格式不符即不予發布。
  • 全線安全預設(Fail-Closed):被拒絕加速的操作退回安全循序路徑,絕不報錯中斷。
  • 所有證據留存於儲存庫中:堅持百分之百實測數據。

為 Nous Research 打造之 Hermes Agent 所設計。 macOS / POSIX 支援分支由 Laban Chen 移植並維護(PR #1)。

About

Kill the tool-call tax: harness tool latency back below model TPS. Fast local lanes, persistent pools, session caches. Scratch lab turned real.

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages