Skip to content

npu: tools that are only offered are dropped, not refused (no proxy needed for the Lemonade page) - #3298

Merged
bong-water-water-bong merged 1 commit into
mainfrom
npu/ignore-tools
Nov 22, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
npu/ignore-tools

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #3287. Owner ask: the NPU route should ignore tools.

Problem. #3193 made the private NPU route and the layer lane refuse any chat carrying tools: their generators cannot install a tool grammar, and a demanded call answered as prose is the silently wrong shape. But the Lemonade web app offers its 19 tools with every chat (tool_choice absent/auto), so every NPU chat from the Lemonade page was a 400 (…private route cannot carry a tool grammar). The appliance has been running a proxy in front of lemond that strips them; it has to be set up again by hand after each install.

Rule. A request that only offers tools (tool_choice absent, "auto" or "none") asks for "a call, or a plain answer". npu_tool_grammar.h already documents that "auto" installs no grammar on the per-op forward either, so a plain answer is a correct reply on every route.

request before now
tools, tool_choice absent / auto / none 400 tools dropped, answered; X-1bit-Tools-Ignored: <n> + a stderr line
tool_choice: "required" / a named function 400 400 (unchanged)
unknown tool_choice string 400 400 (not treated as an offer)
response_format json_schema 400 400 (unchanged, even when offered tools are dropped)

The tools are removed before the template renders (on the ordered copy too), so the prompt does not spend NPU prefill on 19 definitions the route cannot act on. That matches what the proxy did, which was measured working on the AI MAX+ 395 tonight (the 0.6B answered "The capital of France is Paris." with a tool list attached).

Tests. tests/npu_private_route_tools_test.cpp: 9 new cases (offered/auto/none dropped and not refused, required and named kept and refused, unknown string kept, [] untouched, json_schema still refused, the ordered-json copy); all old and new rows pass locally. app/unified.cpp passes g++ -std=c++23 -fsyntax-only. A hardware run on the appliance (Lemonade page chat on the NPU with no proxy) follows once a build carries it.

🤖 Generated with Claude Code

#3193 made the private NPU route and the layer lane refuse any chat that carries tools, because their generators
cannot install a tool grammar and a demanded call answered as prose is the wrong shape. But a request whose
tool_choice is absent, "auto" or "none" only OFFERS tools, and npu_tool_grammar.h already says "auto" installs no
grammar on the per-op forward either: a plain answer is a correct reply to it. The Lemonade web app offers its 19
tools with every chat, so every NPU chat from the Lemonade page was a 400, and the appliance needed a proxy in front
of lemond that stripped them.

npu_drop_offered_tools removes tools/tool_choice/parallel_tool_calls when the call is only offered, before the
refusal and before the template renders (on the ordered copy too), so the prompt does not carry definitions the
route cannot act on. The handler says so: X-1bit-Tools-Ignored: <n> and a stderr line. tool_choice "required", a
named function, an unknown tool_choice string and a json_schema response_format are still refused as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3287 - Partially compliant

Compliant requirements:

  • NPU chat with tools offered. Lemonade's chat page sends its built-in tools with every message, and the NPU route refuses any request that carries tools. When tools are offered but not required, the NPU route should answer and still parse tool calls the model writes.

Non-compliant requirements:

  • Models download into RAM on the live stick.
  • The stick's data partition is not grown on first boot.
  • Boot waits on unrelated USB storage.
  • Stale release-check rows.
  • payload-runpath.
  • xhci-capture.
  • The cut must use the freshly rolled payload.
  • The pre-write probe must be able to stop the write.
  • Keep the shipped image.
  • chat-npu-queue-plain.
  • Qwen3-1.7B on the NPU failed its known-answer gate (4/5) and did not ship.

Requires further human verification:

  • Boot waits on unrelated USB storage.
  • Stale release-check rows.
  • payload-runpath.
  • xhci-capture.
  • The cut must use the freshly rolled payload.
  • The pre-write probe must be able to stop the write.
  • Keep the shipped image.
  • chat-npu-queue-plain.
  • Qwen3-1.7B on the NPU failed its known-answer gate (4/5) and did not ship.
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Tools Dropping Logic

The logic for dropping offered tools in handle_generate may not correctly handle all cases of tool_choice values. Specifically, if tool_choice is a non-string value (e.g., an object), the function npu_drop_offered_tools returns 0, which means it does not drop the tools. This could lead to unexpected behavior if the tool_choice is malformed or not properly handled.

std::size_t tools_ignored = 0;
if (chat) {
    tools_ignored = npu::npu_drop_offered_tools(body);
    if (tools_ignored) {
        res.set_header("X-1bit-Tools-Ignored", std::to_string(tools_ignored));
        std::fprintf(stderr, "1bit unified: %s: ignored %zu offered tool(s) (tool_choice auto/none): this route answers "
                             "without tool calls (engine#3287)\n", e.id.c_str(), tools_ignored);
    }
}
Tool Choice Handling

The npu_drop_offered_tools function assumes that tool_choice is a string when it's not null. If tool_choice is an object or another non-string type, it will return 0 and not drop the tools. This could lead to incorrect behavior if clients send malformed tool_choice values.

if (body.contains("tool_choice") && !body["tool_choice"].is_null()) {
    const auto& c = body["tool_choice"];
    if (!c.is_string()) return 0;  // {"type": "function", ...}: a named call is demanded
    const std::string s = c.template get<std::string>();
    if (s != "auto" && s != "none") return 0;  // "required", or a value this code does not know: left to the refusal
}

@bong-water-water-bong
bong-water-water-bong merged commit b902e15 into main Nov 22, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the npu/ignore-tools branch November 22, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant