Hermes + Qwen3.6:本地 Agent 的一套低成本部署方案

整理 Hermes Agent + Qwen3.6 GGUF 的本地部署方案:用 WSL2、CUDA、llama.cpp 啟動本地模型服務,再把 Hermes Agent 接到 OpenAI-compatible endpoint。

這篇記錄整理一套本地 Agent 部署方案:用 llama.cpp 在 WSL2 中運行 Qwen3.6 GGUF 模型,再把 Hermes Agent 接到本地 OpenAI-compatible API。這樣可以在自己的電腦上獲得一個可長期在線的本地 AI 助手,不再按在線服務的 Token 額度計費。

這套方案適合想體驗本地 AI Agent、又希望保留資料隱私和長期可控性的使用者。它可以用於日常問答、寫作、程式碼輔助、資料整理和簡單自動化任務。需要注意的是,模型規模越大,對顯存要求越高;原文示例使用的是 Qwen3.6-27B,顯存 24GB 更穩。如果顯存較小,應選擇更小尺寸或更低量化的模型。

方案結構

整體鏈路很簡單:

  1. Windows 上安裝 WSL2 和 Ubuntu 24.04。
  2. 在 WSL2 中安裝 CUDA Toolkit、編譯 llama.cpp
  3. 下載 Qwen3.6 GGUF 模型。
  4. llama-server 啟動本地模型服務。
  5. 安裝 Hermes Agent,並把它配置到 http://localhost:8080/v1
  6. 可選:寫啟動腳本,讓 WSL2 打開時自動啟動模型服務。

Hermes 負責 Agent 能力,Qwen3.6 負責本地大模型能力。兩者組合後,可以把電腦變成一個本地私有 AI 助理。

安裝 WSL2 和 Ubuntu

在 Windows PowerShell 管理員視窗中執行:

1
2
wsl --install
wsl --set-default-version 2

重啟後安裝 Ubuntu 24.04:

1
wsl --install -d Ubuntu-24.04

安裝完成後,Ubuntu 會提示設定使用者名稱和密碼。進入 Ubuntu 後,先檢查 NVIDIA GPU 是否能在 WSL2 中正常識別:

1
nvidia-smi

如果無法識別 GPU,通常需要先更新 Windows 端的 NVIDIA 顯示卡驅動。WSL2 會繼承 Windows 驅動,但 CUDA Toolkit 仍需要在 WSL2 內單獨安裝。

安裝 Python 和基礎工具

1
sudo apt update && sudo apt install -y python3-pip python3-venv

後續還需要編譯工具、Git 和 CMake:

1
sudo apt install -y cmake build-essential git

編譯 llama.cpp

先拉取源碼:

1
2
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp

如果 WSL2 中已經有可用 CUDA 環境,可以直接編譯:

1
2
cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89
cmake --build build -j$(nproc)

CMAKE_CUDA_ARCHITECTURES=89 適合 Ada 架構顯示卡,例如 RTX 40 系列。其他顯示卡應按實際架構調整。

如果編譯時報 CUDA Toolkit 缺失,先在 WSL2 中安裝 CUDA Toolkit:

1
2
3
4
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt install -y cuda-toolkit-12-8

安裝完成後配置環境變數:

1
2
3
4
export PATH=/usr/local/cuda-12.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64:$LD_LIBRARY_PATH
echo 'export PATH=/usr/local/cuda-12.8/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

然後重新編譯:

1
2
3
4
cd ~/llama.cpp
rm -rf build
cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89
cmake --build build -j$(nproc)

下載 Qwen3.6 GGUF 模型

原文示例使用 unsloth/Qwen3.6-27B-GGUF 中的 Qwen3.6-27B-UD-Q4_K_XL.gguf

1
2
3
hf download unsloth/Qwen3.6-27B-GGUF \
Qwen3.6-27B-UD-Q4_K_XL.gguf \
--local-dir ~/models/

這個文件約 17GB。如果 Hugging Face 下載慢,可以換 ModelScope 等國內鏡像。顯存不足時不要硬上 27B,可以換更小模型或更低量化版本。

啟動本地模型服務

