In this lesson, we’ll learn how to enhance your agents by adding tools. Tools allow agents to perform specific actions beyond just generating text, making them much more useful for real-world tasks.
Generate your OpenAI API key from OpenAI
Use other LLM providers like Ollama, Anthropic, Groq, Google, etc. Please refer to the Models for more information.
3
Create Agent with Tool
Create app.py
Copy
from praisonaiagents import Agentfrom duckduckgo_search import DDGS# 1. Define the tooldef internet_search_tool(query: str): results = [] ddgs = DDGS() for result in ddgs.text(keywords=query, max_results=5): results.append({ "title": result.get("title", ""), "url": result.get("href", ""), "snippet": result.get("body", "") }) return results# 2. Assign the tool to an agentsearch_agent = Agent( instructions="Perform internet searches to collect relevant information.", tools=[internet_search_tool] # <--- Tool Assignment)# 3. Start Agentsearch_agent.start("Search about AI job trends in 2025")
4
Start Agents
Execute your script:
Terminal
Copy
python app.py
1
Install PraisonAI
Install the core package:
Terminal
Copy
pip install praisonaiagents duckduckgo-search
2
Configure Environment
Terminal
Copy
export OPENAI_API_KEY=your_openai_key
Generate your OpenAI API key from OpenAI
Use other LLM providers like Ollama, Anthropic, Groq, Google, etc. Please refer to the Models for more information.
3
Create Agent with Tool
Create app.py
Copy
from praisonaiagents import Agentfrom duckduckgo_search import DDGS# 1. Define the tooldef internet_search_tool(query: str): results = [] ddgs = DDGS() for result in ddgs.text(keywords=query, max_results=5): results.append({ "title": result.get("title", ""), "url": result.get("href", ""), "snippet": result.get("body", "") }) return results# 2. Assign the tool to an agentsearch_agent = Agent( instructions="Perform internet searches to collect relevant information.", tools=[internet_search_tool] # <--- Tool Assignment)# 3. Start Agentsearch_agent.start("Search about AI job trends in 2025")
4
Start Agents
Execute your script:
Terminal
Copy
python app.py
1
Install PraisonAI
Install the core package and duckduckgo_search package:
Terminal
Copy
pip install praisonai duckduckgo_search
2
Create Custom Tool
To add additional tools/features you need some coding which can be generated using ChatGPT or any LLM
Create a new file tools.py with the following content:
Copy
from duckduckgo_search import DDGSfrom typing import List, Dict# 1. Tooldef internet_search_tool(query: str) -> List[Dict]: """ Perform Internet Search """ results = [] ddgs = DDGS() for result in ddgs.text(keywords=query, max_results=5): results.append({ "title": result.get("title", ""), "url": result.get("href", ""), "snippet": result.get("body", "") }) return results
3
Create Agent
Create a new file agents.yaml with the following content:
Copy
framework: praisonaitopic: create movie script about cat in marsroles: scriptwriter: backstory: Expert in dialogue and script structure, translating concepts into scripts. goal: Write a movie script about a cat in Mars role: Scriptwriter tools: - internet_search_tool # <-- Tool assigned to Agent here tasks: scriptwriting_task: description: Turn the story concept into a production-ready movie script, including dialogue and scene details. expected_output: Final movie script with dialogue and scene details.