google-genai for Python and @google/genai for TypeScript.
How the loop works
- Your code sends the question and the Keenable tools to
client.interactions.create. - If Gemini wants the web,
interaction.stepsholds onefunction_callstep per call, each with aname, anidand anargumentsobject. - Your code runs each call with
run_tool_calland sends onefunction_resultitem per call, withcall_idset to the step’sid, in a new request that setsprevious_interaction_id. - When the steps hold no
function_call,interaction.output_textis the answer.
Prerequisites
- A Gemini API key in
GEMINI_API_KEY. - Python 3 or Node.js with
tsxto run the program. - No Keenable key. The SDK searches without one. To raise the rate limit, set
KEENABLE_API_KEYto an API key.
Tool definition (copy verbatim)
Interactions API function tools are flat:name, description and parameters sit next to type: "function". These are the Keenable SDK’s definitions in that shape:
Gemini Interactions format
TOOLS at run time, so the definitions always match the SDK version you installed. If you paste the JSON instead, check the SDK column of the arguments table: an older run_tool_call drops any argument its version doesn’t offer.
Run the loop
Install the Keenable SDK and Google’s Gen AI SDK:gemini-tools.mts or gemini_tools.py. It asks a question, runs every tool call Gemini makes, and prints the answer:
npx tsx gemini-tools.mts or python gemini_tools.py. The program prints Gemini’s final answer. The question asks for sources, so the answer names the pages Gemini read.
Each function_result carries the Keenable text as a single text part. If a tool call fails, the loop sets is_error: true and sends the error message, so Gemini can try another query or URL. Errors inside a tool call lists what run_tool_call raises.