Skip to main content

Tool Calling (Function Calling)

Tool calling allows GoingMerry models to invoke external tools or code routines. By providing function definitions in the request, the model decides when to output a structured JSON tool call instead of natural language.


1. Defining Tools

To configure tools, pass the tools array parameter inside the /api/chat request body.

curl Example

curl http://localhost:11434/api/chat -d '{
"model": "gemma4",
"messages": [
{
"role": "user",
"content": "What is the weather in Paris right now?"
}
],
"stream": false,
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather for a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
]
}'

2. Model Response Payload

If the model decides to invoke the tool, the returned message object will contain a tool_calls array:

{
"model": "gemma4",
"created_at": "2026-06-05T14:45:00Z",
"message": {
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_10ab32f91",
"type": "function",
"function": {
"name": "get_current_weather",
"arguments": {
"location": "Paris"
}
}
}
]
},
"done": true
}

3. Submitting Tool Outputs

Once you execute the function in your application code, append the output to the message history and resubmit:

curl http://localhost:11434/api/chat -d '{
"model": "gemma4",
"stream": false,
"messages": [
{ "role": "user", "content": "What is the weather in Paris right now?" },
{
"role": "assistant",
"content": "",
"tool_calls": [{ "id": "call_10ab32f91", "type": "function", "function": { "name": "get_current_weather", "arguments": { "location": "Paris" } } }]
},
{
"role": "tool",
"content": "{\"temp\": 18, \"condition\": \"Partly Cloudy\"}"
}
]
}'

The model will compile the tool output and respond with a natural language summary (e.g., "The current weather in Paris is 18°C and partly cloudy.").