LlamaIndex

Long-term memory for LlamaIndex agents

A memory block for LlamaIndex's Memory. Each turn it recalls what this user said in any earlier session, and stores new messages right away.

pip install "llama-index-memory-recallic @ git+https://github.com/Recallic/Recallic#subdirectory=integrations/llama-index"

Python
import os
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.memory import Memory
from llama_index.memory.recallic import RecallicMemoryBlock

block = RecallicMemoryBlock(api_key=os.environ["RECALLIC_SERVICE_KEY"],
                            base_url="http://localhost:8000", user_id="alice")
memory = Memory.from_defaults(session_id="alice-chat-1", memory_blocks=[block])

agent = FunctionAgent(llm=llm, tools=[...])
await agent.run("I moved to Pune in March.", memory=memory)

# days later, a new session with the same user
later = Memory.from_defaults(session_id="alice-chat-2", memory_blocks=[block])
await agent.run("Which city did I move to?", memory=later)   # "You moved to Pune."
  • Recalls on the user's latest message, across sessions and agents, and adds it to the agent's context.
  • When nothing answers, the agent is told there is no record instead of being handed near-misses.
  • Stores new user messages every turn, not only when they fall out of short-term memory.
  • Tested with a real FunctionAgent: a new session answered from memory and declined a question never asked.

Settings

OptionDefaultWhat it does
user_idnonewhose memory this is (needed with a service key)
modeserver'scautious, balanced or helpful
store_immediatelyTruestore each turn; False stores only what LlamaIndex moves out of short-term memory
tell_model_on_declineTruewhen nothing answers, tell the model not to guess

Needs a running Recallic server: set one up with Docker, or deploy it to your own Render account in one click. Nothing goes through us; your data stays on your server.