Skip to content

vllm.tool_parsers.poolside_v1_tool_parser

GLM-4 Tool Call Parser with incremental string streaming support.

This parser fixes the streaming issue reported in Issue #32829 where long string parameters (e.g., file content with 4000+ characters of code) are buffered until complete, causing multi-second delays before the user sees any content.

The fix streams string values incrementally as they arrive, providing a true streaming experience for long content.

Classes:

PoolsideV1ToolParser

Bases: ToolParser

Tool parser for GLM-4 models with incremental string streaming.

This parser emits tool-call deltas incrementally as arguments arrive. For string-type parameters, content is streamed character-by-character rather than waiting for the complete tag.

Methods:

  • adjust_request –

    Adjust request parameters for tool call token handling.

_allowed_types(tool_name, arg_name, tools)

JSON types the argument's schema admits; None if unconstrained.

_complete_json_prefix(json_prefix, allowed_partial_types) staticmethod

Complete a partial JSON prefix into a valid JSON object.

Returns (formatted_prefix, parsed_dict) or None on failure.

Note: partial_json_parser strips trailing whitespace before parsing (complete.py:20), which means the returned slice is shorter than json_prefix when it has trailing whitespace. Since the parser controls the construction of the json_prefix value, this code relies on it being a valid prefix and we only use the fix for the completion of the JSON object.

_json_escape_string_content(s) staticmethod

JSON-escape string content for incremental streaming.

This escapes the content that goes INSIDE a JSON string (between quotes), not including the surrounding quotes themselves.

_revert_last_tool_call_state()

Revert the state allocation for the last tool call.

_tools_enabled(request) staticmethod

Return whether tool parsing should be applied for this request.

adjust_request(request)

Adjust request parameters for tool call token handling.

For required/named tool_choice, skip super().adjust_request() so it does not install JSON guided decoding. These models emit XML tool calls (per the chat template), which JSON guidance would break.