Skip to content

Commit bf94cce

Browse files
committed
refactor(plugins): replace node-llama-cpp with managed llama-server
Move llama.cpp chat and local embeddings onto a verified externally managed llama-server runtime. Remove the in-process native runtime, forked embedding workers, and node-llama-cpp dependency while preserving guided setup, local GGUF models, tool-capable agent runs, diagnostics, and operator docs.
1 parent f73b436 commit bf94cce

85 files changed

Lines changed: 2377 additions & 6957 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/knip.config.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ const config = {
660660
project: ["src/**/*.ts!"],
661661
},
662662
"packages/memory-host-sdk": {
663-
entry: ["src/*.ts!", "src/host/embeddings-worker-child.ts!"],
663+
entry: ["src/*.ts!", "src/host/embeddings.types.ts!"],
664664
project: ["src/**/*.ts!"],
665665
},
666666
"packages/*": {
@@ -827,12 +827,7 @@ const config = {
827827
[`${BUNDLED_PLUGIN_ROOT_DIR}/llama-cpp`]: {
828828
entry: bundledPluginEntries,
829829
project: ["**/*.{js,mjs,ts}!"],
830-
ignoreDependencies: [
831-
// The provider resolves node-llama-cpp from its own package at runtime
832-
// so local embeddings use the plugin-owned native dependency.
833-
"node-llama-cpp",
834-
...bundledPluginIgnoredRuntimeDependencies,
835-
],
830+
ignoreDependencies: bundledPluginIgnoredRuntimeDependencies,
836831
},
837832
[`${BUNDLED_PLUGIN_ROOT_DIR}/lmstudio`]: bundledPluginWorkspace(),
838833
[`${BUNDLED_PLUGIN_ROOT_DIR}/reef`]: {

‎docs/concepts/memory-builtin.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ To set a provider explicitly:
4343

4444
Without an embedding provider, only keyword search is available.
4545

46-
To force local GGUF embeddings, install the official llama.cpp provider
47-
plugin, then point `local.modelPath` at a GGUF file:
46+
To force local GGUF embeddings, install and configure the official llama.cpp
47+
provider, then point `local.modelPath` at a GGUF file:
4848

4949
```bash
5050
openclaw plugins install @openclaw/llama-cpp-provider
@@ -57,7 +57,7 @@ openclaw plugins install @openclaw/llama-cpp-provider
5757
provider: "local",
5858
fallback: "none",
5959
local: {
60-
modelPath: "~/.node-llama-cpp/models/embeddinggemma-300m-qat-Q8_0.gguf",
60+
modelPath: "~/.openclaw/models/llama.cpp/hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf",
6161
},
6262
},
6363
},
@@ -73,7 +73,7 @@ openclaw plugins install @openclaw/llama-cpp-provider
7373
| Gemini | `gemini` | Supports multimodal (image + audio) |
7474
| GitHub Copilot | `github-copilot` | Uses your Copilot subscription |
7575
| LM Studio | `lmstudio` | Local/self-hosted |
76-
| Local | `local` | `@openclaw/llama-cpp-provider` |
76+
| Local | `local` | OpenClaw-managed llama.cpp server |
7777
| Mistral | `mistral` | |
7878
| Ollama | `ollama` | Local/self-hosted |
7979
| OpenAI | `openai` | Default: `text-embedding-3-small` |
@@ -172,7 +172,8 @@ with automatic user modeling.
172172
**Memory search disabled?** Check `openclaw memory status`. If no provider is
173173
detected, set one explicitly or add an API key.
174174

175-
**Local provider not detected?** Confirm the local path exists and run:
175+
**Local provider not detected?** Run interactive llama.cpp setup once, confirm
176+
the local path exists, and run:
176177

177178
```bash
178179
openclaw memory status --deep --agent main

‎docs/concepts/memory-search.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ explicitly:
3030
example `ollama-5080`), as long as that entry sets `api` to `"ollama"` or
3131
another provider id with a memory embedding adapter.
3232

33-
For local embeddings with no API key, install the official llama.cpp provider
34-
plugin and set `provider: "local"`:
33+
For local embeddings with no API key, install and configure the official
34+
llama.cpp provider, then set `provider: "local"`:
3535

3636
```bash
3737
openclaw plugins install @openclaw/llama-cpp-provider
3838
```
3939

40-
Source checkouts still need native build approval: `pnpm approve-builds`, then
41-
`pnpm rebuild node-llama-cpp`.
40+
Choose llama.cpp once in interactive setup. OpenClaw installs a verified
41+
`llama-server`, downloads the embedding GGUF, and writes its managed service
42+
configuration.
4243

4344
Some OpenAI-compatible embedding endpoints require asymmetric `input_type`
4445
labels, such as `"query"` for searches and `"document"`/`"passage"` for indexed
@@ -53,7 +54,7 @@ chunks. Set these with `queryInputType` and `documentInputType`; see
5354
| DeepInfra | `deepinfra` | Yes | Default model `BAAI/bge-m3` |
5455
| Gemini | `gemini` | Yes | Supports image/audio indexing |
5556
| GitHub Copilot | `github-copilot` | No | Uses your Copilot subscription |
56-
| Local | `local` | No | GGUF model, ~0.6 GB auto-download |
57+
| Local | `local` | No | Managed llama.cpp GGUF, ~0.3 GB |
5758
| LM Studio | `lmstudio` | No | Local/self-hosted server |
5859
| Mistral | `mistral` | Yes | |
5960
| Ollama | `ollama` | No | Local/self-hosted server |
@@ -198,8 +199,8 @@ unrelated same-agent sessions still require `"agent"` visibility.
198199
`openclaw memory status --deep`.
199200

200201
**Local embeddings time out?** `ollama`, `lmstudio`, and `local` use longer
201-
provider-owned batch deadlines. Check provider health and rerun
202-
`openclaw memory index --force`.
202+
provider-owned batch deadlines. Run `openclaw memory status --deep` to inspect
203+
the managed server endpoints before rebuilding the index.
203204

204205
**CJK text not found?** Rebuild the FTS index with
205206
`openclaw memory index --force`.

‎docs/gateway/local-model-services.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ Startup is serialized per configured provider and command/argument/env set, so c
2525

2626
If another OpenClaw process already has a healthy server at the same `healthUrl`, this process reuses it without adopting it (each process only manages the child it personally started). Startup and exit logs include bounded, redacted child-output tails plus timing and exit details; configured environment values are never emitted.
2727

28+
## Managed llama.cpp
29+
30+
The official llama.cpp provider generates this shape automatically. Its guided
31+
setup installs a pinned, verified `llama-server`, writes an absolute command and
32+
router preset, selects a free loopback port, and stores the resulting `baseUrl`
33+
and `localService` config. Chat and local embeddings lease the same managed
34+
router through the normal OpenAI-compatible transports.
35+
36+
Do not copy a generated command path between machines. Run llama.cpp setup on
37+
each Gateway host so OpenClaw selects and verifies the matching platform build.
38+
See [llama.cpp Provider](/plugins/llama-cpp).
39+
2840
## Config shape
2941

3042
```json5

‎docs/plugins/llama-cpp.md‎

Lines changed: 105 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,99 @@
11
---
2-
summary: "Run local GGUF text inference and memory embeddings in OpenClaw with llama.cpp"
2+
summary: "Run local GGUF chat and memory embeddings with an OpenClaw-managed llama.cpp server"
33
read_when:
4-
- You want local text inference without an API key or model server
4+
- You want local text inference without an API key or separately managed model server
55
- You want memory search embeddings from a local GGUF model
66
- You are configuring memory.search.provider = "local"
7-
- You need the OpenClaw plugin that owns the node-llama-cpp runtime
7+
- You need to inspect or repair OpenClaw's managed llama.cpp server
88
title: "llama.cpp Provider"
99
sidebarTitle: "llama.cpp Provider"
1010
---
1111

12-
`llama-cpp` is the official external provider plugin for in-process local GGUF
13-
text inference and embeddings. It registers text provider `llama-cpp`,
14-
embedding provider `local`, and owns the `node-llama-cpp` native runtime.
12+
The `llama-cpp` plugin manages a loopback-only `llama-server` for local GGUF
13+
chat and embeddings. OpenClaw installs a pinned, integrity-verified llama.cpp
14+
release, starts it only when a request needs it, reuses it across concurrent
15+
chat and embedding requests, and stops it after an idle period.
1516

16-
Install it before using either local inference or local memory embeddings:
17+
Install the official plugin before using either local inference or local memory
18+
embeddings:
1719

1820
```bash
1921
openclaw plugins install @openclaw/llama-cpp-provider
2022
```
2123

22-
The main `openclaw` npm package does not include `node-llama-cpp`. Keeping the
23-
native dependency in this plugin prevents normal OpenClaw npm updates from
24-
deleting a manually installed runtime inside the OpenClaw package directory.
24+
## Guided setup
2525

26-
## Local text inference
26+
Choose **llama.cpp** once during interactive onboarding or configuration.
27+
OpenClaw then:
2728

28-
Choose **llama.cpp** during interactive onboarding. OpenClaw installs the
29-
official provider plugin, then asks before downloading the default model:
29+
1. Selects the verified llama-server build for the Gateway platform.
30+
2. Verifies the archive SHA-256 and the extracted server version.
31+
3. Downloads and verifies the default chat and embedding models after consent.
32+
4. Writes a durable OpenAI-compatible provider with a loopback `baseUrl` and
33+
`localService` process definition.
34+
5. Live-tests the candidate before saving it.
35+
36+
The default chat model remains:
3037

3138
`hf:unsloth/gemma-4-E4B-it-GGUF/gemma-4-E4B-it-Q4_K_M.gguf`
3239

33-
The Gemma 4 E4B IT Q4_K_M file is about 5.0 GB. OpenClaw offers this default
34-
only on machines with at least 16 GiB of RAM, leaving room for model weights,
35-
context, and Gateway overhead. The default context is automatically sized with
36-
an 8,192-token cap. Configure a larger context only when the machine has enough
37-
memory.
40+
Gemma 4 E4B IT Q4_K_M is about 5.0 GB. OpenClaw offers that download only on
41+
machines with at least 16 GiB of RAM. The default context cap remains 8,192
42+
tokens. The bundled EmbeddingGemma model is about 0.3 GB.
43+
44+
Discovery is read-only. It reports a prepared choice only when the managed
45+
binary, server preset, and selected model already exist; it never installs or
46+
downloads during discovery.
47+
48+
## How requests run
3849

39-
The onboarding discovery check is read-only. It offers llama.cpp automatically
40-
only when the default or configured GGUF file is already in the model cache; it
41-
never downloads during discovery. Ollama and LM Studio remain separate local
42-
service choices and keep their own discovery flows. Manually choosing llama.cpp
43-
is the path that installs the runtime, prompts for the default model download,
44-
and verifies a real model reply before marking setup complete.
50+
The provider uses OpenClaw's normal OpenAI-compatible chat, image, streaming,
51+
and tool transport. `llama-server` applies the GGUF chat template; OpenClaw
52+
executes tool calls and returns their results to the model. The existing
53+
`llamacpp-gbnf` tool-schema compatibility profile remains enabled.
4554

46-
The provider uses the GGUF model's embedded chat template and native
47-
node-llama-cpp function calling. Text streams token by token. Tool calls return
48-
to OpenClaw for execution rather than running inside node-llama-cpp.
55+
One managed router owns separate presets for chat and embeddings. This lets
56+
`memory.search.provider: "local"` use a dedicated embedding GGUF through
57+
`/v1/embeddings` without creating a second OpenClaw process supervisor.
4958

50-
### Use another GGUF model
59+
## Use another GGUF model
5160

52-
Add a model to `models.providers.llama-cpp`. Put a local path or full `hf:` file
53-
URI in `params.modelPath`:
61+
Add the model to `models.providers.llama-cpp.models`, set `params.modelPath`,
62+
make it the selected `llama-cpp/<model-id>`, then run interactive llama.cpp
63+
setup again. `modelPath` accepts:
64+
65+
- an absolute or `~/` local GGUF path;
66+
- a cache-relative GGUF filename;
67+
- a full `hf:` file URI, including `#branch` when needed;
68+
- an HTTPS GGUF URL that publishes a SHA-256 response digest.
69+
70+
Example model entry:
5471

5572
```json5
5673
{
57-
models: {
58-
mode: "merge",
59-
providers: {
60-
"llama-cpp": {
61-
baseUrl: "local://llama-cpp",
62-
api: "openai-completions",
63-
params: {
64-
modelCacheDir: "~/.node-llama-cpp/models",
65-
},
66-
models: [
67-
{
68-
id: "my-local-model",
69-
name: "My local GGUF",
70-
reasoning: false,
71-
input: ["text"],
72-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
73-
contextWindow: 8192,
74-
maxTokens: 2048,
75-
params: {
76-
modelPath: "~/Models/my-model.Q4_K_M.gguf",
77-
contextSize: 8192,
78-
},
79-
compat: { supportsTools: true },
80-
},
81-
],
82-
},
83-
},
84-
},
85-
agents: {
86-
defaults: {
87-
model: { primary: "llama-cpp/my-local-model" },
88-
},
74+
id: "my-local-model",
75+
name: "My local GGUF",
76+
reasoning: false,
77+
input: ["text"],
78+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
79+
contextWindow: 8192,
80+
maxTokens: 2048,
81+
params: {
82+
modelPath: "~/Models/my-model.Q4_K_M.gguf",
83+
contextSize: 8192,
8984
},
85+
compat: { supportsTools: true },
9086
}
9187
```
9288

93-
Inference never downloads a missing model implicitly. For a custom `hf:` URI,
94-
download the GGUF into `modelCacheDir` first. Discovery uses node-llama-cpp's
95-
own read-only cache resolver, including repository, branch, and split-file naming.
89+
The default managed cache is `~/.openclaw/models/llama.cpp`. Existing
90+
`modelCacheDir` settings still win, and setup recognizes the former
91+
`~/.node-llama-cpp/models` default cache so upgrades do not redownload a model
92+
that is already present.
9693

97-
## Memory embedding configuration
94+
## Local memory embeddings
9895

99-
Set `memory.search.provider` to `local`:
96+
Set the memory provider to `local`:
10097

10198
```json5
10299
{
@@ -111,43 +108,57 @@ Set `memory.search.provider` to `local`:
111108
}
112109
```
113110

114-
`local.modelPath` defaults to the `hf:` URI shown above (`embeddinggemma-300m-qat-Q8_0.gguf`).
115-
Point it at a different `hf:` URI or a local `.gguf` file to use another
116-
model. Cache placement and embedding context sizing are managed by the
117-
llama.cpp provider; `memory.search.local` exposes only `modelPath`.
111+
The plugin preserves the historical `local` provider/model cache identity, so
112+
the transport migration does not require a SQLite schema change or automatic
113+
memory reindex. A custom embedding `modelPath` remains its literal index
114+
identity. Run `openclaw memory status --index` if you intentionally change it.
118115

119-
## Native runtime
116+
## Diagnostics
120117

121-
Use Node 24 for the smoothest native install path. Source checkouts using
122-
pnpm may need to approve and rebuild the native dependency:
118+
Run:
123119

124120
```bash
125-
pnpm approve-builds
126-
pnpm rebuild node-llama-cpp
121+
openclaw memory status --deep
122+
openclaw doctor
127123
```
128124

129-
## Memory runtime diagnostics
125+
After the managed embedding server has handled a request, deep status reports
126+
facts observed from `/health`, `/models`, `/props`, and `/metrics`: server build,
127+
model id and path, endpoint state, and configured capabilities. Vision is
128+
reported only when `/props` confirms it. Draft and multimodal projector support
129+
are not currently configured by this plugin and are never inferred from a model
130+
name.
130131

131-
Run `openclaw memory status --deep` after the provider has loaded to inspect
132-
the selected backend and build, device names, GPU offloaded layers, requested
133-
context size, and the last observed VRAM or unified-memory snapshot. The VRAM
134-
values include an observation timestamp because passive status reads do not
135-
reload the model or poll the device.
132+
Local-service startup and exit logs include bounded, redacted stderr tails. See
133+
[Logging](/logging) and [Local model services](/gateway/local-model-services).
136134

137-
The same last-known facts can appear in `openclaw doctor` when the running
138-
Gateway has already used the local provider. A normal status or doctor command
139-
does not load a model just to collect diagnostics.
135+
## Platform requirements
136+
137+
- macOS arm64 uses the official Metal build. macOS x64 uses the CPU build.
138+
- Linux x64 needs glibc 2.34 or newer; Linux arm64 needs glibc 2.38 or newer.
139+
Install the OpenMP runtime (`libgomp1` on Debian/Ubuntu or `libgomp` on
140+
Fedora) if the version probe reports `libgomp.so.1` missing.
141+
- Windows x64 and arm64 use the CPU build and require the Microsoft Visual C++
142+
2015-2022 Redistributable.
143+
- Alpine/musl and platforms without a pinned official build fail with an
144+
actionable manual-server path rather than silently skipping setup.
145+
146+
OpenClaw intentionally does not auto-select CUDA, ROCm, SYCL, OpenVINO, or
147+
Vulkan archives. Those builds add driver and companion-runtime contracts that
148+
cannot be verified safely from onboarding alone.
140149

141150
## Troubleshooting
142151

143-
If `node-llama-cpp` is missing or fails to load, OpenClaw reports the failure
144-
with:
152+
**Binary missing or wrong version:** run interactive llama.cpp setup again. It
153+
reinstalls the pinned build and rewrites the absolute `localService.command`.
154+
155+
**Model missing:** configure a local GGUF path or rerun setup and approve the
156+
verified default download.
145157

146-
1. Install the plugin: `openclaw plugins install @openclaw/llama-cpp-provider`.
147-
2. Use Node 24 for native installs/updates.
148-
3. From a pnpm source checkout: `pnpm approve-builds`, then `pnpm rebuild node-llama-cpp`.
158+
**Server starts but the model fails to load:** inspect `openclaw logs --follow`
159+
and `openclaw memory status --deep`. The managed service error includes the
160+
bounded server stderr tail.
149161

150-
For local inference without an in-process native dependency, use the Ollama or
151-
LM Studio provider instead. For lower-friction local embeddings, set
152-
`memory.search.provider` to a remote embedding provider such as `lmstudio`,
153-
`ollama`, `openai`, or `voyage` instead.
162+
**Only keyword memory matches:** run `openclaw memory status --deep`, repair the
163+
reported endpoint/model issue, then run `openclaw memory index --force` only if
164+
status reports an index identity mismatch.

‎docs/plugins/plugin-inventory.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Each entry lists the package, distribution route, and description.
258258

259259
- **[line](/plugins/reference/line)** (`@openclaw/line`) - npm; ClawHub. OpenClaw LINE channel plugin for LINE Bot API chats.
260260

261-
- **[llama-cpp](/plugins/reference/llama-cpp)** (`@openclaw/llama-cpp-provider`) - npm; ClawHub. Local GGUF text inference and embeddings through node-llama-cpp.
261+
- **[llama-cpp](/plugins/reference/llama-cpp)** (`@openclaw/llama-cpp-provider`) - npm; ClawHub. Managed local llama.cpp server for GGUF chat and embeddings.
262262

263263
- **[lobster](/plugins/reference/lobster)** (`@openclaw/lobster`) - npm; ClawHub. Lobster workflow tool plugin for typed pipelines and resumable approvals.
264264

0 commit comments

Comments
 (0)