User memory long-term
Preferences, constraints, and history about a person that should outlive any one conversation.
user_idAllergic to peanuts
Long-term memory for AI agents
ContextKit turns conversations into facts, keeps them per user, and hands your agent only the few that matter for each request. One Python library. Bring your own model and vector store.
pip install outhad-contextkitai
A hosted cloud with a thin Python SDK is on the way. The library is the way to run it today.
Hi! Can you help me plan meals this week?
Happy to. Anything I should know first?
I'm vegetarian, and I'm allergic to peanuts.
Weeknights I've got maybe 20 minutes to cook.
Got it. Here are five quick dinners to start.
That lentil one was great, thanks.
I've started eating fish again, by the way.
Noted. Want a few fish dishes added?
Sure, nothing too fancy.
How it works
Two calls do most of the work: add when something is said, and search before your
agent answers. Everything else is an option on one of them.
An LLM reads what was said and keeps the facts in it. Each one is compared with what is already stored, then added, merged into an existing memory, or left out.
memory.add(messages, user_id="alice")
Pass infer=False to store text exactly as written.
alice · Mar 02
“I'm vegetarian, and I'm allergic to peanuts.”
When a fact changes, the memory is updated instead of contradicted. The old text is kept on record, so you can see how a fact changed and when.
memory.history(memory_id)
alice · Apr 07
“I've started eating fish again, by the way.”
Before each reply, search one person's memories and put the best few in the prompt. Searches never leave the scope you give them.
memory.search(query, user_id="alice", limit=3)
Turn on the context graph and the memories linked to a match come back with it.
“Any idea what I could cook tonight?”
agent, with 3 memories in the prompt
Grilled salmon with lemon over a quick quinoa salad. I've left out satay sauce and peanut oil because of your allergy.
Memories nobody uses fade. With decay on, each memory gets a score from 0 to 1 for how recently and how often it was used and whether it helped. The lowest are archived to disk or S3 until they are needed again.
memory.archive_low(threshold=0.1)
When someone asks to be forgotten, memory.delete_all(user_id="alice") removes their memories.
Decay is an opt-in layer.
score = 0.6 × recency + 0.3 × use + 0.1 × feedback
Kinds of memory
Each kind is a scope or a feature of the same library, so you can mix them in one store.
Preferences, constraints, and history about a person that should outlive any one conversation.
user_idAllergic to peanuts
What matters for one ticket or run, and nothing else. Clear it when the job is done.
run_idWants the refund on the original card
What one agent learned across the people it serves, or what several agents share on one job.
agent_idLogin builds SQL by concatenation
How the agent got something done, summarised from its own steps, so the next run goes faster.
memory_typeSearch → refundable only → hold seat
What happened, when, and what led to what: dated events with cause and effect links.
build_timelineCache shipped Mon → timeouts Tue
People, products, and services and how they connect, kept in Neo4j, Memgraph, or Neptune.
graph_storealice → works_at → acme
Handbooks, transcripts, and logs stored as written, split into chunks, rejoined when found.
infer=FalseRefunds within 30 days of delivery
Screenshots, photos, and designs, described by a vision model and kept as searchable facts.
enable_visionSpring packaging is sage green
Layers
The core needs an LLM and a vector store. Every layer below is one key in the config and stays off until you add it, with no change in behaviour while it is off. Try the switches.
Core
Fact extraction, add, update, and delete decisions, scoped search, metadata filters, and a history row for every change.
vector_storeQuickstart →Retrieval · what comes back
Entities and relations in a graph database, searched together with the vectors.
graph_storeGuide →Dated events and the cause and effect links between them, so your agent can answer when and why.
tcmgmGuide →Links memories to each other and searches through the links, so the context around a match comes back with it.
context_graphGuide →Feedback, usage, and answers that worked before each add a weighted signal to the ranking.
msprGuide →Governance · what is kept, and for whom
Customer organisations, their departments, and who holds which role, with export and migration.
tenantGuide →Scores memories by use, archives the stale ones, and moves them to disk or S3 until needed.
decay_v2Guide →Finds emails, phone numbers, and keys, redacts them before you store, and encrypts values. You call it on text before add.
outhad_contextkit.memory.privacyGuide →from outhad_contextkit import Memory memory = Memory.from_config({ "vector_store": {"provider": "qdrant"}, "context_graph": {"enabled": True},})
Context graph is on. Turn any layer on or off to see the config change.
Where it fits
Common combinations of kinds of memory and layers.
Remember each customer's products, past tickets, and preferences, so nobody explains twice. Answers marked helpful rank higher next time.
Keep up with tastes and routines that change over months. Old facts are updated rather than contradicted, and the ones nobody uses fade.
Answer “what changed before it broke?” from deploys, incidents, and fixes over time, with the runbooks close at hand.
A researcher, a planner, and an executor share findings on one job through a common run, and each keeps its own lessons.
Give every customer organisation its own memory, with departments, roles, and exports, from a single store.
Redact what must not be stored, keep a record of every change, and delete a person's memories when they ask.
Providers
Configured with one dictionary. Swap any part without touching the rest of your code.
15LLMs
OpenAIdefault, Anthropic, Gemini, Azure OpenAI, AWS Bedrock, Groq, Together, DeepSeek, xAI, Ollama, LM Studio, vLLM, LiteLLM, and more
10embedders
OpenAIdefault, Azure OpenAI, Gemini, Vertex AI, Hugging Face, Ollama, Together, LM Studio, AWS Bedrock, LangChain
16vector stores
Qdrantdefault, pgvector, Chroma, Pinecone, Weaviate, Milvus, MongoDB, Redis, Elasticsearch, OpenSearch, FAISS, Supabase, and more
3graph stores
Neo4j, Memgraph, and AWS Neptune, for graph memory and the context graph's Neo4j backend
All providers and their settings →Run everything locally with Ollama →
Get started
pip install outhad-contextkitai. Python 3.9 or newer.export OPENAI_API_KEY=sk-…. OpenAI is the default; Anthropic, Gemini, Groq, Ollama, and others are a config change away.memory.add(messages, user_id="alice").memory.search(query, user_id="alice"), and put the results in your prompt.from outhad_contextkit import Memory
# Keep memories on disk in ./memory, so they survive a restart.
memory = Memory.from_config({
"vector_store": {"provider": "qdrant", "config": {"path": "./memory", "on_disk": True}},
})
memory.add("I'm allergic to peanuts", user_id="alice")
hits = memory.search("What should I avoid eating?", user_id="alice", limit=3)
for hit in hits["results"]:
print(hit["memory"]) # Allergic to peanuts