vllm_mlx.tool_parsers.auto_tool_parser¶
Auto-detecting tool call parser for vllm-mlx.
View the complete module source at #L1-L414.
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.auto_tool_parser
¶
Auto-detecting tool call parser for vllm-mlx.
Automatically detects and parses tool calls from various model formats.
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser
¶
Bases: ToolParser
Auto-detecting tool call parser.
Tries multiple formats in order:
1. Gemma 4: <|tool_call>call:name{...}
This is the default parser when no specific parser is selected.
Source code in vllm_mlx/tool_parsers/abstract_tool_parser.py
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.MISTRAL_TOKEN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.QWEN_BRACKET_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.QWEN_XML_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.LLAMA_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.NEMOTRON_PATTERN
class-attribute
instance-attribute
¶
NEMOTRON_PATTERN = re.compile('<tool_call>\\s*<function=([^>]+)>(.*?)</function>\\s*</tool_call>', re.DOTALL)
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.NEMOTRON_PARAM_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.BARE_BRACKET_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.BARE_BRACKET_PARTIAL_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.extract_tool_calls
¶
extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls by trying all known formats.
Source code in vllm_mlx/tool_parsers/auto_tool_parser.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 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 | |
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser._parse_raw_json_tool_calls
¶
Parse raw JSON tool calls from text.
Handles: - Single JSON object: {"name": "func", "arguments": {...}} - JSON array: [{...}, {...}]
Source code in vllm_mlx/tool_parsers/auto_tool_parser.py
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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.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 model output.
Uses simple heuristics to detect when a tool call might be complete.
Source code in vllm_mlx/tool_parsers/auto_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.auto_tool_parser.generate_tool_id · function
Generate a unique tool call ID.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
f'call_{uuid.uuid4().hex[:8]}'
Exceptions and behavior
Function generate_tool_id calls uuid.uuid4; returns f'call_{uuid.uuid4().hex[:8]}'.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser · class
Auto-detecting tool call parser.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser
Exceptions and behavior
Class AutoToolParser derives from ToolParser and declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.extract_tool_calls · method
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls by trying all known formats.
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:
result;ExtractedToolCallInformation(tools_called=True, tool_calls=tool_calls, content=content if content else None);ExtractedToolCallInformation(tools_called=True, tool_calls=tool_calls, content=cleaned_text if cleaned_text else None);ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=model_output)
Exceptions and behavior
Method AutoToolParser.extract_tool_calls calls Gemma4ToolParser, gemma_parser.extract_tool_calls, model_output.split, parts[0].strip; has 4 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser._parse_raw_json_tool_calls · method
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser._parse_raw_json_tool_calls(text: str) -> list[dict[str, Any]]
Parse raw JSON tool calls from text.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[dict[str, Any]] - Direct return expressions:
[];tool_calls
Exceptions and behavior
Method AutoToolParser._parse_raw_json_tool_calls calls text.strip, text.startswith, json.loads, isinstance; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.extract_tool_calls_streaming · method
vllm_mlx.tool_parsers.auto_tool_parser.AutoToolParser.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 model 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;{'content': delta_text};{'tool_calls': [{'index': i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'arguments': tc['argu…
Exceptions and behavior
Method AutoToolParser.extract_tool_calls_streaming calls any, self.BARE_BRACKET_PARTIAL_PATTERN.search, self.BARE_BRACKET_PATTERN.search, self.extract_tool_calls; 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 |
|---|---|---|---|---|
generate_tool_id |
function | generate_tool_id() -> str |
Generate a unique tool call ID. | #L22-L24 |
AutoToolParser |
class | AutoToolParser() |
Auto-detecting tool call parser. | #L28-L414 |
AutoToolParser.extract_tool_calls |
method | AutoToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation |
Extract tool calls by trying all known formats. | #L61-L268 |
AutoToolParser._parse_raw_json_tool_calls |
method | AutoToolParser._parse_raw_json_tool_calls(text: str) -> list[dict[str, Any]] |
Parse raw JSON tool calls from text. | #L270-L350 |
AutoToolParser.extract_tool_calls_streaming |
method | AutoToolParser.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 model output. | #L352-L414 |