Tools
This page lays out all the components available in the tools module.
Tip
Tools are the core mechanism for extending Dasshh's capabilities. Use the @tool
decorator to convert functions into tools that the AI assistant can use.
BaseTool
Abstract base class for all tools in Dasshh.
attr
name
The name of the tool
attr
description
The description of the tool
attr
parameters
The parameters of the tool
method
init
Initialize a new BaseTool instance
Parameters:
Param | Default |
Description |
---|---|---|
name | The name of the tool | |
description | The description of what the tool does | |
parameters | Dictionary containing the tool's parameters |
method
call
Execute the tool with the given arguments
Parameters:
Param | Default |
Description |
---|---|---|
*args | Positional arguments to pass to the tool | |
**kwargs | Keyword arguments to pass to the tool |
Raises:
Type | Default |
Description |
---|---|---|
NotImplementedError | If the tool has no implementation |
method
get_declaration
Get the declaration of the tool for the AI model
Returns:
Type | Default |
Description |
---|---|---|
dict | Tool declaration formatted for the AI model |
Raises:
Type | Default |
Description |
---|---|---|
NotImplementedError | If the tool has no implementation |
FunctionTool
A concrete implementation of BaseTool that wraps Python functions.
attr
func
The function wrapped by this tool
method
init
Initialize a new FunctionTool instance
Parameters:
Param | Default |
Description |
---|---|---|
name | The name of the tool | |
description | The description of what the tool does | |
parameters | Dictionary containing the tool's parameters | |
func | None | The callable function to wrap |
method
call
Execute the wrapped function with the given arguments
Parameters:
Param | Default |
Description |
---|---|---|
*args | Positional arguments to pass to the function | |
**kwargs | Keyword arguments to pass to the function |
Returns:
Type | Default |
Description |
---|---|---|
Any | The return value of the wrapped function |
Raises:
Type | Default |
Description |
---|---|---|
NotImplementedError | If no function is set |
method
get_declaration
Get the declaration of the tool formatted for the AI model
Returns:
Type | Default |
Description |
---|---|---|
dict | Tool declaration using litellm's function_to_dict format |
@tool Decorator
The main decorator for creating tools in Dasshh.
decorator
tool
Convert a function into a tool and register it with Dasshh
Usage:
from dasshh.core.tools.decorator import tool
from typing import Dict
@tool
def hello_world(name: str = "World") -> Dict:
"""
A simple greeting tool.
Args:
name (str, optional): The name to greet. Defaults to "World".
Returns:
Dict: A dictionary containing the greeting message.
"""
return {"message": f"Hello, {name}!"}
Parameters:
Param | Default |
Description |
---|---|---|
func | The function to convert into a tool |
Returns:
Type | Default |
Description |
---|---|---|
FunctionTool | A FunctionTool instance wrapping the original function |
Notes:
- The decorator automatically extracts the function name as the tool name
- The function's docstring becomes the tool description
- Function annotations are used to define tool parameters
- The tool is automatically registered with the global Registry
Tip
Checkout this guide to build your own tools.