Package org.machanism.machai.ai.provider
Class GenaiAdapter
java.lang.Object
org.machanism.machai.ai.provider.GenaiAdapter
- All Implemented Interfaces:
Genai
- Direct Known Subclasses:
CodeMieProvider
Delegating
Genai implementation.
This adapter forwards all Genai calls to an underlying provider
instance configured via setProvider(Genai).
Intended use cases include decorating providers (for example, adding
cross-cutting concerns like logging, metrics, retries, or request shaping)
while preserving the Genai contract.
Thread-safety: Instances are not thread-safe unless the delegated provider is thread-safe and access is externally synchronized.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPrompts(FunctionTools functionTool) Scans the providedFunctionToolsinstance for methods annotated withPrompt, and registers each prompt for use during a run.voidaddTools(FunctionTools tools) Registers a set of tool functions that may be invoked during a run.voidclear()Clears any stored files and session/provider state.voidinit(String model, Configurator conf) Initializes the provider with application configuration.voidEnables logging of provider inputs to the given directory.voidinstructions(String instructions) Sets system/session instructions for the current conversation.perform()Executes the provider to produce a response based on the accumulated prompts and state.voidAdds a user prompt to the current session.voidsetErrorHandling(boolean errorHandling) Configures whether tool invocation errors should be returned to the model for conversational recovery or propagated as exceptions.voidsetProjectDir(File projectDir) Sets the working directory for the provider, which may be used by tool handlers.voidsetProvider(Genai provider) Sets the delegate provider.
-
Field Details
-
provider
Delegate provider.Subclasses typically set this value during construction or initialization using
setProvider(Genai).
-
-
Constructor Details
-
GenaiAdapter
public GenaiAdapter()Creates an adapter without a delegate.Call
setProvider(Genai)before invoking any other methods.
-
-
Method Details
-
setProvider
Sets the delegate provider.- Parameters:
provider- the provider to delegate to- Throws:
IllegalArgumentException- ifproviderisnull
-
init
Initializes the provider with application configuration. -
prompt
Adds a user prompt to the current session. -
clear
public void clear()Clears any stored files and session/provider state.This resets the conversation and any accumulated context.
-
instructions
Sets system/session instructions for the current conversation.- Specified by:
instructionsin interfaceGenai- Parameters:
instructions- instruction text
-
perform
Executes the provider to produce a response based on the accumulated prompts and state. -
inputsLog
Enables logging of provider inputs to the given directory. -
setProjectDir
Sets the working directory for the provider, which may be used by tool handlers.- Specified by:
setProjectDirin interfaceGenai- Parameters:
projectDir- the project directory
-
addTools
Registers a set of tool functions that may be invoked during a run.- Specified by:
addToolsin interfaceGenai- Parameters:
tools- theFunctionToolsinstance containing tool methods
-
addPrompts
Scans the providedFunctionToolsinstance for methods annotated withPrompt, and registers each prompt for use during a run.- Specified by:
addPromptsin interfaceGenai- Parameters:
functionTool- theFunctionToolsinstance whose methods will be scanned forPromptannotations
-
setErrorHandling
public void setErrorHandling(boolean errorHandling) Description copied from interface:GenaiConfigures whether tool invocation errors should be returned to the model for conversational recovery or propagated as exceptions.- Specified by:
setErrorHandlingin interfaceGenai- Parameters:
errorHandling-trueto return tool errors as response text;falseto propagate them immediately
-