Package com.tnsai.memory
Class AgentMemoryResolver
java.lang.Object
com.tnsai.memory.AgentMemoryResolver
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
- If
@Memory(shared = true)is present, creates/reuses aSharedMemoryStore - If
@Memory(persistent = true)is present, creates aFileMemoryStore - Otherwise creates an
InMemoryStore
Shared Memory Namespaces
For @Memory(shared = true) the effective namespace is resolved as follows:
- An explicit
@Memory(namespace = "...")always wins. - Otherwise, if the agent was already granted access to one or more namespaces
(via other agents'
shareWithlists, recorded inSharedMemoryRegistry), it joins the granted namespace. Note this depends on resolution order: the granting agent must have been resolved first. - Otherwise the global default namespace "shared" is used,
so all agents that declare
shared = truewithout 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of memory resolution containing the configured store and optional consolidation pipeline. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringGlobal namespace used for@Memory(shared = true)when no explicit namespace is set and the agent was not granted access to another namespace. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasMemoryAnnotations(Class<?> agentClass) Checks if the given class has @Memory or @VectorMemory annotation.Resolves memory configuration from the agent class annotations.
-
Field Details
-
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
Resolves memory configuration from the agent class annotations.- Parameters:
agentClass- the agent class to inspectagentId- the agent ID (used for init and shared memory access)- Returns:
- the resolved memory configuration
-
hasMemoryAnnotations
Checks if the given class has @Memory or @VectorMemory annotation.- Parameters:
agentClass- the class to check- Returns:
- true if memory annotations are present
-