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
Types
Configuration for the AgentMemory feature.
Feature companion object that allows installing the AgentMemory feature in an agent.
Functions
Loads all available facts from memory and adds them to the LLM chat history.
Loads facts about a specific concept from memory and adds them to the LLM chat history.
Extracts and saves facts from the LLM chat history based on the provided concept.