Tools
Describe your own functions and Kiwi asks you to run them. You run them, and you send the result back.
Define a tool
A tool has a name, a description that says when to use it, and an input_schema (JSON Schema for its arguments).
{
"max_tokens": 1024,
"tools": [{
"name": "get_weather",
"description": "The weather in a city right now.",
"input_schema": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}],
"messages": [{ "role": "user", "content": "What is the weather in Almaty?" }]
}Kiwi asks for a call
When Kiwi wants the function run, the answer has a tool_use block and stop_reason is tool_use.
{
"id": "msg_9a1d...",
"type": "message",
"role": "assistant",
"content": [
{ "type": "tool_use", "id": "call_1", "name": "get_weather", "input": { "city": "Almaty" } }
],
"stop_reason": "tool_use",
"usage": { "input_tokens": 61, "output_tokens": 18 }
}Send the result
Run the function yourself, then send the conversation again with the assistant's message and a tool_result block in a user message. Send the same tools again.
{
"max_tokens": 1024,
"tools": [ ... the same tools ... ],
"messages": [
{ "role": "user", "content": "What is the weather in Almaty?" },
{ "role": "assistant", "content": [
{ "type": "tool_use", "id": "call_1", "name": "get_weather", "input": { "city": "Almaty" } }
]},
{ "role": "user", "content": [
{ "type": "tool_result", "tool_use_id": "call_1", "content": "4 C, light snow" }
]}
]
}Things to know
Tool calls are decided by the model and can be wrong: check the arguments before you act on them, above all before anything that cannot be undone. Earlier tool calls and results are given back to Kiwi as plain text, and several calls in one turn are possible. tool_choice says whether a call is required or forbidden (see Messages). Kiwi's own tools, such as web search, are separate from yours and are switched with tool_access and search.