An LLM can generate text, answer questions, and reason about problems. However, it cannot independently access real-time data or execute external operations without additional capabilities.
This is where Tools come in.
In this article, we’ll explore what AI Agent Tools are, how tool calling works, how to implement a simple tool in Python, and how MCP standardizes tool integration.
A Tool is a function that an AI Agent can use to perform a specific task beyond generating text. Common examples include:
Tools complement an LLM’s capabilities by allowing it to access external data and perform specialized operations. For example, an LLM might not know today’s weather. Instead of guessing, it can use a weather tool to retrieve current conditions.
An LLM does not execute external functions by itself. Instead, it generates a request indicating which tool should be called and what arguments should be provided.
Without a tool, the model may invent a sunny forecast. With a WebSearch (or weather) tool, the Agent can retrieve live data and answer accurately.
A typical tool-calling workflow looks like this:
For example, when a user asks about the weather in Paris, the LLM may request a call to weather_tool("Paris"). The Agent executes the function, retrieves the weather information, and provides the result to the LLM for its final response.
The key distinction: The LLM decides which tool to request, while the Agent’s execution environment runs the function.
A well-defined tool typically includes:
Let’s implement a simple calculator tool.
def calculator(a: int, b: int) -> int:"""Multiply two integers."""return a * b
This function multiplies two integers and returns their product. Its tool specification can be represented as:
Tool Name: calculatorDescription: Multiply two integers.Arguments:- a: int- b: intOutput: int
The description provides the information an LLM needs to understand the tool’s purpose and expected arguments. Clear descriptions and accurate type definitions help the model select the appropriate tool and generate valid arguments.
Applications often inject those descriptions into the system message so the model knows which tools are available:
Manually defining tool specifications can become repetitive when an Agent has many tools. Python provides introspection capabilities that allow us to extract information from function definitions automatically.
For example, the inspect module can retrieve a function’s signature.
import inspectdef calculator(a: int, b: int) -> int:"""Multiply two integers."""return a * bsignature = inspect.signature(calculator)print(signature)
Output:
(a: int, b: int) -> int
We can also retrieve the function’s name and documentation:
print(calculator.__name__)print(calculator.__doc__)
Output:
calculatorMultiply two integers.
Together, these properties provide the foundation for generating tool specifications programmatically.
Using a Decorator
A decorator can encapsulate this logic and make tool registration more convenient. Conceptually, a @tool decorator can extract:
__name__.__doc__.inspect.signature().The decorator can then wrap the original function in a reusable Tool object containing its metadata and execution logic. This approach reduces repetitive configuration and makes tool definitions easier to maintain.
Note that extracting type annotations alone does not validate arguments or guarantee that the actual return value matches the declared type. Production implementations may need additional validation.
As AI applications grow, integrating external tools individually can become difficult to maintain.
Model Context Protocol (MCP) is an open protocol that standardizes how applications expose tools and other context to AI systems.
MCP provides several benefits:
MCP does not replace the underlying tool implementation. Instead, it standardizes how compatible applications communicate with tools.