Skip to main content
Gemini decides when to search the web or read a page, and your code runs each call with the Keenable SDK. This page uses the Interactions API in Google’s Gen AI SDKs, google-genai for Python and @google/genai for TypeScript.

How the loop works

  1. Your code sends the question and the Keenable tools to client.interactions.create.
  2. If Gemini wants the web, interaction.steps holds one function_call step per call, each with a name, an id and an arguments object.
  3. Your code runs each call with run_tool_call and sends one function_result item per call, with call_id set to the step’s id, in a new request that sets previous_interaction_id.
  4. When the steps hold no function_call, interaction.output_text is the answer.

Prerequisites

  • A Gemini API key in GEMINI_API_KEY.
  • Python 3 or Node.js with tsx to run the program.
  • No Keenable key. The SDK searches without one. To raise the rate limit, set KEENABLE_API_KEY to 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
The loop below builds this list from the SDK’s 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:
Save this program as gemini-tools.mts or gemini_tools.py. It asks a question, runs every tool call Gemini makes, and prints the answer:
Run it with 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.

Differences from other providers