setTools

fun setTools(toolsJson: String?)

Sets the tool (function) definitions for tool use (function calling). The tools are rendered into the prompt through the chat template on the next setPromptJson call, the output is constrained to the tool call syntax, and the buffered output can be retrieved with getResponseJson().

While tools are set, setPrompt fails with INVALID_STATE. Use setPromptJson from the first turn and retrieve the assistant with getResponseJson(). Delta text remains available for optional streaming previews.

Available for models whose chat template supports tool calling (e.g. Gemma 4).

Parameters

toolsJson

OpenAI-compatible JSON array of tool definitions, e.g. {"type":"function","function":{"name":"get_weather","description":"...","parameters":{...}}} Pass null or an empty string to clear the tools.

Throws

if the JSON is invalid or the operation fails