Interface ContextProvider

All Known Implementing Classes:
AbstractBrowser, AbstractProjectContextProvider, AbstractProjectContextProvider, AnahataToolkit, AsiContainer, Audio, BasicContextProvider, BatchCodeRefiner, BatchCodeRefiner, Benchmarks, Chrome, CodeModel, CodeModel, CodeRefiner, CodeRefiner, CoreContextProvider, Editor, Editor, Firefox, Hints, Hints, History, Host, IDE, IDE, IntellijJava, Java, Maven, Maven, NbJava, NbTerminal, OpenToolWindowsContextProvider, OpenTopComponentsContextProvider, OutputTabsContextProvider, ProjectAlertsContextProvider, ProjectAlertsContextProvider, ProjectContextProvider, ProjectContextProvider, ProjectFilesContextProvider, Projects, Projects, ProjectStructureContextProvider, ProjectStructureContextProvider, Radio, Refactor, Refactor, Resource, ResourceManager, Resources, RunConfigurations, Screens, Session, Shell, Speech, SwingJava, Terminals, TerminalTab, ToolManager, Vcs, YouTube

public interface ContextProvider
Defines the contract for providers that inject just-in-time context into an AI request. Context providers can contribute system instructions or augment the user's prompt through a hierarchical tree structure.
Author:
anahata-ai
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the parent AGI session this context provider is registered under.
    Gets the list of immediate child context providers.
    Gets the designated position of this provider's content in the AI prompt.
    Gets a detailed description of what this context provider does.
    getFlattenedHierarchy(boolean providingOnly)
    Gets a flattened list of this provider and all its descendants in the hierarchy.
    default String
    Gets the fully qualified ID of this provider, reflecting its position in the hierarchy.
    default String
    Generates a machine-readable header string for this context provider, used to identify the source of injected context in the final prompt.
    default String
    Gets an optional icon identifier for this provider.
    Gets the unique identifier for this context provider.
    default int
    Calculates the token count for the system instructions provided by this instance using the active model.
    Gets the human-readable name of this context provider.
    Gets the parent context provider in the hierarchy, if any.
    default int
    Calculates the token count for the RAG content provided by this instance using the active model.
    default List<String>
    Gets a list of system instruction strings provided by this context provider.
    default boolean
    Checks if this provider is effectively providing context, meaning it is enabled AND all its ancestors in the hierarchy are also enabled.
    boolean
    Checks if this context provider is currently active and providing context.
    default void
    Populates the given RagMessage with dynamic, just-in-time context parts.
    default void
    Sets the parent context provider for this instance.
    default void
    setProviding(boolean enabled)
    Sets whether this context provider is enabled.
  • Method Details

    • getId

      String getId()
      Gets the unique identifier for this context provider.
      Returns:
      The provider's ID.
    • getName

      String getName()
      Gets the human-readable name of this context provider.
      Returns:
      The provider's name.
    • getDescription

      String getDescription()
      Gets a detailed description of what this context provider does.
      Returns:
      The provider's description.
    • isProviding

      boolean isProviding()
      Checks if this context provider is currently active and providing context.
      Returns:
      true if providing, false otherwise.
    • isEffectivelyProviding

      default boolean isEffectivelyProviding()
      Checks if this provider is effectively providing context, meaning it is enabled AND all its ancestors in the hierarchy are also enabled.
      Returns:
      true if effectively providing, false otherwise.
    • setProviding

      default void setProviding(boolean enabled)
      Sets whether this context provider is enabled.
      Parameters:
      enabled - true to enable, false to disable.
    • getParentProvider

      default ContextProvider getParentProvider()
      Gets the parent context provider in the hierarchy, if any.
      Returns:
      The parent provider, or null if this is a root provider.
    • setParentProvider

      default void setParentProvider(ContextProvider parent)
      Sets the parent context provider for this instance.
      Parameters:
      parent - The parent provider.
    • getChildrenProviders

      default List<ContextProvider> getChildrenProviders()
      Gets the list of immediate child context providers.
      Returns:
      The list of children, or an empty list if none.
    • getFullyQualifiedId

      default String getFullyQualifiedId()
      Gets the fully qualified ID of this provider, reflecting its position in the hierarchy. The format is typically 'parent.child.id'.
      Returns:
      The dot-separated fully qualified ID.
    • getFlattenedHierarchy

      default List<ContextProvider> getFlattenedHierarchy(boolean providingOnly)
      Gets a flattened list of this provider and all its descendants in the hierarchy.

      If providingOnly is true, the search stops at any provider that is not providing, effectively excluding its entire subtree from the result.

      Parameters:
      providingOnly - if true, only providers where isProviding() is true are included.
      Returns:
      A flat list of the provider hierarchy.
    • getContextPosition

      default ContextPosition getContextPosition()
      Gets the designated position of this provider's content in the AI prompt.
      Returns:
      The context position. Defaults to ContextPosition.PROMPT_AUGMENTATION.
    • getSystemInstructions

      default 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.
      Returns:
      A list of system instruction strings.
      Throws:
      Exception - if an error occurs during instruction generation.
    • populateMessage

      default 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).
      Parameters:
      ragMessage - The message to be augmented with context.
      Throws:
      Exception - if an error occurs during context generation.
    • getHeader

      default String getHeader()
      Generates a machine-readable header string for this context provider, used to identify the source of injected context in the final prompt.
      Returns:
      A formatted header string.
    • getIconId

      default String getIconId()
      Gets an optional icon identifier for this provider. This ID can be used by the UI to look up a specialized icon.
      Returns:
      The provider's icon ID, or null if none.
    • getAgi

      Agi getAgi()
      Gets the parent AGI session this context provider is registered under.
      Returns:
      The active parent AGI session, or null if it cannot be resolved.
    • getInstructionsTokenCount

      default int getInstructionsTokenCount()
      Calculates the token count for the system instructions provided by this instance using the active model.
      Returns:
      The estimated token count.
    • getRagTokenCount

      default int getRagTokenCount()
      Calculates the token count for the RAG content provided by this instance using the active model.
      Returns:
      The estimated token count.