akrstova's picture
Initial version of agent with math and search tools
2a6057d
"""This module contains tools for performing mathematical operations."""
from langchain_core.tools import tool
@tool
def add(x: float, y: float) -> float:
"""
Adds two numbers.
Args:
x (float): the first number
y (float): the second number
"""
return x + y
@tool
def subtract(x: float, y: float) -> float:
"""
Subtracts two numbers.
Args:
x (float): the first number
y (float): the second number
"""
return x - y
@tool
def multiply(x: float, y: float) -> float:
"""
Multiplies two numbers.
Args:
x (float): the first number
y (float): the second number
"""
return x * y
@tool
def divide(x: float, y: float) -> float:
"""
Divides two numbers.
Args:
x (float): the first number
y (float): the second number to divide by
"""
if y == 0:
raise ValueError("Cannot divide by zero")
return x / y
@tool
def modulus(x: float, y: float) -> float:
"""
Returns the remainder when x is divided by y.
Args:
x (float): the dividend
y (float): the divisor
"""
if y == 0:
raise ValueError("Cannot compute modulus with zero divisor")
return x % y
@tool
def power(x: float, y: float) -> float:
"""
Raises x to the power of y.
Args:
x (float): the base number
y (float): the exponent
"""
return x ** y
@tool
def sqrt(x: float) -> float:
"""
Returns the square root of x.
Args:
x (float): the number to find the square root of
"""
if x < 0:
raise ValueError("Cannot compute square root of negative number")
return x ** 0.5