Package org.machanism.machai.ai.provider.impl


package org.machanism.machai.ai.provider.impl
Provides concrete implementations of the Machai generative AI provider abstraction.

This package contains provider adapters that connect Machai's common AI interfaces to specific runtime backends and tool execution strategies. The implementations translate prompts, instructions, tool definitions, web-search configuration, MCP server configuration, embedding requests, and usage accounting between Machai's internal provider model and the corresponding external API or local execution mechanism.

Included providers

  • OpenAIProvider adapts the OpenAI Java SDK Responses API and embedding API. It supports conversational prompting, function tools, MCP tools, web search, usage tracking, and embedding generation for OpenAI-compatible endpoints.
  • AnthropicProvider adapts the Anthropic Java SDK Beta Messages API. It supports message construction, local function tools, optional web search (versions 20250305 and 20260209), MCP server forwarding, prompt-cache control for the last registered tool, and usage tracking.
  • CodeMieProvider integrates with EPAM CodeMie authentication, obtains an OAuth 2.0 access token via password-grant or client-credentials flow, and delegates requests to an appropriate downstream provider based on the configured model prefix: gpt-*, gemini-*, text-embedding-*, codemie-text-embedding-*, and amazon.titan-embed-text-* prefixes are routed to OpenAIProvider; claude-* prefixes are routed to AnthropicProvider.
  • ToolsProvider executes locally registered function tools directly from structured YAML prompts, which is useful for tool-only workflows and deterministic host-side execution. It operates in a fail-fast mode: exceptions from tool execution are propagated immediately rather than being returned as model text.
  • NoneProvider is a disabled provider implementation for configurations that intentionally perform no AI work. It discards submitted input and returns null. Initializing it with the "log" model enables INFO-level logging of provider calls; any other model disables that diagnostic logging.

Typical usage

Applications normally create a provider through the higher-level Machai provider factory or adapter APIs, initialize it with a model name and a Configurator, add any required prompts or tools, and call perform() to execute the request. Providers may be reused after calling clear() to reset accumulated conversation input. Provider-specific setup, including credentials and endpoint configuration, must be supplied through the configurator before initialization.

 Genai provider = new OpenAIProvider();
 provider.init("gpt-4.1", configurator);
 provider.prompt("Summarize the project architecture.");
 String answer = provider.perform();
 provider.clear();
 

The ToolsProvider uses the special model name "yaml" and interprets the last submitted prompt as a YAML tool-call descriptor:

 ToolsProvider provider = new ToolsProvider();
 provider.init("yaml", configurator);
 // Register tools through a package-specific adapter or subclass.
 provider.prompt("tool: myTool\nparams:\n  key: value");
 String result = provider.perform();
 

Configuration keys such as API credentials, base URLs, timeouts, maximum output tokens, tool-call limits, MCP endpoints, and web-search options are interpreted by the individual provider implementations. See each provider's class-level documentation for the supported keys and backend-specific behavior.

Since:
1.2.0
Author:
Viktor Tovstyi
  • Classes
    Class
    Description
    Anthropic-backed implementation of Machai's Genai abstraction.
    Genai implementation that integrates with EPAM CodeMie.
    No-op implementation of Genai that performs no AI processing.
    OpenAI-backed Genai implementation.
    AI provider implementation for managing and invoking host-defined function tools.