IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

ToolParser

ToolParser​

class max.pipelines.modeling.types.ToolParser(*args, **kwargs)

source

Bases: Protocol

Protocol for parsing tool calls from model responses.

Implementations parse model-specific tool calling formats into generic tool call structures. Supports both complete (non-streaming) and incremental (streaming) parsing modes.

Different model architectures use different tool calling formats:

  • Llama models use JSON-based tool calls.
  • Kimi K2.5 uses structural tags like <|tool_call_begin|>.

The serving layer is responsible for translating these generic types to API-specific schemas (for example, OpenAI).

parse_complete()​

parse_complete(response)

source

Parses a complete response into tool calls.

Parameters:

response (str) – The full model response text.

Returns:

A ParsedToolResponse containing any text content and parsed tool calls.

Raises:

ValueError – If the response cannot be parsed.

Return type:

ParsedToolResponse

parse_delta()​

parse_delta(delta)

source

Parses an incremental token delta for streaming tool calls.

Accumulates tokens internally and returns tool call deltas when complete or partial tool calls can be extracted.

Parameters:

delta (str) – The incremental token(s) to process.

Returns:

  • A non-empty list of ParsedToolCallDelta when new content (tool name, id, or argument bytes) is ready to stream.
  • An empty list [] when the parser has consumed the token and is inside the tool-calls section but has no deltas to emit yet; the caller must suppress the raw token from flowing as text content.
  • None when more tokens are needed before anything can be emitted (e.g. buffering a potential section-begin marker).

Return type:

list[ParsedToolCallDelta] | None

reset()​

reset()

source

Resets internal state for a new streaming session.

Return type:

None