Skip to main content

Tool API

The Tool class and its subclasses represent the tools available in your CLI. This page documents the properties and methods of the Tool class and its subclasses.

Tool Class Hierarchy

Hexagon defines several tool classes:

  • Tool: Base class for all tools
    • ActionTool: Tools that perform actions (web, shell)
    • GroupTool: Tools that group other tools

Tool Class

The Tool class is defined in hexagon/domain/tool/__init__.py and uses Pydantic for data validation.

class Tool(BaseModel):
name: str
type: ToolType = ToolType.misc
icon: Optional[str] = None
alias: Optional[str] = None
long_name: Optional[str] = None
description: Optional[str] = None
envs: Optional[Dict[str, Any]] = None
traced: Optional[bool] = True

Properties

PropertyTypeDescriptionRequired
namestrThe name of the toolYes
typeToolTypeThe type of the toolNo (defaults to misc)
iconOptional[str]Icon to displayNo
aliasOptional[str]Short alias for the toolNo
long_nameOptional[str]Longer descriptive nameNo
descriptionOptional[str]Detailed descriptionNo
envsOptional[Dict[str, Any]]Environment-specific configurationsNo
tracedOptional[bool]Whether to trace tool executionNo (defaults to True)

ToolType Enum

The ToolType enum defines the available tool types:

class ToolType(str, Enum):
misc = "misc"
web = "web"
shell = "shell"
hexagon = "hexagon"
group = "group"
function = "function"
separator = "separator"

ActionTool Class

The ActionTool class represents tools that perform actions, such as opening web links or executing shell commands.

class ActionTool(Tool):
action: Union[str, List[str]]

Properties

PropertyTypeDescriptionRequired
actionUnion[str, List[str]]The action to performYes

Methods

MethodDescription
executable_strReturns the action as a string, joining multiple actions with newlines

GroupTool Class

The GroupTool class represents tools that group other tools.

class GroupTool(Tool):
tools: Union[str, List[Union[ActionTool, GroupTool]]]

Properties

PropertyTypeDescriptionRequired
toolsUnion[str, List[Union[ActionTool, GroupTool]]]The tools in the groupYes

Examples

Web Tool

from hexagon.domain.tool import ActionTool, ToolType

web_tool = ActionTool(
name="docs",
alias="d",
long_name="Documentation",
description="Open team documentation",
type=ToolType.web,
action="open_link",
envs={
"dev": "https://docs-dev.example.com",
"prod": "https://docs.example.com"
}
)

Shell Tool

from hexagon.domain.tool import ActionTool, ToolType

shell_tool = ActionTool(
name="deploy",
alias="dep",
long_name="Deploy Service",
description="Deploy the service",
type=ToolType.shell,
action="./scripts/deploy.sh"
)

Group Tool

from hexagon.domain.tool import GroupTool, ActionTool, ToolType

provision_tool = ActionTool(
name="provision",
alias="p",
long_name="Provision Resources",
type=ToolType.shell,
action="./scripts/provision.sh"
)

teardown_tool = ActionTool(
name="teardown",
alias="t",
long_name="Teardown Resources",
type=ToolType.shell,
action="./scripts/teardown.sh"
)

group_tool = GroupTool(
name="infra",
alias="i",
long_name="Infrastructure",
description="Infrastructure tools",
type=ToolType.group,
tools=[provision_tool, teardown_tool]
)