toolResponsePayload static method
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.
Implementation
static Map<String, Object?> toolResponsePayload(String text) {
try {
final decoded = jsonDecode(text);
if (decoded is Map<String, dynamic>) return decoded;
return {'value': decoded};
} on FormatException {
return {'value': text};
}
}