@@ -373,3 +373,49 @@ async def extractor(result) -> str:
373373 output = await tool .on_invoke_tool (tool_context , '{"input": "summarize this"}' )
374374
375375 assert output == "custom output"
376+
377+
378+ @pytest .mark .asyncio
379+ async def test_agent_as_tool_failure_error_function_none_reraises (
380+ monkeypatch : pytest .MonkeyPatch ,
381+ ) -> None :
382+ """If failure_error_function=None, exceptions should propagate to the caller."""
383+ agent = Agent (name = "failing_agent" )
384+
385+ async def fake_run (
386+ cls ,
387+ starting_agent ,
388+ input ,
389+ * ,
390+ context ,
391+ max_turns ,
392+ hooks ,
393+ run_config ,
394+ previous_response_id ,
395+ conversation_id ,
396+ session ,
397+ ):
398+ assert starting_agent is agent
399+ assert input == "hello"
400+ raise RuntimeError ("test failure" )
401+
402+ monkeypatch .setattr (Runner , "run" , classmethod (fake_run ))
403+
404+ tool = agent .as_tool (
405+ tool_name = "failing_agent_tool" ,
406+ tool_description = "Agent tool that raises" ,
407+ is_enabled = True ,
408+ failure_error_function = None ,
409+ )
410+
411+ assert isinstance (tool , FunctionTool )
412+
413+ tool_context = ToolContext (
414+ context = None ,
415+ tool_name = "failing_agent_tool" ,
416+ tool_call_id = "call_1" ,
417+ tool_arguments = '{"input": "hello"}' ,
418+ )
419+
420+ with pytest .raises (RuntimeError , match = "test failure" ):
421+ await tool .on_invoke_tool (tool_context , '{"input": "hello"}' )
0 commit comments