Tool calling
Send tool definitions to the model, execute the call in your application, and return the result with the same ID.
01OpenAI
OpenAI tools
json
{
"model": "gpt-5.6-luna",
"messages": [{"role": "user", "content": "What is the weather in Moscow?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}The response may contain message.tool_calls. Return each result as a tool message with the matching tool_call_id.
02Anthropic
Anthropic tool_use
Preserve the assistant block containing tool_use, execute the tool, and append a user tool_result block.
json
{
"role": "user",
"content": [{
"type": "tool_result",
"tool_use_id": "toolu_...",
"content": "18 C, clear"
}]
}03
Reliable loop
- Do not alter tool-call IDs.
- Preserve assistant and tool-result ordering.
- When streaming, accumulate arguments until complete JSON is available.
- After executing a tool, keep reading until visible text or the next tool call.