Class ToolsProvider
java.lang.Object
org.machanism.machai.ai.provider.AbstractAIProvider
org.machanism.machai.ai.provider.tools.ToolsProvider
- All Implemented Interfaces:
Genai
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 Summary
FieldsModifier and TypeFieldDescription(package private) static org.slf4j.LoggerLogger instance for this provider.Fields inherited from class org.machanism.machai.ai.provider.AbstractAIProvider
chatModel, config, DEFAULT_WEBSEARCH_TYPE_NAME, instructions, lastUsage, LINE_SEPARATOR, LOG_INPUTS_PROP_NAME, LOG_LINE_LENG, LOG_SECTION_SEPARATOR, MAX_OUTPUT_TOKENS, maxOutputTokens, maxToolCalls, MCP_PROP_NAME_PREFIX, PARAGRAPH_SEPARATOR, PASSWORD_PROP_NAME, PROJECT_DIR_PARAM_NAME, projectDir, SERVERID_PROP_NAME, timeoutSec, USERNAME_PROP_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTool(String name, String description, ToolFunction function, ParamDescriptor... paramsDesc) Registers a tool function with the provider.perform()Executes the provider's perform logic.voidAdds a prompt text to the provider's prompt list.Methods inherited from class org.machanism.machai.ai.provider.AbstractAIProvider
addMcpServer, addMcpServers, addPrompt, addPrompts, addTools, addWebSearch, addWebSearch, clear, getParamValue, getProjectDir, getTimeout, init, inputsLog, instructions, logInputs, logInputsSpec, normalize, safelyInvokeTool, setProjectDir, setTimeout, setWorkingDir
-
Field Details
-
logger
static org.slf4j.Logger loggerLogger instance for this provider.
-
-
Constructor Details
-
ToolsProvider
public ToolsProvider()
-
-
Method Details
-
prompt
Adds a prompt text to the provider's prompt list.- Specified by:
promptin interfaceGenai- Overrides:
promptin classAbstractAIProvider- Parameters:
text- the prompt text to add
-
perform
Executes the provider's perform logic.If the
chatModelis 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
nullif 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:
addToolin classAbstractAIProvider- Parameters:
name- the tool namedescription- the tool descriptionfunction- the tool function implementationparamsDesc- parameter descriptors for the tool (optional)
-