Skip to content

vllm.tool_parsers.muse_tool_parser

ATEM tool-call parser for Muse (Muse Spark and Muse Glimmer).

Port of the response_schema tool-call contract from the HuggingFace Muse Glimmer export (convert_muse_glimmer_weights_to_hf.py: MUSE_GLIMMER_RESPONSE_SCHEMA), which Muse Spark shares.

Muse 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|>

to=commentary messages are user-visible updates between tool calls, and like to=user messages they are content; to=developer messages are dropped. 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

Classes:

MuseToolParser

Bases: ToolParser

Methods:

_extract_content(text) classmethod

Return the user-facing body, or the raw text when unframed.

_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 fills in the *: with the name again (get_weather.get_weather), but also with a parameter, a verb or nothing (get_weather.city, get_weather.fetch, get_weather.). The doubled form always collapses to the registered head. Any other suffix collapses only when no registered name lives under head.: with get_weather.temperature also registered, get_weather.fetch may mean a missing sibling, not the bare tool.

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.

_registered_names(request) staticmethod

Names of the tools the client registered on this request.

_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.

_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.

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). Muse 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".

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 Muse parameters are not incremental JSON, so there is nothing meaningful to stream before then.

_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.

_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.

_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.

_trailing_partial_marker_len(text)

Length of the longest suffix of text that prefixes a structural marker.