From d60a3f0d1d92bb887d3789778d478ec10076875b Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Tue, 24 Mar 2026 18:28:19 +0800 Subject: [PATCH] fix: add missing add_tool and merge methods to base ToolSet The internal ToolSet (base.py) was missing add_tool() and merge() methods that the agent code expects. When tmgr.get_full_tool_set() returned a base.py ToolSet, calls to add_tool() and merge() failed. Added: - add_tool() as alias to add() - merge() method to merge another ToolSet This fixes runtime crash: AttributeError: 'ToolSet' object has no attribute 'add_tool' --- astrbot/_internal/tools/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/astrbot/_internal/tools/base.py b/astrbot/_internal/tools/base.py index 6f8f1f57b..56e342799 100644 --- a/astrbot/_internal/tools/base.py +++ b/astrbot/_internal/tools/base.py @@ -100,6 +100,10 @@ class ToolSet: """Add a tool to the set.""" self._tools[tool.name] = tool + def add_tool(self, tool: FunctionTool) -> None: + """Add a tool to the set (alias for add()).""" + self.add(tool) + def remove(self, name: str) -> FunctionTool | None: """Remove and return a tool by name.""" return self._tools.pop(name, None) @@ -126,6 +130,11 @@ class ToolSet: def __len__(self) -> int: return len(self._tools) + def merge(self, other: "ToolSet") -> None: + """Merge another ToolSet into this one.""" + for tool in other.tools: + self.add(tool) + @property def tools(self) -> list[FunctionTool]: """List all tools in this set."""