Class ToolsProvider

java.lang.Object
org.machanism.machai.ai.provider.AbstractAIProvider
org.machanism.machai.ai.provider.tools.ToolsProvider
All Implemented Interfaces:
Genai

public class ToolsProvider extends AbstractAIProvider
AI provider implementation for managing and invoking host-defined function tools.

The ToolsProvider class extends AbstractAIProvider and provides infrastructure for registering tool functions, handling prompts, and executing tool invocations based on structured YAML input. Tools are registered in a map and can be invoked dynamically.

  • Prompts are collected and stored for later processing.
  • Tool functions are registered by name and can be invoked with parameters parsed from YAML.
  • Supports execution mode where the last prompt is interpreted as a YAML tool call description.

Usage Example


 ToolsProvider provider = new ToolsProvider();
 provider.addTool("myTool", "Description", myToolFunction, ...);
 provider.prompt("tool: myTool\nparams:\n  key: value");
 String result = provider.perform();
 
Since:
1.2.0
Author:
Viktor Tovstyi
  • Field Details

    • logger

      static org.slf4j.Logger logger
      Logger instance for this provider.
  • Constructor Details

    • ToolsProvider

      public ToolsProvider()
  • Method Details

    • prompt

      public void prompt(String text)
      Adds a prompt text to the provider's prompt list.
      Specified by:
      prompt in interface Genai
      Overrides:
      prompt in class AbstractAIProvider
      Parameters:
      text - the prompt text to add
    • perform

      public String perform()
      Executes the provider's perform logic.

      If the chatModel is set to "yaml", the last prompt is parsed as a YAML tool call description. The tool name and parameters are extracted, and the corresponding tool function is invoked.

      Returns:
      the result of the tool invocation, or null if not applicable
    • addTool

      protected void addTool(String name, String description, ToolFunction function, ParamDescriptor... paramsDesc)
      Registers a tool function with the provider.

      The tool is added to the internal map by name. Parameter descriptors are accepted but not used in this implementation.

      Specified by:
      addTool in class AbstractAIProvider
      Parameters:
      name - the tool name
      description - the tool description
      function - the tool function implementation
      paramsDesc - parameter descriptors for the tool (optional)