Skip to content

Commit c582199

Browse files
committed
Add __call__ method to Tool
1 parent 7d2ce57 commit c582199

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

autogen/tools/tool.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,16 @@ def register_for_execution(self, agent: "ConversableAgent") -> None:
7070
agent (ConversableAgent): The agent to which the tool will be registered.
7171
"""
7272
agent.register_for_execution()(self)
73+
74+
def __call__(self, *args: Any, **kwargs: Any) -> Any:
75+
"""
76+
Execute the tool by calling its underlying function with the provided arguments.
77+
78+
Args:
79+
*args: Positional arguments to pass to the tool
80+
**kwargs: Keyword arguments to pass to the tool
81+
82+
Returns:
83+
The result of executing the tool's function.
84+
"""
85+
return self._func(*args, **kwargs)

test/tools/test_tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ def test_register_for_execution(self) -> None:
5757
self.tool.register_for_execution(user_proxy)
5858
assert user_proxy.can_execute_function("test_tool")
5959
assert user_proxy.function_map["test_tool"]("Hello") == "Hello!"
60+
61+
def test__call__(self) -> None:
62+
assert self.tool("Hello") == "Hello!"

0 commit comments

Comments
 (0)