contextkit

Long-term memory for AI agents

Remember what matters. Forget the rest.

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

v0.1.4· Python 3.9+· Apache-2.0· Quickstart →

A hosted cloud with a thin Python SDK is on the way. The library is the way to run it today.

conversation · user_id = alice9 messages
  1. alice

    Hi! Can you help me plan meals this week?

  2. agent

    Happy to. Anything I should know first?

  3. alice

    I'm vegetarian, and I'm allergic to peanuts.

  4. alice

    Weeknights I've got maybe 20 minutes to cook.

  5. agent

    Got it. Here are five quick dinners to start.

  6. alice

    That lentil one was great, thanks.

  7. alice

    I've started eating fish again, by the way.

  8. agent

    Noted. Want a few fish dishes added?

  9. alice

    Sure, nothing too fancy.

kept in memory3 facts
  • Allergic to peanutsADD
  • Eats fish, no other meatUPDATEwas Is vegetarian
  • Cooks quick weeknight dinnersADD
Next prompt carries 3 facts, not the chat.

How it works

The life of a memory

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.

  1. 01

    Remember

    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.”

    • +Is vegetarianADD
    • +Allergic to peanutsADD
  2. 02

    Revise

    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.”

    • −Is vegetarian
    • +Eats fish, no other meatUPDATE
    history(memory_id) Mar 02ADDIs vegetarian Apr 07UPDATEIs vegetarian → Eats fish, no other meat
  3. 03

    Recall

    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.

    alice · Apr 28user_id = alice

    “Any idea what I could cook tonight?”

    1. 0.82Allergic to peanuts
    2. 0.79Eats fish, no other meat
    3. 0.61Cooks quick weeknight dinners

    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.

  4. 04

    Forget

    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

    1 ½ 0 0 30 60 90 120 days recency halves every 30 days
    • Allergic to peanuts0.94used 3 days ago · 12 uses · 2 helpful
    • Cooks quick weeknight dinners0.45used 40 days ago · 3 uses
    • Training for a 10k in May0.06last touched 200 days ago · never usedARCHIVED

Kinds of memory

An agent remembers different things for different lengths of time

Each kind is a scope or a feature of the same library, so you can mix them in one store.

User memory long-term

Preferences, constraints, and history about a person that should outlive any one conversation.

user_idAllergic to peanuts

Session memory one task

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

Agent memory shared

What one agent learned across the people it serves, or what several agents share on one job.

agent_idLogin builds SQL by concatenation

Procedural memory how-to

How the agent got something done, summarised from its own steps, so the next run goes faster.

memory_typeSearch → refundable only → hold seat

Episodic memory eventson request

What happened, when, and what led to what: dated events with cause and effect links.

build_timelineCache shipped Mon → timeouts Tue

Relational memory entities

People, products, and services and how they connect, kept in Neo4j, Memgraph, or Neptune.

graph_storealice → works_at → acme

Document memory reference

Handbooks, transcripts, and logs stored as written, split into chunks, rejoined when found.

infer=FalseRefunds within 30 days of delivery

Visual memory images

Screenshots, photos, and designs, described by a vision model and kept as searchable facts.

enable_visionSpring packaging is sage green

How scoping works →Every memory operation →

Layers

Off is a commented-out line

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

Memory engine

always on

Fact extraction, add, update, and delete decisions, scoped search, metadata filters, and a history row for every change.

vector_storeQuickstart →

Retrieval · what comes back

Graph memory

Entities and relations in a graph database, searched together with the vectors.

graph_storeGuide →

Episodic memoryon request

Dated events and the cause and effect links between them, so your agent can answer when and why.

Context graph

Links memories to each other and searches through the links, so the context around a match comes back with it.

context_graphGuide →

Personalized retrieval

Feedback, usage, and answers that worked before each add a weighted signal to the ranking.

Governance · what is kept, and for whom

Tenants

Customer organisations, their departments, and who holds which role, with export and migration.

tenantGuide →

Decay and versioning

Scores memories by use, archives the stale ones, and moves them to disk or S3 until needed.

decay_v2Guide →

Privacy

tools

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 →

Ingest · what goes in

Chunking

Splits long texts into overlapping chunks and merges neighbours back at search time.

chunkingGuide →

Multimodal

A vision model describes each image, and the description is remembered like any other message.

enable_visionGuide →
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

Most products use a few kinds of memory and a layer or two

Common combinations of kinds of memory and layers.

Support agents

Remember each customer's products, past tickets, and preferences, so nobody explains twice. Answers marked helpful rank higher next time.

usersessiondocumentpersonalized retrieval

Personal assistants

Keep up with tastes and routines that change over months. Old facts are updated rather than contradicted, and the ones nobody uses fade.

userproceduralvisualdecay

Coding and DevOps agents

Answer “what changed before it broke?” from deploys, incidents, and fixes over time, with the runbooks close at hand.

episodicrelationaldocumentgraph memory

Multi-agent systems

A researcher, a planner, and an executor share findings on one job through a common run, and each keeps its own lessons.

agentsessionproceduralcontext graph

Software for many companies

Give every customer organisation its own memory, with departments, roles, and exports, from a single store.

tenantsuserprivacydecay

Health, finance, and legal

Redact what must not be stored, keep a record of every change, and delete a person's memories when they ask.

privacychange historytenantsuser

Providers

Your models, your store

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

Four steps to an agent that remembers

  1. Install with pip install outhad-contextkitai. Python 3.9 or newer.
  2. Set a model key with export OPENAI_API_KEY=sk-…. OpenAI is the default; Anthropic, Gemini, Groq, Ollama, and others are a config change away.
  3. Store what the user says with memory.add(messages, user_id="alice").
  4. Search before each reply with 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

Read the quickstart →Browse the docs →