MERIDIAN
Tool calling
Function calling with Meridian — define tools, control tool_choice, and parse streaming tool_calls in responses.
Defining tools
Pass a tools array in your chat completion request. Each tool declares a function with a name, description, and JSON Schema parameters.
{
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, e.g. San Francisco"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["city"]
}
}
}
]
}Controlling tool_choice
The tool_choice parameter governs whether and which tools the model invokes.
// auto — model decides whether to call a tool
"tool_choice": "auto"
// none — model never calls a tool
"tool_choice": "none"
// required — model must call one of the provided tools
"tool_choice": "required"
// force a specific tool
"tool_choice": { "type": "function", "function": { "name": "get_weather" } }Parsing tool_calls in the response
When the model decides to call a tool, the streaming delta contains a tool_calls array. Accumulate fragments by index — arguments arrive as JSON fragments across multiple deltas.
{
"id": "msg_01XzQ2...",
"choices": [{
"delta": {
"tool_calls": [{
"index": 0,
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Portland\",\"unit\":\"fahrenheit\"}"
}
}]
}
}]
}Returning tool results
After executing the function, append a tool role message with the matching tool_call_id. The model uses this to produce its final answer.
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "{\"temperature\": 58, \"condition\": \"overcast\", \"humidity\": 72}"
}← Back to docsMeridian