SdkResponseParser class

Parser for LiteRT-LM SDK Chat Completions JSON responses.

Used by InferenceChat when the active session backend exposes lastRawResponse (FFI/LiteRT-LM path with structured tool_calls). The SDK already converts native <|tool_call>...<tool_call|> Gemma 4 tokens into OpenAI-style JSON via chat_template.jinja + minja, so this helper just walks the JSON and surfaces FunctionCallResponses.

Parsing rules mirror upstream Python Conversation._handle_tool_calls (python/litert_lm/conversation.py).

Constructors

SdkResponseParser()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

buildToolResponsesJson(List<({String name, Object? response})> responses) → String
Build the role-tool message that returns a turn's tool results to the model. One message carries every result, so a model that made parallel calls reads all of their answers before it continues. The item shape mirrors upstream Python Conversation._handle_tool_calls ({"type": "tool_response", "name", "response"}), which the Gemma 4 and FunctionGemma data processors format natively — as <|tool_response>response:NAME{...}<tool_response|> and <start_function_response>response:NAME{...}<end_function_response>.
cleanRawForHistory(String rawJson) → String
Clean a raw SDK response JSON string by recursively stripping <|"|> escape tokens. Used by chat.dart before writing the assistant turn into chat history — without this the next request echoes the escape tokens back to the model and Gemma 4 starts reproducing them in subsequent tool_calls arguments (#248).
extractToolCalls(String jsonStr) → List<FunctionCallResponse>
Extract all function calls from an SDK response JSON string.
serializeToolsForSdk(List<Tool> tools) → String
Serialize tools into the OpenAI Chat Completions JSON format that LiteRT-LM SDK expects in litert_lm_conversation_config_set_tools. SDK then applies chat_template.jinja (via minja) to render native Gemma 4 <|tool>declaration:...<tool|> tokens.
toolResponsePayload(String text) → Map<String, Object?>
The response object for a tool result carried in Message.text, which Message.toolResponse fills with the JSON-encoded map. The runtime formats an object as NAME{key:value,...}; anything else — a hand-built message holding plain text — goes under value, the key FunctionGemma's template uses for a scalar response.