from praisonaiagents import Agent# Define a tool (any Python function)def calculate(expression: str) -> str: """Calculate a math expression""" return str(eval(expression))# Give the tool to your agentagent = Agent( instructions="You help with math problems", tools=[calculate])agent.start("What is 25 * 48?")
Any Python function can be a tool. Just add it to the tools list.
def get_weather(city: str) -> str: """Get the weather for a city""" # Your logic here return f"Weather in {city}: Sunny, 72°F"
2
Add Type Hints
Copy
# Type hints help the agent understand inputs/outputsdef search_web(query: str, max_results: int = 5) -> str: """Search the web for information""" return f"Found {max_results} results for: {query}"
3
Add to Agent
Copy
agent = Agent( instructions="You help users find information", tools=[get_weather, search_web])
from praisonaiagents import Agent# Web search (requires API key)agent = Agent( instructions="Search and summarize", tools=["tavily"] # or "duckduckgo", "you", "exa")# Enable web search simplyagent = Agent( instructions="Research topics", web=True # Built-in web search)