Package uno.anahata.ai.tools


package uno.anahata.ai.tools
Provides the core framework for defining and managing local tools (functions) that the AI model can execute.

This package is central to extending the AI's capabilities beyond simple text generation. It allows developers to expose Java methods as tools that the model can call to interact with the local system, application, or any other service.

Key Components:

  • ToolManager: The main orchestrator for tool management. It discovers tools via annotations, generates the necessary JSON schema for the Gemini API, executes function calls, and handles the user confirmation workflow.
  • AIToolMethod: An annotation used to mark a Java method as a tool callable by the AI. It includes properties for description and context management behavior.
  • AIToolParam: An annotation for describing the parameters of a tool method, which is used to generate a more informative schema for the model.
  • FunctionPrompter: An interface that decouples the tool confirmation process from any specific UI, allowing for flexible implementations (e.g., Swing dialogs, console prompts).
  • FailureTracker: A utility to prevent the model from getting stuck in a loop of repeatedly calling a failing tool.
  • ContextBehavior: An enum that defines how the result of a tool call should affect the conversation context (e.g., as an ephemeral event or a stateful resource update).

Subpackages:

  • uno.anahata.ai.tools.schema: Contains the logic for generating the JSON schema required by the Gemini API from Java method signatures.
  • uno.anahata.ai.tools.spi: Provides a Service Provider Interface with a set of pre-built, generic tools for common tasks like file I/O, shell command execution, and JVM interaction.
  • Class
    Description
    Annotation used to mark a static method as a tool (function) that can be called by the AI model.
    Annotation used to provide metadata for a parameter of a method annotated with AIToolMethod.
    Defines how the output of an AIToolMethod should be treated within the conversation context.
    Represents a tool call that has been successfully executed.
    Tracks consecutive failures of tool calls and implements a temporary blocking mechanism.
    Represents the user's choice when prompted to confirm the execution of one or more tool calls.
    A metadata class that links a Gemini FunctionDeclaration to its underlying Java Method implementation.
    Summarizes the outcome of the entire user interaction and execution phase for a given turn where tool calls were proposed.
    An interface for UI components that can prompt the user to confirm a batch of function calls.
    A value object holding the results of a user confirmation prompt.
    Represents a FunctionCall that has been assigned a short, unique, turn-specific ID.
    A data class representing the state and result of an asynchronous background job.
    Defines the possible states of a background job.
    A special return type for tools that need to send multiple, distinct parts back to the model in a subsequent user message.
    A data class that represents the final outcome of a single proposed tool call.
    Represents the definitive final status of a tool call after user interaction and execution attempts.
    Manages the registration, identification, and execution of local tools (functions).