The DeepSeek-V4 report shows the new tool-call schema. The model invokes tools by writing a block delimited by the special |DSML| token in an XML-like format:
<|DSML|tool_calls>
<|DSML|invoke name="$TOOL_NAME">
<|DSML|parameter name="$PARAMETER_NAME" string="true|false">$PARAMETER_VALUE</|DSML|parameter>
...
</|DSML|invoke>
<|DSML|invoke name="$TOOL_NAME2">
...
</|DSML|invoke>
</|DSML|tool_calls>
"String parameters should be specified as is and set string="true". For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set string="false"."
Implement parse_tool_calls(text):
text is an assistant message that may contain any amount of ordinary text and zero or more <|DSML|tool_calls>...</|DSML|tool_calls> blocks.{"name": tool_name, "parameters": {param_name: value, ...}}, one per <|DSML|invoke> element, in document order, with parameter order preserved.string="true" keeps its raw text verbatim (it may span lines); one with string="false" is decoded with json.loads, so 3 becomes an int, true becomes True, null becomes None, and arrays and objects become lists and dicts.Implement format_tool_calls(calls), the inverse: emit one <|DSML|tool_calls> block containing one <|DSML|invoke> per call and one <|DSML|parameter> line per parameter, in order, with each tag on its own line joined by \n and no trailing newline. Python str values are written as is with string="true"; every other value is written as json.dumps(value) with string="false". An empty list formats to the empty string. The round trip parse_tool_calls(format_tool_calls(calls)) == calls must hold.
re.S flag so . matches newlines, are enough.string="(true|false)" as a group and branch on it.isinstance(value, str) decides the string attribute when formatting.