Hello... I have a question:
How can I pass some parameters inside the tool's function?
I want to have something like this:
def multiply(x: int, y: int, alpha: float) -> float:
"""Multiply two numbers."""
return x * y * alpha
......
# In another file
alpha = 0.1
multiply_tool = FunctionTool.from_defaults(fn=multiply, alpha=alpha)
agent = ReActAgent.from_tools([multiply_tool], llm=llm, verbose=True)
I found 2 solutions:
- Bad solution:
In a new file create an additional function:
alpha = 0.1
def new_multiply_fn(x: int, y: int) -> float:
"""Multiply two numbers."""
return multiply_fn(x, y, alpha)
- Better solution. Wrap tool function in class:
class ToolFunctionWrapper:
def __init__(self, alpha):
self.alpha = alpha
def multiply(x: int, y: int) -> float:
"""Multiply two numbers."""
return x * y * self.alpha
tool = ToolFunctionWrapper(alpha=0.1)
multiply_tool = FunctionTool.from_defaults(fn=tool.multiply)
agent = ReActAgent.from_tools([multiply_tool], llm=llm, verbose=True)
Maybe there is a better way to do this?