Skip to main content
A Mistral model decides when to search the web or read a page, and your code runs each call with the Keenable SDK. Mistral’s chat API takes tools in the same format the SDK exports, so you pass TOOLS as is.

How the loop works

  1. Your code sends the conversation and TOOLS to client.chat.complete.
  2. If the model wants the web, the assistant message holds tool_calls (toolCalls in TypeScript), each with an id and a function with name and arguments.
  3. Your code appends the assistant message, runs each call with run_tool_call, and appends one role: "tool" message per call with the tool name, the call id and the result.
  4. When the assistant message has no tool calls, its content is the answer.

Prerequisites

  • A Mistral API key in MISTRAL_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)

Mistral takes each tool as type: "function" with a nested function object holding name, description and parameters. That is the format of the Keenable SDK’s TOOLS:
Chat Completions format
The loop below passes the SDK’s TOOLS directly, 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 Mistral’s SDK:
Save this program as mistral-tools.mts or mistral_tools.py. It asks a question, runs every tool call the model makes, and prints the answer:
Run it with npx tsx mistral-tools.mts or python mistral_tools.py. The program prints the model’s final answer. The question asks for sources, so the answer names the pages the model read. In Python, Mistral’s SDK imports from mistralai.client. The TypeScript SDK uses camelCase fields: toolCalls and toolCallId. If a tool call fails, the loop sends the error message as the tool result so the model can retry. Errors inside a tool call lists what run_tool_call raises.

Differences from other providers