fix: prevent tool description cache mutation (#3540)

This commit is contained in:
koala553 authored and GitHub committed 2026-11-05 10:10:17 +08:00
1 parent c8e60d1325
commit c59b29c723
1 file changed
+6 -3
@@ -47,9 +47,12 @@ class ToolManager:
return all_tools
def get_function_descriptions(self) -> List[Dict[str, Any]]:
"""获取所有工具的函数描述(OpenAI格式)"""
"""获取所有工具的函数描述(OpenAI格式)
返回缓存的浅拷贝,防止调用方就地修改污染缓存。
"""
if self._cached_function_descriptions is not None:
return self._cached_function_descriptions
return list(self._cached_function_descriptions)
descriptions = []
tools = self.get_all_tools()
@@ -57,7 +60,7 @@ class ToolManager:
descriptions.append(tool_definition.description)
self._cached_function_descriptions = descriptions
return descriptions
return list(descriptions)
def has_tool(self, tool_name: str) -> bool:
"""检查是否存在指定工具"""