Skip to content

vllm.tool_parsers.streaming

Classes:

Functions:

RequiredToolCallScanner dataclass

Incremental scanner owning the text of one required-tool-call stream.

Methods:

  • scan –

    Append and scan new text, retaining lexical state across deltas.

scan(delta_text)

Append and scan new text, retaining lexical state across deltas.

_RequiredToolCallSpan dataclass

Where one element of a tool_choice="required" array sits in the text.

The model output for tool_choice="required" is a JSON array of {"name": ..., "parameters": ...} objects. name is only set once its string value is closed and decodes as JSON; name_end is the offset just past that closing quote. args_start/args_end are the character offsets of the parameters value (args_end is None while the value is still being generated).

All offsets are prefix-stable: scanning any prefix of the text yields the same spans truncated to that prefix. That is what lets one scan of the current text tell what an earlier, shorter text had already revealed.

Methods:

  • ready_at –

    Whether the first length characters of the text already made

ready_at(length)

Whether the first length characters of the text already made this call streamable: its name was complete and its parameters value had started.

extract_named_tool_call_streaming(*, delta_text, function_name, function_name_returned, tool_call_idx, tool_call_id_type, tokenizer, tool_call_array_index=0)

Build a streaming tool-call delta for forced named tool choice.

extract_required_tool_call_streaming(*, delta_text, scanner, tool_call_idx, tool_call_id_type)

Stream required tool calls from new text using a per-stream scanner.

The first chunk of each call carries its id, name and available arguments; subsequent chunks carry only new argument text. A delta may start several calls. The scanner owns accumulated text and lexical state.