Tool Base Classes
Core base classes and data structures for the tools framework.
Tool
The base class for all tools that provides a common interface for both synchronous and asynchronous tool execution.
rllm.tools.tool_base.Tool
Abstract base class for all tools that provides a common interface.
All tools should inherit from this class and implement either: - forward() for synchronous tools - async_forward() for asynchronous tools
Source code in rllm/tools/tool_base.py
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 | |
json
property
Return the tool's information in a standardized format for tool registration.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict[str, Any]: Tool information including name, description, and parameters. Expected format: { "type": "function", "function": { "name": self.name, "description": "Description of what the tool does", "parameters": { "type": "object", "properties": { # Parameter definitions }, "required": ["list", "of", "required", "parameters"] } } } |
__init__
Initialize the tool with a name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tool, used for tool registry and calling. |
None
|
description
|
str
|
A description of the tool's purpose and functionality. |
None
|
function
|
Callable
|
Function to convert to tool format. |
None
|
Source code in rllm/tools/tool_base.py
forward
Synchronous implementation of the tool functionality. Override this method for synchronous tools.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
ToolOutput
|
The result of the tool execution. |
Source code in rllm/tools/tool_base.py
async_forward
async
Asynchronous implementation of the tool functionality. Override this method for asynchronous tools.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
ToolOutput
|
The result of the tool execution. |
Source code in rllm/tools/tool_base.py
__call__
Make the tool instance callable. - If use_async is True, delegates to async_forward - If use_async is False, delegates to forward - If use_async is None (default), uses async_forward if implemented, otherwise forward
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments to pass to the implementation |
()
|
|
use_async
|
Whether to use the async implementation (if None, auto-detect) |
False
|
|
**kwargs
|
Keyword arguments to pass to the implementation |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
The result of the tool execution, which may be a coroutine if using async_forward |
Source code in rllm/tools/tool_base.py
ToolCall
Data structure representing a tool call with name and arguments.
rllm.tools.tool_base.ToolCall
dataclass
ToolOutput
Data structure representing the output of a tool execution, including results, errors, and metadata.
rllm.tools.tool_base.ToolOutput
dataclass
Source code in rllm/tools/tool_base.py
__str__
Convert the tool output to a string representation.
Source code in rllm/tools/tool_base.py
to_string
Convert the tool output to a string representation.
Example usage
tool_output = ToolOutput(name="calculator", output=42) result_string = tool_output.to_string()