mjschock's picture
Refactor agent structure by modularizing agent implementations into separate directories for web, data analysis, and media agents. Remove legacy code from agents.py, prompts.py, and tools.py, enhancing maintainability. Update main_v2.py to reflect new import paths and agent initialization. Add new tools for enhanced functionality, including web searching and data extraction. Update requirements.txt to include necessary dependencies for new tools.
837e221 unverified
raw
history blame
1 kB
from typing import Dict, Any
import math
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)}