Package com.tnsai.llm

Interface LLMCapabilities

All Known Implementing Classes:
ModelCapabilities

public interface LLMCapabilities
Describes the capabilities of an LLM provider/model.

LLMCapabilities provides a standardized way to discover what features a particular LLM model supports. This enables capability-driven model selection, automatic fallback, and smart routing.

Why Capabilities?

Different LLM models have vastly different capabilities:

  • GPT-4o supports vision, but GPT-3.5 doesn't
  • Some models support function calling, others don't
  • Context windows vary from 4K to 2M tokens
  • Not all models support JSON mode

With LLMCapabilities, you can:


 // Auto-select a vision model
 LLMClient client = router.selectByCapability(cap -> cap.supportsVision());

 // Fallback if function calling not available
 if (!client.getCapabilities().supportsFunctionCalling()) {
     return handleWithoutTools(message);
 }
 

Usage Example


 LLMClient client = new OpenAIClient("gpt-4o");
 LLMCapabilities caps = client.getCapabilities();

 // Check capabilities before use
 if (caps.supportsVision()) {
     response = client.chat(List.of(textPart, imagePart), system, history, tools);
 } else {
     response = client.chat(textPart.getText(), system, history, tools);
 }

 // Check context limit
 int maxContext = caps.getMaxInputTokens();
 if (estimatedTokens > maxContext) {
     // Truncate or summarize
 }
 

Capability Discovery

Capabilities can be discovered in two ways:

  1. Static: Hardcoded based on model name (fast, offline)
  2. Runtime: Queried from provider API (accurate, requires API call)

Model Profiles

Common model capability profiles:

ModelVisionToolsJSONContext
GPT-4oYesYesYes128K
GPT-4-turboYesYesYes128K
GPT-3.5-turboNoYesYes16K
Claude Sonnet 4YesYesYes200K
Claude 3 OpusYesYesYes200K
Gemini 2.5 FlashYesYesYes1M
Llama 3.2NoYesNo128K
Mistral LargeNoYesYes128K
See Also:
  • Method Details

    • supportsStreaming

      boolean supportsStreaming()
      Whether the model supports streaming responses. Most modern LLMs support this.
    • supportsVision

      boolean supportsVision()
      Whether the model can process images (vision capability). Examples: GPT-4o, Claude 3, Gemini
    • supportsFunctionCalling

      boolean supportsFunctionCalling()
      Whether the model supports function/tool calling. This is critical for agent-based applications.
    • supportsStructuredOutput

      boolean supportsStructuredOutput()
      Whether the model supports structured JSON output mode. When enabled, model output is guaranteed to be valid JSON.
    • supportsSystemPrompt

      default boolean supportsSystemPrompt()
      Whether the model supports system prompts. Some older models don't distinguish system from user messages.
    • supportsParallelFunctionCalls

      default boolean supportsParallelFunctionCalls()
      Whether the model supports parallel function calls. Some models can request multiple tool calls in a single response.
    • getMaxInputTokens

      int getMaxInputTokens()
      Maximum input tokens (context window). This is the combined limit for system prompt + history + user message.
    • knowsInputWindow

      default boolean knowsInputWindow()
      Whether getMaxInputTokens() is the model's own window rather than a placeholder for a model the provider does not list. A caller that sizes a budget from the window treats a placeholder as unknown.
      Returns:
      true unless the window is a placeholder
      Since:
      0.18.0
    • getMaxOutputTokens

      int getMaxOutputTokens()
      Maximum output tokens the model can generate. Some models have separate input/output limits.
    • getContextWindow

      default int getContextWindow()
      Total context window (usually same as maxInputTokens for most models).
    • getSupportedModalities

      Set<LLMCapabilities.Modality> getSupportedModalities()
      Returns the list of supported input modalities.
      Returns:
      Set of supported modalities (TEXT, IMAGE, AUDIO, etc.)
    • supportsModality

      default boolean supportsModality(LLMCapabilities.Modality modality)
      Checks if a specific modality is supported.
    • getProviderName

      String getProviderName()
      The provider name (OpenAI, Anthropic, Google, etc.).
    • getModelId

      String getModelId()
      The model identifier.
    • getModelVersion

      default Optional<String> getModelVersion()
      Model version if applicable.
    • getInputCostPer1KTokens

      default Optional<Double> getInputCostPer1KTokens()
      Cost per 1000 input tokens in USD. Returns empty if pricing not available.
    • getOutputCostPer1KTokens

      default Optional<Double> getOutputCostPer1KTokens()
      Cost per 1000 output tokens in USD. Returns empty if pricing not available.
    • getEstimatedLatencyMs

      default Optional<Long> getEstimatedLatencyMs()
      Estimated average latency for first token (TTFT) in milliseconds. Useful for latency-sensitive applications.
    • supportsCodeExecution

      default boolean supportsCodeExecution()
      Whether the model supports code execution (like Code Interpreter).
    • supportsWebBrowsing

      default boolean supportsWebBrowsing()
      Whether the model supports web browsing.
    • supportsFileUpload

      default boolean supportsFileUpload()
      Whether the model supports file uploads.
    • supportsReasoning

      default boolean supportsReasoning()
      Whether the model has reasoning/thinking capabilities (like o1).
    • getAdditionalCapabilities

      default Map<String,Object> getAdditionalCapabilities()
      Returns additional provider-specific capabilities. This is an extension point for capabilities not covered by the interface.
    • getDescription

      default String getDescription()
      Returns a human-readable description of the model.
    • meetsRequirements

      default boolean meetsRequirements(boolean requiresVision, boolean requiresTools, int minContextTokens)
      Checks if the model is suitable for a given use case.
      Parameters:
      requiresVision - Whether vision capability is required
      requiresTools - Whether function calling is required
      minContextTokens - Minimum context window size
      Returns:
      true if the model meets all requirements
    • requireToolCalling

      default void requireToolCalling()
      Validates that this model supports tool/function calling.

      Call this before sending tools to the LLM to get a clear error instead of silent failure or a generic exception.

      Throws:
      ToolCallNotSupportedException - if tool calling is not supported
    • requireStreaming

      default void requireStreaming()
      Validates that this model supports streaming.
      Throws:
      LLMCapabilityException - if streaming is not supported
    • requireVision

      default void requireVision()
      Validates that this model supports vision/image input.
      Throws:
      LLMCapabilityException - if vision is not supported