llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Eval bug: Tool calling on qwen3.5 often triggers a promp reprocessing in the next turn

Open erazortt opened this issue 7 months ago • 17 comments

Name and Version

$ ./llama-cli.exe --version ggml_cuda_init: found 1 CUDA devices (Total VRAM: 48934 MiB): Device 0: NVIDIA RTX PRO 5000 Blackwell, compute capability 12.0, VMM: yes, VRAM: 48934 MiB version: 8792 (f4b5bf2f3) built with MSVC 19.44.35225.0 for x64

Operating systems

Windows

GGML backends

CUDA

Hardware

Ryzen 7800 + Blackwell Pro 5000

Models

all Qwen3.5

Problem description & steps to reproduce

When a promt includes tool calls, the next turn will be very often forced to reprocess the whole promt.

First Bad Commit

No response

Relevant log output

There is nothing special in the log apart from the information that the checkpoints are getting erased and that the promt is getting reprocessed.

erazortt avatar Apr 14 '26 13:04 erazortt

I assume you are using some harness like OpenCode? Opencode is known to "eat" blocks, which will invalidate cache and require reprocessing of previous turn. https://github.com/anomalyco/opencode/issues/19081

Some other ones have similar issue, so it might be harness issue, afaik its not a problem with llamacpp.

You can try and use reasoning-format to deepseek i think with qwen3.5 so it parses into reasoning_context field

michal-zurkowski avatar Apr 14 '26 14:04 michal-zurkowski

I can also see this issue on Pi Coding Agent, but it's sporadic. Sometimes it caches, sometimes it has to reprocess. I haven't found the pattern yet.

0cc4m avatar Apr 14 '26 14:04 0cc4m

try this template fix: https://www.reddit.com/r/LocalLLaMA/comments/1sg076h/i_tracked_a_major_cache_reuse_issue_down_to_qwen/

gtrak avatar Apr 14 '26 14:04 gtrak

Actually I was just using Llama.cpp with tools. Simple ones, like get date. When used muiltiple times in a chat is already enough to trigger the reprocessing.

erazortt avatar Apr 14 '26 16:04 erazortt

try this template fix: https://www.reddit.com/r/LocalLLaMA/comments/1sg076h/i_tracked_a_major_cache_reuse_issue_down_to_qwen/

already done that

erazortt avatar Apr 14 '26 16:04 erazortt

It is really sime to reproduce this:

  • Hook up the most simple tool in the mcp setting of the llama.cpp frontend
  • start to chat with your model. As soon as there are some tool calls in the chat, the prompt is almost guaranteed to reprocess

While this might not be a big deal for small models, f[r big models half offloaded on RAM this for sure is very problematic.

erazortt avatar Apr 14 '26 16:04 erazortt

This is by design. The template preserves reasoning between tool calls if they occur after the last user message. However, once a new user message comes in, the previous assistant messages are stripped of their reasoning traces which triggers prompt reprocessing.

Almost all modern reasoning models work this way, it's how they can guide themselves in an agentic loop.

You can modify the chat template to circumvent this, but you'll likely lose model performance, e.g. it will be "lazy".

aldehir avatar Apr 14 '26 20:04 aldehir

Why does it only happen sometimes, then?

0cc4m avatar Apr 14 '26 21:04 0cc4m

Why does it only happen sometimes, then?

I couldn't tell you without a payload showing the messages list, only that this is expected behavior when tool calling with "interleaved reasoning" models. Although I wouldn't expect it to reprocess the entire prompt unless the entire prompt is a single agentic loop of interleaving reasoning traces and tool calls.

aldehir avatar Apr 15 '26 02:04 aldehir

Is there a way to dump actual model input in the server?

0cc4m avatar Apr 15 '26 04:04 0cc4m

Do you mean obtain the prompt that is fed to the model? I've been doing this often to capture raw model input/output:

$ curl http://localhost:8080/apply-template -d '{"messages": [{"role": "system", "content": "..."}, {"role": "user", "content": "..."}]}' > prompt.txt
$ curl http://localhost:8080/v1/completions -d @prompt.txt

aldehir avatar Apr 15 '26 04:04 aldehir

This is by design. The template preserves reasoning between tool calls if they occur after the last user message. However, once a new user message comes in, the previous assistant messages are stripped of their reasoning traces which triggers prompt reprocessing.

Almost all modern reasoning models work this way, it's how they can guide themselves in an agentic loop.

You can modify the chat template to circumvent this, but you'll likely lose model performance, e.g. it will be "lazy".

Well, but this however also happens with reasoning completly disabled. To me it appeared totally independent of whether reasoning is enabled or not.

erazortt avatar Apr 15 '26 07:04 erazortt

Do you mean obtain the prompt that is fed to the model? I've been doing this often to capture raw model input/output:

$ curl http://localhost:8080/apply-template -d '{"messages": [{"role": "system", "content": "..."}, {"role": "user", "content": "..."}]}' > prompt.txt
$ curl http://localhost:8080/v1/completions -d @prompt.txt

Could you please elaborate a little more? I do not understand how you are interacting here. How would you talk to the model in what you just posted?

erazortt avatar Apr 15 '26 07:04 erazortt

It's only helpful for inspecting the generated prompt and how it responds when you add additional messages. You can check the common prefix and see if the prompt changes despite no semantic change (e.g., reasoning disabled but template still changes after a user message).

aldehir avatar Apr 16 '26 16:04 aldehir

Yes, but how is that supposed to work, when the mcp connection is done by the llama.cpp frontend, when you are not using that frontend?

erazortt avatar Apr 17 '26 16:04 erazortt

I'm sorry for the misunderstanding. That comment was directed at @0cc4m if he was interested in digging further. It has no applicability to the normal user.

aldehir avatar Apr 17 '26 17:04 aldehir

Ok thanks bro

في الجمعة، 17 أبريل 2026 18:27 Aldehir Rojas @.***> كتب:

aldehir left a comment (ggml-org/llama.cpp#21903) https://github.com/ggml-org/llama.cpp/issues/21903#issuecomment-4270008933

I'm sorry for the misunderstanding. That comment was directed at @0cc4m https://github.com/0cc4m if he was interested in digging further. It has no applicability to the normal user.

— Reply to this email directly, view it on GitHub https://github.com/ggml-org/llama.cpp/issues/21903?email_source=notifications&email_token=CBTQ2IQWR4FSVELCWIPLJP34WJSP3A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMRXGAYDAOBZGMZ2M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-4270008933, or unsubscribe https://github.com/notifications/unsubscribe-auth/CBTQ2IQD2XZPDXGHU56Y2JT4WJSP3AVCNFSM6AAAAACXY4Z6S6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DENZQGAYDQOJTGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

mollahmasud977-sys avatar Apr 17 '26 20:04 mollahmasud977-sys

reprocessing AGENTS.md every time...

sswtodo avatar May 28 '26 18:05 sswtodo