Tool calling
Tool calling lets a model ask you to run a function and then use the result. The
wire format is OpenAI’s tools / tool_choice.
Check before you build:
curl "https://api.resetdata.ai/api/v1/models/detail?slug=zai/glm-5.2" \ -H "Authorization: Bearer $RESETDATA_API_KEY" \ | jq '.supported_parameters | map(select(. == "tools" or . == "tool_choice"))'Several capable text models — and all image, audio, embedding and reranker models — do not offer tool calling. The catalog in the app shows a Function-calling badge derived from the same check.
The loop
Section titled “The loop”tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a city.", "parameters": { "type": "object", "properties": { "city": {"type": "string", "description": "City name"}, }, "required": ["city"], }, },}]
messages = [{"role": "user", "content": "What's the weather in Sydney?"}]
resp = client.chat.completions.create( model="zai/glm-5.2", messages=messages, tools=tools,)msg = resp.choices[0].message
if msg.tool_calls: messages.append(msg) # keep the model's request for call in msg.tool_calls: args = json.loads(call.function.arguments) result = get_weather(**args) # you run it messages.append({ "role": "tool", "tool_call_id": call.id, "content": json.dumps(result), })
resp = client.chat.completions.create( # send results back model="zai/glm-5.2", messages=messages, tools=tools, )
print(resp.choices[0].message.content)Four steps: you send tools, the model asks for one, you execute it and append the
result with its tool_call_id, then call again so the model can answer. We
never execute anything — tools run entirely in your code.
Controlling when tools are used
Section titled “Controlling when tools are used”tool_choice |
Behaviour |
|---|---|
"auto" |
Model decides. The usual choice. |
"none" |
Never call a tool. |
{"type": "function", "function": {"name": "..."}} |
Force a specific tool. |
Practical notes
Section titled “Practical notes”- Descriptions are the interface. The model chooses from your
descriptiontext, so write it for a reader who cannot see your code. - Validate arguments. Arguments are model-generated JSON. Parse defensively and never pass them unchecked into anything with side effects.
- Handle several calls at once.
tool_callsis an array; a model may request multiple tools in one turn. - Every turn costs tokens. Tool definitions are re-sent as input on each call, and the loop means several round trips per user question — see Usage and costs.
- Bound the loop. Cap iterations so a model that keeps requesting tools cannot spin indefinitely.
- Tool quality varies. Support being declared doesn’t mean every model is equally reliable at multi-step tool use. Test with your actual tools before committing.