How To Run Hermes Agent Locally with an 8GB GPU Card

Run Hermes Agent completely offline on an 8GB NVIDIA GPU using Docker Compose, llama.cpp CUDA, Q4_K_M quantization, Flash Attention, and KV cache quantization for 8K-32K context.

Running an autonomous AI agent completely offline on an 8GB GPU (such as an NVIDIA RTX 4060 or RTX 3060 Ti) is very doable—provided you manage your VRAM budget carefully. Unlike basic chat, an agent like Hermes Agent sends large system prompts, tool schemas, and multi-turn command outputs on every request. If your context window is too small, the agent forgets its tools; if your KV cache spills into system RAM, inference crawls.

This guide walks through a complete, working Docker Compose stack—llama.cpp (CUDA), Hermes Agent, and Caddy—tuned specifically to fit within an 8GB VRAM envelope while preserving an 8K–32K token context window.

1. Prerequisites

  • Linux host with an 8GB NVIDIA GPU and up-to-date CUDA-capable NVIDIA drivers (verify with nvidia-smi).
  • Docker & Docker Compose v2 (docker compose version).
  • NVIDIA Container Toolkit installed and configured so containers can access the GPU (nvidia-ctk).

2. Model Selection & 8GB VRAM Optimization

On an 8GB card, every megabyte counts. Generic dense 8B models in Q4_K_M (~4.9 GB weights) often hit a practical ceiling of 4K–8K context once you add CUDA runtime overhead (~500 MB) and the KV cache.

To push into a comfortable 8K–32K context window for agentic tool calling, combine three techniques:

  • Use Q4_K_M quantization: FP16 models won’t fit at all, and Q8_0 leaves almost no room for context. Q4_K_M is the sweet spot for quality vs. VRAM.
  • Pick KV-efficient architectures: Models with Hybrid Attention (such as Qwen3.5-9B) or compact MoE architectures have a dramatically smaller KV cache footprint than standard dense transformers, letting you run 16K–32K context inside 8GB VRAM.
  • Enable Flash Attention + KV Cache Quantization: Passing --flash-attn on and --cache-type-k q8_0 --cache-type-v q8_0 to llama-server cuts KV cache memory nearly in half with negligible quality loss.
  • Enable Jinja tool calling: Hermes Agent relies on structured tool calls—pass --jinja so llama.cpp parses the model’s native tool-call template.

3. Docker Compose Stack (llama.cpp + Hermes Agent + Caddy)

Notice that only llama-cpp needs GPU access. hermes is lightweight and talks to llama-cpp over the internal Docker network via its OpenAI-compatible /v1 endpoint.

Create a project directory and save this docker-compose.yml:

services:
  llama-cpp:
    image: ghcr.io/ggml-org/llama.cpp:server-cuda
    container_name: llama-cpp
    volumes:
      - ./models:/models:ro
    ports:
      - "127.0.0.1:8080:8080"
    command: >
      --model /models/model.gguf
      --host 0.0.0.0
      --port 8080
      --n-gpu-layers 99
      --ctx-size 16384
      --flash-attn on
      --cache-type-k q8_0
      --cache-type-v q8_0
      --jinja
    deploy:
      resources:
        limits:
          memory: 8G
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    restart: unless-stopped

  hermes:
    image: nousresearch/hermes-agent:latest
    container_name: hermes
    depends_on:
      - llama-cpp
    environment:
      - LOG_LEVEL=INFO
    volumes:
      - ./hermes_data:/root/.hermes
    deploy:
      resources:
        limits:
          memory: 2G
          pids: 100
    restart: unless-stopped

  caddy:
    image: caddy:latest
    container_name: caddy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - hermes
    restart: unless-stopped

volumes:
  caddy_data:
  caddy_config:

4. Configure Caddy and Hermes Agent

Create ./caddy/Caddyfile to front the Hermes web dashboard or API on your local network (replace hermes.local with your hostname or LAN IP):

hermes.local {
    tls internal
    reverse_proxy hermes:8000
}

Next, configure Hermes Agent to use your local llama-cpp container as a custom OpenAI-compatible provider. Instead of hand-editing config.yaml, use the Hermes CLI inside the container (or before starting it):

# Point Hermes at the local llama.cpp OpenAI-compatible endpoint
docker compose exec hermes hermes config set model.provider custom
docker compose exec hermes hermes config set model.base_url http://llama-cpp:8080/v1
docker compose exec hermes hermes config set model.api_key sk-local
docker compose exec hermes hermes config set model.default model.gguf

5. Download a Model and Launch

Place your Q4_K_M GGUF model in ./models/model.gguf (for example, a Qwen3.5-9B Q4_K_M GGUF), then start the stack:

mkdir -p models caddy hermes_data
# Example: place your chosen Q4_K_M GGUF at ./models/model.gguf
docker compose up -d

6. Verify GPU Offload and Agent Tool Calling

Confirm that all layers are loaded into VRAM, the OpenAI endpoint is responding, and Hermes can complete a local turn:

# 1. Check VRAM usage on the host (should sit around 6.0–7.5 GB under load)
nvidia-smi

# 2. Verify llama-server is serving /v1/models
curl -s http://127.0.0.1:8080/v1/models | jq .

# 3. Run a one-shot Hermes query against the local model
docker compose exec hermes hermes chat -q "Check the current disk usage with df -h and summarize it."

If nvidia-smi shows 100% VRAM saturation or tokens-per-second drops sharply, lower --ctx-size from 16384 to 8192 and restart llama-cpp. With KV quantization enabled and a compact Q4_K_M model, you get fast, private, zero-API-cost agent execution on a single 8GB card.

Leave a Reply