Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Create Custom Tools
Step 1: Install the praisonai Package
First, you need to install the praisonai package. Open your terminal and run the following command:
Next, create a file named tools.py and add the following code to define the InternetSearchTool:
from duckduckgo_search import DDGS
from praisonai_tools import BaseTool
class InternetSearchTool(BaseTool):
name: str = "Internet Search Tool"
description: str = "Search Internet for relevant information based on a query or latest news"
def _run(self, query: str):
ddgs = DDGS()
results = ddgs.text(keywords=query, region='wt-wt', safesearch='moderate', max_results=5)
return results
Step 3: Define the Agent Configuration
Create a file named agents.yaml and add the following content to configure the agent:
framework: crewai
topic: research about the causes of lung disease
agents: # Canonical: use 'agents' instead of 'roles'
research_analyst:
instructions: # Canonical: use 'instructions' instead of 'backstory' Experienced in analyzing scientific data related to respiratory health.
goal: Analyze data on lung diseases
role: Research Analyst
tasks:
data_analysis:
description: Gather and analyze data on the causes and risk factors of lung diseases.
expected_output: Report detailing key findings on lung disease causes.
tools:
- InternetSearchTool
To run the PraisonAI tool, simply type the following command in your terminal:
If you want to run the AG2 framework (Formerly AutoGen), use:
praisonai --framework autogen
Prerequisites
Ensure you have the duckduckgo_search package installed. If not, you can install it using:
pip install duckduckgo_search
That’s it! You should now have the PraisonAI tool installed and configured.
pip install praisonai duckduckgo-search
export OPENAI_API_KEY="Enter your API key"
praisonai --init research about the latest AI News and prepare a detailed report
- Add
- InternetSearchTool in the agents.yaml file in the tools section.
- Create a file called tools.py and add this code tools.py
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.
Create a file called tools.py in the same directory as the agents.yaml file.
# example tools.py
from duckduckgo_search import DDGS
from praisonai_tools import BaseTool
class InternetSearchTool(BaseTool):
name: str = "InternetSearchTool"
description: str = "Search Internet for relevant information based on a query or latest news"
def _run(self, query: str):
ddgs = DDGS()
results = ddgs.text(keywords=query, region='wt-wt', safesearch='moderate', max_results=5)
return results
Add the tool to the agents.yaml file as show below under the tools section - InternetSearchTool.
framework: crewai
topic: research about the latest AI News and prepare a detailed report
agents: # Canonical: use 'agents' instead of 'roles'
research_analyst:
instructions: # Canonical: use 'instructions' instead of 'backstory' Experienced in gathering and analyzing data related to AI news trends.
goal: Analyze AI News trends
role: Research Analyst
tasks:
gather_data:
description: Conduct in-depth research on the latest AI News trends from reputable
sources.
expected_output: Comprehensive report on current AI News trends.
tools:
- InternetSearchTool
Python Code Custom Tools
For praisonaiagents package users, you can create custom tools using the @tool decorator or BaseTool class.
from praisonaiagents import Agent, tool
@tool
def search(query: str) -> str:
"""Search the web for information."""
return f"Results for: {query}"
@tool
def calculate(expression: str) -> float:
"""Evaluate a math expression."""
return eval(expression)
agent = Agent(
instructions="You are a helpful assistant",
tools=[search, calculate]
)
agent.start("Search for AI news and calculate 15*4")
from praisonaiagents import Agent, BaseTool
class WeatherTool(BaseTool):
name = "weather"
description = "Get current weather for a location"
def run(self, location: str) -> str:
return f"Weather in {location}: 72°F, Sunny"
agent = Agent(
instructions="You are a weather assistant",
tools=[WeatherTool()]
)
agent.start("What's the weather in Paris?")
Create tools that auto-register when installed:
pyproject.toml
[project]
name = "my-praisonai-tools"
version = "1.0.0"
dependencies = ["praisonaiagents"]
[project.entry-points."praisonaiagents.tools"]
my_tool = "my_package:MyTool"
my_package/init.py
from praisonaiagents import BaseTool
class MyTool(BaseTool):
name = "my_tool"
description = "My custom tool"
def run(self, param: str) -> str:
return f"Result: {param}"
Usage
After pip install, tools are auto-discovered:
from praisonaiagents import Agent
agent = Agent(tools=["my_tool"]) # Works automatically!