AgentMemory

Memory implementation for AI agents that provides persistent storage and retrieval of facts.

The AgentMemory feature enables agents to:

  • Store information (facts) for later retrieval

  • Organize memory by concepts, subjects, and scopes

  • Share knowledge between different agents based on scope

  • Extract facts from conversation history

  • Load relevant facts into the agent's context

This class serves as the main interface for memory operations within an agent, combining the memory provider with the agent's LLM context to seamlessly integrate memory capabilities into the agent's workflow.

To install the AgentMemory feature in your agent:

val agent = AIAgents(
strategy = myStrategy,
promptExecutor = myExecutor
) {
// Install memory feature with custom configuration
install(AgentMemory) {
// Configure memory provider (required)
memoryProvider = LocalFileMemoryProvider(
config = LocalMemoryConfig("my-agent-memory"),
storage = SimpleStorage(JVMFileSystemProvider),
root = Path("memory/data")
)

// Configure scope names (optional)
featureName = "code-assistant"
productName = "my-ide"
organizationName = "my-company"
}
}

Example usage within an agent node:

val rememberUserPreference by node {
withMemory {
// Save a fact about user preference
agentMemory.save(
fact = SingleFact(
concept = Concept("preferred-language", "User's preferred programming language"),
value = "Kotlin"
),
subject = MemorySubjects.User,
scope = MemoryScope.Product("my-ide")
)
}
}

See also

Constructors

Link copied to clipboard
constructor(agentMemory: AgentMemoryProvider, llm: AIAgentLLMContext, scopesProfile: MemoryScopesProfile)

Types

Link copied to clipboard

Configuration for the AgentMemory feature.

Link copied to clipboard

Feature companion object that allows installing the AgentMemory feature in an agent.

Functions

Link copied to clipboard
suspend fun loadAllFactsToAgent(scopes: List<MemoryScopeType> = MemoryScopeType.entries, subjects: List<MemorySubject> = MemorySubject.registeredSubjects)

Loads all available facts from memory and adds them to the LLM chat history.

Link copied to clipboard
suspend fun loadFactsToAgent(concept: Concept, scopes: List<MemoryScopeType> = MemoryScopeType.entries, subjects: List<MemorySubject> = MemorySubject.registeredSubjects)

Loads facts about a specific concept from memory and adds them to the LLM chat history.

Link copied to clipboard
suspend fun saveFactsFromHistory(concept: Concept, subject: MemorySubject, scope: MemoryScope, preserveQuestionsInLLMChat: Boolean = false)

Extracts and saves facts from the LLM chat history based on the provided concept.