TOOLS unchanged and use the loop on Tool calling.
How the loop works
- Your code sends the question and the Keenable tools to
client.responses.create. - If the model wants the web,
response.outputholds onefunction_callitem per call, each with aname, acall_idandargumentsas a JSON string. - Your code runs each call with
run_tool_calland sends onefunction_call_outputitem per call, with the matchingcall_id, in a new request that setsprevious_response_id. - When the output holds no
function_callitem,response.output_textis the answer.
Prerequisites
- An OpenAI API key in
OPENAI_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)
Responses API function tools are flat:name, description and parameters sit next to type, with no nested function object. These are the Keenable SDK’s definitions in that shape:
OpenAI Responses format
strict is false because the search tool has optional arguments, and OpenAI’s strict mode requires every property to be listed in required. If you leave strict out, the Responses API tries to make the schema strict and falls back to non-strict when it can’t.
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 OpenAI’s SDK:openai-tools.mts or openai_tools.py. It asks a question, runs every tool call the model makes, and prints the answer:
npx tsx openai-tools.mts or python openai_tools.py. The program prints the model’s final answer. The question asks for sources, so the answer names the pages the model read.
previous_response_id makes OpenAI keep the conversation between requests, so each follow-up sends only the tool outputs. To keep the conversation on your side instead, append response.output and your function_call_output items to an input list and send the whole list each time. If a tool call fails, the loop sends the error message as the output so the model can retry. Errors inside a tool call lists what run_tool_call raises.