Package org.machanism.machai.ai.provider
This package contains the core contracts, shared infrastructure, and utility types for AI providers, including request initialization, prompt and instruction handling, tool registration, resource registration, embedding generation, usage tracking, input logging, and working-directory propagation. It establishes the common behavior that allows higher-level application code to interact with different model vendors without depending on provider-specific SDK details.
Core contracts
Genaidefines the primary lifecycle and execution contract for conversational and tool-enabled AI providers, covering initialization, prompting, instruction setting, tool and resource registration, error handling configuration, and response generation.EmbeddingProviderdefines the contract for providers that can generate embedding vectors for semantic and similarity-based workflows.
Base and adapter implementations
AbstractAIProvidersupplies reusable base behavior for configuration-driven providers, including timeout handling, request input logging, optional web-search support, MCP server registration, annotation-driven tool and prompt discovery, guarded tool invocation with configurable error handling, and reflective method invocation for tool and prompt callbacks.GenaiAdapterprovides a delegating implementation for theGenailifecycle and request operations. It enables wrapper, adapter, and decorator patterns such as cross-cutting logging, metrics, retries, or request shaping around a concreteGenaiinstance.
Support utilities
TypeConverterprovides conversion between Java types and their simplified schema-compatible string representations (e.g.,"string","integer","array","object"), and performs runtime conversion of string inputs to typed Java objects—including collections, maps, primitives, and arbitrary types with single-argument string constructors.
Concrete provider implementations
The org.machanism.machai.ai.provider.impl sub-package contains
concrete provider adapters that connect Machai's common AI interfaces to
specific runtime backends:
OpenAIProvideradapts the OpenAI Responses API and embedding API, supporting conversational prompting, function tools, MCP tools, web search, usage tracking, and embedding generation for OpenAI-compatible endpoints.AnthropicProvideradapts the Anthropic Claude Beta Messages API, supporting function tools, optional web search, MCP server forwarding, prompt-cache control, and usage tracking.CodeMieProviderintegrates with EPAM CodeMie authentication and delegates to the appropriate downstream provider (OpenAIProviderorAnthropicProvider) based on the configured model prefix.ToolsProviderexecutes locally registered function tools directly from structured YAML prompts, useful for tool-only workflows and deterministic host-side execution.NoneProviderprovides a disabled implementation for configurations that intentionally perform no AI work. It discards submitted input and returnsnull; initializing it with the"log"model enables INFO-level diagnostic logging.
Typical usage
Application code typically resolves a concrete provider, initializes it
with runtime configuration and a model identifier, optionally adds
instructions, prompts, tools, resources, and file context, and then invokes
the common API to perform generation or embedding operations. Providers are
stateful during a request-building session: call Genai.clear() before
starting an independent conversation on a reusable instance. Provider-specific
configuration, credentials, endpoints, timeouts, and feature flags are read
from the supplied Configurator; usage information, when supported by
the backend, is maintained by the concrete provider implementation.
Configurator conf = ...;
Genai provider = new OpenAIProvider();
provider.init("gpt-4.1", conf);
provider.instructions("You are a helpful assistant.");
provider.prompt("Summarize the project architecture.");
String answer = provider.perform();
provider.clear();
-
ClassDescriptionBase implementation of the
Genaicontract shared by concrete provider integrations.EmbeddingProvider defines the contract for AI embedding providers.Contract for a generative-AI provider integration.DelegatingGenaiimplementation.Internal logging utility for tool inputs, results, and execution errors.Defines the types of operations whose activity can be logged.Utility class for converting between Java types and their string representations, as well as mapping Java types to simplified type names (e.g., "string", "integer", "array").