Class AsiContainer

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class AsiContainer extends AnahataToolkit
The definitive toolkit for managing and inspecting the ASI container and its active sessions. This toolkit provides deep visibility into the 'Working Memory' and 'Long-Term Context' of the ASI across all sessions.
Author:
anahata
  • Constructor Details

    • AsiContainer

      public AsiContainer()
  • Method Details

    • getSystemInstructions

      public List<String> getSystemInstructions() throws Exception
      Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.

      Provides core instructions on how to programmatically query the container's AI providers and API keys from within NbJava scripts.

      Returns:
      A list of system instruction strings.
      Throws:
      Exception - if an error occurs during instruction generation.
    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Populates the given RagMessage with dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).

      Populates the RAG message with container-level overview metadata, including host application ID, working directory, default template configuration, configured AI providers (summarized model counts), and active AGI sessions.

      Parameters:
      ragMessage - The target RAG message to populate.
      Throws:
      Exception - If an error occurs during message population.
    • listActiveAgis

      public String listActiveAgis()
      Returns a Markdown table of all active AGI sessions in the container.
      Returns:
      A Markdown table listing sessions.
    • toMarkupTable

      public static String toMarkupTable(List<AbstractModel> models)
      Converts a list of models into a formatted Markdown table.
      Parameters:
      models - The list of models to format.
      Returns:
      A Markdown formatted table.
    • listAiProviders

      public String listAiProviders(boolean includeModelIds)
      Returns a Markdown table of all configured AI providers, including their UUIDs, enabled status, class FQNs, endpoints, API key statuses, and model counts or model IDs.
      Parameters:
      includeModelIds - Whether to include the full comma-separated list of model IDs (true) or just the total count (false).
      Returns:
      A Markdown formatted table summarizing the container's AI providers.
    • listAiModels

      public String listAiModels(String providerUuid)
      Returns a Markdown table of available models for a specific AI provider or all providers if providerUuid is null.
      Parameters:
      providerUuid - Optional unique UUID of the AI provider. If null or empty, lists models across all providers.
      Returns:
      A Markdown table of models.
    • findModels

      public String findModels(String query, List<ResponseModality> responseModalities)
      Finds and filters AI models across all effectively enabled providers using a regex or text query AND required response modalities.

      The search evaluates an AND condition:

      • Query Regex: If provided, matches case-insensitively against model ID, display name, description, supported actions, or response modalities.
      • Response Modalities: If provided (e.g. [IMAGE, TEXT]), filters to models that support ALL requested response modalities.
      Parameters:
      query - Optional regex or keyword query to match against model ID, display name, description, actions, or modalities.
      responseModalities - Optional list of required response modalities (e.g. [IMAGE], [AUDIO], [VIDEO]). The model must support all listed modalities.
      Returns:
      A Markdown formatted table of matching models.
    • getAgiDetails

      public String getAgiDetails(String sessionId)
      Returns detailed metadata for a specific AGI session, including its enabled toolkits, context providers, and managed resources.
      Parameters:
      sessionId - The unique ID of the session.
      Returns:
      A Markdown summary of the session details.
    • createNewAgi

      public String createNewAgi(boolean open, boolean autoReplyTools, String nickName, String aiProviderUUID, String modelID, List<String> toolkitFqns, List<String> resourceURIs, String initialMessage, Map<String, ToolPermission> toolPermissions, ThinkingLevel thinkingLevel, List<ResponseModality> responseModalities)
      Creates a new AGI session with comprehensive configuration options.
      Parameters:
      open - Whether to open the new AGI session in the host UI.
      autoReplyTools - Whether to automatically execute tool calls for the new session without waiting for manual user intervention.
      nickName - the nickname for the new AGI
      aiProviderUUID - Optional UUID of the AI provider to use. Will use container default if null.
      modelID - Optional ID of the AI model to select. Will use container default if null.
      toolkitFqns - Optional list of fully qualified toolkit class names to enable.
      resourceURIs - Optional list of resource URIs to register in the new session.
      initialMessage - Optional message to send to the new AGI immediately after creation.
      toolPermissions - Optional map of tool permission overrides for this session (e.g. tool name -> PROMPT, APPROVE_ALWAYS, DENY).
      thinkingLevel - the startup thinking level for the new AGI
      responseModalities - Optional list of response modalities for this session (e.g. ['TEXT', 'IMAGE'], ['IMAGE'], ['AUDIO']).
      Returns:
      A confirmation message with the new session ID.
    • createNewAgiInternal

      public Agi createNewAgiInternal(boolean open, boolean autoReplyTools, String nickName, String aiProviderUUID, String modelID, List<String> toolkitFqns, List<String> resourceURIs, String initialMessage, Map<String, ToolPermission> toolPermissions, ThinkingLevel thinkingLevel, List<ResponseModality> responseModalities)
      Internal helper to construct, register, and bootstrap a new AGI session.
      Parameters:
      open - Whether to open the new AGI session in the host UI.
      autoReplyTools - Whether to automatically execute tool calls.
      nickName - Optional nickname.
      aiProviderUUID - Optional provider UUID.
      modelID - Optional model ID.
      toolkitFqns - Optional list of toolkit class FQNs.
      resourceURIs - Optional list of resource URIs.
      initialMessage - Optional initial message to send.
      toolPermissions - Optional tool permission overrides.
      thinkingLevel - Optional thinking level.
      responseModalities - Optional response modalities.
      Returns:
      The newly created Agi instance.
    • generateMedia

      public String generateMedia(String prompt, String aiProviderUUID, String modelID, List<String> resourceURIs, List<ResponseModality> responseModalities, String nickName, boolean open, String saveToPath, ThinkingLevel thinkingLevel) throws Exception
      Generates media (images, audio, video) using a generative AI model in a single shot.
      Parameters:
      prompt - The descriptive prompt for the media to generate.
      aiProviderUUID - The UUID of the AI provider to use.
      modelID - The ID of the AI model to use.
      resourceURIs - Optional list of resource URIs (e.g. source image files or URLs) to register as context for image-to-image or multimodal generation.
      responseModalities - Optional list of response modalities (defaults to ['TEXT', 'IMAGE']).
      nickName - Optional nickname for the background AGI session.
      open - Whether to open the sub-AGI session in the UI.
      saveToPath - Optional file path to save the generated media directly to disk.
      thinkingLevel - Optional thinking level. If null or NONE, thoughts are disabled for media generation.
      Returns:
      A markdown formatted summary of the generation result.
      Throws:
      Exception - If an error occurs during generation.
    • closeAgi

      public String closeAgi(String sessionId)
      Closes the UI tab/window of a specific active AGI session without disposing it.
      Parameters:
      sessionId - The unique ID of the session to close.
      Returns:
      A confirmation message.
    • disposeAgi

      public String disposeAgi(String sessionId) throws IOException
      Permanently disposes of an active AGI session, closing its UI, shutting down its executors, and archiving its session file.
      Parameters:
      sessionId - The unique ID of the session to dispose.
      Returns:
      A confirmation message.
      Throws:
      IOException
    • dumpHistory

      public String dumpHistory(String sessionId)
      Returns a plain text dump of the entire conversation history for a session.
      Parameters:
      sessionId - Optional session ID. If null, the current session is used.
      Returns:
      A text dump of the history.