Create Handler
Here’s a step-by-step guide to creating a new custom handler in SuperAgentX
, inheriting from BaseHandler
(superagentx.handler.base.BaseHandler
), to enhance and extend the system’s functionality.
Step 1: Creating a New Handler
Now, we will create a new class FileHandler
that inherits from BaseHandler
. This class will handle reading a text file
and filtering the contents based on a search query.
Here’s the FileHandler implementation:
Step 2: Define Handler Method(s).
Now, let’s define a method inside the handler to perform an action, like processing data from the given method.
This tool
(superagentx.handler.decorators.tool
) decorator is used to preserve llm tool function
when you wrap it in a new function, often used in custom decorators.
Write a docstring for the method based on the parameters provided. The docstring should be clear, detailed, and understandable by an LLM (Large Language Model). The description should be 3 to 4 lines long with a brief explanation, and parameter can be in a single line.
Step 3: Testing the Handler
To test the FileHandler class, create a sample text file and use the handler to search for specific terms.
create the sample.txt file
Create a file named sample.txt
in the same directory as your script with the following content:
Use the FileHandler
class to search for the term "file"
:
Full Code
Expected Output:
When you run this code, it will output: