Building custom tools helps you create smart helpers that do specific jobs for you. It makes your AI more useful and fits your unique needs.
0
0
Building custom tools in Agentic AI
Introduction
You want your AI to answer questions about your own documents.
You need the AI to perform special tasks like booking appointments or checking your calendar.
You want to add new abilities to your AI that it doesn't have by default.
You want to connect your AI to other apps or websites to get real-time data.
You want to control how the AI works by giving it clear instructions and tools.
Syntax
Agentic AI
class CustomTool: def __init__(self, name, description, func): self.name = name self.description = description self.func = func def run(self, input_data): return self.func(input_data) # Example usage: # def my_tool_function(data): # # process data # return result # tool = CustomTool('ToolName', 'What this tool does', my_tool_function) # output = tool.run(input_data)
Define a class or function that wraps your tool's logic.
Give your tool a clear name and description so the AI knows when to use it.
Examples
A simple function that says hello to a given name.
Agentic AI
def greet(name): return f"Hello, {name}!"
A tool class that calculates math expressions given as strings.
Agentic AI
class MathTool: def __init__(self): pass def run(self, expression): return eval(expression)
Creating a tool instance and running it with input 'Alice'.
Agentic AI
tool = CustomTool('Greet', 'Says hello to someone', greet) print(tool.run('Alice'))
Sample Model
This program builds a custom tool that reverses any text you give it. It shows how to define the tool, create it, and use it.
Agentic AI
class CustomTool: def __init__(self, name, description, func): self.name = name self.description = description self.func = func def run(self, input_data): return self.func(input_data) # Define a tool function that reverses text def reverse_text(text): return text[::-1] # Create the tool reverse_tool = CustomTool('ReverseText', 'Reverses the input text', reverse_text) # Use the tool input_string = 'hello world' output = reverse_tool.run(input_string) print(f"Input: {input_string}") print(f"Output: {output}")
OutputSuccess
Important Notes
Make sure your tool functions are simple and do one clear job.
Test your tools separately before connecting them to your AI agent.
Keep tool descriptions clear so the AI can pick the right tool when needed.
Summary
Custom tools let you add special skills to your AI.
Each tool has a name, description, and a function that does the work.
Use tools to make your AI smarter and more helpful for your tasks.