[PR #4828] [CLOSED] [Engine] tool_choice "required" with several tools gives a real call, not raw markup, on chat and messages #5198

Closed
opened 2026-11-07 16:33:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4828
Author: @gdevenyi
Created: 10/31/2026
Status: ❌ Closed

Base: main ← Head: api/tool-choice-required-opening


📝 Commits (1)

  • c9d1d40 tool_choice "required" with several tools: write only "<tool_call>\n", because from a written "<function=" the model went on with names no tool has and the reply came back as text

📊 Changes

3 files changed (+10 additions, -10 deletions)

View changed files

📝 serve/frontend.py (+2 -2)
📝 serve/test_frontend.py (+1 -1)
📝 serve/test_server.py (+7 -7)

📄 Description

Problem and result

On a real model, tool_choice: "required" on /v1/chat/completions, and {"type": "any"} on /v1/messages, gave no call when the request had two or more tools. The reply was a 200 holding raw <tool_call> markup as text.

The server wrote <tool_call>\n<function= for the model, and Qwen3.8 went on with a name the request never offered (getTime, call_ExternalTool00, update_plan, parse_time).

Now the server writes only <tool_call>\n, and the model writes <function=NAME> itself. Every forced run gave a call to an offered tool.

Real engine, two tools offered, the same script on both sides. Calls to an offered tool:

Route and choice Thinking Prompt main This PR
chat, "required", whole off "What time is it in Paris right now?" 0/10 10/10
chat, "required", whole off "Say hi." 0/10 10/10
chat, "required", streamed off the Paris prompt 0/5 5/5
chat, "required", streamed off "Say hi." 0/5 5/5
chat, "required", whole on the Paris prompt 4/5 5/5
chat, "required", whole on "Say hi." 0/5 5/5
messages, any, whole off the Paris prompt 0/10 10/10
messages, any, whole off "Say hi." 0/10 10/10
messages, any, whole on the Paris prompt 3/5 5/5
messages, any, whole on "Say hi." 0/5 5/5

Totals: main 7/70, this PR 70/70.

#790 (closed) added forced_call. #3441 (closed) is about the same symptom, a malformed <function=...> block coming back as plain content, from another cause. No open issue reports this. It is a focused fix, so there is no scope issue. I found the problem while checking a change for /v1/responses, which I am sending as a separate PR on top of this one.

Approach

One line in forced_call. A named choice, and "required" with one tool, still write the whole <function=NAME>\n, because the server knows the name.

The cause is not proven. The vocabulary has =get (27362) as one token, so a model's own <function=get_time> likely does not pass through a lone =. I did not test that explanation. What I measured is the result of the change.

DeepSeek does not change. to_dsml_force returns the same text for the old and the new opening (<|DSML| calls>\n<|DSML| invoke name="), checked by calling it. So the same problem could exist there; I did not run DeepSeek.

Requests with auto, none, no tool_choice, a named choice or one tool never reach this line.

Validation

Revision: c9d1d402 against base c62d5e3a. Linux, Python 3.12.

Real engine: RTX 5080 16 GB, engine 0.1.55 from release v0.2.9, Qwen3.8-Flash-Next IQ3_S, context 65536, temperature 0.7, tools get_time and get_weather, 127.0.0.1. Plain HTTP, no SDK.

Passed:

  • The table above. One server for each side, one model load each, temperature 0.7.
  • Which tool, on this PR: get_time in every Paris run. On "Say hi." the choice varies between the two tools, as nothing in the prompt fits either.
  • The server log's "did not read as a call of a declared tool" line: 63 times on main, 0 on this PR. The main count also covers the Responses runs of the same session, which do not force a call.
  • auto is not forced, chat, 3 runs each, both sides: the Paris prompt get_time 3/3, "Say hi." text 3/3.
  • python -m unittest serve.test_server serve.test_frontend serve.test_anthropic_base_url serve.test_chat_tool_results serve.test_dsv41: 461 tests, failures=1, skipped=1. The failure is listed below.
  • The changed tests on the base: serve.test_server.ForcedToolChoice and serve.test_frontend.ForcedCallOpening give failures=10 on c62d5e3a.

Failed:

  • serve.test_server.GpuChoice.test_hip_ordinal: AssertionError: '0,1' != '1,0'. It fails the same way on c62d5e3a. Nothing here touches it.

Not run:

  • Streaming on /v1/messages.
  • Any other model, quantization or card. DeepSeek V4.1-Flash and Qwen3.6 were not run. This is one model and two prompts.
  • More than two tools.
  • A real agent client. These runs used plain HTTP.
  • Windows, macOS, and HIP, SYCL, CUDA and Metal builds. The change is Python only, so no build.

Limits

  • There is still no grammar. A model can write prose or an unknown name after <tool_call>\n. That did not happen in these 70 forced runs, and its rate on other models is not measured.
  • On "Say hi." the model must call something, so it makes up an argument. That is what required asks for.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W53iURzvDQMjnYemag8uvv


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4828 **Author:** [@gdevenyi](https://github.com/gdevenyi) **Created:** 10/31/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `api/tool-choice-required-opening` --- ### 📝 Commits (1) - [`c9d1d40`](https://github.com/Niko1221/Strata/commit/c9d1d402993c731cf2c38d341bc71d024d7c60b9) tool_choice "required" with several tools: write only "<tool_call>\n", because from a written "<function=" the model went on with names no tool has and the reply came back as text ### 📊 Changes **3 files changed** (+10 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+2 -2) 📝 `serve/test_frontend.py` (+1 -1) 📝 `serve/test_server.py` (+7 -7) </details> ### 📄 Description ## Problem and result On a real model, `tool_choice: "required"` on `/v1/chat/completions`, and `{"type": "any"}` on `/v1/messages`, gave no call when the request had two or more tools. The reply was a 200 holding raw `<tool_call>` markup as text. The server wrote `<tool_call>\n<function=` for the model, and Qwen3.8 went on with a name the request never offered (`getTime`, `call_ExternalTool00`, `update_plan`, `parse_time`). Now the server writes only `<tool_call>\n`, and the model writes `<function=NAME>` itself. Every forced run gave a call to an offered tool. Real engine, two tools offered, the same script on both sides. Calls to an offered tool: | Route and choice | Thinking | Prompt | `main` | This PR | | --- | --- | --- | --- | --- | | chat, `"required"`, whole | off | "What time is it in Paris right now?" | 0/10 | 10/10 | | chat, `"required"`, whole | off | "Say hi." | 0/10 | 10/10 | | chat, `"required"`, streamed | off | the Paris prompt | 0/5 | 5/5 | | chat, `"required"`, streamed | off | "Say hi." | 0/5 | 5/5 | | chat, `"required"`, whole | on | the Paris prompt | 4/5 | 5/5 | | chat, `"required"`, whole | on | "Say hi." | 0/5 | 5/5 | | messages, `any`, whole | off | the Paris prompt | 0/10 | 10/10 | | messages, `any`, whole | off | "Say hi." | 0/10 | 10/10 | | messages, `any`, whole | on | the Paris prompt | 3/5 | 5/5 | | messages, `any`, whole | on | "Say hi." | 0/5 | 5/5 | Totals: `main` 7/70, this PR 70/70. ## Related discussion #790 (closed) added `forced_call`. #3441 (closed) is about the same symptom, a malformed `<function=...>` block coming back as plain content, from another cause. No open issue reports this. It is a focused fix, so there is no scope issue. I found the problem while checking a change for `/v1/responses`, which I am sending as a separate PR on top of this one. ## Approach One line in `forced_call`. A named choice, and `"required"` with one tool, still write the whole `<function=NAME>\n`, because the server knows the name. **The cause is not proven.** The vocabulary has `=get` (27362) as one token, so a model's own `<function=get_time>` likely does not pass through a lone `=`. I did not test that explanation. What I measured is the result of the change. **DeepSeek does not change.** `to_dsml_force` returns the same text for the old and the new opening (`<|DSML| calls>\n<|DSML| invoke name="`), checked by calling it. So the same problem could exist there; I did not run DeepSeek. Requests with `auto`, `none`, no `tool_choice`, a named choice or one tool never reach this line. ## Validation Revision: c9d1d402 against base c62d5e3a. Linux, Python 3.12. Real engine: RTX 5080 16 GB, engine 0.1.55 from release v0.2.9, Qwen3.8-Flash-Next IQ3_S, context 65536, temperature 0.7, tools `get_time` and `get_weather`, 127.0.0.1. Plain HTTP, no SDK. **Passed:** - The table above. One server for each side, one model load each, temperature 0.7. - Which tool, on this PR: `get_time` in every Paris run. On "Say hi." the choice varies between the two tools, as nothing in the prompt fits either. - The server log's "did not read as a call of a declared tool" line: 63 times on `main`, 0 on this PR. The `main` count also covers the Responses runs of the same session, which do not force a call. - `auto` is not forced, chat, 3 runs each, both sides: the Paris prompt `get_time` 3/3, "Say hi." text 3/3. - `python -m unittest serve.test_server serve.test_frontend serve.test_anthropic_base_url serve.test_chat_tool_results serve.test_dsv41`: 461 tests, failures=1, skipped=1. The failure is listed below. - The changed tests on the base: `serve.test_server.ForcedToolChoice` and `serve.test_frontend.ForcedCallOpening` give failures=10 on c62d5e3a. **Failed:** - `serve.test_server.GpuChoice.test_hip_ordinal`: `AssertionError: '0,1' != '1,0'`. It fails the same way on c62d5e3a. Nothing here touches it. **Not run:** - Streaming on `/v1/messages`. - Any other model, quantization or card. DeepSeek V4.1-Flash and Qwen3.6 were not run. This is one model and two prompts. - More than two tools. - A real agent client. These runs used plain HTTP. - Windows, macOS, and HIP, SYCL, CUDA and Metal builds. The change is Python only, so no build. ## Limits - There is still no grammar. A model can write prose or an unknown name after `<tool_call>\n`. That did not happen in these 70 forced runs, and its rate on other models is not measured. - On "Say hi." the model must call something, so it makes up an argument. That is what `required` asks for. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01W53iURzvDQMjnYemag8uvv --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:33:24 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5198
No description provided.