Create Custom Tools
Quick Start
Step 1: Install the praisonai Package
First, you need to install the praisonai package. Open your terminal and run the following command:
Step 2: Create the InternetSearchTool
Next, create a file named tools.py and add the following code to define the InternetSearchTool:
Step 3: Define the Agent Configuration
Create a file namedagents.yaml and add the following content to configure the agent:
Step 4: Run the PraisonAI Tool
To run the PraisonAI tool, simply type the following command in your terminal:Prerequisites
Ensure you have theduckduckgo_search package installed. If not, you can install it using:
Other information
TL;DR to Create a Custom Tool
- Add
- InternetSearchToolin the agents.yaml file in the tools section. - Create a file called tools.py and add this code tools.py
Pre-requisite to Create a Custom Tool
agents.yaml file should be present in the current directory.
If it doesn’t exist, create it by running the command praisonai --init research about the latest AI News and prepare a detailed report.
Step 1 to Create a Custom Tool
Create a file called tools.py in the same directory as the agents.yaml file.Step 2 to Create a Custom Tool
Add the tool to the agents.yaml file as show below under the tools section- InternetSearchTool.
Python Code Custom Tools
Forpraisonaiagents package users, you can create custom tools using the @tool decorator or BaseTool class.
Using @tool Decorator
Using BaseTool Class
Expressive Parameter Types
Create tools with rich type annotations for better schema generation:Creating a Pip-Installable Tool Package
Create tools that auto-register when installed:pyproject.toml
my_package/init.py
Usage
Afterpip install, tools are auto-discovered:
What Happens During Validation
The@tool decorator and BaseTool instances now validate schemas automatically to ensure OpenAI compatibility.
Automatic validation when using @tool:
- The
@tooldecorator validates at creation time and logs warnings (doesn’t raise) parameters(if set manually) must includepropertiesfor OpenAI compatibility- Validation failures are logged - scan your logs for
Tool validation warning for ...
Tool Name Collisions: When developing custom tools, avoid naming conflicts with existing tools. If you have multiple environments with overlapping tool names, use the Allowed Tools feature to whitelist specific tools.
Best Practices
Use simple function signatures
Use simple function signatures
Define tools as plain Python functions with clear type hints -
def my_tool(query: str) -> str.Write descriptive docstrings
Write descriptive docstrings
The agent reads tool docstrings to decide when to call them - be specific about what the tool does.
Always return strings
Always return strings
Return a string from tool functions - even for errors - so the agent can process the result.
Test tools independently
Test tools independently
Call your tool function directly with test inputs before adding it to an agent.
Related
Custom Tools
Build your own agent tools
Tools Overview
Browse PraisonAI tool documentation

