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")