The loop
- You send the conversation plus a list of tools, each with a JSON Schema for its arguments.
- The model decides. If a tool would help, it returns an assistant message with
tool_callsinstead of plain text. Each call has anid, the functionnameandargumentsas a JSON string. - You run it. Parse the arguments, call your real function, and capture the output.
- You reply with a message of role
tool, the matchingtool_call_id, and the output ascontent. - The model answers, or asks for another tool. Repeat until it replies with text.
Tips
- Write clear tool descriptions. The model picks tools based on them.
- Always validate the arguments. The model can produce missing or wrong values.
- Never let a tool do something risky, like deleting data or spending money, without a check in your own code.
- Coding tools such as Roo Code depend on tool calling, so a model's tool support matters when you choose one.
Example
This request offers one tool. Check Tool Calling on luv13 to confirm which models and options luv13 supports.
curl https://api.luv13.ai/v1/chat/completions \
-H "Authorization: Bearer $LUV13_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "luv13/glm-5.3-flash",
"messages": [{"role": "user", "content": "What is the weather in Phoenix?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}'If the model wants the tool, the reply's choices[0].message.tool_calls holds the call. get_weather here is only an example. You write the real function.
