On this page
The @tool decorator wraps a typed async function (first parameter a Pydantic model) into a ToolTemplate; ToolTemplate.bind() supplies dependencies and produces a ready-to-use Tool with input validation and rendering.
#tool.src.orxtra.tool._decorator
#tool.src.orxtra.tool._decorator
Decorator-based tool definition infrastructure.
The @tool decorator converts a typed async function into a ToolTemplate -- an unbound tool definition that can be bound with dependencies to produce a standard Tool.
#ToolTemplate
An unbound tool definition. Call .bind(**deps) to get a Tool.
Created by the @tool decorator. The template captures the function, its Pydantic params model, renderer, and metadata. Dependencies are supplied later via bind(), producing a ready-to-use Tool.
#bind
def bind(self, *, name: str | None=None, namespace: str | None=None, tags: frozenset[str] | None=None, **deps: Any) -> ToolBind dependencies to produce a ready-to-use Tool.
Args:
name: Override the template's name on the produced Tool.
Useful for tools like exec where each instance is named after its executable.
namespace: Override the template's namespace on the produced Tool.tags: Override the template's tags on the produced Tool.**deps: Keyword arguments forwarded to the decorated function.
#tool
def tool(name: str, description: str, *, renderer: Renderer[Any], suspending: bool=False, namespace: str='', tags: frozenset[str]=frozenset()) -> Callable[..., ToolTemplate[Any]]Decorator that creates a ToolTemplate from a typed async function.
The decorated function's first parameter must be typed as a Pydantic BaseModel subclass (the validated input). Remaining **kwargs are the bound dependencies supplied via ToolTemplate.bind().
Example::
class ReadParams(BaseModel): path: str
@tool("read", "Read a file.", renderer=TextRenderer()) async def read_file(params: ReadParams, *, fs: FileSystem) -> str: return fs.read(params.path)
# Later: t = read_file.bind(fs=real_fs) # returns a Tool