Function Calling
How It Works
User message --> Model --> tool_calls response
|
Your code executes function
|
Tool result sent back --> Model --> Final responseDefining Tools
{
"model": "dos-ai",
"messages": [
{ "role": "user", "content": "What is the weather in Hanoi?" }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a given city.",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city name, e.g. 'Hanoi' or 'Ho Chi Minh City'."
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit. Defaults to celsius."
}
},
"required": ["city"]
}
}
}
]
}Best Practices for Tool Definitions
Handling Tool Calls
Sending Tool Results
Multiple Tool Calls
Controlling Tool Use
Value
Behavior
Complete Example
Python
JavaScript
cURL
Error Handling
Issue
Cause
Solution
Next Steps
Last updated