File size: 426 Bytes
488dc3e
 
 
1bbca12
488dc3e
1bbca12
488dc3e
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from langchain_core.tools import tool
from sympy import sympify
import logging

logger = logging.getLogger(__name__)

@tool
async def calculator_tool(expression: str) -> str:
    """Evaluate a mathematical expression"""
    try:
        result = sympify(expression)
        return str(result)
    except Exception as e:
        logger.error(f"Error evaluating expression '{expression}': {e}")
        return f"Error: {str(e)}"