2424from .models .interface import Model
2525from .prompts import DynamicPromptFunction , Prompt , PromptUtil
2626from .run_context import RunContextWrapper , TContext
27- from .tool import FunctionTool , FunctionToolResult , Tool , function_tool
27+ from .tool import (
28+ FunctionTool ,
29+ FunctionToolResult ,
30+ Tool ,
31+ ToolErrorFunction ,
32+ default_tool_error_function ,
33+ function_tool ,
34+ )
2835from .tool_context import ToolContext
2936from .util import _transforms
3037from .util ._types import MaybeAwaitable
@@ -411,6 +418,7 @@ def as_tool(
411418 previous_response_id : str | None = None ,
412419 conversation_id : str | None = None ,
413420 session : Session | None = None ,
421+ failure_error_function : ToolErrorFunction | None = default_tool_error_function ,
414422 ) -> Tool :
415423 """Transform this agent into a tool, callable by other agents.
416424
@@ -433,12 +441,15 @@ def as_tool(
433441 agent run. The callback receives an `AgentToolStreamEvent` containing the nested
434442 agent, the originating tool call (when available), and each stream event. When
435443 provided, the nested agent is executed in streaming mode.
444+ failure_error_function: If provided, generate an error message when the tool (agent) run
445+ fails. The message is sent to the LLM. If None, the exception is raised instead.
436446 """
437447
438448 @function_tool (
439449 name_override = tool_name or _transforms .transform_string_function_style (self .name ),
440450 description_override = tool_description or "" ,
441451 is_enabled = is_enabled ,
452+ failure_error_function = failure_error_function ,
442453 )
443454 async def run_agent (context : ToolContext , input : str ) -> Any :
444455 from .run import DEFAULT_MAX_TURNS , Runner
0 commit comments