Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Function Calling (Tool Use)

Function calling, or tool use, lets a language model request an external function with JSON arguments that the application runs and returns.

Function calling, also called tool calling or tool use, is the ability of a large language model (LLM) to answer with a request to run an external function instead of plain text. The application describes each available tool with a name, a purpose, and a JSON Schema for its arguments. When a request needs live data or an action, the model replies with the tool's name and JSON arguments, the application runs the function, and the model writes its answer from the result. The model never executes anything itself. Meta's Toolformer showed in February 2023 that a model could teach itself to insert API calls into its own text, and OpenAI added function calling to its API on June 13, 2023, with models fine-tuned to detect when a function is needed and to format arguments that match its signature. Every major model provider now supports it, and open models learn it through their instruction tuning and chat templates.

How Function Calling Works#

A tool call is a round trip between the model and the application, repeated until the model has what it needs:

The code below plays both sides of one round trip in the format of OpenAI's function calling guide, with the model's reply written out so it runs without an API key:

import json

from jsonschema import validate

# The tool definition sent with the request: a name, a purpose, and a JSON Schema for the arguments
tool = {
    "type": "function",
    "name": "get_order_status",
    "description": "Look up the shipping status of an order by its number.",
    "parameters": {
        "type": "object",
        "properties": {"order_id": {"type": "string", "pattern": "^[0-9]+$"}},
        "required": ["order_id"],
    },
}

# The model's output is a function call whose arguments arrive as a JSON string
call = {"type": "function_call", "call_id": "call_1", "name": "get_order_status", "arguments": '{"order_id": "4417"}'}
args = json.loads(call["arguments"])
validate(args, tool["parameters"])  # Raises before anything runs if the arguments break the schema

# The application runs its own function and returns the result under the same call_id
orders = {"4417": "Shipped, arriving Thursday"}
print({"type": "function_call_output", "call_id": call["call_id"], "output": orders[args["order_id"]]})

It prints {'type': 'function_call_output', 'call_id': 'call_1', 'output': 'Shipped, arriving Thursday'}, the item the application appends to the conversation before calling the model again. Setting "strict": true on a tool makes the API apply constrained decoding, so the arguments the model generates always match the schema.

Choosing and Chaining Tools#

Models can emit several independent calls in one turn, such as checking two orders at once, and an application can force a specific tool, require some tool, or forbid tools for a turn. Chaining calls across turns, where each result decides the next call, is the loop that turns a model into an AI agent running inside an agent harness. The Berkeley Function Calling Leaderboard evaluates these skills: picking the right function, filling its arguments, making parallel and multi-turn calls, and declining when no tool fits. Because tool results return to the model as input, a web page or document fetched by a tool can carry a prompt injection, so applications give tools the least privilege they need and ask a person before purchases, deletions, or sent messages.

Vision models make natural tools because their output is already structured. In Ultralytics YOLO, Results.summary() returns each object a YOLO26 model finds as a dictionary of class name, class index, confidence, and box coordinates, a list that json.dumps turns directly into a tool result, so a chat model or vision-language model (VLM) can count and locate objects in a photo by calling predict mode.

  • Computer use agents: Operate software through screenshots, clicks, and keystrokes, which covers applications without an API. A function call reaches the same result in one structured request wherever an API exists.
  • Structured outputs: Constrains a model's final reply to a schema, such as extracting fields from an invoice. Function calling uses the same schemas to request an action and expects a result back.
  • Retrieval-augmented generation (RAG): Adds retrieved documents to the prompt. A search tool can implement RAG, and agentic RAG lets the model decide when to search and what to search for.
  • Model Context Protocol (MCP): An open protocol, introduced by Anthropic in November 2024, through which applications discover tools served by external programs. The model still invokes an MCP tool through function calling.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports
Computer vision in sports
Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery
Computer vision for aerial imagery
Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace
Computer vision in aerospace
Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security
Computer vision in security
Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics
Computer vision in robotics
Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics
Computer vision in logistics
Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail
Computer vision in retail
Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare
Computer vision in healthcare
Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing
Computer vision in manufacturing
Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive
Computer vision in automotive
Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture
Computer vision in agriculture
Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports
Computer vision in sports
Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery
Computer vision for aerial imagery
Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace
Computer vision in aerospace
Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security
Computer vision in security
Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics
Computer vision in robotics
Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics
Computer vision in logistics
Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail
Computer vision in retail
Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare
Computer vision in healthcare
Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing
Computer vision in manufacturing
Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive
Computer vision in automotive
Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture
Computer vision in agriculture
Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning