3737from ._tools import (
3838 FunctionInvocationLayer ,
3939 FunctionTool ,
40+ ToolTypes ,
41+ normalize_tools ,
4042)
4143from ._types import (
4244 AgentResponse ,
@@ -616,12 +618,7 @@ def __init__(
616618 id : str | None = None ,
617619 name : str | None = None ,
618620 description : str | None = None ,
619- tools : FunctionTool
620- | Callable [..., Any ]
621- | MutableMapping [str , Any ]
622- | Any
623- | Sequence [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ]
624- | None = None ,
621+ tools : ToolTypes | Callable [..., Any ] | Sequence [ToolTypes | Callable [..., Any ]] | None = None ,
625622 default_options : OptionsCoT | None = None ,
626623 context_providers : Sequence [BaseContextProvider ] | None = None ,
627624 ** kwargs : Any ,
@@ -667,24 +664,14 @@ def __init__(
667664
668665 # Get tools from options or named parameter (named param takes precedence)
669666 tools_ = tools if tools is not None else opts .pop ("tools" , None )
670- tools_ = cast (
671- FunctionTool
672- | Callable [..., Any ]
673- | MutableMapping [str , Any ]
674- | list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ]]
675- | None ,
676- tools_ ,
677- )
678667
679668 # Handle instructions - named parameter takes precedence over options
680669 instructions_ = instructions if instructions is not None else opts .pop ("instructions" , None )
681670
682671 # We ignore the MCP Servers here and store them separately,
683672 # we add their functions to the tools list at runtime
684- normalized_tools : list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ]] = ( # type:ignore[reportUnknownVariableType]
685- [] if tools_ is None else tools_ if isinstance (tools_ , list ) else [tools_ ] # type: ignore[list-item]
686- )
687- self .mcp_tools : list [MCPTool ] = [tool for tool in normalized_tools if isinstance (tool , MCPTool )] # type: ignore[misc]
673+ normalized_tools = normalize_tools (tools_ )
674+ self .mcp_tools : list [MCPTool ] = [tool for tool in normalized_tools if isinstance (tool , MCPTool )]
688675 agent_tools = [tool for tool in normalized_tools if not isinstance (tool , MCPTool )]
689676
690677 # Build chat options dict
@@ -767,12 +754,7 @@ def run(
767754 * ,
768755 stream : Literal [False ] = ...,
769756 session : AgentSession | None = None ,
770- tools : FunctionTool
771- | Callable [..., Any ]
772- | MutableMapping [str , Any ]
773- | Any
774- | list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ]
775- | None = None ,
757+ tools : ToolTypes | Callable [..., Any ] | Sequence [ToolTypes | Callable [..., Any ]] | None = None ,
776758 options : ChatOptions [ResponseModelBoundT ],
777759 ** kwargs : Any ,
778760 ) -> Awaitable [AgentResponse [ResponseModelBoundT ]]: ...
@@ -784,12 +766,7 @@ def run(
784766 * ,
785767 stream : Literal [False ] = ...,
786768 session : AgentSession | None = None ,
787- tools : FunctionTool
788- | Callable [..., Any ]
789- | MutableMapping [str , Any ]
790- | Any
791- | list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ]
792- | None = None ,
769+ tools : ToolTypes | Callable [..., Any ] | Sequence [ToolTypes | Callable [..., Any ]] | None = None ,
793770 options : OptionsCoT | ChatOptions [None ] | None = None ,
794771 ** kwargs : Any ,
795772 ) -> Awaitable [AgentResponse [Any ]]: ...
@@ -801,12 +778,7 @@ def run(
801778 * ,
802779 stream : Literal [True ],
803780 session : AgentSession | None = None ,
804- tools : FunctionTool
805- | Callable [..., Any ]
806- | MutableMapping [str , Any ]
807- | Any
808- | list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ]
809- | None = None ,
781+ tools : ToolTypes | Callable [..., Any ] | Sequence [ToolTypes | Callable [..., Any ]] | None = None ,
810782 options : OptionsCoT | ChatOptions [Any ] | None = None ,
811783 ** kwargs : Any ,
812784 ) -> ResponseStream [AgentResponseUpdate , AgentResponse [Any ]]: ...
@@ -817,12 +789,7 @@ def run(
817789 * ,
818790 stream : bool = False ,
819791 session : AgentSession | None = None ,
820- tools : FunctionTool
821- | Callable [..., Any ]
822- | MutableMapping [str , Any ]
823- | Any
824- | list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ]
825- | None = None ,
792+ tools : ToolTypes | Callable [..., Any ] | Sequence [ToolTypes | Callable [..., Any ]] | None = None ,
826793 options : OptionsCoT | ChatOptions [Any ] | None = None ,
827794 ** kwargs : Any ,
828795 ) -> Awaitable [AgentResponse [Any ]] | ResponseStream [AgentResponseUpdate , AgentResponse [Any ]]:
@@ -1002,12 +969,7 @@ async def _prepare_run_context(
1002969 * ,
1003970 messages : str | Message | Sequence [str | Message ] | None ,
1004971 session : AgentSession | None ,
1005- tools : FunctionTool
1006- | Callable [..., Any ]
1007- | MutableMapping [str , Any ]
1008- | Any
1009- | list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ]
1010- | None ,
972+ tools : ToolTypes | Callable [..., Any ] | Sequence [ToolTypes | Callable [..., Any ]] | None ,
1011973 options : Mapping [str , Any ] | None ,
1012974 kwargs : dict [str , Any ],
1013975 ) -> _RunContext :
@@ -1037,9 +999,7 @@ async def _prepare_run_context(
1037999 )
10381000
10391001 # Normalize tools
1040- normalized_tools : list [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ] = (
1041- [] if tools_ is None else tools_ if isinstance (tools_ , list ) else [tools_ ]
1042- )
1002+ normalized_tools = normalize_tools (tools_ )
10431003 agent_name = self ._get_agent_name ()
10441004
10451005 # Resolve final tool list (runtime provided tools + local MCP server tools)
@@ -1345,12 +1305,7 @@ def __init__(
13451305 id : str | None = None ,
13461306 name : str | None = None ,
13471307 description : str | None = None ,
1348- tools : FunctionTool
1349- | Callable [..., Any ]
1350- | MutableMapping [str , Any ]
1351- | Any
1352- | Sequence [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ] | Any ]
1353- | None = None ,
1308+ tools : ToolTypes | Callable [..., Any ] | Sequence [ToolTypes | Callable [..., Any ]] | None = None ,
13541309 default_options : OptionsCoT | None = None ,
13551310 context_providers : Sequence [BaseContextProvider ] | None = None ,
13561311 middleware : Sequence [MiddlewareTypes ] | None = None ,
0 commit comments