fabricatio_tool.models.tool
A module for defining tools and toolboxes.
This module provides classes for defining tools and toolboxes, which can be used to manage and execute callable functions with additional functionalities such as logging, execution info, and briefing.
Classes
A class representing a tool with a callable source function. |
|
A class representing a collection of tools. |
Module Contents
- class fabricatio_tool.models.tool.Tool[**P, R](/, **data: Any)
Bases:
fabricatio_core.models.generic.WithBriefingA class representing a tool with a callable source function.
This class encapsulates a callable function (source) and provides methods to invoke it, log its execution, and generate a brief description (briefing) of the tool.
- source: Callable[P, R]
The source function of the tool.
- model_post_init(__context: Any) None
Initialize the tool with a name and a source function.
This method sets the tool’s name and description based on the source function’s name and docstring.
- Parameters:
__context (Any) – Context passed during model initialization.
- Raises:
RuntimeError – If the tool does not have a source function.
- invoke(*args: P.args, **kwargs: P.kwargs) R
Invoke the tool’s source function with the provided arguments.
This method logs the invocation of the tool and then calls the source function with the given arguments.
- Parameters:
*args (P.args) – Positional arguments to be passed to the source function.
**kwargs (P.kwargs) – Keyword arguments to be passed to the source function.
- Returns:
The result of the source function.
- Return type:
R
- class fabricatio_tool.models.tool.ToolBox(/, **data: Any)
Bases:
fabricatio_core.models.generic.WithBriefingA class representing a collection of tools.
This class manages a list of tools and provides methods to add tools, retrieve tools by name, and generate a brief description (briefing) of the toolbox.
- collect_tool[**P, R](*, confirm: bool = tool_config.confirm_on_ops, logging: bool = tool_config.logging_on_ops) Callable[[Callable[P, R]], Callable[P, R]]
- collect_tool(func: Callable[P, R]) Callable[P, R]
Add a callable function to the toolbox as a tool.
This method wraps the function with logging execution info and adds it to the toolbox.
- Parameters:
- Returns:
The added function.
- Return type:
Callable[P, R]
- add_tool[**P, R](func: Callable[P, R], *, confirm: bool = tool_config.confirm_on_ops, logging: bool = tool_config.logging_on_ops) Self
Add a callable function to the toolbox as a tool.
This method wraps the function with logging execution info and adds it to the toolbox.
- Parameters:
- Returns:
The current instance of the toolbox.
- Return type:
Self
- property briefing: str
Return a brief description of the toolbox.
This method generates a brief description of the toolbox, including its name, description, and a list of tools.
- Returns:
A brief description of the toolbox.
- Return type: