What's The Difference Between Tools & Functions?
They're related, but not exactly the same thing…
In the context of large language model (LLM) development, tools and functions are closely related concepts but not exactly the same thing…
Even-though the two terms are being used interchangeably…
They both refer to mechanisms that allow LLMs to extend their capabilities beyond pure text generation, such as by
interacting with external APIs,
performing calculations via a math lib, or
retrieving data.
However, there are key distinctions in terminology, implementation and scope…
…especially across different frameworks and APIs.
Functions are tools, but tools are more than functions.
Functions
A single, well-defined operation with input/output.
Functions also know as Function Calling…
This term originated in early LLM APIs, like OpenAI’s initial implementation.
It specifically refers to defining JSON schemas for callable functions that the LLM can invoke.
The model would output a structured call (for example, with function name and arguments) instead of just text, allowing developers to execute the function externally and feed the result back to the model.
With the data being prepared in the right format to be sent to the external system, and the LLM having identified where the call should go.
This was a way to make LLMs more agentic by grounding their responses in real-world actions.
In older OpenAI APIs, you’d pass a functions parameter to define these.
It typically supported single function calls per response and was more rigid.
The Biggest Misconception About Function Calling
When using the OpenAI API with function calling, the model itself does not run the functions and interact with external systems.
Instead, it generates parameters for potential function calls.
Your application then decides how to handle these parameters, maintaining full control over whether to call the suggested function or take another action.
Language Models Autonomy & Function-Driven Decisions
In AI language models, the introduction of functions adds a new layer of autonomy.
The function calling capability allows the model to independently determine whether a function call is needed to handle a particular task or if it should respond directly.
By doing so, the model dynamically selects the most suitable response strategy based on the context, enhancing both its adaptability and effectiveness.
This decision-making power introduces a more nuanced autonomy, enabling the model to switch seamlessly between execution and conversation.
Tools
Anything an AI Agent can use to extend its capabilities. Often multi-step, environment-aware.
Tools also known as Tool Calling…
This is the more modern and generalised term, often used as an evolution or replacement for functions.
A tool is any external capability or resource that a model or AI Agent can use to extend its reasoning and act on the world.
Tools go beyond single, well-defined functions: they can include APIs, databases, code execution environments, calculators, web browsers, computer use, etc.
The defining feature of a tool is that it provides the model with capabilities it cannot perform internally, allowing it to fetch information, compute values, or manipulate data in ways that augment its knowledge and reasoning.
While functions are structured, predictable operations, tools are a broader category — they can be composed of multiple functions, interactive environments, or systems — and they form the backbone of AI agents’ ability to execute complex, multi-step workflows autonomously.
Practical Code Example
Function →
get_order_status(order_id)
(predictable schema: delivered or not).Tool →
python_repl(code)
(a mini Python evaluator the model can use for arbitrary logic).
pip install openai==0.28
import os
import openai
import math
# --- Prompt for API key in Colab ---
import getpass
os.environ["OPENAI_API_KEY"] = getpass.getpass("Enter your OpenAI API Key: ")
openai.api_key = os.environ["OPENAI_API_KEY"]
# --- Function (structured, predictable schema) ---
def get_order_status(order_id: str):
"""Simulated function: returns structured order delivery info."""
orders = {"A100": True, "B200": False}
return {"order_id": order_id, "delivered": orders.get(order_id, False)}
# --- Tool (general capability: here, a Python REPL) ---
def python_repl(code: str):
"""Simulated tool: executes arbitrary Python code."""
try:
result = eval(code, {"__builtins__": None, "math": math}, {})
return {"code": code, "result": result}
except Exception as e:
return {"code": code, "error": str(e)}
# --- Example of combining function + tool ---
def demo_run():
print("=== Function Example ===")
print("Calling get_order_status('A100')...")
status = get_order_status("A100")
print("Result:", status)
print("\n=== Tool Example ===")
print("Calling python_repl('math.sqrt(16) + 2')...")
calc = python_repl("math.sqrt(16) + 2")
print("Result:", calc)
print("\n=== (Optional) Ask GPT to reason about results ===")
response = openai.ChatCompletion.create(
model="gpt-4o-mini", # lightweight reasoning model
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f"Order status: {status}. Calculation: {calc}. Summarize the difference between a function and a tool in this demo."}
]
)
print("GPT Response:", response["choices"][0]["message"]["content"])
demo_run()
Output:
=============================================
Function Example
=============================================
Calling get_order_status('A100')...
Result:
{'order_id': 'A100', 'delivered': True}
=============================================
Tool Example
=============================================
Calling python_repl('math.sqrt(16) + 2')...
Result:
{'code': 'math.sqrt(16) + 2', 'result': 6.0}
=============================================
(Optional) Ask GPT to reason about results
=============================================
GPT Response:
In this demo, we can summarize the difference
between a function and a tool as follows:
- Function:
A function is a specific block of code designed
to perform a particular task, usually defined
with inputs and outputs. In the calculation
example, `math.sqrt(16) + 2` represents a
function call, where the function `math.sqrt()`
takes an input (16), computes its square root,
and returns the result, which is then used in
further calculations.
- Tool:
A tool is a broader concept that encompasses any
resource or utility that assists in performing a
task. It can include various functions, but also
involves the context and environment in which
those functions are utilized. In this demo, the
entire calculation process, including both the
function `math.sqrt()` and the additional
arithmetic (+2), can be seen as a tool for
obtaining a specific result (6.0).
In essence, while a function is a component of a
tool, the tool itself represents the combined
application and utility of one or more functions
to achieve a practical goal.
The Colab notebook view:
Chief Evangelist @ Kore.ai | I’m passionate about exploring the intersection of AI and language. Language Models, AI Agents, Agentic Apps, Dev Frameworks & Data-Driven Tools shaping tomorrow.
COBUS GREYLING
Where AI Meets Language | Language Models, AI Agents, Agentic Applications, Development Frameworks & Data-Centric…www.cobusgreyling.com