Tool Loader¶
- ibm_watsonx_gov.tools.core.tool_loader.load_tool(tool_name: str, **kwargs)¶
Method to load a tool based on tool name and other parameters
- Parameters:
tool_name (str) – Name of the registered tool
headers (Optional[headers]) –
Dynamic headers to be supplied to the tool
If the user supplies static headers (whose value do not change) no need of supplying this header while loading.
- User is expected to provide the information related to dynamic headers while tool loading . Types of dynamic headers
If the tool is registered with header value $DYNAMIC HEADERS it is mandatory to supply the information while tool loading
If the tool is registered with convention headers_key: $header_key this information should be supplied as part of environment
**kwargs – Optional configuration based on the tool .(Eg: Configuration properties for OOTB tool)
- Returns:
A Langchain/Langgraph compatible tool object
- Return type:
Tool
Examples:¶
- Basic example to load a tool
from ibm_watsonx_gov.tools import load_tool tool = load_tool(tool_name=<TOOL_NAME>)
- Example of tool loading that expects configuration
from ibm_watsonx_gov.tools import load_tool from ibm_watsonx_gov.tools.clients import get_tool_info tool_details = get_tool_info(tool_name=<TOOL_NAME>) tool_config = tool_details.get("entity").get("config) config = { <Provide the properties as per the details in tool config> } tool = load_tool(tool_name=<TOOL_NAME>,**config)
- Example of tool loading that expects headers
from ibm_watsonx_gov.tools import load_tool from ibm_watsonx_gov.tools.clients import get_tool_info tool_details = get_tool_info(tool_name=<TOOL_NAME>) headers = tool_details.get("entity").get("endpoint").get("headers") headers = { "Authorization":"Bearer __TOKEN__" #Need to supply dynamic headers } tool = load_tool(tool_name=<TOOL_NAME>,headers=headers)