Skip to content

fix: parse GLM's <arg_key>/<arg_value> tool calls in both servers - #35

Closed
jeidbugs404 wants to merge 1 commit into
ashhart:mainfrom
jeidbugs404:fix/glm-tool-calls
Closed

jeidbugs404 wants to merge 1 commit into
ashhart:mainfrom
jeidbugs404:fix/glm-tool-calls

Conversation

@jeidbugs404

Copy link
Copy Markdown
Contributor

GLM-4.5 and later, including GLM-5.3-Flash (the glm5_next recipe), write a tool call as the function name followed by key/value pairs:

<tool_call>get_weather<arg_key>city</arg_key><arg_value>Paris</arg_value><arg_key>days</arg_key><arg_value>3</arg_value></tool_call>

That is the format the checkpoint's own chat_template.jinja asks for and writes back into the history (a string value as itself, any other value with tojson). Neither server reads it today:

  • CUDA server (cuda/server.py, parse_tool_calls) reads Qwen <function=…><parameter=…> or JSON bodies only, so a GLM call stays in the reply as text: the client gets finish_reason: "stop" and no tool_calls. On v0.3.4.1 with the GLM-5.3-Flash EXL3 checkpoint on two DGX Sparks, 5 of 5 tool-call requests came back that way.
  • HTTP server (server/http.py, parse_tool_calls_from_content) raises unsupported tool_call payload format for the same block.

Change

  • server/http.py gets parse_glm_tool_call_block(block, tools). Both parsers call it only after their existing JSON and Qwen attempts fail, so those formats keep precedence and behave as before.
  • Values are typed by the offered tool's schema:
    • A parameter declared with a non-string type is read as JSON, since the template wrote it with tojson. If it doesn't parse, it stays text.
    • A string or untyped parameter keeps its exact text, whitespace included, so a resent history renders back to the tokens the model wrote. This is the same concern as the comment on the Qwen parameter regex.
  • A call to a tool the client didn't offer stays in the reply as text, as for the other formats.

Tests

tests/test_glm_tool_calls.py runs 17 cases through both parsers:

  • typed arguments;
  • exact string text;
  • JSON-looking string values;
  • non-JSON text for a typed parameter;
  • a call without arguments;
  • two calls with surrounding text;
  • a tool that wasn't offered;
  • Qwen <function=…> and JSON bodies, unchanged.

11 of the cases fail on main and all 17 pass here.

pytest --ignore=tests/cuda on Linux without MLX or torch gives 146 passed and 28 skipped. The 4 failures and 2 collection errors are identical on main, since they need MLX or torch. ruff check reports nothing new on the changed files.

Prepared with AI coding assistants. The fix and the test results above were produced and checked locally as described.

GLM-4.5 and later (GLM-5.3-Flash among them) write a tool call as the function name followed by <arg_key>/<arg_value> pairs. The CUDA server left such a call in the reply as text and the HTTP server raised 'unsupported tool_call payload format'. Both now read it after their existing JSON and Qwen attempts, typing values by the offered tool's schema.
@ashhart

ashhart commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Thanks @jeidbugs404 for the GLM tool-call fix. It's integrated with the GLM Mac work, with one parser in both servers, and moves with it to 0.3.5.1 in the next few days. The PR stays open until then, and you'll be credited as the author when it lands.

ashhart pushed a commit that referenced this pull request Sep 28, 2026
Pull request #35 by jeidbugs404. GLM-4.5 and later (GLM-5.3-Flash among them) write a tool call as the
function name followed by <arg_key>/<arg_value> pairs. The CUDA server left such a call in the reply as text and
the HTTP server raised 'unsupported tool_call payload format'. Both now read it after their existing JSON and
Qwen attempts, typing values by the offered tool's schema (parse_glm_tool_call_block), with 17 test cases
through both parsers.

Adapted by the maintainer to land on the 0.3.5 line:
- The HTTP hunk moved from server/http.py to server/tools.py, where 0.3.5 keeps the parser, and the CUDA server
  imports the parser from there.
- The tests sit in tests/test_glm_tool_calls_servers.py beside the existing GLM tool-call tests, importing from
  server/tools.py.
- One case, test_qwen_function_blocks_are_unchanged[http-server], expects Qwen parameter values as text; since
  0.3.5 the Mac server types them by the tool's schema. That expectation, and the one GLM implementation both
  servers share, follow in the next commit.
@ashhart

ashhart commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Your parser shipped in 0.3.6 (4fb2528, under your name). Both servers now read GLM's <arg_key>/<arg_value> calls, and GLM's and Gemma 4's call formats go through one parser built around yours. Thank you. Tool calls on GLM just work now.

Release: https://github.com/ashhart/TensorFold/releases/tag/v0.3.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants