22from deprecated import deprecated
33from typing import Literal , Any
44
5+ from collections .abc import Iterator
6+
57from collections .abc import Awaitable , Callable
68from .mcp_client import MCPClient
79
@@ -32,7 +34,7 @@ class FunctionTool:
3234 mcp_client : MCPClient | None = None
3335 """MCP 客户端,当 origin 为 mcp 时有效"""
3436
35- def __repr__ (self ):
37+ def __repr__ (self ) -> str :
3638 return f"FuncTool(name={ self .name } , parameters={ self .parameters } , description={ self .description } , active={ self .active } , origin={ self .origin } )"
3739
3840 def __dict__ (self ) -> dict [str , Any ]:
@@ -53,14 +55,14 @@ class ToolSet:
5355 This class provides methods to add, remove, and retrieve tools, as well as
5456 convert the tools to different API formats (OpenAI, Anthropic, Google GenAI)."""
5557
56- def __init__ (self , tools : list [FunctionTool ] | None = None ):
58+ def __init__ (self , tools : list [FunctionTool ] | None = None ) -> None :
5759 self .tools : list [FunctionTool ] = tools or []
5860
5961 def empty (self ) -> bool :
6062 """Check if the tool set is empty."""
6163 return len (self .tools ) == 0
6264
63- def add_tool (self , tool : FunctionTool ):
65+ def add_tool (self , tool : FunctionTool ) -> None :
6466 """Add a tool to the set."""
6567 # 检查是否已存在同名工具
6668 for i , existing_tool in enumerate (self .tools ):
@@ -69,7 +71,7 @@ def add_tool(self, tool: FunctionTool):
6971 return
7072 self .tools .append (tool )
7173
72- def remove_tool (self , name : str ):
74+ def remove_tool (self , name : str ) -> None :
7375 """Remove a tool by its name."""
7476 self .tools = [tool for tool in self .tools if tool .name != name ]
7577
@@ -87,7 +89,7 @@ def add_func(
8789 func_args : list ,
8890 desc : str ,
8991 handler : Callable [..., Awaitable [Any ]],
90- ):
92+ ) -> None :
9193 """Add a function tool to the set."""
9294 params = {
9395 "type" : "object" , # hard-coded here
@@ -107,7 +109,7 @@ def add_func(
107109 self .add_tool (_func )
108110
109111 @deprecated (reason = "Use remove_tool() instead" , version = "4.0.0" )
110- def remove_func (self , name : str ):
112+ def remove_func (self , name : str ) -> None :
111113 """Remove a function tool by its name."""
112114 self .remove_tool (name )
113115
@@ -238,32 +240,34 @@ def convert_schema(schema: dict) -> dict:
238240 return declarations
239241
240242 @deprecated (reason = "Use openai_schema() instead" , version = "4.0.0" )
241- def get_func_desc_openai_style (self , omit_empty_parameter_field : bool = False ):
243+ def get_func_desc_openai_style (
244+ self , omit_empty_parameter_field : bool = False
245+ ) -> list [dict ]:
242246 return self .openai_schema (omit_empty_parameter_field )
243247
244248 @deprecated (reason = "Use anthropic_schema() instead" , version = "4.0.0" )
245- def get_func_desc_anthropic_style (self ):
249+ def get_func_desc_anthropic_style (self ) -> list [ dict ] :
246250 return self .anthropic_schema ()
247251
248252 @deprecated (reason = "Use google_schema() instead" , version = "4.0.0" )
249- def get_func_desc_google_genai_style (self ):
253+ def get_func_desc_google_genai_style (self ) -> dict :
250254 return self .google_schema ()
251255
252256 def names (self ) -> list [str ]:
253257 """获取所有工具的名称列表"""
254258 return [tool .name for tool in self .tools ]
255259
256- def __len__ (self ):
260+ def __len__ (self ) -> int :
257261 return len (self .tools )
258262
259- def __bool__ (self ):
263+ def __bool__ (self ) -> bool :
260264 return len (self .tools ) > 0
261265
262- def __iter__ (self ):
266+ def __iter__ (self ) -> Iterator :
263267 return iter (self .tools )
264268
265- def __repr__ (self ):
269+ def __repr__ (self ) -> str :
266270 return f"ToolSet(tools={ self .tools } )"
267271
268- def __str__ (self ):
272+ def __str__ (self ) -> str :
269273 return f"ToolSet(tools={ self .tools } )"
0 commit comments