Python class
ToolParser
ToolParser
class max.interfaces.ToolParser(*args, **kwargs)
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)
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:
parse_delta()
parse_delta(delta)
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 list of tool call deltas if any can be extracted, or None if more tokens are needed.
-
Return type:
-
list[ParsedToolCallDelta] | None
reset()
reset()
Resets internal state for a new streaming session.
-
Return type:
-
None
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!