-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcalculator.py
More file actions
68 lines (48 loc) · 1.42 KB
/
calculator.py
File metadata and controls
68 lines (48 loc) · 1.42 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
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Simple agent implementation showing how to create custom tools.
"""
import asyncio
from workflows_acp.models import Tool
from workflows_acp.acp_wrapper import start_agent
def add(x: int, y: int) -> int:
return x + y
def subtract(x: int, y: int) -> int:
return x - y
def multiply(x: int, y: int) -> int:
return x * y
def divide(x: int, y: int) -> str | float:
if y == 0:
return "Cannot divide by 0"
return x / y
add_tool = Tool(
name="add",
description="Add two integers together",
fn=add,
)
subtract_tool = Tool(
name="subtract",
description="Subtract the second integer from the first",
fn=subtract,
)
multiply_tool = Tool(
name="multiply",
description="Multiply two integers together",
fn=multiply,
)
divide_tool = Tool(
name="divide",
description="Divide the first integer by the second. Returns an error message if dividing by zero.",
fn=divide,
)
AGENT_TASK = "You provide the user with assistance related to calculations, leveraging your tools to perform sums, subtractions, multiplications and divisions."
async def main() -> None:
await start_agent(
agent_task=AGENT_TASK,
tools=[add_tool, subtract_tool, multiply_tool, divide_tool],
use_mcp=False,
)
if __name__ == "__main__":
# execute with toad (or any other ACP client)
# with toad:
# toad acp "python3 /path/to/calculator.py"
asyncio.run(main())