Function calling
Equip Meridian with tools it can invoke. Define a JSON schema, set tool_choice, and receive structured arguments ready for your Python runtime.
Defining a tool
A tool is a JSON object with a name, description, and a JSON Schema parameters block. Meridian uses the schema to validate arguments before calling your function.
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Return current conditions for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, e.g. Stockholm"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["city"]
}
}
}
]Controlling tool_choice
By default Meridian decides whether to call a tool. Force a specific tool — or require any tool — with the tool_choice parameter.
| Value | Behaviour |
|---|---|
| "auto" | Model decides (default). |
| "required" | Model must call some tool. |
| {"type": "function", "function": {"name": "get_weather"}} | Force a specific named tool. |
| "none" | Disable tool use entirely. |
Python example
Send tools alongside your prompt, inspect the response for a tool_calls array, execute the matching function, and return the result to Meridian.
import meridian
client = meridian.Client()
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Return current conditions for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}
]
response = client.chat.completions.create(
model="meridian-1",
messages=[{"role": "user", "content": "What's the weather in Oslo?"}],
tools=tools,
tool_choice="auto",
)
# Check if the model wants to call a tool
if response.choices[0].message.tool_calls:
tool_call = response.choices[0].message.tool_calls[0]
if tool_call.function.name == "get_weather":
import json
args = json.loads(tool_call.function.arguments)
city = args["city"]
# Call your actual weather API here
result = f"It is 12 °C and cloudy in {city}."
# Return the tool result to Meridian
response = client.chat.completions.create(
model="meridian-1",
messages=[
{"role": "user", "content": "What's the weather in Oslo?"},
response.choices[0].message,
{"role": "tool", "tool_call_id": tool_call.id, "content": result},
],
)
print(response.choices[0].message.content)