Skip to content

Model-capability guardrails + larger-model prerequisites (anti-fabrication, KV-cache quant, per-model n_ctx, Gemma-12B tool parsing) - #1345

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1332-model-capability-guardrails
Jun 5, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1332-model-capability-guardrails

Conversation

@malibio

@malibio malibio commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Closes #1332

Michael Libio and others added 2 commits June 5, 2026 20:08
Anti-fabrication guard: detect and suppress responses where the model
claims first-person actions ("I created", "successfully updated", etc.)
without any actual tool calls — the 12B@8K fabrication pattern observed
in #1329. Tool-failure surfacing: append a warning note when tools
errored but the model's narrative omits any mention of failure.

KV-cache quantization: add KvCacheQuantType (Q8_0/Q4_0) to ChatConfig
and wire type_k/type_v through to LlamaContextParams in the llama.cpp
context — Q8_0 halves KV memory footprint with negligible quality loss,
unblocking larger models (12B@32K KV cache drops from 10.24GB to ~5GB).

Per-model n_ctx: daemon now reads context_window and default_temperature
from the model catalog (GgufModelManager::model_spec_for) rather than
falling back to ChatConfig::default()'s hardcoded 32_768.

Co-Authored-By: Claude <[email protected]>
…and KV quant wiring

Anti-fabrication guard: replace all_tool_executions.is_empty() with a
dedicated any_real_tool_calls boolean set when tool calls execute. The
old condition prevented the guard from firing in the final iteration of
any multi-iteration turn where a prior iteration made real tool calls —
exactly the scenario where a 12B model is most likely to fabricate.

Tool-failure surfacing: replace the model's response text entirely rather
than appending a warning note. Appending produced contradictory output
("The node was updated successfully. ⚠️ Note: ... encountered an error.")

KV cache quantization: add type_k/type_v to ChatModelSpec and CatalogEntry,
propagate through model_spec_for → daemon ChatConfig construction. Set
Q8_0 on gemma-4-31b-q4km (halves the ~10GB F16 KV cache at 32K context,
making 31B viable on 24GB Apple Silicon). Re-export KvCacheQuantType from
nlp-engine public API.

Skipped: trailing-space sentinel asymmetry in "i set "/"i made " — the
false-negative case (sentence-final phrase with no following character)
is implausible in real model output.
Skipped: recommended_model_spec/model_spec_for deduplication — cleanup
with no behavioral effect.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Review fixes (commit daeeadd)

3 confirmed bugs addressed:

  1. Anti-fabrication guard scope — replaced all_tool_executions.is_empty() with a dedicated any_real_tool_calls boolean. The old condition meant the guard could never fire in any iteration after real tool calls in earlier iterations of the same turn — the exact scenario where 12B models fabricate.

  2. Tool-failure messaging — now replaces the model's response entirely rather than appending ⚠️ Note: to a success claim. Avoids contradictory output like "The node was updated successfully. ⚠️ Note: Update node encountered an error."

  3. KV quant dead code — added type_k/type_v to ChatModelSpec and CatalogEntry, wired through model_spec_for → daemon ChatConfig construction. gemma-4-31b-q4km now gets Q8_0 (~5GB KV cache instead of ~10GB at 32K context). Re-exported KvCacheQuantType from nlp-engine public API.

2 findings skipped:

  • Trailing-space sentinel asymmetry ("i set " vs "i've set") — false-negative only fires on sentence-final phrasing with no following character (e.g. "I set."), which is implausible in real model output.
  • recommended_model_spec/model_spec_for deduplication — cleanup with no behavioral effect.

@malibio
malibio merged commit 418f354 into main Jun 5, 2026
@malibio
malibio deleted the worktree-issue-1332-model-capability-guardrails branch June 5, 2026 18:40
malibio added a commit that referenced this pull request Jun 22, 2026
…ation, KV-cache quant, per-model n_ctx, Gemma-12B tool parsing) (#1345)

* Add model-capability guardrails and larger-model prerequisites (#1332)

Anti-fabrication guard: detect and suppress responses where the model
claims first-person actions ("I created", "successfully updated", etc.)
without any actual tool calls — the 12B@8K fabrication pattern observed
in #1329. Tool-failure surfacing: append a warning note when tools
errored but the model's narrative omits any mention of failure.

KV-cache quantization: add KvCacheQuantType (Q8_0/Q4_0) to ChatConfig
and wire type_k/type_v through to LlamaContextParams in the llama.cpp
context — Q8_0 halves KV memory footprint with negligible quality loss,
unblocking larger models (12B@32K KV cache drops from 10.24GB to ~5GB).

Per-model n_ctx: daemon now reads context_window and default_temperature
from the model catalog (GgufModelManager::model_spec_for) rather than
falling back to ChatConfig::default()'s hardcoded 32_768.

Co-Authored-By: Claude <[email protected]>

* Address review: fix fabrication guard scope, tool-failure messaging, and KV quant wiring

Anti-fabrication guard: replace all_tool_executions.is_empty() with a
dedicated any_real_tool_calls boolean set when tool calls execute. The
old condition prevented the guard from firing in the final iteration of
any multi-iteration turn where a prior iteration made real tool calls —
exactly the scenario where a 12B model is most likely to fabricate.

Tool-failure surfacing: replace the model's response text entirely rather
than appending a warning note. Appending produced contradictory output
("The node was updated successfully. ⚠️ Note: ... encountered an error.")

KV cache quantization: add type_k/type_v to ChatModelSpec and CatalogEntry,
propagate through model_spec_for → daemon ChatConfig construction. Set
Q8_0 on gemma-4-31b-q4km (halves the ~10GB F16 KV cache at 32K context,
making 31B viable on 24GB Apple Silicon). Re-export KvCacheQuantType from
nlp-engine public API.

Skipped: trailing-space sentinel asymmetry in "i set "/"i made " — the
false-negative case (sentence-final phrase with no following character)
is implausible in real model output.
Skipped: recommended_model_spec/model_spec_for deduplication — cleanup
with no behavioral effect.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
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.

Model-capability guardrails + larger-model prerequisites (anti-fabrication, KV-cache quant, per-model n_ctx, Gemma-12B tool parsing)

1 participant