根據自己的模型文件名啟動 llama-server

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
~/llama.cpp/build/bin/llama-server \
--model ~/models/Qwen3.6-27B-UD-Q4_K_XL.gguf \
--n-gpu-layers 99 \
--ctx-size 32768 \
--flash-attn on \
--temp 1.0 \
--top-p 0.95 \
--top-k 20 \
--presence-penalty 1.5 \
--port 8080

啟動成功後,在 Windows 瀏覽器訪問:

1
http://localhost:8080

如果要讓 Hermes Agent 或其他 OpenAI-compatible 客戶端調用,API 地址通常是:

1
http://localhost:8080/v1

Thinking 模式取捨

Qwen3.6 預設可能啟用 Thinking 模式。它適合複雜推理、複雜程式碼問題、多步驟分析,但速度會慢一些。

如果想關閉 Thinking 模式,可以停止服務後增加 --chat-template-kwargs 參數:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
~/llama.cpp/build/bin/llama-server \
--model ~/models/Qwen3.6-27B-UD-Q4_K_XL.gguf \
--n-gpu-layers 99 \
--ctx-size 32768 \
--flash-attn on \
--temp 1.0 \
--top-p 0.95 \
--top-k 20 \
--presence-penalty 1.5 \
--chat-template-kwargs '{"enable_thinking":false}' \
--port 8080

關閉 Thinking 後,簡單問答、寫作、程式碼補全和解釋程式碼會更快;但複雜演算法設計、疑難 Debug 和架構分析仍建議開啟 Thinking。

安裝 Hermes Agent

保持 llama-server 運行,再新開一個 WSL2 終端安裝 Hermes Agent:

1
curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash

安裝腳本會處理 Python、Node.js、ripgrep、ffmpeg 等依賴。配置模型端點時選擇自訂 endpoint:

1
2
3
URL: http://localhost:8080/v1
API Key: 12345678
Model: 自動識別

API Key 對本地 llama-server 來說可以隨便填一個佔位值。配置完成後,可以繼續接 Telegram、微信、QQ、Discord 等聊天工具,讓 Hermes Agent 透過這些入口調用本地模型並執行任務。

自動啟動模型服務

可以寫一個啟動腳本,讓 WSL2 終端打開時自動啟動模型服務。

創建腳本:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
cat > ~/start-llm.sh << 'EOF'
#!/bin/bash
echo "Starting Qwen3.6-27B llama-server..."
~/llama.cpp/build/bin/llama-server \
--model ~/models/Qwen3.6-27B-UD-Q4_K_XL.gguf \
--n-gpu-layers 99 \
--ctx-size 65536 \
--flash-attn on \
--temp 1.0 \
--top-p 0.95 \
--top-k 20 \
--presence-penalty 1.5 \
--port 8080 \
--host 0.0.0.0 &
echo "llama-server started, PID: $!"
echo "API: http://localhost:8080/v1"
echo "Chat UI: http://localhost:8080"
EOF
chmod +x ~/start-llm.sh

寫入 .bashrc

1
2
3
4
echo '# Auto-start llama-server' >> ~/.bashrc
echo 'if ! pgrep -f "llama-server" > /dev/null 2>&1; then' >> ~/.bashrc
echo '    ~/start-llm.sh' >> ~/.bashrc
echo 'fi' >> ~/.bashrc

這樣每次打開 WSL2 終端時,如果 llama-server 沒有運行,就會自動啟動;如果已經在運行,就會跳過,避免重複啟動。

注意事項

  1. 27B 模型對顯存要求較高,24GB 顯存體驗更穩;顯存較小時應換小模型。
  2. --ctx-size 65536 會顯著增加顯存和記憶體壓力,不穩定時先降到 32768 或更低。
  3. WSL2 中 CUDA Toolkit 和 Windows 顯示卡驅動都要正常,缺一邊都可能導致 CUDA 編譯或運行失敗。
  4. Hermes Agent 接本地服務時,本質上是調用 OpenAI-compatible API,關鍵是 http://localhost:8080/v1 能正常回應。
  5. 如果要從手機或其他設備訪問,需要額外處理 Windows 防火牆、區域網地址和安全隔離,不要把本地模型服務直接暴露到公網。

相關連結

记录并分享
使用 Hugo 建立
主題 StackJimmy 設計