Create deterministic_tools.py
Browse files
agents/tools/deterministic_tools.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from crewai.tools import tool
|
| 2 |
+
|
| 3 |
+
class DeterministicTools():
|
| 4 |
+
@tool("Add Tool")
|
| 5 |
+
def add_tool(a: float, b: float) -> float:
|
| 6 |
+
"""Add two numbers.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
a (float): First number
|
| 10 |
+
b (float): Second number
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
number: Result
|
| 14 |
+
"""
|
| 15 |
+
return a + b
|
| 16 |
+
|
| 17 |
+
@tool("Subtract Tool")
|
| 18 |
+
def subtract_tool(a: float, b: float) -> float:
|
| 19 |
+
"""Subtract two numbers.
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
a (float): First number
|
| 23 |
+
b (float): Second number
|
| 24 |
+
|
| 25 |
+
Returns:
|
| 26 |
+
number: Result
|
| 27 |
+
"""
|
| 28 |
+
return a - b
|
| 29 |
+
|
| 30 |
+
@tool("Multiply Tool")
|
| 31 |
+
def multiply_tool(a: float, b: float) -> float:
|
| 32 |
+
"""Multiply two numbers.
|
| 33 |
+
Args:
|
| 34 |
+
a (float): First number
|
| 35 |
+
b (float): Second number
|
| 36 |
+
|
| 37 |
+
Returns:
|
| 38 |
+
number: Result
|
| 39 |
+
"""
|
| 40 |
+
return a * b
|
| 41 |
+
|
| 42 |
+
@tool("Divide Tool")
|
| 43 |
+
def divide_tool(a: float, b: float) -> float:
|
| 44 |
+
"""Divide two numbers.
|
| 45 |
+
|
| 46 |
+
Args:
|
| 47 |
+
a (float): First number
|
| 48 |
+
b (float): Second number
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
number: Result
|
| 52 |
+
|
| 53 |
+
Raises:
|
| 54 |
+
RuntimeError: If processing fails
|
| 55 |
+
"""
|
| 56 |
+
if b == 0:
|
| 57 |
+
raise RuntimeError("Cannot divide by zero.")
|
| 58 |
+
|
| 59 |
+
return a / b
|
| 60 |
+
|
| 61 |
+
@tool("Modulus Tool")
|
| 62 |
+
def modulus_tool(a: float, b: float) -> float:
|
| 63 |
+
"""Get the modulus of two numbers.
|
| 64 |
+
|
| 65 |
+
Args:
|
| 66 |
+
a (float): First number
|
| 67 |
+
b (float): Second number
|
| 68 |
+
|
| 69 |
+
Returns:
|
| 70 |
+
number: Result
|
| 71 |
+
"""
|
| 72 |
+
return a % b
|