# metagpt/tools/libs/calculator.py
from metagpt.tools.tool_registry import register_tool
# “math”的tag用于将工具分类为数学工具,include_functions 参数用于指定要包含的函数。这有利于`DataInterpreter`选择并理解工具
@register_tool(tags=["math"], include_functions=["__init__", "add", "subtract", "multiply", "divide", "factorial"])
一个简单的计算器工具,可以执行基本的算术运算并计算阶乘。
raise ValueError("输入必须是非负整数")
return math.factorial(n)