Interface Genai

All Known Implementing Classes:
AbstractAIProvider, AnthropicProvider, CodeMieProvider, CodeMieProvider.ClaudeProviderExtension, CodeMieProvider.OpenAIProviderExtension, GenaiAdapter, NoneProvider, OpenAIProvider, ToolsProvider

public interface Genai
Contract for a generative-AI provider integration.

A Genai represents a concrete implementation (for example OpenAI, Gemini, a local model, etc.) capable of:

  • Collecting prompts and system instructions for a conversation,
  • Attaching local or remote files for provider-side processing,
  • Registering tool functions that may be invoked during a run.

Implementations may keep session state between calls. Use clear() to reset conversation state.

Typical usage

 Configurator conf = ...;
 Genai provider = GenaiProviderManager.getProvider("OpenAI:gpt-4o-mini", conf);

 provider.instructions("You are a helpful assistant.");
 provider.prompt("Hello!");
 String response = provider.perform();

 provider.clear();
 
Author:
Viktor Tovstyi
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Scans the provided FunctionTools instance for methods annotated with Prompt, and registers each prompt for use during a run.
    void
    Scans the provided FunctionTools instance for methods annotated with Resource, and registers each resource for use during a run.
    void
    Registers a set of tool functions that may be invoked during a run.
    void
    Clears any stored files and session/provider state.
    void
    init(String model, Configurator conf)
    Initializes the provider with application configuration.
    void
    instructions(String instructions)
    Sets system/session instructions for the current conversation.
    Executes the provider to produce a response based on the accumulated prompts and state.
    void
    prompt(String text)
    Adds a user prompt to the current session.
    void
    Configures the list of tool names that are enabled and allowed to be used by the AI provider.
    void
    setErrorHandling(boolean errorHandling)
    Configures whether tool invocation errors should be returned to the model for conversational recovery or propagated as exceptions.
    void
    setProjectDir(File projectDir)
    Sets the working directory for the provider, which may be used by tool handlers.
  • Method Details

    • init

      void init(String model, Configurator conf)
      Initializes the provider with application configuration.
      Parameters:
      model - the model identifier or name to use
      conf - configuration source
    • prompt

      void prompt(String text)
      Adds a user prompt to the current session.
      Parameters:
      text - the prompt text
    • clear

      void clear()
      Clears any stored files and session/provider state.

      This resets the conversation and any accumulated context.

    • instructions

      void instructions(String instructions)
      Sets system/session instructions for the current conversation.
      Parameters:
      instructions - instruction text
    • perform

      String perform()
      Executes the provider to produce a response based on the accumulated prompts and state.
      Returns:
      the provider response as a string
    • addTools

      void addTools(FunctionTools tools)
      Registers a set of tool functions that may be invoked during a run.
      Parameters:
      tools - the FunctionTools instance containing tool methods
    • addPrompts

      void addPrompts(FunctionTools tools)
      Scans the provided FunctionTools instance for methods annotated with Prompt, and registers each prompt for use during a run.
      Parameters:
      tools - the FunctionTools instance whose methods will be scanned for Prompt annotations
    • addResources

      void addResources(FunctionTools tools)
      Scans the provided FunctionTools instance for methods annotated with Resource, 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.

      Parameters:
      tools - the FunctionTools instance whose methods will be scanned for resource annotations
    • setProjectDir

      void setProjectDir(File projectDir)
      Sets the working directory for the provider, which may be used by tool handlers.
      Parameters:
      projectDir - the project directory
    • setErrorHandling

      void setErrorHandling(boolean errorHandling)
      Configures whether tool invocation errors should be returned to the model for conversational recovery or propagated as exceptions.
      Parameters:
      errorHandling - true to return tool errors as response text; false to propagate them immediately
    • setEnabledTools

      void setEnabledTools(String[] tools)
      Configures the list of tool names that are enabled and allowed to be used by the AI provider.

      If the specified array is null or empty, all registered tools are typically enabled by default. Only tools whose identifiers are present in this collection will be active during provider execution.

      Parameters:
      tools - the array of unique tool names to enable; if null or empty, all tools are enabled