Models marked Tool calling in Models accept OpenAI-format tools.
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "Is it raining in Singapore?"}]
first = client.chat.completions.create(model="zai-org/GLM-5.3", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]
messages.append(first.choices[0].message)
messages.append({"role": "tool", "tool_call_id": call.id, "content": '{"raining": true, "temp_c": 27}'})
final = client.chat.completions.create(model="zai-org/GLM-5.3", messages=messages, tools=tools)
print(final.choices[0].message.content)
tool_choice
| Value | Behavior |
|---|---|
"auto" (default) |
The model decides whether to call a tool |
"none" |
Never call a tool |
"required" |
Must call at least one tool, where the model supports it |
{"type": "function", "function": {"name": "…"}} |
Force a specific tool, where the model supports it |
Tips
- Keep tool descriptions short and specific; the model reads them as part of the prompt (and you pay for those tokens).
- Validate tool arguments before executing them — they’re generated text.
- For many parallel calls, check
parallel_tool_callssupport per model in models.json.