Annotation Interface Memory


@Documented @Retention(RUNTIME) @Target(TYPE) public @interface Memory
Configures memory and state management for agents.

Defines conversation memory, vector memory, and persistence settings for maintaining agent state across interactions.

Consolidation lifecycle (TAN-5049)

When Memory.Conversation.enabled() is true (the default), the framework creates a MemoryConsolidationPipeline for the agent during initialization and drives it from the agent lifecycle: Agent.stop() triggers a final consolidation pass via onSessionEnd(). The pipeline is exposed through Agent.getConsolidationPipeline() — periodic auto-consolidation is NOT started automatically (no interval is configured here); call startAutoConsolidation(Duration) on the pipeline if time-based consolidation is desired.

Usage


 @Memory(
     conversation = @Conversation(maxMessages = 100, strategy = Strategy.SLIDING_WINDOW),
     vector = @Vector(dimensions = 1536, provider = "pinecone", index = "agent-memory"),
     persistence = @Persistence(store = "redis", ttlSeconds = 86400)
 )
 public class ResearchAgent extends Agent { ... }
 
Author:
TnsAI Team
  • Element Details

    • conversation

      Memory.Conversation conversation
      Conversation memory configuration.

      When Memory.Conversation.enabled() is true, a consolidation pipeline is created and wired into the agent lifecycle: a final consolidation runs on Agent.stop(), and the pipeline is available via Agent.getConsolidationPipeline() for manual or scheduled use.

      Returns:
      conversation settings
      Default:
      @com.tnsai.annotations.Memory.Conversation
    • vector

      Vector memory configuration.
      Returns:
      vector memory settings
      Default:
      @com.tnsai.annotations.Memory.Vector
    • persistence

      Memory.Persistence persistence
      State persistence configuration.
      Returns:
      persistence settings
      Default:
      @com.tnsai.annotations.Memory.Persistence
    • persistent

      boolean persistent
      Whether to enable memory across sessions.
      Returns:
      true for persistent memory
      Default:
      false
    • namespace

      String namespace
      Memory namespace/scope.

      Isolates memory between different contexts.

      When combined with shared(), an explicit namespace always wins: agents sharing memory must declare the same namespace (or be routed to it via shareWith()). When left empty, the effective shared namespace is resolved by AgentMemoryResolver: the agent joins a namespace it was granted access to via another agent's shareWith list, or falls back to the global default namespace "shared".

      Returns:
      namespace name
      Default:
      ""
    • shared

      boolean shared
      Whether to share memory with other agents.

      With an empty namespace(), all agents that declare shared = true share the global default namespace "shared", unless the agent was granted access to a specific namespace via another agent's shareWith() list — in that case it joins the granted namespace. Joining a granted namespace depends on resolution order: the granting agent must be initialized before the granted agent.

      Every agent receives a viewer-bound view of the shared store that enforces the namespace access control list on every operation.

      Returns:
      true if shared
      Default:
      false
    • shareWith

      String[] shareWith
      Agent IDs to share memory with.

      Only applies if shared = true.

      Each listed agent is granted access to this agent's shared namespace. A listed agent that itself declares shared = true without an explicit namespace joins this namespace when it is resolved after this agent (see shared()).

      Returns:
      agent IDs
      Default:
      {}