mjschock's picture
Enhance agent functionality in main_v2.py by adding WikipediaSearchTool and updating DuckDuckGoSearchTool and VisitWebpageTool parameters. Modify agent initialization to accommodate new tools and increase max results and output length. Update requirements.txt to include Wikipedia-API dependency. Refactor imports for better organization across agent modules.
e4c7240 unverified
import math
from typing import Any, Dict
from smolagents import tool
@tool
def perform_calculation(expression: str) -> Dict[str, Any]:
"""
Safely evaluate a mathematical expression.
Args:
expression: Mathematical expression to evaluate
Returns:
Dictionary containing the result or error message
"""
try:
# Define allowed names
allowed_names = {
"abs": abs,
"round": round,
"min": min,
"max": max,
"sum": sum,
"len": len,
"pow": pow,
"math": math,
}
# Clean the expression
cleaned_expr = expression.strip()
# Evaluate using safer methods (this is still a simplified example)
# In a real implementation, use a proper math expression parser
result = eval(cleaned_expr, {"__builtins__": {}}, allowed_names)
return {"result": result}
except Exception as e:
return {"error": str(e)}