Repository navigation
feat(llama-cpp): in-process local GGUF text inference provider - #109444
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efb068e718
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| createStreamFn: ({ config, provider }) => | ||
| createLlamaCppStreamFn({ | ||
| providerConfig: config?.models?.providers?.[provider], | ||
| }), |
There was a problem hiding this comment.
Route simple completions through the local stream
This only wires the in-process llama.cpp implementation into embedded agent runs; routes that call completeWithPreparedSimpleCompletionModel (for example tool-title/utility-model flows) go through prepareModelForSimpleCompletion, which skips registerProviderStreamForModel whenever getApiProvider(model.api) already exists. Because the default model keeps api: "openai-completions", those simple-completion calls fall back to the built-in OpenAI-compatible HTTP transport with baseUrl: "local://llama-cpp" instead of node-llama-cpp, so they fail once a llama-cpp model is selected. Add a wrapSimpleCompletionStreamFn/alias path that uses this provider stream for simple completions too.
Useful? React with 👍 / 👎.
| "provider": "llama-cpp", | ||
| "method": "local", | ||
| "choiceId": "llama-cpp", | ||
| "appGuidedDiscovery": true, |
There was a problem hiding this comment.
Expose the download setup path before discovery succeeds
With only appGuidedDiscovery in the manifest, this choice is considered by setup only after detectLlamaCppSetup finds an already-cached GGUF; I checked setup-inference.ts/setup-inference-auth-options.ts, and the manual/auth option lists require appGuidedSecret or appGuidedAuth, while activation rejects custom methods outside the discovery path. That makes runLlamaCppSetup and its consented 2.5 GB download unreachable for fresh users, so onboarding never offers the advertised manual llama.cpp setup unless they predownload/configure the model themselves.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d0d8a8513
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const modelCap = | ||
| typeof model.contextTokens === "number" && model.contextTokens > 0 | ||
| ? Math.floor(model.contextTokens) | ||
| : DEFAULT_LLAMA_CPP_CONTEXT_SIZE; |
There was a problem hiding this comment.
Fall back to contextWindow for custom GGUF models
When a user configures a llama.cpp model with only contextWindow (the documented and required provider/native limit in ModelDefinitionConfig) and omits the optional contextTokens, this code ignores that configured window and always caps the native context at 8192. That makes custom GGUF entries like the docs example unable to request larger contexts, and can also request too large a context for intentionally smaller models; the fallback should use model.contextWindow before DEFAULT_LLAMA_CPP_CONTEXT_SIZE, matching the core runtime's contextTokens ?? contextWindow convention.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…law#109444) * feat(llama-cpp): add in-process text inference * test(llama-cpp): narrow setup provider fixture * fix(llama-cpp): trim public surface and refresh docs map * fix(llama-cpp): import Context type in inference test
…law#109444) * feat(llama-cpp): add in-process text inference * test(llama-cpp): narrow setup provider fixture * fix(llama-cpp): trim public surface and refresh docs map * fix(llama-cpp): import Context type in inference test
What Problem This Solves
OpenClaw has no zero-dependency local inference route: onboarding requires a cloud key, a CLI login, or an already-installed runtime (Ollama/LM Studio). A machine with none of those cannot complete setup at all. The
llama-cppplugin today is embedding-only, despite already owning thenode-llama-cppdependency.Why This Change Was Made
Extends
extensions/llama-cppwith an in-process text-inference provider — the universal local fallback for the local-model onboarding track (related: #109228):src/inference-provider.ts: fully customcreateStreamFnon node-llama-cpp's low-levelLlamaChat.generateResponse— streaming text deltas, native tool calls viaChatModelFunctions(chosen overdefineChatSessionFunction, which executes handlers internally; OpenClaw must own tool execution), token usage from the sequence token meter, abort handling including queued-abort, and a commented process-owned single-slot model/context cache.src/setup.ts+ manifest: read-onlyappGuidedSetup.detect(offers the provider only when a model file is already cached — discovery never downloads), success-gatedprepare, and an interactiverunwith an explicit consent prompt before the ~2.5 GB model download (resumable, viacreateModelDownloader).src/defaults.ts: default modelQwen3-4B-Instruct-2507 Q4_K_M(hf:bartowski/..., verified 2,497,280,736 bytes). Chosen deliberately over Gemma 4 E4B: the E4B GGUF is ~5 GB with ~6 GB resident — OOM territory on the 8 GB machines this fallback targets — while a live bench of the actual system-agent contract shows the 2507 instruct model handles the approval flows correctly (see Evidence). Users can pointparams.modelPathat any GGUF.contextTokens/params.contextSizecaps (local KV allocation cost).User Impact
openclaw onboardgains a "Local model (llama.cpp)" option on every OS with no accounts, no daemons, and one consented download; once a model is cached, guided onboarding auto-detects it. Existing embedding behavior unchanged.Evidence
node scripts/run-vitest.mjs extensions/llama-cpp— 3 files, 29 passed (stream mapping, tools, cache switching, queued aborts, setup discovery/consent/HF branches).createLlamaCppStreamFnwith a downloaded GGUF — resolution, load, streamed deltas, usage accounting (26 in / 7 out), and stop reasons all correct end-to-end.Related: #109228 (local-model onboarding track).