Class AgentMemoryResolver

java.lang.Object
com.tnsai.memory.AgentMemoryResolver

public final class AgentMemoryResolver extends Object
Resolves memory configuration from @Memory and @VectorMemory annotations.

This resolver is called by AgentInitializer during agent initialization. It processes the annotations and creates the appropriate MemoryStore configuration.

Resolution Priority

  1. If @Memory(shared = true) is present, creates/reuses a SharedMemoryStore
  2. If @Memory(persistent = true) is present, creates a FileMemoryStore
  3. Otherwise creates an InMemoryStore

Shared Memory Namespaces

For @Memory(shared = true) the effective namespace is resolved as follows:

  1. An explicit @Memory(namespace = "...") always wins.
  2. Otherwise, if the agent was already granted access to one or more namespaces (via other agents' shareWith lists, recorded in SharedMemoryRegistry), it joins the granted namespace. Note this depends on resolution order: the granting agent must have been resolved first.
  3. Otherwise the global default namespace "shared" is used, so all agents that declare shared = true without a namespace share the same memory.

The returned store is a viewer-bound SharedMemoryStore view (SharedMemoryStore.viewFor(String)) that enforces the namespace ACL on every operation.

@VectorMemory Support

If @VectorMemory is present, the resolver looks up a VectorStoreProvider for VectorMemory.provider(). inmemory is bundled. Any other name without a registered SPI fails agent initialization — it does not silently fall back to TF-IDF.

See Also:
  • Field Details

    • DEFAULT_SHARED_NAMESPACE

      public static final String DEFAULT_SHARED_NAMESPACE
      Global namespace used for @Memory(shared = true) when no explicit namespace is set and the agent was not granted access to another namespace.
      See Also:
  • Method Details

    • resolve

      public static AgentMemoryResolver.MemoryResolution resolve(Class<?> agentClass, String agentId)
      Resolves memory configuration from the agent class annotations.
      Parameters:
      agentClass - the agent class to inspect
      agentId - the agent ID (used for init and shared memory access)
      Returns:
      the resolved memory configuration
    • hasMemoryAnnotations

      public static boolean hasMemoryAnnotations(Class<?> agentClass)
      Checks if the given class has @Memory or @VectorMemory annotation.
      Parameters:
      agentClass - the class to check
      Returns:
      true if memory annotations are present