Article·npmjs.com
ai-agentsllmragcontext-engineeringopen-sourcepythonopenclawopenclaw-engramqmd
@joshuaswarren/openclaw-engram
Implement local-first, persistent memory for your OpenClaw AI agents using Engram. It leverages LLMs for intelligent information extraction, stores data in markdown, and uses hybrid search (QMD) for efficient retrieval, enhancing agent context and learning.
intermediate30 min5 steps
The play
- Install OpenClaw EngramAdd the OpenClaw Engram library to your project dependencies. This makes the memory plugin available for your OpenClaw agents.
- Initialize Engram MemoryInstantiate the Engram memory plugin within your OpenClaw agent's setup. Specify a directory for local memory storage.
- Enable LLM-Powered ExtractionConfigure your agent to feed relevant interactions into Engram. The plugin uses an integrated LLM to intelligently extract and summarize key information for storage.
- Store Memories in MarkdownEngram automatically stores extracted memories in human-readable markdown files within your specified `memory_path`. Periodically inspect these files to understand your agent's knowledge base.
- Retrieve Context with Hybrid SearchQuery Engram for relevant past memories. It employs QMD for hybrid (keyword + semantic) search, ensuring efficient and contextually accurate retrieval for your agent's current tasks.
Starter code
from openclaw_engram import EngramMemory
# Initialize Engram with a local memory path
memory = EngramMemory(memory_path='./my_agent_data/memory')
# Simulate an agent learning something new
agent_interaction = "The user mentioned that the primary goal for Q3 is to reduce cloud spending by 15%."
# Store this interaction as a memory
# (In a real OpenClaw agent, this would be part of its memory management loop)
print(f"Storing new memory: '{agent_interaction}'")
memory.store_raw_text(agent_interaction)
# Simulate an agent needing to recall information
query = "What are the key objectives for Q3?"
retrieved_info = memory.retrieve(query)
print(f"\nQuery: '{query}'")
print(f"Retrieved from memory: {retrieved_info}")
# You can also manually inspect the './my_agent_data/memory' directory for markdown files.Source