vllm_mlx.tool_parsers.qwen3_xml_tool_parser¶
Qwen 3.5 XML tool call parser for vllm-mlx.
View the complete module source at #L1-L1559.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser
¶
Qwen 3.5 XML tool call parser for vllm-mlx.
Handles Qwen 3.5's XML parameter format:
<tool_call>
<function=func_name>
<parameter=param1>value1</parameter>
</function>
</tool_call>
Authority: Qwen 3.5 HF chat template, vLLM PR #25028 (from Qwen API team).
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.logger
module-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.ChatCompletionToolsParam
module-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaFunctionCall
dataclass
¶
Incremental function name and argument payload used by the XML parser.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall
dataclass
¶
DeltaToolCall(index: int = 0, id: Optional[str] = None, type: str = 'function', function: Optional[DeltaFunctionCall] = None)
Incremental indexed tool call produced by the XML parser shim.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall.index
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall.id
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall.type
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall.function
class-attribute
instance-attribute
¶
function: Optional[DeltaFunctionCall] = None
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage
dataclass
¶
DeltaMessage(content: Optional[str] = None, tool_calls: Optional[list[DeltaToolCall]] = None, role: Optional[str] = None, reasoning_content: Optional[str] = None)
Incremental content, reasoning, and tool calls from the parser shim.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage.content
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage.tool_calls
class-attribute
instance-attribute
¶
tool_calls: Optional[list[DeltaToolCall]] = None
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage.role
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage.reasoning_content
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._FunctionDef
¶
Wrap a function definition dict for attribute access.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._FunctionDef.__slots__
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef
¶
Wrap a tool definition dict for attribute access.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef.__slots__
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef._func
instance-attribute
¶
_func = _FunctionDef(d.get('function', {}))
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser
¶
Streaming XML parser for Qwen 3.5 <tool_call> format.
Architecture
- Preprocessing (
_preprocess_before_xml_parse): scans raw text for<parameter=name>tags, extracts type hints from tool schemas, and rewrites the XML into expat-parseable form. - Expat parsing: an incremental
xml.parsers.expatparser firesstart_element/end_element/character_datacallbacks. - Type coercion (
_coerce_param_value): converts string values to int/float/bool/object/array based on JSON Schema type hints. Complex types use a deferredast.literal_eval+json.loadsfallback. - Auto-closing: if the model truncates output mid-tag, the parser synthesizes closing tags so partial tool calls are still extractable.
Streaming: update(delta) feeds incremental text. Completed tool calls
are emitted via get_streaming_output() as they close. State resets
between tool calls within the same response.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.tools
instance-attribute
¶
tools: Union[list[ChatCompletionToolsParam], None] = None
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.tool_call_start_token
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.tool_call_end_token
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.function_start_token
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.function_end_token
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.parameter_start_token
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.parameter_end_token
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._TOOL_TAG_PREFIXES
class-attribute
instance-attribute
¶
_TOOL_TAG_PREFIXES = ('<tool_call>', '</tool_call>', '<function=', '</function>', '<parameter=', '</parameter>')
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.reset_streaming_state
¶
Reset streaming parsing state
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.parse_single_streaming_chunks
¶
parse_single_streaming_chunks(xml_chunk: str) -> DeltaMessage
Parse single streaming XML chunk and return Delta response This is the actual streaming interface that receives chunks one by one and maintains internal state
Parameters:
-
xml_chunk(str) –Single XML chunk string
Returns: DeltaMessage: Contains delta information generated by this chunk, returns empty response if no complete elements
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._escape_xml_special_chars
¶
Escape XML special characters Args: text: Original text Returns: Escaped text
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._process_complete_xml_elements
¶
Process complete XML elements in buffer
Returns:
-
bool(bool) –Whether complete elements were found and processed
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._should_skip_element
¶
Determine whether an element should be skipped
Parameters:
-
element(str) –Element to evaluate
Returns:
-
bool(bool) –True means should skip, False means should process
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._looks_like_partial_tool_open
¶
True if fragment could complete into a tool-related XML tag.
Covers two shapes
fragmentis a prefix of a known tag head (e.g.<funct).fragmentalready past the=marker and accumulating the attribute name (e.g.<function=Ag) — waiting on>.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._find_next_complete_element
¶
Find next complete XML element from specified position
Parameters:
-
start_pos(int) –Position to start searching
Returns:
-
Optional[str]–(Complete element string, element end position),
-
int–returns (None, start_pos) if no complete element found
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._merge_new_deltas_to_single_response
¶
_merge_new_deltas_to_single_response(initial_count: int) -> DeltaMessage
Merge newly generated deltas from this processing into a single DeltaMessage
Parameters:
-
initial_count(int) –Delta count before processing
Returns:
-
DeltaMessage–Merged DeltaMessage containing all newly generated delta information
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._preprocess_xml_chunk
¶
Preprocess XML chunk, handle non-standard formats, and escape special characters
Parameters:
-
chunk(str) –Original XML chunk
Returns:
-
str–Processed XML chunk
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._emit_delta
¶
_emit_delta(delta: DeltaMessage)
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._auto_close_open_parameter_if_needed
¶
Before starting to process new elements,
if there are unclosed tags from before,
automatically complete their endings to the parser.
- If there are unclosed parameters,
it's equivalent to feeding </parameter>
- When about to start a new function or tool_call,
if there are unclosed functions, complete </function>.
- When about to start a new tool_call,
if there are unclosed tool_calls, complete </tool_call>.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._start_element
¶
Handle XML start element events
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._flush_pending_implicit_delta
¶
Emit a deferred bare-
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._abandon_pending_implicit_tool_call
¶
Roll back a deferred bare-
Drops the pending function-name delta and unwinds the synthesised
wrapper state so no tool_call is ever emitted for this fragment.
Returns (raw_text, buffered_text) so the caller can restore the
original prose (raw <function=...> tag + any whitespace held while
waiting on commitment) as user-visible content.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._char_data
¶
Handle XML character data events
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._end_element
¶
Handle XML end element events
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.setup_parser
¶
Set up XML parser event handlers
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.set_tools
¶
set_tools(tools: Union[list[ChatCompletionToolsParam], None])
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._get_next_call_id
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._extract_function_name
¶
Extract function name from various formats
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._extract_parameter_name
¶
Extract parameter name from various formats
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._get_param_type
¶
Get parameter type based on tool configuration, defaults to string Args: param_name: Parameter name
Returns:
-
str–Parameter type
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.repair_param_type
¶
Repair unknown parameter types by treating them as string Args: param_type: Parameter type
Returns:
-
str–Repaired parameter type
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._convert_param_value
¶
Convert value based on parameter type Args: param_value: Parameter value param_type: Parameter type
Returns:
-
Any–Converted value
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._convert_for_json_streaming
¶
Convert converted_value based on whether it's empty and if type is string Args: converted_value: Converted value param_type: Parameter type
Returns:
-
str–Converted string for streaming output
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._reset_xml_parser_after_tool_call
¶
Each tool_call is treated as a separate XML document, so we need to reset the parser after each tool_call.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser
¶
Bases: ToolParser
XML tool call parser for Qwen 3.5 models, adapted for vllm-mlx.
Core parsing logic from vLLM PR #25028 (Qwen API team). Uses expat-based streaming XML parser with type coercion, deferred parsing for complex types, and auto-closing of malformed XML.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.SUPPORTS_NATIVE_TOOL_FORMAT
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser._xml_parser
instance-attribute
¶
_xml_parser = StreamingXMLToolCallParser()
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser._wrap_tools
staticmethod
¶
_wrap_tools(request: dict[str, Any] | None) -> list[_ToolDef] | None
Convert tool definition dicts to _ToolDef wrappers for attribute access.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.extract_tool_calls
¶
extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls from complete Qwen 3.5 output.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.extract_tool_calls_streaming
¶
extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] | None = None, current_token_ids: Sequence[int] | None = None, delta_token_ids: Sequence[int] | None = None, request: dict[str, Any] | None = None) -> dict[str, Any] | None
Extract tool calls from streaming Qwen 3.5 output.
Returns dict with 'tool_calls' and/or 'content' keys, or None to suppress the chunk.
Source code in vllm_mlx/tool_parsers/qwen3_xml_tool_parser.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaFunctionCall · class
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaFunctionCall(name: Optional[str] = None, arguments: str = '')
Incremental function name and argument payload used by the XML parser.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name |
Optional[str] |
no |
None |
Optional constructor field; defaults to None. |
arguments |
str |
no |
'' |
Optional constructor field; defaults to ''. |
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaFunctionCall
Exceptions and behavior
Class DeltaFunctionCall declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall · class
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall(index: int = 0, id: Optional[str] = None, type: str = 'function', function: Optional[DeltaFunctionCall] = None)
Incremental indexed tool call produced by the XML parser shim.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
index |
int |
no |
0 |
Optional constructor field; defaults to 0. |
id |
Optional[str] |
no |
None |
Optional constructor field; defaults to None. |
type |
str |
no |
'function' |
Optional constructor field; defaults to 'function'. |
function |
Optional[DeltaFunctionCall] |
no |
None |
Optional constructor field; defaults to None. |
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaToolCall
Exceptions and behavior
Class DeltaToolCall declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage · class
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage(content: Optional[str] = None, tool_calls: Optional[list[DeltaToolCall]] = None, role: Optional[str] = None, reasoning_content: Optional[str] = None)
Incremental content, reasoning, and tool calls from the parser shim.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
content |
Optional[str] |
no |
None |
Optional constructor field; defaults to None. |
tool_calls |
Optional[list[DeltaToolCall]] |
no |
None |
Optional constructor field; defaults to None. |
role |
Optional[str] |
no |
None |
Optional constructor field; defaults to None. |
reasoning_content |
Optional[str] |
no |
None |
Optional constructor field; defaults to None. |
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.DeltaMessage
Exceptions and behavior
Class DeltaMessage declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._FunctionDef · class
Wrap a function definition dict for attribute access.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
d |
dict |
yes |
none |
Required positional or keyword input. |
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._FunctionDef
Exceptions and behavior
Class _FunctionDef declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._FunctionDef.__init__ · method
Method _FunctionDef.__init__ updates self._d.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
d |
dict |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Method _FunctionDef.__init__ updates self._d.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._FunctionDef.name · method
Method _FunctionDef.name calls self._d.get; returns self._d.get('name', '').
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
self._d.get('name', '')
Exceptions and behavior
Method _FunctionDef.name calls self._d.get; returns self._d.get('name', '').
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._FunctionDef.parameters · method
Method _FunctionDef.parameters calls self._d.get; returns self._d.get('parameters', {}).
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
self._d.get('parameters', {})
Exceptions and behavior
Method _FunctionDef.parameters calls self._d.get; returns self._d.get('parameters', {}).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef · class
Wrap a tool definition dict for attribute access.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
d |
dict |
yes |
none |
Required positional or keyword input. |
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef
Exceptions and behavior
Class _ToolDef declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef.__init__ · method
Method _ToolDef.__init__ updates self._d, self._func; calls _FunctionDef, d.get.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
d |
dict |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Method _ToolDef.__init__ updates self._d, self._func; calls _FunctionDef, d.get.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef.type · method
Method _ToolDef.type calls self._d.get; returns self._d.get('type', 'function').
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
self._d.get('type', 'function')
Exceptions and behavior
Method _ToolDef.type calls self._d.get; returns self._d.get('type', 'function').
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser._ToolDef.function · method
Method _ToolDef.function returns self._func.
Parameters
This callable has no explicit inputs.
Returns
- Type:
_FunctionDef - Direct return expressions:
self._func
Exceptions and behavior
Method _ToolDef.function returns self._func.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser · class
Streaming XML parser for Qwen 3.5 <tool_call> format.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser
Exceptions and behavior
Class StreamingXMLToolCallParser declares 27 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.__init__ · method
Method StreamingXMLToolCallParser.__init__ updates self.tools, self.tool_call_start_token, self.tool_call_end_token, self.function_start_token; calls self.reset_streaming_state.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method StreamingXMLToolCallParser.__init__ updates self.tools, self.tool_call_start_token, self.tool_call_end_token, self.function_start_token; calls self.reset_streaming_state.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.reset_streaming_state · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.reset_streaming_state() -> not annotated
Reset streaming parsing state
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method StreamingXMLToolCallParser.reset_streaming_state updates self.deltas, self.tool_call_index, self.current_call_id, self.last_completed_call_id; calls ParserCreate, self.setup_parser.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.parse_single_streaming_chunks · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.parse_single_streaming_chunks(xml_chunk: str) -> DeltaMessage
Parse single streaming XML chunk and return Delta response This is the actual streaming interface that receives chunks one by one and maintains internal state Args: xml_chunk: Single XML chunk string Returns: DeltaMessage: Contains delta information generated by this chunk, returns empty response if no complete elements
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
xml_chunk |
str |
yes |
none |
Single XML chunk string |
Returns
- Type:
DeltaMessage - Direct return expressions:
result_delta;text_delta;DeltaMessage(content=None)
Exceptions and behavior
Method StreamingXMLToolCallParser.parse_single_streaming_chunks updates self.streaming_buffer, self.text_content_buffer; calls len, self._process_complete_xml_elements, xml_chunk.count, sum; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._escape_xml_special_chars · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._escape_xml_special_chars(text: str) -> str
Escape XML special characters Args: text: Original text Returns: Escaped text
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Original text |
Returns
- Type:
str - Direct return expressions:
text
Exceptions and behavior
Method StreamingXMLToolCallParser._escape_xml_special_chars calls xml_escapes.items, text.replace; returns text.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._process_complete_xml_elements · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._process_complete_xml_elements() -> bool
Process complete XML elements in buffer Returns: bool: Whether complete elements were found and processed
Parameters
This callable has no explicit inputs.
Returns
- Type:
bool - Direct return expressions:
found_any
Exceptions and behavior
Method StreamingXMLToolCallParser._process_complete_xml_elements updates self.last_processed_pos, self.text_content_buffer, self._current_raw_element; calls len, self._find_next_complete_element, self._should_skip_element, self._preprocess_xml_chunk; returns found_any.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._should_skip_element · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._should_skip_element(element: str) -> bool
Determine whether an element should be skipped Args: element: Element to evaluate Returns: bool: True means should skip, False means should process
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
element |
str |
yes |
none |
Element to evaluate |
Returns
- Type:
bool - Direct return expressions:
False;True;not element
Exceptions and behavior
Method StreamingXMLToolCallParser._should_skip_element updates self.text_content_buffer; calls element.startswith; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._looks_like_partial_tool_open · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._looks_like_partial_tool_open(fragment: str) -> bool
True if fragment could complete into a tool-related XML tag.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
fragment |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;True
Exceptions and behavior
Method StreamingXMLToolCallParser._looks_like_partial_tool_open calls fragment.startswith, prefix.startswith; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._find_next_complete_element · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._find_next_complete_element(start_pos: int) -> tuple[Optional[str], int]
Find next complete XML element from specified position Args: start_pos: Position to start searching Returns: (Complete element string, element end position), returns (None, start_pos) if no complete element found
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
start_pos |
int |
yes |
none |
Position to start searching |
Returns
- Type:
tuple[Optional[str], int] - Direct return expressions:
(None, start_pos);(buffer[:tag_end], start_pos + tag_end);(buffer[:tag_end2 + 1], start_pos + tag_end2 + 1);(buffer, start_pos + len(buffer));(text_content, start_pos + next_tag_pos);(remaining, start_pos + len(remaining))
Exceptions and behavior
Method StreamingXMLToolCallParser._find_next_complete_element calls buffer.startswith, buffer.find, self._looks_like_partial_tool_open, len; has 6 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._merge_new_deltas_to_single_response · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._merge_new_deltas_to_single_response(initial_count: int) -> DeltaMessage
Merge newly generated deltas from this processing into a single DeltaMessage Args: initial_count: Delta count before processing Returns: Merged DeltaMessage containing all newly generated delta information
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
initial_count |
int |
yes |
none |
Delta count before processing |
Returns
- Type:
DeltaMessage - Direct return expressions:
DeltaMessage(content=None);new_deltas[0];DeltaMessage(content=merged_content if merged_content else None, tool_calls=merged_tool_calls)
Exceptions and behavior
Method StreamingXMLToolCallParser._merge_new_deltas_to_single_response calls len, DeltaMessage, merged_tool_calls.append; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._preprocess_xml_chunk · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._preprocess_xml_chunk(chunk: str) -> str
Preprocess XML chunk, handle non-standard formats, and escape special characters Args: chunk: Original XML chunk Returns: Processed XML chunk
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
chunk |
str |
yes |
none |
Original XML chunk |
Returns
- Type:
str - Direct return expressions:
f'{safe_text}</parameter>';self._escape_xml_special_chars(original_chunk);'';processed
Exceptions and behavior
Method StreamingXMLToolCallParser._preprocess_xml_chunk updates self.defer_current_parameter, self.deferred_param_raw_value, self._pre_inside_parameter, self._pre_param_buffer; calls chunk.startswith, re.sub, processed.startswith, self._escape_xml_special_chars; has 4 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._emit_delta · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._emit_delta(delta: DeltaMessage) -> not annotated
Emit Delta response (streaming output)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
delta |
DeltaMessage |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Method StreamingXMLToolCallParser._emit_delta calls self.deltas.append.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._auto_close_open_parameter_if_needed · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._auto_close_open_parameter_if_needed(incoming_tag: Optional[str] = None) -> not annotated
Before starting to process new elements, if there are unclosed tags from before, automatically complete their endings to the parser.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
incoming_tag |
Optional[str] |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
not annotated
Exceptions and behavior
Method StreamingXMLToolCallParser._auto_close_open_parameter_if_needed calls self._end_element.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._start_element · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._start_element(name: str, attrs: dict[str, str]) -> not annotated
Handle XML start element events
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name |
str |
yes |
none |
Required positional or keyword input. |
attrs |
dict[str, str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Method StreamingXMLToolCallParser._start_element updates self.parameters, self.current_call_id, self.current_param_is_first, self.tool_call_index; calls self._auto_close_open_parameter_if_needed, self._get_next_call_id, name.startswith, self._start_element; returns None.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._flush_pending_implicit_delta · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._flush_pending_implicit_delta() -> None
Emit a deferred bare-
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method StreamingXMLToolCallParser._flush_pending_implicit_delta updates self._pending_implicit_delta, self._pending_implicit_raw_text, self._pending_implicit_text_buffer; calls self._emit_delta.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._abandon_pending_implicit_tool_call · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._abandon_pending_implicit_tool_call() -> tuple[str, str]
Roll back a deferred bare-
Parameters
This callable has no explicit inputs.
Returns
- Type:
tuple[str, str] - Direct return expressions:
(raw_text, buffered_text)
Exceptions and behavior
Method StreamingXMLToolCallParser._abandon_pending_implicit_tool_call updates self._pending_implicit_delta, self._pending_implicit_raw_text, self._pending_implicit_text_buffer, self.implicit_tool_call_wrapper; calls self._reset_xml_parser_after_tool_call; returns (raw_text, buffered_text).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._char_data · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._char_data(data: str) -> not annotated
Handle XML character data events
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
data |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Method StreamingXMLToolCallParser._char_data updates self._pending_implicit_text_buffer, self.should_emit_end_newline, self.current_param_value, self.start_quote_emitted; calls data.strip, self._abandon_pending_implicit_tool_call, self._emit_delta, DeltaMessage; returns None.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._end_element · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._end_element(name: str) -> not annotated
Handle XML end element events
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Method StreamingXMLToolCallParser._end_element updates self.should_emit_end_newline, self.current_param_name, self.current_param_value, self.current_param_value_converted; calls name.startswith, self._auto_close_open_parameter_if_needed, ast.literal_eval, json.dumps; returns None.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.setup_parser · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.setup_parser() -> not annotated
Set up XML parser event handlers
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method StreamingXMLToolCallParser.setup_parser updates self.parser.buffer_text, self.parser.StartElementHandler, self.parser.EndElementHandler, self.parser.CharacterDataHandler.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.set_tools · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.set_tools(tools: Union[list[ChatCompletionToolsParam], None]) -> not annotated
Set tool configuration information
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tools |
Union[list[ChatCompletionToolsParam], None] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Method StreamingXMLToolCallParser.set_tools updates self.tools.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._get_next_call_id · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._get_next_call_id() -> not annotated
Generate unique call ID
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
f'call_{uuid.uuid4().hex[:24]}'
Exceptions and behavior
Method StreamingXMLToolCallParser._get_next_call_id calls uuid.uuid4; returns f'call_{uuid.uuid4().hex[:24]}'.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._extract_function_name · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._extract_function_name(name: str, attrs: dict[str, str]) -> Optional[str]
Extract function name from various formats
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name |
str |
yes |
none |
Required positional or keyword input. |
attrs |
dict[str, str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[str] - Direct return expressions:
attrs['name'];parts[1];None
Exceptions and behavior
Method StreamingXMLToolCallParser._extract_function_name calls name.split, len; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._extract_parameter_name · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._extract_parameter_name(name: str, attrs: dict[str, str]) -> Optional[str]
Extract parameter name from various formats
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name |
str |
yes |
none |
Required positional or keyword input. |
attrs |
dict[str, str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[str] - Direct return expressions:
attrs['name'];parts[1];None
Exceptions and behavior
Method StreamingXMLToolCallParser._extract_parameter_name calls name.split, len; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._get_param_type · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._get_param_type(param_name: str) -> str
Get parameter type based on tool configuration, defaults to string Args: param_name: Parameter name Returns: Parameter type
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
param_name |
str |
yes |
none |
Parameter name |
Returns
- Type:
str - Direct return expressions:
'string';self.repair_param_type(str(properties[param_name].get('type', 'string')));self.repair_param_type(str(param_config.get('type', 'string')))
Exceptions and behavior
Method StreamingXMLToolCallParser._get_param_type calls hasattr, isinstance, self.repair_param_type, str; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.repair_param_type · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser.repair_param_type(param_type: str) -> str
Repair unknown parameter types by treating them as string Args: param_type: Parameter type Returns: Repaired parameter type
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
param_type |
str |
yes |
none |
Parameter type |
Returns
- Type:
str - Direct return expressions:
param_type;'string'
Exceptions and behavior
Method StreamingXMLToolCallParser.repair_param_type calls param_type.startswith; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._convert_param_value · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._convert_param_value(param_value: str, param_type: str) -> Any
Convert value based on parameter type Args: param_value: Parameter value param_type: Parameter type Returns: Converted value
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
param_value |
str |
yes |
none |
Parameter value |
param_type |
str |
yes |
none |
Parameter type |
Returns
- Type:
Any - Direct return expressions:
None;param_value;int(param_value);float_param_value if float_param_value - int(float_param_value) != 0 else int(float_param_value);param_value == 'true'
Exceptions and behavior
Method StreamingXMLToolCallParser._convert_param_value calls param_value.lower, param_type.strip().lower, param_type.strip, param_type.startswith; has 5 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._convert_for_json_streaming · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._convert_for_json_streaming(converted_value: Any, param_type: str) -> str
Convert converted_value based on whether it's empty and if type is string Args: converted_value: Converted value param_type: Parameter type Returns: Converted string for streaming output
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
converted_value |
Any |
yes |
none |
Converted value |
param_type |
str |
yes |
none |
Parameter type |
Returns
- Type:
str - Direct return expressions:
'';json.dumps(converted_value, ensure_ascii=False)[1:-1];json.dumps(converted_value, ensure_ascii=False);converted_value
Exceptions and behavior
Method StreamingXMLToolCallParser._convert_for_json_streaming calls json.dumps, isinstance; has 4 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._reset_xml_parser_after_tool_call · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.StreamingXMLToolCallParser._reset_xml_parser_after_tool_call() -> not annotated
Each tool_call is treated as a separate XML document, so we need to reset the parser after each tool_call.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method StreamingXMLToolCallParser._reset_xml_parser_after_tool_call updates self.parser, self.last_completed_call_id, self.current_call_id, self.current_function_name; calls ParserCreate, self.setup_parser.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser · class
XML tool call parser for Qwen 3.5 models, adapted for vllm-mlx.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokenizer |
not annotated |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser
Exceptions and behavior
Class Qwen3XMLToolParser derives from ToolParser and declares 4 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.__init__ · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.__init__(tokenizer = None) -> not annotated
Method Qwen3XMLToolParser.__init__ updates self._xml_parser; calls super().__init__, super, StreamingXMLToolCallParser, logger.info.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokenizer |
not annotated |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
not annotated
Exceptions and behavior
Method Qwen3XMLToolParser.__init__ updates self._xml_parser; calls super().__init__, super, StreamingXMLToolCallParser, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser._wrap_tools · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser._wrap_tools(request: dict[str, Any] | None) -> list[_ToolDef] | None
Convert tool definition dicts to _ToolDef wrappers for attribute access.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
dict[str, Any] \| None |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[_ToolDef] | None - Direct return expressions:
[_ToolDef(t) for t in request['tools']];None
Exceptions and behavior
Method Qwen3XMLToolParser._wrap_tools calls request.get, _ToolDef; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.extract_tool_calls · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls from complete Qwen 3.5 output.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_output |
str |
yes |
none |
Required positional or keyword input. |
request |
dict[str, Any] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
ExtractedToolCallInformation - Direct return expressions:
ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=result.content if result.content else model_out…;ExtractedToolCallInformation(tools_called=len(tool_calls) > 0, tool_calls=tool_calls, content=result.content)
Exceptions and behavior
Method Qwen3XMLToolParser.extract_tool_calls calls self.strip_think_tags, self._xml_parser.reset_streaming_state, self._wrap_tools, self._xml_parser.set_tools; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.extract_tool_calls_streaming · method
vllm_mlx.tool_parsers.qwen3_xml_tool_parser.Qwen3XMLToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] | None = None, current_token_ids: Sequence[int] | None = None, delta_token_ids: Sequence[int] | None = None, request: dict[str, Any] | None = None) -> dict[str, Any] | None
Extract tool calls from streaming Qwen 3.5 output.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
previous_text |
str |
yes |
none |
Required positional or keyword input. |
current_text |
str |
yes |
none |
Required positional or keyword input. |
delta_text |
str |
yes |
none |
Required positional or keyword input. |
previous_token_ids |
Sequence[int] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
current_token_ids |
Sequence[int] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
delta_token_ids |
Sequence[int] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
request |
dict[str, Any] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
dict[str, Any] | None - Direct return expressions:
None;{'tool_calls': tool_calls};{'content': result.content}
Exceptions and behavior
Method Qwen3XMLToolParser.extract_tool_calls_streaming calls self._xml_parser.reset_streaming_state, self._wrap_tools, self._xml_parser.set_tools, self._xml_parser.parse_single_streaming_chunks; has 3 explicit return paths.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
DeltaFunctionCall |
class | DeltaFunctionCall(name: Optional[str] = None, arguments: str = '') |
Incremental function name and argument payload used by the XML parser. | #L54-L58 |
DeltaToolCall |
class | DeltaToolCall(index: int = 0, id: Optional[str] = None, type: str = 'function', function: Optional[DeltaFunctionCall] = None) |
Incremental indexed tool call produced by the XML parser shim. | #L62-L68 |
DeltaMessage |
class | DeltaMessage(content: Optional[str] = None, tool_calls: Optional[list[DeltaToolCall]] = None, role: Optional[str] = None, reasoning_content: Optional[str] = None) |
Incremental content, reasoning, and tool calls from the parser shim. | #L72-L78 |
_FunctionDef |
class | _FunctionDef(d: dict) |
Wrap a function definition dict for attribute access. | #L85-L99 |
_FunctionDef.__init__ |
method | _FunctionDef.__init__(d: dict) -> not annotated |
Method _FunctionDef.__init__ updates self._d. |
#L90-L91 |
_FunctionDef.name |
method | _FunctionDef.name() -> str |
Method _FunctionDef.name calls self._d.get; returns self._d.get('name', ''). |
#L94-L95 |
_FunctionDef.parameters |
method | _FunctionDef.parameters() -> dict |
Method _FunctionDef.parameters calls self._d.get; returns self._d.get('parameters', {}). |
#L98-L99 |
_ToolDef |
class | _ToolDef(d: dict) |
Wrap a tool definition dict for attribute access. | #L102-L117 |
_ToolDef.__init__ |
method | _ToolDef.__init__(d: dict) -> not annotated |
Method _ToolDef.__init__ updates self._d, self._func; calls _FunctionDef, d.get. |
#L107-L109 |
_ToolDef.type |
method | _ToolDef.type() -> str |
Method _ToolDef.type calls self._d.get; returns self._d.get('type', 'function'). |
#L112-L113 |
_ToolDef.function |
method | _ToolDef.function() -> _FunctionDef |
Method _ToolDef.function returns self._func. |
#L116-L117 |
StreamingXMLToolCallParser |
class | StreamingXMLToolCallParser() |
Streaming XML parser for Qwen 3.5 <tool_call> format. |
#L126-L1427 |
StreamingXMLToolCallParser.__init__ |
method | StreamingXMLToolCallParser.__init__() -> not annotated |
Method StreamingXMLToolCallParser.__init__ updates self.tools, self.tool_call_start_token, self.tool_call_end_token, self.function_start_token; calls self.reset_streaming_state. |
#L146-L156 |
StreamingXMLToolCallParser.reset_streaming_state |
method | StreamingXMLToolCallParser.reset_streaming_state() -> not annotated |
Reset streaming parsing state | #L158-L208 |
StreamingXMLToolCallParser.parse_single_streaming_chunks |
method | StreamingXMLToolCallParser.parse_single_streaming_chunks(xml_chunk: str) -> DeltaMessage |
Parse single streaming XML chunk and return Delta response This is the actual streaming interface that receives chunks one by one and maintains internal state Args: xml_chunk: Single XML chunk string Returns: DeltaMessage: Contains delta information generated by this chunk, returns empty response if no complete elements | #L210-L330 |
StreamingXMLToolCallParser._escape_xml_special_chars |
method | StreamingXMLToolCallParser._escape_xml_special_chars(text: str) -> str |
Escape XML special characters Args: text: Original text Returns: Escaped text | #L332-L351 |
StreamingXMLToolCallParser._process_complete_xml_elements |
method | StreamingXMLToolCallParser._process_complete_xml_elements() -> bool |
Process complete XML elements in buffer Returns: bool: Whether complete elements were found and processed | #L353-L438 |
StreamingXMLToolCallParser._should_skip_element |
method | StreamingXMLToolCallParser._should_skip_element(element: str) -> bool |
Determine whether an element should be skipped Args: element: Element to evaluate Returns: bool: True means should skip, False means should process | #L440-L474 |
StreamingXMLToolCallParser._looks_like_partial_tool_open |
method | StreamingXMLToolCallParser._looks_like_partial_tool_open(fragment: str) -> bool |
True if fragment could complete into a tool-related XML tag. |
#L488-L501 |
StreamingXMLToolCallParser._find_next_complete_element |
method | StreamingXMLToolCallParser._find_next_complete_element(start_pos: int) -> tuple[Optional[str], int] |
Find next complete XML element from specified position Args: start_pos: Position to start searching Returns: (Complete element string, element end position), returns (None, start_pos) if no complete element found | #L503-L569 |
StreamingXMLToolCallParser._merge_new_deltas_to_single_response |
method | StreamingXMLToolCallParser._merge_new_deltas_to_single_response(initial_count: int) -> DeltaMessage |
Merge newly generated deltas from this processing into a single DeltaMessage Args: initial_count: Delta count before processing Returns: Merged DeltaMessage containing all newly generated delta information | #L571-L633 |
StreamingXMLToolCallParser._preprocess_xml_chunk |
method | StreamingXMLToolCallParser._preprocess_xml_chunk(chunk: str) -> str |
Preprocess XML chunk, handle non-standard formats, and escape special characters Args: chunk: Original XML chunk Returns: Processed XML chunk | #L635-L748 |
StreamingXMLToolCallParser._emit_delta |
method | StreamingXMLToolCallParser._emit_delta(delta: DeltaMessage) -> not annotated |
Emit Delta response (streaming output) | #L750-L752 |
StreamingXMLToolCallParser._auto_close_open_parameter_if_needed |
method | StreamingXMLToolCallParser._auto_close_open_parameter_if_needed(incoming_tag: Optional[str] = None) -> not annotated |
Before starting to process new elements, if there are unclosed tags from before, automatically complete their endings to the parser. | #L754-L777 |
StreamingXMLToolCallParser._start_element |
method | StreamingXMLToolCallParser._start_element(name: str, attrs: dict[str, str]) -> not annotated |
Handle XML start element events | #L779-L888 |
StreamingXMLToolCallParser._flush_pending_implicit_delta |
method | StreamingXMLToolCallParser._flush_pending_implicit_delta() -> None |
Emit a deferred bare- |
#L890-L900 |
StreamingXMLToolCallParser._abandon_pending_implicit_tool_call |
method | StreamingXMLToolCallParser._abandon_pending_implicit_tool_call() -> tuple[str, str] |
Roll back a deferred bare- |
#L902-L928 |
StreamingXMLToolCallParser._char_data |
method | StreamingXMLToolCallParser._char_data(data: str) -> not annotated |
Handle XML character data events | #L930-L1025 |
StreamingXMLToolCallParser._end_element |
method | StreamingXMLToolCallParser._end_element(name: str) -> not annotated |
Handle XML end element events | #L1027-L1206 |
StreamingXMLToolCallParser.setup_parser |
method | StreamingXMLToolCallParser.setup_parser() -> not annotated |
Set up XML parser event handlers | #L1208-L1213 |
StreamingXMLToolCallParser.set_tools |
method | StreamingXMLToolCallParser.set_tools(tools: Union[list[ChatCompletionToolsParam], None]) -> not annotated |
Set tool configuration information | #L1215-L1217 |
StreamingXMLToolCallParser._get_next_call_id |
method | StreamingXMLToolCallParser._get_next_call_id() -> not annotated |
Generate unique call ID | #L1219-L1221 |
StreamingXMLToolCallParser._extract_function_name |
method | StreamingXMLToolCallParser._extract_function_name(name: str, attrs: dict[str, str]) -> Optional[str] |
Extract function name from various formats | #L1223-L1233 |
StreamingXMLToolCallParser._extract_parameter_name |
method | StreamingXMLToolCallParser._extract_parameter_name(name: str, attrs: dict[str, str]) -> Optional[str] |
Extract parameter name from various formats | #L1235-L1247 |
StreamingXMLToolCallParser._get_param_type |
method | StreamingXMLToolCallParser._get_param_type(param_name: str) -> str |
Get parameter type based on tool configuration, defaults to string Args: param_name: Parameter name Returns: Parameter type | #L1249-L1287 |
StreamingXMLToolCallParser.repair_param_type |
method | StreamingXMLToolCallParser.repair_param_type(param_type: str) -> str |
Repair unknown parameter types by treating them as string Args: param_type: Parameter type Returns: Repaired parameter type | #L1289-L1315 |
StreamingXMLToolCallParser._convert_param_value |
method | StreamingXMLToolCallParser._convert_param_value(param_value: str, param_type: str) -> Any |
Convert value based on parameter type Args: param_value: Parameter value param_type: Parameter type Returns: Converted value | #L1317-L1371 |
StreamingXMLToolCallParser._convert_for_json_streaming |
method | StreamingXMLToolCallParser._convert_for_json_streaming(converted_value: Any, param_type: str) -> str |
Convert converted_value based on whether it's empty and if type is string Args: converted_value: Converted value param_type: Parameter type Returns: Converted string for streaming output | #L1373-L1395 |
StreamingXMLToolCallParser._reset_xml_parser_after_tool_call |
method | StreamingXMLToolCallParser._reset_xml_parser_after_tool_call() -> not annotated |
Each tool_call is treated as a separate XML document, so we need to reset the parser after each tool_call. | #L1397-L1427 |
Qwen3XMLToolParser |
class | Qwen3XMLToolParser(tokenizer = None) |
XML tool call parser for Qwen 3.5 models, adapted for vllm-mlx. | #L1442-L1559 |
Qwen3XMLToolParser.__init__ |
method | Qwen3XMLToolParser.__init__(tokenizer = None) -> not annotated |
Method Qwen3XMLToolParser.__init__ updates self._xml_parser; calls super().__init__, super, StreamingXMLToolCallParser, logger.info. |
#L1454-L1460 |
Qwen3XMLToolParser._wrap_tools |
method | Qwen3XMLToolParser._wrap_tools(request: dict[str, Any] \| None) -> list[_ToolDef] \| None |
Convert tool definition dicts to _ToolDef wrappers for attribute access. | #L1463-L1467 |
Qwen3XMLToolParser.extract_tool_calls |
method | Qwen3XMLToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation |
Extract tool calls from complete Qwen 3.5 output. | #L1469-L1507 |
Qwen3XMLToolParser.extract_tool_calls_streaming |
method | Qwen3XMLToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] \| None = None, current_token_ids: Sequence[int] \| None = None, delta_token_ids: Sequence[int] \| None = None, request: dict[str, Any] \| None = None) -> dict[str, Any] \| None |
Extract tool calls from streaming Qwen 3.5 output. | #L1509-L1559 |