/ src / python / txtai / agent / tool / function.py
function.py
 1  """
 2  Function imports
 3  """
 4  
 5  from smolagents import Tool
 6  
 7  
 8  class FunctionTool(Tool):
 9      """
10      A FunctionTool takes descriptive configuration and injects it along with a target function into an LLM prompt.
11      """
12  
13      # pylint: disable=W0231
14      def __init__(self, config):
15          """
16          Creates a FunctionTool.
17  
18          Args:
19              config: `name`, `description`, `inputs`, `output` and `target` configuration
20          """
21  
22          # Tool parameters
23          self.name = config["name"]
24          self.description = config["description"]
25          self.inputs = config["inputs"]
26          self.output_type = config.get("output", config.get("output_type", "any"))
27          self.target = config["target"]
28  
29          # pylint: disable=C0103
30          # Skip forward signature validation
31          self.skip_forward_signature_validation = True
32  
33          # Validate parameters and initialize tool
34          super().__init__()
35  
36      def forward(self, *args, **kwargs):
37          """
38          Runs target function.
39  
40          Args:
41              args: positional args
42              kwargs: keyword args
43  
44          Returns:
45              result
46          """
47  
48          return self.target(*args, **kwargs)