Class GenaiAdapter
- All Implemented Interfaces:
Genai
- Direct Known Subclasses:
CodeMieProvider
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.voidaddResources(FunctionTools tools) Scans the providedFunctionToolsinstance for methods annotated withResource, and registers each resource 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.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.voidsetEnabledTools(String[] tools) Configures the list of tool names that are enabled and allowed to be used by the AI provider.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. -
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
-
addResources
Scans the providedFunctionToolsinstance for methods annotated withResource, and registers each resource for use during a run.This method inspects the given class instance to register executable resource utilities that can be dynamically called by the AI model during generation processes.
- Specified by:
addResourcesin interfaceGenai- Parameters:
tools- theFunctionToolsinstance whose methods will be scanned for resource annotations
-
setErrorHandling
public void setErrorHandling(boolean errorHandling) Configures 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
-
setEnabledTools
Configures the list of tool names that are enabled and allowed to be used by the AI provider.If the specified array is
nullor empty, all registered tools are typically enabled by default. Only tools whose identifiers are present in this collection will be active during provider execution.- Specified by:
setEnabledToolsin interfaceGenai- Parameters:
tools- the array of unique tool names to enable; ifnullor empty, all tools are enabled
-