Tool Registry
The tool registry provides a centralized way to register, store, and retrieve tools. It supports both individual tool registration and batch registration of multiple tools.
Features
- Register individual tools or batches of tools
- Retrieve tools by name
- List all registered tools
- Singleton pattern for global access
rllm.tools.registry
ToolRegistry
A registry for tools that handles registration, retrieval, and management.
Source code in rllm/tools/registry.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
__new__
Implement singleton pattern to ensure there's only one registry instance.
__init__
Initialize the registry if it hasn't been initialized yet.
register
Register a tool with the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to register the tool under |
required |
tool_cls
|
type[Tool]
|
The tool class to register |
required |
Source code in rllm/tools/registry.py
register_all
Register multiple tools at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools_dict
|
dict[str, type[Tool]]
|
A dictionary mapping names to tool classes |
required |
Source code in rllm/tools/registry.py
get
Get a tool class by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tool to retrieve |
required |
Returns:
| Type | Description |
|---|---|
type[Tool] | None
|
The tool class if found, None otherwise |
instantiate
Instantiate a tool by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tool to instantiate |
required |
*args
|
Positional arguments to pass to the tool constructor |
()
|
|
**kwargs
|
Keyword arguments to pass to the tool constructor |
{}
|
Returns:
| Type | Description |
|---|---|
Tool | None
|
An instance of the tool if found, None otherwise |
Source code in rllm/tools/registry.py
list_tools
clear
unregister
Unregister a tool by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tool to unregister |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the tool was unregistered, False if it wasn't found |
Source code in rllm/tools/registry.py
__contains__
Check if a tool is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tool to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the tool is registered, False otherwise |
__getitem__
Get a tool class by name using dictionary-like syntax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tool to retrieve |
required |
Returns:
| Type | Description |
|---|---|
type[Tool]
|
The tool class |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the tool is not found |
Source code in rllm/tools/registry.py
__setitem__
Register a tool using dictionary-like syntax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to register the tool under |
required |
tool_cls
|
type[Tool]
|
The tool class to register |
required |
Source code in rllm/tools/registry.py
__iter__
__len__
to_dict
Convert the registry to a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, type[Tool]]
|
A dictionary mapping tool names to tool classes |