-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtools.py
More file actions
41 lines (35 loc) · 1.22 KB
/
tools.py
File metadata and controls
41 lines (35 loc) · 1.22 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
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
#
# Copyright (C) 2026 Tencent. All rights reserved.
#
# tRPC-Agent-Python is licensed under Apache-2.0.
""" Tools for the LangGraph agent. """
from langchain_core.tools import tool
from trpc_agent_sdk.agents import langgraph_tool_node
@tool
@langgraph_tool_node
def calculate(operation: str, a: float, b: float) -> str:
"""Perform basic mathematical operations.
Args:
operation: Operation type ('add', 'subtract', 'multiply', 'divide')
a: First number
b: Second number
Returns:
Calculation result as a string
"""
try:
if operation == "add":
result = a + b
elif operation == "subtract":
result = a - b
elif operation == "multiply":
result = a * b
elif operation == "divide":
if b == 0:
return "Error: Cannot divide by zero"
result = a / b
else:
return f"Error: Unknown operation '{operation}'"
return f"Calculation result: {a} {operation} {b} = {result}"
except Exception as e: # pylint: disable=broad-except
return f"Calculation error: {str(e)}"