Skip to content

Local model: lean prompt on the active-model path too (not just agent)#186

Merged
straff2002 merged 1 commit into
mainfrom
fix/local-model-lean-prompt-sendmessage
Jul 5, 2026
Merged

Local model: lean prompt on the active-model path too (not just agent)#186
straff2002 merged 1 commit into
mainfrom
fix/local-model-lean-prompt-sendmessage

Conversation

@straff2002

Copy link
Copy Markdown
Owner

Follow-up to #184. On-device confirmation of #184 showed the local model still got an 8241-token prompt and hit the new guard (Prompt is too long … 8241 tokens; limit 4096).

Why #184 missed it

#184 gave the on-device model a lean prompt only via sendViaLocalAgent (the fast-tier agent route). But when gemma-4 is the user's active model, turns go through sendMessagesendLocal with the full ~100-tool system prompt (~8k tokens). That path still built the fat prompt. The good news: #184's guard did its job — a clean "switch to a cloud model" error instead of the earlier Jetsam/OOM crash.

Fix

Extract the lean-prompt build into a shared LLMService.leanOnDevicePrompt(...) and use it for both on-device routes so they can't diverge again:

  • sendMessage now branches on isOnDevice (.local / .appleOnDevice) → lean prompt (persona/location/memory only; no ~100-tool dump, no playbook/shortcuts/OpenClaw).
  • sendViaLocalAgent refactored to call the same helper.
  • sendLocal still receives includeTools and appends its own reduced ~12-tool block, so the model keeps usable tools — only the prompt drops the dump.

Gates

build-for-testing ✅ · full suite 1603 / 0 ✅ · Release ✅

⚠️ On-device verification

Confirm the log's tokenIDs.shape now drops well under 4096 for a normal question and the local model returns an answer. The token-count reduction can't be measured headlessly (no MLX in the sim); the guard from #184 remains the backstop if any path still overshoots.

🤖 Generated with Claude Code

#184 gave the on-device agent a lean prompt, but only via sendViaLocalAgent.
When gemma-4 is the ACTIVE model, turns go through sendMessage → sendLocal
with the full ~100-tool system prompt (~8k tokens), so on-device queries
still hit the prompt-too-long guard (8241 tokens > 4096) and failed.

Extract the lean-prompt build into a shared `leanOnDevicePrompt` helper and
use it for BOTH on-device paths (active-model sendMessage and fast-tier
sendViaLocalAgent) so they can't diverge again. On-device (.local and
.appleOnDevice) now always gets persona/location/memory only — no tool dump,
no playbook/shortcuts/OpenClaw. sendLocal still receives includeTools and
appends its own reduced ~12-tool block, so the model keeps usable tools.

Gates: build-for-testing, full suite 1603/0, Release — all green. Needs
on-device confirmation the token count now drops well under 4096 and a
local-model question returns an answer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@straff2002
straff2002 merged commit e29df92 into main Jul 5, 2026
@straff2002
straff2002 deleted the fix/local-model-lean-prompt-sendmessage branch July 13, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant