Class ProcessProviderAdapter

java.lang.Object
org.machanism.machai.process.provider.ProcessProviderAdapter
All Implemented Interfaces:
ProcessProvider
Direct Known Subclasses:
CodeMieProvider

public class ProcessProviderAdapter extends Object implements ProcessProvider
Delegating ProcessProvider implementation.

This adapter forwards all ProcessProvider calls to an underlying provider instance configured via setProvider(ProcessProvider).

Intended use cases include decorating providers (for example, adding cross-cutting concerns like logging, metrics, retries, or request shaping) while preserving the ProcessProvider contract.

Thread-safety: Instances are not thread-safe unless the delegated provider is thread-safe and access is externally synchronized.

  • Field Details

  • Constructor Details

    • ProcessProviderAdapter

      public ProcessProviderAdapter()
      Creates an adapter without a delegate.

      Call setProvider(ProcessProvider) before invoking any other methods.

  • Method Details

    • setProvider

      public void setProvider(ProcessProvider provider)
      Sets the delegate provider.
      Parameters:
      provider - the provider to delegate to
      Throws:
      IllegalArgumentException - if provider is null
    • init

      public void init(String model, Configurator conf)
      Initializes the provider with application configuration.
      Specified by:
      init in interface ProcessProvider
      Parameters:
      model - the model identifier or name to use
      conf - configuration source used to initialize the provider
    • prompt

      public void prompt(String text)
      Adds a user prompt to the current session.

      Prompts are accumulated until ProcessProvider.perform() or ProcessProvider.clear() is called. The exact message format sent to the provider is implementation specific.

      Specified by:
      prompt in interface ProcessProvider
      Parameters:
      text - the prompt text
    • clear

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

      This resets the conversation and any accumulated context.

      Specified by:
      clear in interface ProcessProvider
    • instructions

      public void instructions(String instructions)
      Sets system/session instructions for the current conversation.

      Calling this method replaces any previously configured instructions. A null value may be used to clear them when supported by the implementation.

      Specified by:
      instructions in interface ProcessProvider
      Parameters:
      instructions - instruction text
    • perform

      public String perform()
      Executes the provider to produce a response based on the accumulated prompts, instructions, files, and registered capabilities.

      Whether the accumulated session is retained after execution is provider specific. Call ProcessProvider.clear() when a new independent conversation is required.

      Specified by:
      perform in interface ProcessProvider
      Returns:
      the provider response as a string
    • setProjectDir

      public void setProjectDir(File projectDir)
      Sets the working directory for the provider, which may be supplied to tool, prompt, and resource handlers.
      Specified by:
      setProjectDir in interface ProcessProvider
      Parameters:
      projectDir - the project directory, or null to clear the current directory
    • addTools

      public void addTools(FunctionTools tools, String[] enabledTools)
      Registers the tools exposed by the given FunctionTools implementation, optionally restricting registration to a filtered subset of tools.

      Implementations are expected to discover tool definitions on the provided tools instance (typically via annotated methods) and make them available for use, applying the enablement filter described below.

      Specified by:
      addTools in interface ProcessProvider
      Parameters:
      tools - the FunctionTools implementation containing the tool definitions to register; must not be null.
      enabledTools - an optional array of regular expression patterns controlling which tools are registered.

      Each tool is identified internally by a fully qualified name built in the format <ClassName>:<toolName>, where:

      • <ClassName> is the fully qualified class name of the tools implementation, and
      • <toolName> is the tool's declared name (or the method name if no explicit name is provided).
      A tool is registered only if its fully qualified name matches at least one of the given patterns. If enabledTools is null, all available tools are registered without filtering.
    • addPrompts

      public void addPrompts(FunctionTools functionTool)
      Scans the provided FunctionTools instance for methods annotated with Prompt and registers each prompt for use during a run.

      The prompt name, description, role, and parameters are obtained from the annotation and the method signature.

      Specified by:
      addPrompts in interface ProcessProvider
      Parameters:
      functionTool - the FunctionTools instance whose methods will be scanned for Prompt annotations
    • addResources

      public 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 resource utilities that can be dynamically called by the AI model during generation processes.

      Specified by:
      addResources in interface ProcessProvider
      Parameters:
      tools - the FunctionTools instance 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. This setting does not suppress provider or configuration errors unrelated to tool invocation.
      Specified by:
      setErrorHandling in interface ProcessProvider
      Parameters:
      errorHandling - true to return tool errors as response text; false to propagate them immediately
    • getToolNames

      public List<String> getToolNames()
      Description copied from interface: ProcessProvider
      Returns the names of tools currently registered with the provider.

      The returned names may be used for diagnostics, filtering, request construction, or tool-invocation processing. The ordering and mutability of the returned list are provider-specific.

      Specified by:
      getToolNames in interface ProcessProvider
      Returns:
      the names of registered tools, or an empty list when no tools are registered