vllm.parser.engine.parser_engine
¶
Parser engine base that handles both reasoning and tool call
extraction with a single StreamingParserEngine.
Classes:
-
ParserEngine–A
Parserbacked by a single declarative engine config. -
ReasoningEnd–Where reasoning ends in a token sequence.
-
ToolCallSlot–
ParserEngine
¶
Bases: Parser
A Parser backed by a single declarative engine config.
Subclasses set the ParserEngineConfig in __init__ to define the
complete output format for a model (reasoning + tool calls).
Methods:
-
adjust_initial_state_from_prompt–See
ReasoningParser.adjust_initial_state_from_prompt. -
count_reasoning_tokens–Return reasoning tokens observed by the parser engine so far.
-
extract_tool_calls_from_content–Extract tool calls from reasoning-stripped content.
-
find_reasoning_end–First reasoning end in
token_ids, and if its token is content. -
set_prompt_token_ids–Start parsing in content when the prompt already closes reasoning,
Attributes:
-
implicit_reasoning_end_token_ids(frozenset[int]) –Reasoning-end tokens that are also content, e.g. a tool-call start.
implicit_reasoning_end_token_ids
property
¶
Reasoning-end tokens that are also content, e.g. a tool-call start.
_coalesce_tool_call_deltas(deltas)
staticmethod
¶
Merge entries that share the same index into one per index.
_coerce_dict(args, properties)
staticmethod
¶
Coerce all values in args using properties schemas.
_coerce_value(value, schema)
staticmethod
¶
Coerce a single value according to its schema.
Returns (coerced_value, changed).
_fix_arg_types(args_json, func_name)
¶
Correct parameter types using the tool schema.
String values are coerced via coerce_to_schema_type.
Nested objects and arrays are recursed into when the schema
defines properties or items. Without a schema, values
stay as strings.
_safe_arg_prefix(json_str, string_keys=None)
staticmethod
¶
Return the prefix of json_str up to the last top-level value.
Middle values (followed by a comma) are stable across streaming
ticks and included. The trailing value is excluded for non-string
values because type coercion may change its serialised form between
ticks, which would violate the startswith(prev) prefix invariant.
String values for keys in string_keys are prefix-stable, so stream
their unterminated content instead of buffering long arguments until
the closing tag arrives.
Also returns whether the returned prefix stops inside that trailing string, so streamed text may be appended to it. This holds even when json_str closes the string: converters serialise an open raw value as a closed JSON string.
_single_pass_parse(text, token_ids, initial_state=None)
¶
Reset, feed, finish, and extract results in one pass.
Must be called as a unit — _events_to_delta populates tool
state that _build_extracted_result reads.
_streamable_string_keys(properties)
staticmethod
¶
Return keys whose trailing string values can safely stream.
None means there is no schema, so all string values keep their
JSON representation as strings. With a schema, only fields that can
remain strings are safe to emit before the value is closed; fields
coerced to bool/number/null/object/array may serialize differently.
_strip_trailing_reasoning(delta)
¶
Strip trailing whitespace from reasoning, deferring it until we know whether more reasoning follows or reasoning has ended.
Runs in parse_delta after _events_to_delta (and any
subclass overrides) so that overrides see the raw reasoning text.
Gated by strip_trailing_reasoning_whitespace; when disabled,
passes through unchanged.
adjust_initial_state_from_prompt(prompt_token_ids)
¶
See ReasoningParser.adjust_initial_state_from_prompt.
count_reasoning_tokens(token_ids)
¶
Return reasoning tokens observed by the parser engine so far.
extract_tool_calls_from_content(content, request)
¶
Extract tool calls from reasoning-stripped content.
Unlike extract_tool_calls which re-parses the full model
output, this method starts the parser engine in CONTENT state
so it can parse content that has already had reasoning stripped.
find_reasoning_end(token_ids)
¶
First reasoning end in token_ids, and if its token is content.
set_prompt_token_ids(prompt_token_ids)
¶
Start parsing in content when the prompt already closes reasoning, as with continue_final_message or a template that switches thinking off. Only configs with turn boundaries can tell a closed block in this turn from one in an earlier turn, so others are left as is.
ReasoningEnd
¶
ToolCallSlot
¶
Methods:
-
search_name–Group 1 of the leftmost
patternmatch in the args, orNone.
search_name(pattern)
¶
Group 1 of the leftmost pattern match in the args, or None.
Each call scans only the args appended since the last call, plus the tail where a partial match may still complete. The first match is kept as the slot's name for its lifetime, so every call must pass the same name pattern.