strands.tools.loader
Tool loading utilities.
load_tool_from_string
Section titled “load_tool_from_string”def load_tool_from_string(tool_string: str) -> list[AgentTool]Defined in: src/strands/tools/loader.py:23
Load tools follows strands supported input string formats.
This function can load a tool based on a string in the following ways:
- Local file path to a module based tool:
./path/to/module/tool.py - Module import path
2.1. Path to a module based tool:
strands_tools.file_read2.2. Path to a module with multiple AgentTool instances (@tool decorated):tests.fixtures.say_tool2.3. Path to a module and a specific function:tests.fixtures.say_tool:say
load_tools_from_file_path
Section titled “load_tools_from_file_path”def load_tools_from_file_path(tool_path: str) -> list[AgentTool]Defined in: src/strands/tools/loader.py:45
Load module from specified path, and then load tools from that module.
This function attempts to load the passed in path as a python module, and if it succeeds, then it tries to import strands tool(s) from that module.
load_tools_from_module_path
Section titled “load_tools_from_module_path”def load_tools_from_module_path(module_tool_path: str) -> list[AgentTool]Defined in: src/strands/tools/loader.py:77
Load strands tool from a module path.
Example module paths: my.module.path my.module.path:tool_name
load_tools_from_module
Section titled “load_tools_from_module”def load_tools_from_module(module: ModuleType, module_name: str) -> list[AgentTool]Defined in: src/strands/tools/loader.py:108
Load tools from a module.
First checks if the passed in module has instances of DecoratedToolFunction classes as atributes to the module. If so, then it returns them as a list of tools. If not, then it attempts to load the module as a module based tool.
ToolLoader
Section titled “ToolLoader”class ToolLoader()Defined in: src/strands/tools/loader.py:152
Handles loading of tools from different sources.
load_python_tools
Section titled “load_python_tools”@staticmethoddef load_python_tools(tool_path: str, tool_name: str) -> list[AgentTool]Defined in: src/strands/tools/loader.py:156
DEPRECATED: Load a Python tool module and return all discovered function-based tools as a list.
This method always returns a list of AgentTool (possibly length 1). It is the canonical API for retrieving multiple tools from a single Python file.
load_python_tool
Section titled “load_python_tool”@staticmethoddef load_python_tool(tool_path: str, tool_name: str) -> AgentToolDefined in: src/strands/tools/loader.py:243
DEPRECATED: Load a Python tool module and return a single AgentTool for backwards compatibility.
Use load_python_tools to retrieve all tools defined in a .py file (returns a list).
This function will emit a DeprecationWarning and return the first discovered tool.
load_tool
Section titled “load_tool”@classmethoddef load_tool(cls, tool_path: str, tool_name: str) -> AgentToolDefined in: src/strands/tools/loader.py:262
DEPRECATED: Load a single tool based on its file extension for backwards compatibility.
Use load_tools to retrieve all tools defined in a file (returns a list).
This function will emit a DeprecationWarning and return the first discovered tool.
load_tools
Section titled “load_tools”@classmethoddef load_tools(cls, tool_path: str, tool_name: str) -> list[AgentTool]Defined in: src/strands/tools/loader.py:282
DEPRECATED: Load tools from a file based on its file extension.
Arguments:
tool_path- Path to the tool file.tool_name- Name of the tool.
Returns:
A single Tool instance.
Raises:
FileNotFoundError- If the tool file does not exist.ValueError- If the tool file has an unsupported extension.Exception- For other errors during tool loading.