Skip to content

vllm.reasoning.muse_reasoning_parser

Reasoning-content parser for Muse. Port of the reasoning_content rule from the HuggingFace Muse MUSE_GLIMMER_RESPONSE_SCHEMA (synced with internal master). Muse emits chain-of-thought in to=self channels delimited by <|message|> ... <|eom|>: to=self<|message|>...reasoning...<|eom|> Spark also routes recipient-less messages to reasoning, commentary to content, and drops developer messages. The Glimmer compatibility profile retains its original channel semantics. Because Muse's framing markers (<|message|>, <|eom|>) are not guaranteed to be single vocab tokens across every checkpoint's tokenizer, this parser works on the decoded text with regexes rather than the single start/end-token base class. Usage: --reasoning-parser muse

Classes:

MuseReasoningParser

Bases: ReasoningParser

Methods:

_classify_bodies(text) classmethod

Split text into (reasoning_body, content_body), channel-aware. Framing markers and tool channels contribute nothing -- the tool parser owns those. A body ends at <|eom|> / <|eot|>, at the next channel header, or at end-of-text (an OPEN body, which is held back).

_scoped_turn(text) classmethod

Current assistant turn with reasoning spans removed.

_tool_channel_remainder(text) classmethod

Text from the first tool-channel header onward, framing INCLUDED. DelegatingParser.parse_delta rebuilds current_text from whatever this parser returns as .content on the transition delta and commits it; anything not returned is destroyed. It must start AT the to=<name><|message|> header -- handing over the text after the header loses the recipient, and the tool parser then sees a bare <|message|>, classifies it as the content channel, and leaks the ATEM markup.

adjust_request(request)

Preserve Muse's ATEM framing tokens in the decoded output. vLLM's serving default is skip_special_tokens=True, which strips <|start|> / <|message|> / <|eom|> / <|eot|> before the parsers run, collapsing reasoning into content and breaking channel scoping. Unlike the base tool-parser hook we do NOT touch structured_outputs -- Muse emits native ATEM, not JSON.

count_reasoning_tokens(token_ids)

Count reasoning-body tokens, excluding header and marker tokens.

extract_reasoning_streaming(previous_text, current_text, delta_text, previous_token_ids, current_token_ids, delta_token_ids)

Channel-aware streaming split of reasoning vs content. Classifies the full current_text and emits only what has not been emitted yet, so no framing token is ever surfaced and a delta straddling a channel boundary only contributes the portion inside a real body.

get_streaming_fallback_content(previous_text, request)

Promote un-surfaced content when the stream ends mid-reasoning. DelegatingParser.finalize_generation calls this when reasoning_ended is still False. Returns only the channel-classified to=user body, and only the portion not already streamed.

is_reasoning_end(input_ids)

Whether the model has left reasoning and opened a TOOL channel. A to=user answer is NOT a reason to leave the reasoning phase -- this parser surfaces that content itself. Only a real tool channel switches the DelegatingParser phase machine over to the tool parser. Both closed and unterminated reasoning spans are stripped before the check, so an <atem:invoke> the model merely echoes inside its CoT never flips the phase.

_current_assistant_turn(text)

Return only the text generated in the current assistant turn. is_reasoning_end is evaluated on the PROMPT token-ids at stream start, and an Muse prompt legitimately contains ATEM markers (render_tool_defs writes a literal <atem:function_calls> example into the system message, and prior assistant turns may carry real tool calls). Anchoring on the last channel-open keeps prompt text from deciding the phase.

_muse_messages(text)

Yield recipient, body, completion status, and framed text per message.

_trim_open_body(body)

Hold back any tail of a still-growing body that could still be framing. Iterated to a fixpoint because the two cases compose: " to=skill<" needs the partial-marker trim (<) before the partial-header trim can see " to=skill". Trimming only once leaks the recipient name as reasoning.