vllm.tool_parsers.muse_glimmer_tool_parser ¶
ATEM tool-call parser for MuseGlimmer.
Faithful port of the MuseGlimmer response_schema tool-call contract from the HuggingFace MuseGlimmer export (convert_muse_glimmer_weights_to_hf.py: MUSE_GLIMMER_RESPONSE_SCHEMA).
MuseGlimmer emits tool calls in an XML-ish ATEM format inside channel-scoped messages:
<|start|>assistant to=self<|message|>...reasoning...<|eom|>
<|start|>assistant to=<tool>.<fn><|message|>
<atem:function_calls>
<atem:invoke name="tool.fn">
<atem:parameter name="arg">value</atem:parameter>
</atem:invoke>
</atem:function_calls><|eom|> # non-final call
<|start|>assistant to=user<|message|>...final answer...<|eot|>
Channel scoping is essential: an <atem:invoke> echoed inside a to=self reasoning block or a to=user final answer must NOT be parsed as a real tool call.
Rather than subtracting reasoning/answer spans with regex substitutions (the approach the HF response_schema uses, which is safe only on a complete, well-formed turn), this parser segments the output into messages and then selects the tool-channel bodies. On a complete turn the two are equivalent; on a truncated or damaged turn, subtraction can delete a valid tool call (an unterminated to=self block makes the non-greedy strip run to the next <|eom|>, which belongs to the tool-call message) whereas selection cannot.
Usage: --enable-auto-tool-choice --tool-call-parser muse_glimmer
Classes:
MuseGlimmerToolParser ¶
Bases: ToolParser
Methods:
-
adjust_request–Force special tokens through, and keep JSON guided decoding off.
-
extract_tool_calls_streaming–Incremental ATEM streaming for tool calls AND content.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
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 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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 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 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
_extract_content(text) classmethod ¶
Return the user-facing body, or the raw text when unframed.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
_normalize_name(emitted, registered) staticmethod ¶
Map an emitted ATEM invoke name back to a registered tool name.
When a client registers a BARE name (e.g. get_weather) the shipped chat template renders the valid recipient as "get_weather.*", and the model duly emits get_weather.get_weather. Collapsing that doubled form is safe: head and tail are identical and the collapsed name is registered.
Anything else is passed through unchanged. Matching on the trailing segment alone is NOT safe -- an emitted weather.get against a registered {calendar.get} has a unique leaf match and would silently dispatch the wrong tool.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
_registered_names(request) staticmethod ¶
Names of the tools the client registered on this request.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
_tool_channel_text(text) classmethod ¶
Concatenate the bodies of messages addressed to a tool.
Falls back to the whole text when no message header is present at all -- that means the framing never reached us (skip_special_tokens was on, or the chunk carrying the header was dropped upstream), and scanning everything is strictly better than returning nothing.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
_visible_channels(text) classmethod ¶
Return (content, reasoning, content_open, reasoning_open).
The *_open flags say whether that channel's LAST message is still being generated; only then must the caller hold back a partial structural marker. Tracking them per channel matters: a closed reasoning block whose text happens to end in < would otherwise stay permanently truncated while a later content message is open.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
adjust_request(request) ¶
Force special tokens through, and keep JSON guided decoding off.
skip_special_tokens defaults to True on both ChatCompletionRequest and ResponsesRequest. Every rule in this parser keys off <|message|> / <|eom|> / <|eot|> / <|start|>, so with the default the channel framing is stripped before we see it: message segmentation finds nothing, reasoning-channel invokes are indistinguishable from real ones, and the raw ATEM markup falls through to the client as content. Set it unconditionally and FIRST -- not only for tools requests, and not relying on the reasoning parser to have set it.
For required/named tool_choice the base hook installs a JSON schema constraint (ToolParser.adjust_request -> get_json_schema_from_tools). MuseGlimmer emits ATEM XML, so under that constraint it writes JSON inside the tool channel -- <atem:function_calls>[{"name": ... -- with no <atem:invoke> for this parser to find. Skip the base hook so those choices decode natively, the same as "auto".
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
extract_tool_calls_streaming(previous_text, current_text, delta_text, previous_token_ids, current_token_ids, delta_token_ids, request) ¶
Incremental ATEM streaming for tool calls AND content.
This parser owns every delta once reasoning has ended: in vllm/parser/abstract_parser.py::parse_delta the "pass through as content" fallback is guarded by not self._in_tool_call_phase(state), and _in_tool_call_phase is simply tool_parser is not None and state.reasoning_ended. So with a tool parser loaded that fallback is dead code, and returning None here DISCARDS the delta. Anything we do not emit -- including the to=user final answer -- never reaches the client. Hence content is emitted here, not left to the reasoning parser.
Tool calls are surfaced only when an <atem:invoke> block becomes complete: the XML is opaque until closed and MuseGlimmer parameters are not incremental JSON, so there is nothing meaningful to stream before then.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
_decode_value(raw) ¶
JSON-decode a parameter value when possible, else keep the raw string.
Mirrors the schema's x-parser: json with allow_non_json: True.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
_iter_messages(text) ¶
Segment text into assistant messages.
Yields (recipient, body, closed) per message, where recipient is None for a bare <|message|> header and closed is False for a message that has not (yet) seen <|eom|> / <|eot|>.
A message is also terminated by the start of the NEXT header. Without that, a reasoning block whose <|eom|> is missing (truncation, or a chunk dropped at the reasoning -> tool transition) would absorb the tool-call message that follows it and the call would be lost -- the same defect the subtractive regexes have.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
_safe_open_body(body) ¶
Trim the tail of a still-growing body to what is safe to emit now.
Holds back anything that could still turn out to be structural, so the emitted prefix only ever grows. Chunks under speculative decoding are large enough that markers routinely straddle them.
Source code in vllm/tool_parsers/muse_glimmer_tool_parser.py
_trailing_partial_marker_len(text) ¶
Length of the longest suffix of text that prefixes a structural marker.