Pycrolis commited on
Commit
bc81f5d
·
1 Parent(s): 64a08a8

feat(tool): add tool for summing integer lists

Browse files
Files changed (2) hide show
  1. ShrewdAgent.py +2 -0
  2. tools/maths.py +33 -0
ShrewdAgent.py CHANGED
@@ -13,6 +13,7 @@ from langgraph.pregel import PregelProtocol
13
  from loguru import logger
14
  from pydantic import SecretStr
15
 
 
16
  from tools.excel_to_text import excel_to_text
17
  from tools.execute_python_code_from_file import execute_python_code_from_file
18
  from tools.produce_classifier import produce_classifier
@@ -50,6 +51,7 @@ class ShrewdAgent:
50
  sort_words_alphabetically,
51
  excel_to_text,
52
  execute_python_code_from_file,
 
53
  ]
54
  self.llm = ChatOpenAI(
55
  model="gpt-4o-mini",
 
13
  from loguru import logger
14
  from pydantic import SecretStr
15
 
16
+ from tools import maths
17
  from tools.excel_to_text import excel_to_text
18
  from tools.execute_python_code_from_file import execute_python_code_from_file
19
  from tools.produce_classifier import produce_classifier
 
51
  sort_words_alphabetically,
52
  excel_to_text,
53
  execute_python_code_from_file,
54
+ maths,
55
  ]
56
  self.llm = ChatOpenAI(
57
  model="gpt-4o-mini",
tools/maths.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+
3
+ from langchain_core.tools import tool
4
+ from loguru import logger
5
+
6
+
7
+ @tool("add_integers_tool", parse_docstring=True)
8
+ def add_integers(numbers: List[int]) -> int:
9
+ """
10
+ Add a list of integers together and return their sum.
11
+
12
+ This tool takes a list of integers and calculates their sum. It's useful for
13
+ performing basic arithmetic operations on multiple numbers at once.
14
+
15
+ Args:
16
+ numbers (List[int]): A list of integers to be summed.
17
+
18
+ Returns:
19
+ int: The sum of all integers in the input list.
20
+ """
21
+ logger.info(f"use add_integers with param: {numbers}")
22
+ if not numbers:
23
+ raise ValueError("Input list cannot be empty")
24
+
25
+ try:
26
+ return sum(numbers)
27
+ except TypeError as e:
28
+ raise TypeError("All elements in the list must be integers") from e
29
+
30
+
31
+ if __name__ == "__main__":
32
+ result = add_integers.invoke({"numbers": [10577, 10037, 10107, 9888, 10089, 10061, 10089, 9917, 10031]})
33
+ print(result)