Skip to main content
The user asks in plain language; custom tools extend what the agent can do beyond built-ins.

Create Custom Tools

Quick Start

1

Install

2

Create a custom tool

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 named agents.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:
If you want to run the AG2 framework (Formerly AutoGen), use:

Prerequisites

Ensure you have the duckduckgo_search package installed. If not, you can install it using:
That’s it! You should now have the PraisonAI tool installed and configured.

Other information

TL;DR to Create a Custom Tool

  • Add - InternetSearchTool in 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

For praisonaiagents 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:
See the Tool Parameter Types page for complete guide.

Creating a Pip-Installable Tool Package

Create tools that auto-register when installed:

pyproject.toml

my_package/init.py

Usage

After pip 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:
Important notes:
  • The @tool decorator validates at creation time and logs warnings (doesn’t raise)
  • parameters (if set manually) must include properties for OpenAI compatibility
  • Validation failures are logged - scan your logs for Tool validation warning for ...
Example that will raise ToolValidationError at agent creation:
For comprehensive validation details and error fixes, see Tool Schema Validation.
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

Define tools as plain Python functions with clear type hints - def my_tool(query: str) -> str.
The agent reads tool docstrings to decide when to call them - be specific about what the tool does.
Return a string from tool functions - even for errors - so the agent can process the result.
Call your tool function directly with test inputs before adding it to an agent.

Custom Tools

Build your own agent tools

Tools Overview

Browse PraisonAI tool documentation