@@ -39,13 +39,29 @@ async def async_function_for_testing_with_2_arg_and_no_tool_context(arg1, arg2):
39
39
return arg1
40
40
41
41
42
+ class AsyncCallableWith2ArgsAndNoToolContext :
43
+
44
+ async def __call__ (self , arg1 , arg2 ):
45
+ assert arg1
46
+ assert arg2
47
+ return arg1
48
+
49
+
42
50
def function_for_testing_with_1_arg_and_tool_context (arg1 , tool_context ):
43
51
"""Function for testing with 1 arge and tool context."""
44
52
assert arg1
45
53
assert tool_context
46
54
return arg1
47
55
48
56
57
+ class AsyncCallableWith1ArgAndToolContext :
58
+
59
+ async def __call__ (self , arg1 , tool_context ):
60
+ assert arg1
61
+ assert tool_context
62
+ return arg1
63
+
64
+
49
65
def function_for_testing_with_2_arg_and_no_tool_context (arg1 , arg2 ):
50
66
"""Function for testing with 2 arge and no tool context."""
51
67
assert arg1
@@ -83,6 +99,16 @@ async def test_run_async_with_tool_context_async_func():
83
99
assert result == "test_value_1"
84
100
85
101
102
+ @pytest .mark .asyncio
103
+ async def test_run_async_with_tool_context_async_callable ():
104
+ """Test that run_async calls the callable with tool_context when tool_context is in signature (async callable)."""
105
+
106
+ tool = FunctionTool (AsyncCallableWith1ArgAndToolContext ())
107
+ args = {"arg1" : "test_value_1" }
108
+ result = await tool .run_async (args = args , tool_context = MagicMock ())
109
+ assert result == "test_value_1"
110
+
111
+
86
112
@pytest .mark .asyncio
87
113
async def test_run_async_without_tool_context_async_func ():
88
114
"""Test that run_async calls the function without tool_context when tool_context is not in signature (async function)."""
@@ -92,6 +118,15 @@ async def test_run_async_without_tool_context_async_func():
92
118
assert result == "test_value_1"
93
119
94
120
121
+ @pytest .mark .asyncio
122
+ async def test_run_async_without_tool_context_async_callable ():
123
+ """Test that run_async calls the callable without tool_context when tool_context is not in signature (async callable)."""
124
+ tool = FunctionTool (AsyncCallableWith2ArgsAndNoToolContext ())
125
+ args = {"arg1" : "test_value_1" , "arg2" : "test_value_2" }
126
+ result = await tool .run_async (args = args , tool_context = MagicMock ())
127
+ assert result == "test_value_1"
128
+
129
+
95
130
@pytest .mark .asyncio
96
131
async def test_run_async_with_tool_context_sync_func ():
97
132
"""Test that run_async calls the function with tool_context when tool_context is in signature (synchronous function)."""
0 commit comments