Tool calling
Declare local functions, execute them in your application, and return results to the model.
Tool calling lets a model request a function that your application executes. KosCompute never executes the function for you.
1. Declare the tool¶
{
"model": "qwen/qwen3.8-27b",
"messages": [{"role": "user", "content": "What is the weather in Brno?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Return current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
"additionalProperties": false
}
}
}],
"tool_choice": "auto",
"max_completion_tokens": 400
}
2. Execute the call¶
Read choices[0].message.tool_calls. Parse each function's arguments JSON, validate it again in your application, apply authorization, and execute the local function. Never treat model-generated arguments as trusted input.
3. Return the result¶
Append the assistant message containing tool_calls, then append a tool message with the matching ID:
{"role":"tool","tool_call_id":"call_abc123","content":"{\"temperature_c\":21}"}
Send the expanded conversation in a second completion request.
Tool choice¶
auto lets the model decide, none prevents a call, required requests a call, and a named function selects one tool. Backend behavior for required can be model-specific. In particular, some routes can guarantee required choice only with one named function; the Responses adapter rejects combinations it cannot guarantee instead of pretending they are equivalent.
Responses uses function_call output items and function_call_output input items joined by call_id. See the Responses guide for that shape.