chat: tagged calls whose name the opener opens -- GLM-5's <tool_call>NAME<arg_key>

GLM-5 writes <tool_call>NAME<arg_key>K</arg_key><arg_value>V</arg_value>...</tool_call>: no
prefix of the name's own and no suffix, the name ends at the first argument or at the call's
close. The tagged family now takes an empty name_suffix when name_prefix opens the call (no
call_open): the derivation from the template makes the per-call opener the prefix and its closer
call_end, the grammar takes eps() for the suffix, and the streaming parser finds the name's end
byte by byte (name_stop, name_plausible) and reads the closing tag as the first item of the
body. arg_name_suffix and arg_value_prefix may both be set and are read back to back, so
chat_format_markers keeps both tags. value_newlines comes from a probe render of the template
rather than a constant (GLM and MiniCPM false, Qwen true). The ABI struct is unchanged; its
comments say what an empty name_suffix means now.

chatparse_test: GLM's template serves tools; the derived format equals the one a plugin would
declare; every rendered reply in the corpus reads back as the message it rendered, split at
every byte; and replies that stray from the grammar. Each fails without this change. The Gemma
refusal names call_end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Opus 5.5 authored and Claude Code (srv-dev01) committed 2026-10-19 15:34:15 +02:00
1 parent 5ac0bc9690
commit e60810116c
6 files changed
+507 -22

No files matched your search

+12 -5
View File
@@ -22,12 +22,16 @@
* Qwen3.6 / Qwen3.8 <tool_call>\n<function=NAME>\n<parameter=ARG>\nVALUE\n</parameter>\n
* </function>\n</tool_call>
* MiniCPM5 <function name="NAME"><param name="ARG">VALUE</param></function>
* GLM-5 <tool_call>NAME<arg_key>ARG</arg_key><arg_value>VALUE</arg_value>
* </tool_call>
*
* A call's name sits between a prefix and a suffix and the call ends with its own close; each
* argument is a name between a prefix and a suffix, then a value ending at its own suffix; calls
* may be wrapped one by one. Arguments are typed by the tool's JSON schema: a string-typed one is
* raw text (optionally CDATA-wrapped), any other type is JSON, and text that does not parse as
* JSON is taken raw, since models often write Python literals into a tag.
* may be wrapped one by one. A name may also have no suffix of its own (GLM): it then ends where
* the first argument or the call's close begins, and that tag is read as what it is. Arguments
* are typed by the tool's JSON schema: a string-typed one is raw text (optionally CDATA-wrapped),
* any other type is JSON, and text that does not parse as JSON is taken raw, since models often
* write Python literals into a tag.
*
* Object family (ChatArgs::Object): a call is its name and one object holding the arguments.
*
@@ -107,8 +111,9 @@ struct ChatFormat {
/* Around each call: "<tool_call>\n", "</tool_call>". When set, a call written without it
* (name_prefix alone) is still read as a call (chatparse.h). */
std::string call_open, call_close;
/* "<function=", ">\n". In the object family name_suffix may be empty; the name then ends at
* the object's `{`. */
/* "<function=", ">\n". name_suffix may be empty: in the object family the name then ends at
* the object's `{`; in the tagged family, where name_prefix must open the call (no
* call_open), at the first arg_prefix or call_end, which stay part of the call's body. */
std::string name_prefix, name_suffix;
std::string call_end; /* "</function>\n"; may be empty for an object */
@@ -120,6 +125,8 @@ struct ChatFormat {
bool object_bare_keys = false;
std::string arg_prefix; /* "<parameter=" */
/* What ends a name and opens its value. Both may be set (GLM: "</arg_key>", "<arg_value>"):
* they are then read as one delimiter, written back to back. */
std::string arg_name_suffix; /* ">\n" (MiniCPM: empty, the value prefix ends it) */
std::string arg_value_prefix; /* "" (MiniCPM: "\">") */
std::string arg_value_suffix; /* "</parameter>\n" */