feat(coding-agent): add llama.cpp router integration

This commit is contained in:
Mario Zechner
2026-07-17 16:24:21 +02:00
parent 5124c61b25
commit f1a466b19d
17 changed files with 1347 additions and 9 deletions
+1
View File
@@ -41,6 +41,7 @@ For the full first-run flow, see [Quickstart](quickstart.md).
- [Quickstart](quickstart.md) - install, authenticate, and run a first session.
- [Using Pi](usage.md) - interactive mode, slash commands, context files, and CLI reference.
- [Providers](providers.md) - subscription and API-key setup for built-in providers.
- [llama.cpp](llama-cpp.md) - run a local router and manage models with `/llama`.
- [Security](security.md) - project trust, sandbox boundaries, and vulnerability reporting.
- [Containerization](containerization.md) - sandbox pi with Gondolin, Docker, or OpenShell.
- [Settings](settings.md) - global and project settings.
+97
View File
@@ -0,0 +1,97 @@
# llama.cpp
Pi supports the [llama.cpp](https://github.com/ggml-org/llama.cpp) router server. The router discovers multiple GGUF models and loads or unloads them on demand.
Use a current llama.cpp build with router support. Follow the [build instructions](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md) or install a [prebuilt release](https://github.com/ggml-org/llama.cpp/releases) for your platform.
## Start the router
Start `llama-server` without `--model` or `-m`. Passing a model starts single-model mode instead of router mode.
```bash
llama-server \
--models-dir ~/models \
--no-models-autoload \
--jinja \
--host 127.0.0.1 \
--port 8080 \
-ngl 999 \
-c 32768
```
Important options:
- `--models-dir ~/models` discovers local GGUF files.
- `--no-models-autoload` keeps loading explicit through `/llama`.
- `--jinja` enables compatible chat templates and tool calling.
- `-ngl 999` offloads as many layers as possible to the GPU.
- `-c 32768` sets the context window for each loaded model. Omit it to use the model's native context, which may require substantially more memory.
A single-file model can sit directly in the model directory. Put multimodal and multi-shard models in separate subdirectories:
```text
~/models/
├── llama-3.2-1b-Q4_K_M.gguf
├── gemma-3-4b-it-Q4_K_M/
│ ├── gemma-3-4b-it-Q4_K_M.gguf
│ └── mmproj-F16.gguf
└── large-model-Q4_K_M/
├── large-model-Q4_K_M-00001-of-00003.gguf
├── large-model-Q4_K_M-00002-of-00003.gguf
└── large-model-Q4_K_M-00003-of-00003.gguf
```
Restart the router after manually adding files. For per-model context sizes and other options, use [llama.cpp model presets](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md#model-presets).
## Configure Pi
Start Pi and configure the provider:
```text
/login llama.cpp
```
Enter the router URL and optional API key. The default URL is `http://127.0.0.1:8080`.
Environment variables can configure the same values without `/login`:
```bash
export LLAMA_BASE_URL=http://127.0.0.1:8080
export LLAMA_API_KEY=optional-secret
pi
```
If the server uses an API key, start `llama-server` with the matching `--api-key` value. Keep `--host 127.0.0.1` for local-only access.
## Manage models
Run:
```text
/llama
```
- Select an unloaded model to load it.
- Select a loaded model to unload it.
- Select **Download model…** and enter `owner/repository[:quant]` to download from Hugging Face.
- Press Escape during a load or download to confirm cancellation.
If other models are loaded, Pi asks whether to unload them first or keep them loaded. Pi does not silently unload models and never deletes model files. The router may be shared with other clients, so `/llama` always displays the router's current state.
Only loaded models appear in `/model`. After loading a model, run `/model` to select it for the current Pi session.
If the router disconnects, `/llama` shows **Retry** and **Close**. Retry reconnects and refreshes model state without replaying the interrupted operation.
## Troubleshooting
Check that the router is reachable:
```bash
curl http://127.0.0.1:8080/health
curl http://127.0.0.1:8080/models
```
- **No models in `/llama`:** Check `--models-dir`, the directory layout, and restart the router.
- **Model missing from `/model`:** Load it with `/llama` first.
- **Load fails or uses too much memory:** Lower `-c` or unload another model.
- **Server is not in router mode:** Start it without `--model`, `-m`, or `-hf`.
+7
View File
@@ -8,6 +8,7 @@ Pi supports subscription-based providers via OAuth and API key providers via env
- [API Keys](#api-keys)
- [Auth File](#auth-file)
- [Cloud Providers](#cloud-providers)
- [llama.cpp](#llamacpp)
- [Custom Providers](#custom-providers)
- [Resolution Order](#resolution-order)
@@ -274,6 +275,12 @@ export GOOGLE_CLOUD_LOCATION=us-central1
Or set `GOOGLE_APPLICATION_CREDENTIALS` to a service account key file.
## llama.cpp
Pi supports the llama.cpp router server. Configure it with `/login llama.cpp`, manage loaded models with `/llama`, and select a loaded model with `/model`.
See [llama.cpp](llama-cpp.md) for server setup, model directory layout, environment variables, and command usage.
## Custom Providers
**Via models.json:** Add Ollama, LM Studio, vLLM, or any provider that speaks a supported API (OpenAI Completions, OpenAI Responses, Anthropic Messages, Google Generative AI). See [models.md](models.md).
+1
View File
@@ -37,6 +37,7 @@ Type `/` in the editor to open command completion. Extensions can register custo
| Command | Description |
|---------|-------------|
| `/login`, `/logout` | Manage OAuth or API-key credentials |
| [`/llama`](llama-cpp.md) | Download, load, and unload llama.cpp router models |
| `/model` | Switch models |
| `/scoped-models` | Enable/disable models for Ctrl+P cycling |
| `/settings` | Thinking level, theme, message delivery, transport |