Skip to content

Tool Calling

Tool calling (a.k.a. function calling) lets a model emit structured calls into JSON tool definitions you supply. ai& supports tool calling on both the OpenAI Chat Completions and Anthropic Messages surfaces.

tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
response = client.chat.completions.create(
model="...",
messages=[{"role": "user", "content": "Weather in Tokyo?"}],
tools=tools,
tool_choice="auto",
)

OpenAI-shape requests can set parallel_tool_calls: true (the default) to let the model emit multiple tool calls in a single turn.

  • "auto" — model decides whether to call a tool (default when tools is set).
  • "none" — disable tool use for this request.
  • "required" — force the model to call a tool.
  • { "type": "function", "function": { "name": "..." } } — force a specific tool.