@@ -26,9 +26,7 @@ async def test_argless_function():
2626 tool = function_tool (argless_function )
2727 assert tool .name == "argless_function"
2828
29- result = await tool .on_invoke_tool (
30- ToolContext (context = None , tool_name = tool .name , tool_call_id = "1" ), ""
31- )
29+ result = await tool .on_invoke_tool (ToolContext (context = None , tool_call_id = "1" ), "" )
3230 assert result == "ok"
3331
3432
@@ -41,13 +39,11 @@ async def test_argless_with_context():
4139 tool = function_tool (argless_with_context )
4240 assert tool .name == "argless_with_context"
4341
44- result = await tool .on_invoke_tool (ToolContext (None , tool_name = tool . name , tool_call_id = "1" ), "" )
42+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), "" )
4543 assert result == "ok"
4644
4745 # Extra JSON should not raise an error
48- result = await tool .on_invoke_tool (
49- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), '{"a": 1}'
50- )
46+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), '{"a": 1}' )
5147 assert result == "ok"
5248
5349
@@ -60,19 +56,15 @@ async def test_simple_function():
6056 tool = function_tool (simple_function , failure_error_function = None )
6157 assert tool .name == "simple_function"
6258
63- result = await tool .on_invoke_tool (
64- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), '{"a": 1}'
65- )
59+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), '{"a": 1}' )
6660 assert result == 6
6761
68- result = await tool .on_invoke_tool (
69- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), '{"a": 1, "b": 2}'
70- )
62+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), '{"a": 1, "b": 2}' )
7163 assert result == 3
7264
7365 # Missing required argument should raise an error
7466 with pytest .raises (ModelBehaviorError ):
75- await tool .on_invoke_tool (ToolContext (None , tool_name = tool . name , tool_call_id = "1" ), "" )
67+ await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), "" )
7668
7769
7870class Foo (BaseModel ):
@@ -100,9 +92,7 @@ async def test_complex_args_function():
10092 "bar" : Bar (x = "hello" , y = 10 ),
10193 }
10294 )
103- result = await tool .on_invoke_tool (
104- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), valid_json
105- )
95+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), valid_json )
10696 assert result == "6 hello10 hello"
10797
10898 valid_json = json .dumps (
@@ -111,9 +101,7 @@ async def test_complex_args_function():
111101 "bar" : Bar (x = "hello" , y = 10 ),
112102 }
113103 )
114- result = await tool .on_invoke_tool (
115- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), valid_json
116- )
104+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), valid_json )
117105 assert result == "3 hello10 hello"
118106
119107 valid_json = json .dumps (
@@ -123,16 +111,12 @@ async def test_complex_args_function():
123111 "baz" : "world" ,
124112 }
125113 )
126- result = await tool .on_invoke_tool (
127- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), valid_json
128- )
114+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), valid_json )
129115 assert result == "3 hello10 world"
130116
131117 # Missing required argument should raise an error
132118 with pytest .raises (ModelBehaviorError ):
133- await tool .on_invoke_tool (
134- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), '{"foo": {"a": 1}}'
135- )
119+ await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), '{"foo": {"a": 1}}' )
136120
137121
138122def test_function_config_overrides ():
@@ -192,9 +176,7 @@ async def run_function(ctx: RunContextWrapper[Any], args: str) -> str:
192176 assert tool .params_json_schema [key ] == value
193177 assert tool .strict_json_schema
194178
195- result = await tool .on_invoke_tool (
196- ToolContext (None , tool_name = tool .name , tool_call_id = "1" ), '{"data": "hello"}'
197- )
179+ result = await tool .on_invoke_tool (ToolContext (None , tool_call_id = "1" ), '{"data": "hello"}' )
198180 assert result == "hello_done"
199181
200182 tool_not_strict = FunctionTool (
@@ -209,8 +191,7 @@ async def run_function(ctx: RunContextWrapper[Any], args: str) -> str:
209191 assert "additionalProperties" not in tool_not_strict .params_json_schema
210192
211193 result = await tool_not_strict .on_invoke_tool (
212- ToolContext (None , tool_name = tool_not_strict .name , tool_call_id = "1" ),
213- '{"data": "hello", "bar": "baz"}' ,
194+ ToolContext (None , tool_call_id = "1" ), '{"data": "hello", "bar": "baz"}'
214195 )
215196 assert result == "hello_done"
216197
@@ -221,7 +202,7 @@ def my_func(a: int, b: int = 5):
221202 raise ValueError ("test" )
222203
223204 tool = function_tool (my_func )
224- ctx = ToolContext (None , tool_name = tool . name , tool_call_id = "1" )
205+ ctx = ToolContext (None , tool_call_id = "1" )
225206
226207 result = await tool .on_invoke_tool (ctx , "" )
227208 assert "Invalid JSON" in str (result )
@@ -245,7 +226,7 @@ def custom_sync_error_function(ctx: RunContextWrapper[Any], error: Exception) ->
245226 return f"error_{ error .__class__ .__name__ } "
246227
247228 tool = function_tool (my_func , failure_error_function = custom_sync_error_function )
248- ctx = ToolContext (None , tool_name = tool . name , tool_call_id = "1" )
229+ ctx = ToolContext (None , tool_call_id = "1" )
249230
250231 result = await tool .on_invoke_tool (ctx , "" )
251232 assert result == "error_ModelBehaviorError"
@@ -269,7 +250,7 @@ def custom_sync_error_function(ctx: RunContextWrapper[Any], error: Exception) ->
269250 return f"error_{ error .__class__ .__name__ } "
270251
271252 tool = function_tool (my_func , failure_error_function = custom_sync_error_function )
272- ctx = ToolContext (None , tool_name = tool . name , tool_call_id = "1" )
253+ ctx = ToolContext (None , tool_call_id = "1" )
273254
274255 result = await tool .on_invoke_tool (ctx , "" )
275256 assert result == "error_ModelBehaviorError"
0 commit comments