What does a tool call do?
OpenAI uses function calling, also known as tool calling, to let models interact with external systems and access data outside their training data. In an API request, the application can send a list of available tools along with the user’s prompt. The model may decide that completing the task requires data or functionality provided by one of those tools.
For example, one tool available to the model might retrieve weather information for a location. Another might look up account details using a user ID or initiate a refund for a missing order. In OpenAI’s terminology, a function is a specific type of tool defined using JSON Schema. The function definition gives the model a way to pass data to the application. The application code can then use that data to retrieve information or perform an action the model suggests.
A tool call is a special response generated by the model. In OpenAI’s weather example, the model can answer a prompt about the weather in Paris by calling get_weather. In that call, Paris is the value of the location argument. The tool then uses the input from the call to produce a result. The call in the model’s initial response and the result produced by the tool are separate parts of the workflow.
The function calling workflow
OpenAI describes tool use as a multi-step conversation between the application and the model. In the first request, the application supplies the tools the model can call. If the model returns a tool call, the application uses the input from the call to run its own code. It then sends a second request containing the tool output. The model can respond with a final answer or make further tool calls.
In the weather example, the first request includes the tool definition and the user’s question. The model’s call contains the tool name and the location argument. After using that input to get the result, the application sends the tool definition, the original prompt, the model’s call, and the tool output back to the model. The model can then use that information to give the user a text response.
Tool output is tied to a specific call made by the model. OpenAI’s examples use call_id to make that connection. The output can be structured JSON or plain text. In the weather example, the JSON object contains fields for the temperature and its unit. Images or file contents can also be passed as tool output. The model can use the content produced by the tool in its next response.
Anthropic also describes a round trip for tools defined by the application. Claude decides when to call a tool based on the user’s request and the tool description. When it calls a tool that runs in the application, the response includes a tool_use block. The application performs the operation and returns the result in a tool_result block. Claude can then use that result to answer the original question.
Anthropic distinguishes tools by where their code runs. User-defined client tools run in the application. For these tools, Claude returns stop_reason: "tool_use" and one or more tool_use blocks. Server tools run on Anthropic’s infrastructure. For some client tools whose schemas Anthropic publishes, the application still executes the call and returns a tool_result.
In Anthropic’s client tool example, the first request defines the get_weather tool. The tool’s input_schema field contains an object and marks the location field as required. The tool_use block in Claude’s response contains the tool name and input. In the second request, the tool_use_id in tool_result links the result to the ID of the original call.
Fields in a function definition
According to OpenAI, function definitions are typically declared in the tools parameter of each API request. The type field in the definition is set to function. The name field gives the function’s name, and description explains when and how to use it. The JSON Schema in parameters defines the function’s input arguments. The strict field specifies whether strict mode applies to the function call.
In OpenAI’s get_weather definition, parameters is defined as an object. The properties field contains location and units, both declared as string. For units, the enum lists celsius and fahrenheit as possible values. The definition’s required list includes both fields, and additionalProperties is set to false.