()
| 250 | |
| 251 | @pytest.mark.asyncio |
| 252 | async def test_complex_args_function(): |
| 253 | tool = function_tool(complex_args_function, failure_error_function=None) |
| 254 | assert tool.name == "complex_args_function" |
| 255 | |
| 256 | valid_json = json.dumps( |
| 257 | { |
| 258 | "foo": Foo(a=1).model_dump(), |
| 259 | "bar": Bar(x="hello", y=10), |
| 260 | } |
| 261 | ) |
| 262 | result = await tool.on_invoke_tool( |
| 263 | ToolContext(None, tool_name=tool.name, tool_call_id="1", tool_arguments=valid_json), |
| 264 | valid_json, |
| 265 | ) |
| 266 | assert result == "6 hello10 hello" |
| 267 | |
| 268 | valid_json = json.dumps( |
| 269 | { |
| 270 | "foo": Foo(a=1, b=2).model_dump(), |
| 271 | "bar": Bar(x="hello", y=10), |
| 272 | } |
| 273 | ) |
| 274 | result = await tool.on_invoke_tool( |
| 275 | ToolContext(None, tool_name=tool.name, tool_call_id="1", tool_arguments=valid_json), |
| 276 | valid_json, |
| 277 | ) |
| 278 | assert result == "3 hello10 hello" |
| 279 | |
| 280 | valid_json = json.dumps( |
| 281 | { |
| 282 | "foo": Foo(a=1, b=2).model_dump(), |
| 283 | "bar": Bar(x="hello", y=10), |
| 284 | "baz": "world", |
| 285 | } |
| 286 | ) |
| 287 | result = await tool.on_invoke_tool( |
| 288 | ToolContext(None, tool_name=tool.name, tool_call_id="1", tool_arguments=valid_json), |
| 289 | valid_json, |
| 290 | ) |
| 291 | assert result == "3 hello10 world" |
| 292 | |
| 293 | # Missing required argument should raise an error |
| 294 | with pytest.raises(ModelBehaviorError): |
| 295 | await tool.on_invoke_tool( |
| 296 | ToolContext( |
| 297 | None, tool_name=tool.name, tool_call_id="1", tool_arguments='{"foo": {"a": 1}}' |
| 298 | ), |
| 299 | '{"foo": {"a": 1}}', |
| 300 | ) |
| 301 | |
| 302 | |
| 303 | def test_function_config_overrides(): |
nothing calls this directly
no test coverage detected