zz Building new tools - supercog-ai/community GitHub Wiki
Agent tools are implemented as python classes. The tool class should export one or more instance methods as functions for use by the agent.
Tool classes should inherit from the ToolFactory
base class:
from supercog.engine.tool_factory import ToolFactory, ToolCategory
class BasicDataTool(ToolFactory):
def __init__(self):
super().__init__(
id="basic_data_functions",
system_name="Basic Data",
category=ToolCategory.CATEGORY_BUILTINS,
logo_url=""https://banner2.cleanpng.com/20180605",
help="These are basic data functions for the agent to use",
auth_config={},
)
def get_tools(self) -> List[Callable]:
return self.wrap_tool_functions([
self.load_full_preview_content,
])
def load_full_preview_content(self, var_name: str) -> str:
""" Returns the full contents (max 1000 rows) for the given object (dataframe or preview)
For dataframes returns data in CSV format."""
return ...
The key is the get_tools
method which returns the set of functions to attach to the agent.
Note the following about each function:
- You should return either string or a value that can be easily serialized to a string.
dict
is serialized as JSON. - You must provide a docstring for the function which describes its purpose.
- Generally its not required to describe the parameters as long as they have logical names.
Here are other special notes:
- In the
init
call you can passtool_uses_env_vars=True
to indicate that your tool references Env Vars. This will automatically enable functions for the agent to verify the presence of Env Vars or request them from the user.