continue icon indicating copy to clipboard operation
continue copied to clipboard

System message tools parser assumes tool calls are positionally terminal

Open shanevcantwell opened this issue 8 months ago • 2 comments

Summary

The system message tools parser (interceptSystemToolCalls.ts) assumes tool calls must appear at the end of a response — one per response, nothing after. This is an architectural constraint that doesn't exist in the tool calling paradigm itself.

Behavior

  1. After a tool call completes, any subsequent content is silently dropped (lines 100-103)
  2. A second tool call in the same response is never parsed — parseState?.done breaks the loop (line 49)
  3. The system message suffix instructs models: "You can only call ONE tool at a time. You MUST stop generating after the closing codeblock"

Meanwhile the agent system message says "call multiple tools simultaneously."

Why this matters

Native tool calling APIs (OpenAI, Anthropic) allow models to interleave text and tool calls freely, and to make multiple calls in a single response. The system message tools path restricts models to a subset of that — one tool call, must be terminal — creating a capability gap that makes local models on this path appear less capable than they are.

The suffix instruction is a consequence of the parser limitation, not the other way around. The parser was built with the positional assumption, and the instruction exists to keep models inside those bounds.

Where

  • core/tools/systemMessageTools/interceptSystemToolCalls.ts
    • Line 49: parseState?.done breaks on second tool call
    • Lines 100-103: content after completed tool call dropped
  • core/tools/systemMessageTools/toolCodeblocks/index.ts
    • systemMessageSuffix (~line 71): "ONE tool at a time"

Context

This is a design limitation, not a simple bug. Fixing it means the parser needs to handle multiple tool calls per response, text between tool calls, and tool calls at any position. That's a meaningful rearchitecture of the stream interception logic.

Related

  • #11070 — parser false positives (separate issue, but compounds this)
  • #11072 — TOOL_NAME keyword echo
  • LM Studio lmstudio-community/app#1592 — similar positional assumptions in their parser

shanevcantwell avatar Mar 05 '26 12:03 shanevcantwell

@shanevcantwell this is a good issue, thanks for bringing back up.

Original intent was that we found many models fail to terminate the system tool calls correctly, often enough that it was better to just only allow one than to assume the model will interleave correctly. But I agree both local models and parsers have improved enough to reevaluate. There's a PR up to fix this, I'll take a look at it.

RomneyDa avatar Mar 23 '26 19:03 RomneyDa

This issue hasn't been updated in 90 days and will be closed after an additional 10 days without activity. If it's still important, please leave a comment and share any new information that would help us address the issue.

github-actions[bot] avatar Jun 22 '26 02:06 github-actions[bot]

This issue was closed because it wasn't updated for 10 days after being marked stale. If it's still important, you are welcome to leave a comment and this will keep the issue open. However please note that this repo is no longer being actively maintained.

github-actions[bot] avatar Jul 03 '26 02:07 github-actions[bot]