buildToolResponseJson static method
Build the JSON message that delivers a tool execution result back to
the model on the next turn. Format mirrors upstream Python
serve.py::gemini_to_litertlm_message and Gemma 4 data processor's
FormatToolResponse.
SDK then renders this as native
<|tool_response>response:NAME{...}<tool_response|> tokens.
Implementation
static String buildToolResponseJson({
required String toolName,
required Object? response,
String? toolCallId,
}) =>
jsonEncode({
'role': 'tool',
'content': [
{
'name': toolName,
'response': response,
},
],
if (toolCallId != null) 'tool_call_id': toolCallId,
});