Run Hermes Agent with local Gemma 4 and llama.cpp on macOS
Introduction
Explore the local agent architecture on macOS
Build llama.cpp from source for macOS
Download and benchmark Gemma 4 E4B on macOS
Serve Gemma 4 E4B with a 64K context window
Install and configure Nous Research Hermes Agent
Validate Hermes Agent code fixing on macOS
Next Steps
Run Hermes Agent with local Gemma 4 and llama.cpp on macOS
Local autonomous agent capabilities
Autonomous agents place different demands on local inference than chat sessions. Each user request can result in multiple back-and-forth tool calls. These tools calls include listing directories, reading files, editing code, and running verification commands.
The tool calls might need the following resources:
- Large context windows: Hermes Agent needs at least a 64K context window to hold system prompts, tool schemas, file contents, and multi-step conversation history.
- Fast prompt prefill: Hermes Agent sends an ~11K-token system prompt and tool schema on the first turn of a session. Metal GPU acceleration helps process this large prompt faster.
- Predictable memory usage: An 8-bit quantized key-value (KV) cache keeps the
llama-servermemory footprint compact in macOS Unified Memory Architecture (UMA). This leaves plenty of headroom even on 16 GB and 24 GB Macs.
System architecture
You’ll build local Gemma 4 inference on your Apple silicon Mac and connect Hermes Agent to the llama.cpp server. You’ll then verify that the agent can fix and test a Python script.
The runtime consists of two local processes communicating over loopback HTTP:
+-----------------------------------------------------------------------+
| User Terminal (zsh) |
+-----------------------------------+-----------------------------------+
|
v
+-----------------------------------------------------------------------+
| Nous Research Hermes Agent |
| - Autonomous planning and multi-step tool loop |
| - Built-in tools: shell, filesystem, skills |
+-----------------------------------+-----------------------------------+
|
| OpenAI-compatible HTTP API
| http://127.0.0.1:8080/v1
v
+-----------------------------------------------------------------------+
| llama-server (llama.cpp) |
| - Metal GPU offload (-ngl 99) + Accelerate + Arm KleidiAI (SME) |
| - 64K context (-c 65536), Flash Attention (-fa on), q8_0 KV cache |
+-----------------------------------+-----------------------------------+
|
v
+-----------------------------------------------------------------------+
| Apple Silicon Unified Memory (16 GB+) |
| - Memory-mapped Gemma 4 E4B GGUF weights (~4.3 GB on disk) |
| - 64K quantized KV cache (q8_0) + Metal buffers shared with GPU |
+-----------------------------------------------------------------------+
The CPU and integrated Metal GPU share a unified physical memory space without PCIe copies. Offloading all layers with -ngl 99 lets Metal kernels access model weights directly. Apple Accelerate and Arm KleidiAI kernels handle CPU-side Basic Linear Algebra Subprograms (BLAS) and fallback paths. On M4 and M5 Macs, the kernels use hardware extensions such as Scalable Matrix Extension (SME).
llama-server exposes an OpenAI-compatible /v1 API. This API allows you to switch models or adjust GPU offloading without changing your Hermes Agent workflow.
Memory budget with a 64K context window
To size a local agent for a 64K context window, you need to account for the model weights. You also need to consider the runtime KV cache and Metal buffers. Using 4-bit quantized model weights (Q4_0) together with an 8-bit quantized KV cache (q8_0) and Flash Attention (-fa on) keeps memory usage compact. It also preserves long-context accuracy.
| Component | Gemma 4 E4B | Notes |
|---|---|---|
Model weights (mmap clean memory) | ~2.9–4.3 GB | Memory-mapped from the 4.3 GB GGUF file as layers are accessed |
64K KV cache (q8_0) and Metal buffers | ~1.0 GB | Observed dirty physical footprint (955 MB) after multi-turn tool calls |
| macOS, desktop apps, and Hermes Agent | ~8–10 GB | Varies with open browsers, editors, and active terminal sessions |
| Total estimated unified memory | ~12–15 GB | Fits comfortably on 16 GB or larger Apple silicon Macs |
What you’ve learned and what’s next
You’ve reviewed the local agent architecture and the Apple silicon unified memory data path. You’ve also learned about the 64K context memory budget for running Gemma 4 E4B with llama.cpp on macOS.
Next, you’ll verify your Apple silicon Mac environment and compile llama.cpp from source with Metal and Arm KleidiAI optimizations.