Skip to content

vllm.parser.engine.streaming_parser_engine

Streaming parser engine that orchestrates token ID scanning, incremental lexing, and state-machine-driven semantic event emission.

Classes:

StreamingParserEngine

Consumes (delta_text, delta_token_ids) pairs and produces a stream of SemanticEvent instances.

This is the main entry point for streaming parsing. Create one per request (it is stateful).

The pipeline is::

delta_text + delta_token_ids
    → TokenIDScanner  (special token pre-lexing)
    → IncrementalLexer  (text → terminal tokens with prefix buffering)
    → State Machine  (terminal → semantic events)
    → list[SemanticEvent]

Usage::

engine = StreamingParserEngine(config, tokenizer)
for each streaming delta:
    events = engine.feed(delta_text, delta_token_ids)
    # convert events to DeltaMessage

Methods:

  • reset –

    Reset mutable state for reuse across requests.

_compute_reasoning_markup_terminals()

Terminals the skip_reasoning_parsing bypass may neutralize.

Only reasoning-exclusive markers qualify: every transition they participate in stays within CONTENT/REASONING and emits nothing but reasoning events. Inkling's <|end_message|> is labelled THINK_END yet also closes text, header, and tool blocks; bypassing a shared marker would eat that structure, so one impure marker disables the bypass for the whole config.

_feed_args_text(text)

Feed text into the JSON argument streaming buffer.

Streams argument characters incrementally while holding back closing braces/brackets that might change as more input arrives.

_feed_json_collection_text(text)

Split a framed sequence of JSON objects into individual tool calls.

_flush_safe_args()

Emit buffered argument characters up to the safe-end watermark.

Top-level closing braces are held back (safe_end not advanced) until confirmed safe by a subsequent character or finish().

reset(initial_state=None)

Reset mutable state for reuse across requests.

Preserves cached immutable structures (compiled terminals, resolved token IDs, lexer shape, token text cache) to avoid redundant initialization work.