Converts to a JSON object matching the Ollama API tool call format.
Arguments passed to the function (JSON object).
Optional tool call identifier.
Name of the function called.
// ToolFunction serialization auto tf = ToolFunction("get_weather", "Fetch weather data", parseJSON(`{"type":"object","properties":{"city":{"type":"string"}}}`)); auto jtf = tf.toJson(); assert(jtf["name"].str == "get_weather"); assert(jtf["description"].str == "Fetch weather data"); assert(jtf["parameters"]["type"].str == "object"); // Tool serialization — JSON key must be "function" (not "function_") auto tool = Tool("function", tf); auto jt = tool.toJson(); assert(jt["type"].str == "function"); assert("function" in jt); assert(jt["function"]["name"].str == "get_weather"); // ToolCall with id and arguments auto tc = ToolCall("call-1", "get_weather", parseJSON(`{"city":"Paris"}`)); auto jtc = tc.toJson(); assert(jtc["id"].str == "call-1"); assert(jtc["function"]["name"].str == "get_weather"); assert(jtc["function"]["arguments"]["city"].str == "Paris"); // ToolCall without id — id key must be absent auto tc2 = ToolCall("", "sum", parseJSON(`{"a":1,"b":2}`)); auto jtc2 = tc2.toJson(); assert("id" !in jtc2); assert(jtc2["function"]["name"].str == "sum");
Represents a tool/function call made by the model in a chat response.
Access via response["message"]["tool_calls"] when the model calls a tool.