Custom Code Tool - Hello World
This sample code demonstrates how you can use aidputils to test your Custom Code tool.
The Hello World example is the simplest possible Custom Code tool. It defines a single tool class that accepts a name parameter and returns a greeting. Use it as a starting point for your own tool.
tool_implementation.py
from aidputils.agents.tools.custom_tools.base import CustomToolBase
@BaseTool.register
class HelloTool(CustomToolBase):
"""A simple greeting tool."""
@classmethod
def _execute_tool(cls, conf, runtime_params, **context_vars):
name = runtime_params.get("name", "World")
return {"greeting": f"Hello, {name}!"}
tool_config.json
{
"displayName": "Hello Tool",
"description": "A simple hello world tool",
"tools": [
{
"toolClassName": "HelloTool",
"displayName": "Hello Tool",
"description": "Returns a hello world greeting",
"version": "1.0.0",
"schema": [
{
"name": "name",
"type": "string",
"description": "Name to greet"
}
],
"conf": {}
}
]
}
requirements.txt
# no depsPackage the three files at the root of a ZIP archive and upload the ZIP through the Package tab. Once uploaded, switch to the Parameters tab, fill in the Description if you want to override the default, and switch to the Test tab to invoke the tool. With name="Alice", the tool returns:
{"greeting": "Hello, Alice!"}