MemoryManager

org.llm4s.agent.memory.MemoryManager

High-level memory management for agents.

MemoryManager provides semantic operations on top of the raw MemoryStore, including entity extraction, memory consolidation, and intelligent retrieval strategies.

This is the primary interface for agent memory integration.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def consolidateMemories(olderThan: Instant, minCount: Int): Result[MemoryManager]

Summarize and consolidate old memories.

Summarize and consolidate old memories.

This operation can reduce memory usage by combining related memories into summaries.

Value parameters

minCount

Minimum memories to trigger consolidation

olderThan

Only consolidate memories older than this

Attributes

Returns

Updated manager or error

def extractEntities(text: String, conversationId: Option[String]): Result[MemoryManager]

Extract and store entity mentions from text.

Extract and store entity mentions from text.

Uses NLP or LLM to identify entities in the text and create entity memories.

Value parameters

conversationId

Optional conversation context

text

Text to analyze

Attributes

Returns

Updated manager with extracted entities

def getConversationContext(conversationId: String, maxMessages: Int): Result[String]

Get recent conversation context.

Get recent conversation context.

Value parameters

conversationId

The conversation to retrieve

maxMessages

Maximum messages to include

Attributes

Returns

Formatted conversation history

def getEntityContext(entityId: EntityId): Result[String]

Get all known facts about an entity.

Get all known facts about an entity.

Value parameters

entityId

The entity to query

Attributes

Returns

Formatted entity knowledge

def getRelevantContext(query: String, maxTokens: Int, filter: MemoryFilter): Result[String]

Retrieve relevant context for a query.

Retrieve relevant context for a query.

This is the main method for memory-augmented generation. Returns memories most relevant to the given query, formatted as context for the LLM.

Value parameters

filter

Additional filter criteria

maxTokens

Approximate maximum tokens of context

query

The user's query

Attributes

Returns

Formatted context string

def getUserContext(userId: Option[String]): Result[String]

Get facts known about the user.

Get facts known about the user.

Value parameters

userId

Optional user identifier

Attributes

Returns

Formatted user knowledge

def recordConversation(messages: Seq[Message], conversationId: String): Result[MemoryManager]

Record a complete conversation.

Record a complete conversation.

Value parameters

conversationId

Identifier for this conversation

messages

The conversation messages

Attributes

Returns

Updated manager or error

def recordEntityFact(entityId: EntityId, entityName: String, fact: String, entityType: String, importance: Option[Double]): Result[MemoryManager]

Store a fact about an entity.

Store a fact about an entity.

Value parameters

entityId

The entity this fact is about

entityName

Human-readable entity name

entityType

Type of entity (person, organization, concept, etc.)

fact

The fact to store

importance

Optional importance score

Attributes

Returns

Updated manager or error

def recordKnowledge(content: String, source: String, metadata: Map[String, String]): Result[MemoryManager]

Store knowledge from an external source.

Store knowledge from an external source.

Value parameters

content

The knowledge content

metadata

Additional metadata

source

Source identifier (file path, URL, etc.)

Attributes

Returns

Updated manager or error

def recordMessage(message: Message, conversationId: String, importance: Option[Double]): Result[MemoryManager]

Record a conversation turn.

Record a conversation turn.

Value parameters

conversationId

Identifier for this conversation

importance

Optional importance score

message

The message to record

Attributes

Returns

Updated manager or error

def recordTask(description: String, outcome: String, success: Boolean, importance: Option[Double]): Result[MemoryManager]

Record a completed task and its outcome.

Record a completed task and its outcome.

Value parameters

description

Task description

importance

Optional importance score

outcome

What happened

success

Whether the task succeeded

Attributes

Returns

Updated manager or error

def recordUserFact(fact: String, userId: Option[String], importance: Option[Double]): Result[MemoryManager]

Store a fact about the user.

Store a fact about the user.

Value parameters

fact

The fact about the user

importance

Optional importance score

userId

Optional user identifier

Attributes

Returns

Updated manager or error

Get memory statistics.

Get memory statistics.

Attributes

The underlying memory store.

The underlying memory store.

Attributes