-- SPDX-FileCopyrightText: © 2026 Vladimir Zorin -- SPDX-License-Identifier: LicenseRef-OWL-1.0-or-later -- Licensed under OWL v1.0+. See LICENSE. local json = require("cjson.safe") local M = {} local stringify_output = function(output) if type(output) == "string" then return output end if output == nil then return "" end local ok, encoded = pcall(json.encode, output) if ok and encoded then return encoded end return tostring(output) end function M.build_tool_result_message(call_id, output) return { role = "tool", tool_call_id = call_id, content = stringify_output(output), } end return M