-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalculator-agent.py
More file actions
35 lines (29 loc) · 990 Bytes
/
calculator-agent.py
File metadata and controls
35 lines (29 loc) · 990 Bytes
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
import asyncio
from agentpy.agent import Agent, tool, auto
@tool
def add(a: float, b: float) -> float:
"""Adds two numbers."""
return a + b
@tool
def subtract(a: float, b: float) -> float:
"""Subtracts second number from the first number."""
return a - b
@tool
def multiply(a: float, b: float) -> float:
"""Multiplies two numbers."""
return a * b
@tool
def divide(a: float, b: float) -> float:
"""Divides first number by the second number. Returns 'None' if division by zero is attempted."""
return a / b if b != 0 else None
async def amain():
agent = Agent(
"I am a Calculator Agent. You can perform basic arithmetic operations like addition, subtraction, multiplication, and division.",
tools=auto() # This automatically detects and registers all @tool functions
)
await agent.cli(persistent=False)
if __name__ == "__main__":
try:
asyncio.run(amain())
except KeyboardInterrupt:
print("Exiting...")