from duckduckgo_search import DDGSdef search_web(query: str) -> str: """Search the web for information""" results = DDGS().text(query, max_results=3) return str(results)
3
Add Tool to Agent
from praisonaiagents import Agentagent = Agent( instructions="Search and summarize information", tools=[search_web] # Add your tool here)agent.start("Search for AI trends in 2025")
from duckduckgo_search import DDGSdef search_web(query: str) -> str: """Search the web for information""" results = [] for r in DDGS().text(query, max_results=5): results.append(f"- {r['title']}: {r['body']}") return "\n".join(results)
from praisonaiagents import Agentfrom duckduckgo_search import DDGS# Tool 1: Web searchdef search_web(query: str) -> str: """Search the web for information""" results = DDGS().text(query, max_results=3) return str(results)# Tool 2: Calculatordef calculate(expression: str) -> str: """Calculate a math expression""" try: return str(eval(expression)) except: return "Error"# Agent with multiple toolsagent = Agent( name="ResearchAssistant", instructions="Search the web and do calculations to help users", tools=[search_web, calculate])agent.start("What is the population of Tokyo? Calculate 10% of that number.")
from praisonaiagents import Agent# Built-in web searchagent = Agent( instructions="Research topics", web=True # Enable built-in web search)# Or use specific search providersagent = Agent( instructions="Research topics", tools=["tavily", "duckduckgo"] # Named tools)