shrewd-agent / tools /maths.py
Pycrolis
feat(tool): add tool for summing integer lists
bc81f5d
raw
history blame contribute delete
987 Bytes
from typing import List
from langchain_core.tools import tool
from loguru import logger
@tool("add_integers_tool", parse_docstring=True)
def add_integers(numbers: List[int]) -> int:
"""
Add a list of integers together and return their sum.
This tool takes a list of integers and calculates their sum. It's useful for
performing basic arithmetic operations on multiple numbers at once.
Args:
numbers (List[int]): A list of integers to be summed.
Returns:
int: The sum of all integers in the input list.
"""
logger.info(f"use add_integers with param: {numbers}")
if not numbers:
raise ValueError("Input list cannot be empty")
try:
return sum(numbers)
except TypeError as e:
raise TypeError("All elements in the list must be integers") from e
if __name__ == "__main__":
result = add_integers.invoke({"numbers": [10577, 10037, 10107, 9888, 10089, 10061, 10089, 9917, 10031]})
print(result)