Creating Your Own Custom Tool
This is an example of how to create a custom tool that can be registered to GLChat.
This documentation has been deprecated and moved to the GL SDK Gitbook
Installation
# you can use a Conda environment
pip install gllm-plugin-binaryCreating a Custom Tool
Create a new Python file for your tool, e.g.,
my_calculator_tool.py.Import necessary modules. You typically will need:
BaseToolfromgllm_agents,BaseModelandFieldfrompydantic,tool_plugindecorator fromgllm_plugin.tools.
Define an input schema if needed. If your tool requires specific inputs, define a Pydantic
BaseModelsubclass. Use the PydanticFieldto add the description and validation for each input parameter.
from pydantic import BaseModel, Field
class MyCalculatorToolInput(BaseModel):
param1: int = Field(..., description="Description for parameter 1")
param2: str = Field(..., description="Description for parameter 2")
param3: int = Field(..., description="Description for parameter 3")Create a tool class that inherits from
gllm_agents.BaseTool.Apply the
@tool_plugin(version="...")decorator to your class so that your custom tool can be registered to GLChat.Set the required attributes for your class:
name: A unique string identifier for your tool.description: A clear, concise description of what the tool does. This description will be used by the AI agent to decide when to use the tool.args_schema: Set this to your Pydantic input schema class defined in Step #3. If your tool takes no input, you may omit this and use the default value.
Implement the
_runmethod. This is the core logic of your tool. It receives the input parameters defined in yourargs_schemaas arguments and should return a string result.
Once you create your tool, you can try running it by following Running a Custom Tool and Agent Locally or Running a Custom Tool and Agent in GLChat guide.
Last updated