lollmsbot 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,151 @@
1
+ """
2
+ Tools package for LollmsBot.
3
+
4
+ This package provides a collection of built-in tools for the Agent framework,
5
+ including filesystem operations, HTTP requests, calendar management, and
6
+ shell command execution. It also provides the ToolRegistry for dynamic
7
+ tool registration and discovery.
8
+
9
+ Example:
10
+ >>> from lollmsbot.tools import get_default_tools, ToolRegistry
11
+ >>> tools = get_default_tools()
12
+ >>> registry = ToolRegistry()
13
+ >>> for tool in tools:
14
+ ... registry.register(tool)
15
+ """
16
+
17
+ from lollmsbot.agent import Tool, ToolResult, ToolError
18
+
19
+ # Import all tool classes
20
+ from lollmsbot.tools.filesystem import FilesystemTool
21
+ from lollmsbot.tools.http import HttpTool
22
+ from lollmsbot.tools.calendar import CalendarTool
23
+ from lollmsbot.tools.shell import ShellTool
24
+
25
+
26
+ class ToolRegistry:
27
+ """Dynamic registry for tool registration and discovery.
28
+
29
+ The ToolRegistry provides a centralized way to manage tool instances,
30
+ allowing dynamic registration, lookup, and enumeration of available tools.
31
+
32
+ Attributes:
33
+ _tools: Dictionary mapping tool names to tool instances.
34
+
35
+ Example:
36
+ >>> registry = ToolRegistry()
37
+ >>> registry.register(FilesystemTool())
38
+ >>> tool = registry.get("filesystem")
39
+ >>> all_tools = registry.list_tools()
40
+ """
41
+
42
+ def __init__(self) -> None:
43
+ """Initialize an empty tool registry."""
44
+ self._tools: dict[str, Tool] = {}
45
+
46
+ def register(self, tool: Tool) -> None:
47
+ """Register a tool in the registry.
48
+
49
+ Args:
50
+ tool: Tool instance to register.
51
+
52
+ Raises:
53
+ ValueError: If a tool with the same name is already registered.
54
+ """
55
+ if tool.name in self._tools:
56
+ raise ValueError(f"Tool '{tool.name}' is already registered")
57
+ self._tools[tool.name] = tool
58
+
59
+ def unregister(self, tool_name: str) -> Tool | None:
60
+ """Remove a tool from the registry.
61
+
62
+ Args:
63
+ tool_name: Name of the tool to remove.
64
+
65
+ Returns:
66
+ The removed tool if found, None otherwise.
67
+ """
68
+ return self._tools.pop(tool_name, None)
69
+
70
+ def get(self, tool_name: str) -> Tool | None:
71
+ """Get a tool by name.
72
+
73
+ Args:
74
+ tool_name: Name of the tool to retrieve.
75
+
76
+ Returns:
77
+ The tool instance if found, None otherwise.
78
+ """
79
+ return self._tools.get(tool_name)
80
+
81
+ def list_tools(self) -> list[Tool]:
82
+ """List all registered tools.
83
+
84
+ Returns:
85
+ List of all registered tool instances.
86
+ """
87
+ return list(self._tools.values())
88
+
89
+ def clear(self) -> None:
90
+ """Remove all tools from the registry."""
91
+ self._tools.clear()
92
+
93
+ def __contains__(self, tool_name: str) -> bool:
94
+ """Check if a tool name is registered.
95
+
96
+ Args:
97
+ tool_name: Name to check.
98
+
99
+ Returns:
100
+ True if the tool is registered, False otherwise.
101
+ """
102
+ return tool_name in self._tools
103
+
104
+ def __len__(self) -> int:
105
+ """Get the number of registered tools."""
106
+ return len(self._tools)
107
+
108
+ def __repr__(self) -> str:
109
+ return f"ToolRegistry({list(self._tools.keys())})"
110
+
111
+
112
+ def get_default_tools() -> list[Tool]:
113
+ """Get a list of default tool instances.
114
+
115
+ Returns a list containing instantiated default tools:
116
+ - FilesystemTool: File and directory operations
117
+ - HttpTool: HTTP requests and API calls
118
+ - CalendarTool: Date and time management
119
+ - ShellTool: Safe shell command execution
120
+
121
+ Returns:
122
+ List of default tool instances.
123
+
124
+ Example:
125
+ >>> tools = get_default_tools()
126
+ >>> for tool in tools:
127
+ ... print(f"Loaded: {tool.name}")
128
+ """
129
+ return [
130
+ FilesystemTool(),
131
+ HttpTool(),
132
+ CalendarTool(),
133
+ ShellTool(),
134
+ ]
135
+
136
+
137
+ __all__ = [
138
+ # Base classes from agent module
139
+ "Tool",
140
+ "ToolResult",
141
+ "ToolError",
142
+ # Tool registry
143
+ "ToolRegistry",
144
+ # Tool classes
145
+ "FilesystemTool",
146
+ "HttpTool",
147
+ "CalendarTool",
148
+ "ShellTool",
149
+ # Utility functions
150
+ "get_default_tools",
151
+ ]