forked from humanlayer/humanlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-math_example.py
More file actions
55 lines (41 loc) · 1.33 KB
/
01-math_example.py
File metadata and controls
55 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from llama_toolkit import LlamaToolkit
from humanlayer import HumanLayer
hl = HumanLayer(
verbose=True,
# run_id is optional -it can be used to identify the agent in approval history
run_id="langchain-math",
)
# Example usage
def main():
toolkit = LlamaToolkit(model_name="llama3.1", temperature=0.1)
# Define your custom functions
@toolkit.add_function()
def calculate_square(x: int) -> int:
"""Calculate the square of a number."""
return x * x
@toolkit.add_function()
def add_numbers(x: int, y: int) -> int:
"""Add two numbers together."""
return x + y
@toolkit.add_function()
@hl.require_approval()
def multiply_numbers(x: int, y: int) -> int:
"""Multiply two numbers together."""
return x * y
# Create agent
agent = toolkit.create_agent()
print("Llama Agent Ready with Custom Functions!")
query = "multiply 5 and 3, then add 10 to the result"
try:
response = agent.invoke(query)
print(f"\nFinal Answer: {response}")
except Exception as e:
print(f"Error: {str(e)}")
if __name__ == "__main__":
main()
"""
Example queries to test:
1. "multiply 5 and 3, then add 10 to the result"
2. "calculate the square of 7, then multiply it by 2"
3. "add 5 and 3, then calculate the square of the result"
"""