#5805 [Engine] serve: read a tool call written without its wrapper inside the reasoning, and unwrap a lone <parameter=arguments>

open · @andreasknopke · 0 Kommentare · Auf GitHub

Server & APIAMD / HIPNVIDIA / CUDAModels & quantsSecurityWindows

Beschreibung

## Problem and result

A model that drifts off the template's call form writes the call without its `<tool_call>` wrapper:

```
<function=exec>
<parameter=arguments>{"path": "...", ...}</parameter>
</function>
```

`tool_call_recovery` already reads that form in the answer, but the reasoning branch of the parser only looked for `<tool_call>`, so the same call written while thinking stayed in `reasoning_content`: no `tool_calls`, `finish_reason: "stop"`, and the agent waited for a tool result that never came (Qwen3.8-Flash-Next UD-IQ3_XXS over `/v1/chat/completions`, opencode; it is the case in #5804). Second, the whole argument object in one `<parameter=arguments>` reached the client as one parameter named `arguments` - `{"arguments": {"path": ...}}` instead of `{"path": ...}` - so even a recognised call carried the wrong arguments, streamed and whole.

After the change the reasoning reads the bare call like the answer does, and the client gets the schema's own arguments.

## Related discussion

Fixes #5804. Next to #4751 and #4071 (calls returned as text), and it extends the reasoning rules of #804/#1058 and the end-of-output rescue of #4427 to the bare form. No scope change: `tool_call_recovery` stays the switch.

## Approach

Where the two defects sit on `c1ff07f1`:

- `serve/frontend.py:1326` `_bare_opener()` has one caller, at `serve/frontend.py:1817`, in the `content` branch of `_feed()`. The `reasoning` branch (`serve/frontend.py:1744`) matches `<tool_call>` only. The change consults the bare form there too, and in the `finish()` rescue for a call whose `</function>` ends the thinking.
- `serve/frontend.py:1144` `parse_tool_call()` (and `serve/frontend.py:1498` `_scan()` for the streamed JSON) build the arguments from the `<parameter=...>` names as written. The change unwraps a lone first `<parameter=arguments>` when the tool does not declare that parameter.

The gates stay the answer's plus the reasoning's own: a declared name, the start of a line, outside a code fence and inline code. A `<function=>` directly after a line that only quotes the wrapper (`<tool_call>`, `<toolcall>`, `<tool-call>`) stays text, and prose after the call still means it was a quote, not an act. A `</tool_call>` written after a bare call is dropped instead of being emitted as reasoning or answer text, and `_close_scan()` emits the unwrapped object, so the assembled stream equals the final arguments.

Nothing changes for the wrapped form, for templates without tools, or with `tool_call_recovery: false`.

## Validation

**Passed:** `python -m unittest discover -s serve -t .` in a worktree of `c1ff07f1` with this change: 1579 tests, OK (31 skipped). Targeted: `serve.test_tool_call_recovery_bare` (new), `serve.test_frontend`, `serve.test_tool_routes`, `serve.test_tool_corpus`, `serve.test_reasoning_tools`, `serve.test_reasoning_rescue`, `serve.test_server`, `serve.test_tool_opener_misspelt`, `serve.test_quoted_call_values`, `serve.test_native_tool_parser` - 452 + 83 tests, OK. Environment: Windows 11, Tesla V100 32 GB, CUDA 12 engine.

Before the change, the snippet in #5804 through the HTTP route (stream and non-stream) returned `finish_reason: "stop"` with no `tool_calls`; after it, `finish_reason: "tool_calls"` with `arguments: {"path": "...", "content": "..."}`, and the streamed deltas assemble to the same object.

**Failed:** none observed.

**Not run:** no model-in-the-loop run on this machine (the opencode session that found it is the reporter's); no HIP, SYCL or Metal build.

## Limits

Only the argument object itself is unwrapped: `{"arguments": {"arguments": ...}}` stays as it is, and a tool that really declares an `arguments` parameter keeps the parameter. The bare form stays subject to the wrapper's quote rules, so a call the model merely shows as an example is still text.

Co-authored-by: Copilot <[email protected]>

Mehr auf der Site

Links zu Install, Modellen, Releases.