How to Add Tools to an AI Agent
1. Why Does an AI Agent Needs Tools?.
Start with the fundamental problem
Agent without tools
User --> Agent --> LLM --> Response
Without tools AI assistant may explain how to check an order.
Agent with Tools
User -->Agent -->Select tools -->API/System -->Result -->Agent -->Response
With tools AI Agent can actually retrieve the last order information from the backend system.
2.What Is a Tool in an AI Agent?
A tool is a function, that provide to an AI agent that allows it to interact with applications, API, database, or external service that an AI Agent can use to perform a specific task.
For example, an AI agent may know how to check the weather, but it needs a weather API tool to get the current weather information.

2.How a Tool Works
The basic flow looks like this:
User → AI Agent → Select Tool → Execute Tool → Tool Result → AI Agent → Response
For example:
User:
What is the weather in Mumbai today?
AI Agent:
The agent understands that it needs current weather information.
Agent → Weather Tool:get_weather("Mumbai")
Weather Tool:
Returns current weather data.
3.What Is the Role of Tools in an AI Agent?
Tools give an AI Agent the ability to interact with the outside world. without tools, an agent mainly works with the information and capabilities available to its model. With tools, it can perform actions such as:
- Search for information
- Get real-time weather
- Perform calculations
- Read or update databases
- Send emails
- Call external APIs
- Read or create files
- Schedule appointments
So, the tool acts as a bridge between the AI Agent and external systems.
4. Different Types of Agent Tools
1.Search Tools
Used when the agent needs to find current or external information.
Examples:
- Web search
- Document search
- Knowledge-base search
- Company/product search
2.API Tools
These tools allow an agent to communicate with external applications through APIs.
Examples:
- Weather API
- Stock market API
- Payment API
- CRM API
- Maps API
- Shipping API
3.Calculation Tools
Used for mathematical or data-processing operations.
Examples:
- Calculator
- Python execution
- Statistical calculations
- Financial calculations
- Currency conversion
Food-Grade Material: Small USB blender uses food-grade non-toxic and environmengtally friendly PP& ABS materials. With the most advanced CS+C(Cold Spin+Centrifugal) Technology
4.Database Tools
These allow an agent to read or modify structured data
Examples:
- MySQL
- PostgreSQL
- MongoDB
- Oracle
- Redis
5.File and Document Tools
Used to work with documents and files.
Examples:
- PDF reader
- Word document reader
- Excel reader
- CSV processor
- File search
6.Memory Tools
Memory tools allow agents to store and retrieve information across conversations or tasks.
Examples:
- Short-term conversation memory
- Long-term memory
- Vector database
- User preference storage
- Session storage
7.Code Execution Tools
These allow agents to execute code.
Examples:
- Python
- JavaScript
- SQL
- Shell commands
- Data-processing scripts
8.Authentication Tools
These tools help agents interact with secured system
Examples:
- OAuth 2.0
- API keys
- JWT
- SSO
- Authentication services
9.Communication Tools
These allow agents to communicate with users or other systems.
Examples:
- SMS
- Slack
- Microsoft Teams
- Notifications
10.Transaction Tools
These tools allow agents to perform business transactions.
Examples:
- Place an order
- Cancel an order
- Book a ticket
- Make a payment
- Create an invoice
- Check order status
11. Location and Navigation Tools‘
Used when an agent needs geographical information.
Examples:
- Maps
- Geocoding
- Distance calculation
- Route planning
- Nearby business search
Tools Implementation
user_name = os.getenv("RAK_USER")
user_token = os.getenv("USER_TOKEN")
url = "https://rkdigitalschool.com/1/messages.json"
if user_name:
if user_name.startswith("u"):
print("user found and looks good")
else:
print("user found but doesn't start with u")
else:
print("User not found")
if user_token:
if user_token.startswith("a"):
print("token found and looks good")
else:
print("token found but doesn't start with a")
else:
print("token not found")
# Remember this?
def push(message):
print(f"Push: {message}")
payload = {"user": user_name, "token": user_token, "message": message}
requests.post(url, data=payload)
push("HEY!!")
push
# Now this:
@function_tool
def push_tool(message: str) -> str:
""" Send the given message to the user as a push notification """
payload = {"user": user_name, "token": user_token, "message": message}
result = requests.post(url, data=payload).status_code
return f"Push sent with API status code {result}"
push_tool
push_tool.description
notifier = Agent(name="Notifier", model="gpt-5.4-mini", instructions="You notify the user upon request", tools=[push_tool])
with trace("Pizza has arrived"):
result = await Runner.run(notifier, "Notify the user that the pizza is here")
print(result.final_output)
Explanation:
user_name = os.getenv("RAK_USER")
user_token = os.getenv("USER_TOKEN")
os.getenv() reads a value from your environment variables.
Why use environment variables?
You generally should not hard-code sensitive information such as tokens directly in Python code. this keeps the token outside your source code.
Defining the API URL
url = "https://rkdigitalschool.com/1/messages.json"
This is the API endpoint where your notification request will be sent.
Checking whether the username exists
if user_name:
if user_name.startswith("u"):
print("user found and looks good")
else:
print("user found but doesn't start with u")
else:
print("User not found")
Checking the token
if user_token:
if user_token.startswith("a"):
print("token found and looks good")
else:
print("token found but doesn't start with a")
else:
print("token not found")
It checks two things:
- Does a token exist?
- Does it start with
"a"?
Creating the normal Python function
def push(message):
print(f"Push: {message}")
payload = {
"user": user_name,
"token": user_token,
"message": message
}
requests.post(url, data=payload)
This is a normal Python function.
Converting the function into an AI Agent tool
@function_tool
def push_tool(message: str) -> str:
""" Send the given message to the user as a push notification """
payload = {"user": user_name, "token": user_token, "message": message}
result = requests.post(url, data=payload).status_code
return f"Push sent with API status code {result}"
Converts your Python function into a tool that an AI Agent can use.this is a major concept in agentic AI.
Building the payload
payload = {
"user": user_name,
"token": user_token,
"message": message
}
Sending the request
result = requests.post(url, data=payload).status_code
This sends the POST request. the important difference from the previous function is that you’re now capturing the HTTP status code.
Returning the result to the Agent
return f"Push sent with API status code {result}"
Creating the Agent with tool
notifier = Agent(
name="Notifier",
model="gpt-5.4-mini",
instructions="You notify the user upon request",
tools=[push_tool]
)
Running the Agent
with trace("Pizza has arrived"):
result = await Runner.run(notifier, "Notify the user that the pizza is here")
print(result.final_output)
This creates a trace around the Agent execution. It can help you inspect what happened during the Agent run, such as the model execution and tool calls.
Runner.run()
result = await Runner.run(
notifier,
"Notify the user that the pizza is here"
)
This starts the Agent.
The user request is:
Notify the user that the pizza is here
The Agent receives this request.
Getting the final answer
print(result.final_output)
prints the Agent’s final response.
For example, it might produce:
The user has been notified that the pizza is here.
The exact wording depends on the model.
Complete architecture

4.How tool selection works
Example: Suppose an agent has these tools.
- get_weather()
- search_web()
- calculate()
- send_email()
The user asks:”What is the weather in Mumbai today?”
The agent understands:
- I need current weather information
get_weather()can provide current weathercalculate()is not relevantsend_email()is not relevantsearch_web()may not be necessary
So it selects:
get_weather("Mumbai")
Then it receives:
Temperature: 31°C
Condition: Cloudy
How does the LLM know what each tool does?
When you create a tool, you provide a tool name, description, parameters, and sometimes usage instructions.
For Example
@function_tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
...
The important part is: Get the current weather for a city.
The model sees this description and can understand , “This tool is useful when the user asks about current weather.”
If this article helped you learn something new, consider supporting us. Your small contribution helps us continue creating free, useful content for everyone.
