kpbotla's picture
Upload 5 files
b2746c2 verified
raw
history blame contribute delete
440 Bytes
from smolagents import tool
@tool
def python(code: str) -> str:
"""
Evaluates a math expression using sandboxed eval.
Args:
code (str): A simple Python expression to evaluate.
Returns:
str: The result of the evaluation or error message.
"""
try:
result = str(eval(code, {"__builtins__": {}}))
return f"Answer: {result}"
except Exception as e:
return f"Error: {str(e)}"