-
Notifications
You must be signed in to change notification settings - Fork 2
/
single_agent_example.py
53 lines (41 loc) · 1.27 KB
/
single_agent_example.py
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
from agento import Agent, print_history
from typing import List
# Define the functions that the agents can use
def get_apples(quantity: int) -> List[str]:
"""
Get a certain quantity of apples.
Args:
quantity (int): The quantity of apples to get.
Returns:
List[str]: A list of apples.
"""
return ["Apple" for _ in range(quantity)]
def eat_apples(apples: List[str], quantity: int) -> List[str]:
"""
Eat a certain quantity of apples.
Args:
apples (List[str]): A list of apples.
quantity (int): The quantity of apples to eat.
Returns:
List[str]: The remaining apples.
"""
return apples[quantity:] if quantity < len(apples) else []
def sell_apples(apples: List[str]) -> str:
"""
Sell all the apples provided.
Args:
apples (List[str]): A list of apples.
Returns:
str: The money earned from selling the apples.
"""
return f"${len(apples) * 1}"
# Define the agent
agent = Agent(
name="Apple Agent",
instructions="You are an apple seller. You can get, eat or sell apples.",
functions=[get_apples, eat_apples, sell_apples],
)
# Run the agent
history = agent("Can you get 4 apples, eat 1 of them and sell the rest?")
# Print the history
print_history(history)