0
0
Agentic AIml~5 mins

Why tools extend agent capabilities in Agentic AI

Choose your learning style9 modes available
Introduction

Tools help agents do more things and solve bigger problems. They add new skills and information that agents alone don't have.

When an agent needs to access up-to-date information like weather or news
When an agent must perform tasks outside its built-in knowledge, like booking a flight
When an agent needs to use special software or databases to answer questions
When an agent should combine multiple skills, like language understanding and math calculations
When an agent must interact with other systems or APIs to complete a task
Syntax
Agentic AI
agent = Agent()
agent.add_tool(tool_name, tool_function)
result = agent.use_tool(tool_name, input_data)

The agent is first created.

Tools are added to give the agent new abilities.

Examples
This adds a calculator tool so the agent can do math.
Agentic AI
agent.add_tool('calculator', calculate_function)
result = agent.use_tool('calculator', '2 + 2')
This adds a weather tool so the agent can get current weather info.
Agentic AI
agent.add_tool('weather_api', get_weather)
weather = agent.use_tool('weather_api', 'New York')
Sample Model

This program shows an agent that can do math and greet people by adding two tools. It then uses these tools to get results.

Agentic AI
class Agent:
    def __init__(self):
        self.tools = {}

    def add_tool(self, name, func):
        self.tools[name] = func

    def use_tool(self, name, input_data):
        if name in self.tools:
            return self.tools[name](input_data)
        else:
            return 'Tool not found'

# Define a simple calculator tool

def calculator(expression):
    try:
        return str(eval(expression))
    except Exception:
        return 'Invalid expression'

# Define a simple greeting tool

def greeter(name):
    return f'Hello, {name}!'

# Create agent and add tools
agent = Agent()
agent.add_tool('calculator', calculator)
agent.add_tool('greeter', greeter)

# Use tools
calc_result = agent.use_tool('calculator', '3 * 4')
greet_result = agent.use_tool('greeter', 'Alice')

print(calc_result)
print(greet_result)
OutputSuccess
Important Notes

Tools let agents handle tasks they were not originally designed for.

Adding tools is like giving an agent new gadgets to solve problems.

Always check if the tool exists before using it to avoid errors.

Summary

Tools expand what an agent can do beyond its built-in skills.

Agents use tools to access new information or perform special tasks.

Adding and using tools is simple and makes agents more helpful.