Skip to main content

Tulving

The context-budget engine for AI agents.

Status: v0.1 feature-complete — in pre-release verification. Installable from source today; the name-holding PyPI release is 0.0.1 while v0.1.0 goes through final testing.

Tulving is a model-agnostic Python SDK that gives an AI agent persistent, structured, searchable working memory — and, as its headline capability, curates that memory back into a fixed token budget:

ctx = memory.curate("resuming work on the auth refactor", token_budget=4000)
print(ctx.content)          # a prompt-ready block, already redacted, within budget
print(ctx.token_count, ctx.budget_remaining, ctx.sources_consulted)

curate() selects, ranks, decays, and trims your agent's memories into a block that fits the budget you hand it — so you spend context tokens on what matters instead of dumping a whole store into the prompt. curate(mode="orient") produces a cold-start briefing for a fresh session.

Named after Endel Tulving, the psychologist who established that memory has types (episodic vs semantic). Typed memories — facts, decisions, observations, plans, summaries, each with its own lifecycle — are Tulving's core data model.

Zero infrastructure: one SQLite file, no server, no API key required. Vectors are optional.

📖 New here? Read the User Guide — using Tulving with LM Studio, Claude Code, and the MCP Inspector; verifying it works; and measuring the value it adds over no memory.


Install

Requires Python 3.11+.

pip install tulving                 # core engine (stdlib + hnswlib only)

Optional extras:

pip install "tulving[local]"        # local embeddings (sentence-transformers)
pip install "tulving[openai]"       # OpenAI embeddings
pip install "tulving[anthropic]"    # Claude LLM for session summaries
pip install "tulving[mcp]"          # MCP server for Claude Code

The core engine works with no embedder (key-exact lookup + importance/recency curation). Add [local] or [openai] to enable semantic search.


Quickstart

from tulving import Memory, MemoryType

memory = Memory("./agent_memory", agent_id="my-agent")

# Store typed memories. A repeated key supersedes the old entry (never raises).
memory.store(
    "We chose SQLite over Postgres for zero-infra local deployment.",
    type=MemoryType.DECISION,
    key="decision:datastore",
    tags=["architecture"],
)
memory.store("The auth token TTL is 15 minutes.", type=MemoryType.FACT)

# Exact recall by key.
entry = memory.get("decision:datastore")
print(entry.content)

# Curate into a token budget — the headline primitive.
ctx = memory.curate("what did we decide about storage?", token_budget=2000)
print(ctx.content)

Enable semantic search by passing an embedder:

from tulving import Memory, LocalEmbedder      # pip install "tulving[local]"

memory = Memory("./agent_memory", embedding_adapter=LocalEmbedder())
results = memory.search("database choice", top_k=5)
for r in results:
    print(f"{r.score:.2f}  {r.match_type}  {r.entry.content}")

Typed memories

Type Meaning Decay
FACT a discrete piece of information decays over time
DECISION a choice made and its reasoning never decays, exempt from eviction
OBSERVATION something noticed or analyzed decays over time
PLAN an intended future action decays over time
SUMMARY a system-generated digest created by summarization, not by callers

Importance is computed lazily on read (base_importance * 0.5^(age / half_life[type])). Nothing is ever destroyed — low-importance entries are archived, not deleted, and DECISION/pinned entries survive eviction.


MCP server (Claude Code & other MCP clients)

Tulving ships a thin, local-only (stdio, no network) MCP server exposing six tools: memory_store, memory_get, memory_search, memory_curate, memory_forget, memory_list_keys (orient = memory_curate(mode="orient")).

pip install "tulving[mcp,local]"
tulving-mcp --memory-path ./agent_memory --embedding local

Register it with Claude Code (.mcp.json or your MCP client config):

{
  "mcpServers": {
    "tulving": {
      "command": "tulving-mcp",
      "args": ["--memory-path", "./agent_memory", "--embedding", "local"]
    }
  }
}

Flags fall back to env vars (TULVING_MEMORY_PATH, TULVING_EMBEDDING_ADAPTER, TULVING_LLM_ADAPTER, TULVING_LLM_MODEL, TULVING_DEFAULT_TOKEN_BUDGET). --llm claude enables session summaries (needs [anthropic] + ANTHROPIC_API_KEY); with no LLM the server degrades loudly to deterministic markers. A second process on the same path is refused (single-writer safety, ADR-015).


Export / import

Full JSON round-trip for backup, migration, or sharing. Exports are an emission surface: redaction is on by default (secret-shaped tokens and sensitive keys are masked), with a loud keyword-only opt-out for trusted backups.

# By default the export file must live inside the memory directory; pass
# allowed_root to write elsewhere (leaf names are whitelisted, dirs contained).
memory.export_json("backup.json", allowed_root=".")                  # redacted, sharing-safe
memory.export_json("backup.json", allowed_root=".",
                   include_sensitive=True, include_archived=True)    # full plaintext backup

report = memory.import_json("backup.json", on_key_conflict="skip")   # or "supersede"
print(report.entries_imported, report.entries_reembedded, report.warnings)

Imported entries are re-embedded (unless the embedding model matches exactly) and their IDs/reference graph are consistently remapped.


What v0.1 ships

  • Core memory engine — store / get / semantic search over typed memories; upsert-by-key supersede; zero infrastructure (one SQLite file, local vectors optional).
  • Token-budget curation — curate(query, token_budget) + orient mode.
  • Lazy decay & eviction — per-type importance decay; decisions/pinned never evicted; archive, never destroy.
  • Sessions — per-agent session tracking, end-of-session summarization, abandoned-session recovery on startup.
  • MCP server — six tools, single-writer safety, loud llm=None degradation.
  • Adapters & export — pluggable embeddings (local/openai) and LLM (anthropic); JSON round-trip export/import with default-on redaction.

Deferred to later versions (see docs/adrs/adr-016): knowledge graph, multi-agent machinery, semantic contradiction detection, Postgres backend, and additional export formats.


Development

git clone https://github.com/govanxa/tulving.git
cd tulving
python -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
pip install -e ".[dev,mcp]"

pytest                                    # full suite
pytest --cov=tulving --cov-report=term-missing
mypy tulving/                             # strict
ruff check tulving/ tests/ && ruff format --check tulving/ tests/

CI runs these same gates plus a cross-platform test matrix (Linux + Windows × Python 3.11–3.13) on every push — see .github/workflows/ci.yml.

The User Guide covers real-world usage (LM Studio, Claude Code, MCP Inspector), behavior verification, and how to measure Tulving against having no memory at all.


By the same author: Kairos (kairos-ai) — contract-enforced AI workflows — and its kairos-ai-evidence plugin for contract-validated evidence evaluation. A kairos-ai-tulving integration plugin is planned.

License

Apache 2.0

Metadata

Release files for tulving 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tulving 0.1.1
File Size Uploaded Provenance Actions
tulving-0.1.1.tar.gz 119.9 kB With provenance Details for tulving-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tulving 0.1.1
File Interpreter ABI Platform Actions
tulving-0.1.1-py3-none-any.whl Python 3 none any Details for tulving-0.1.1-py3-none-any.whl

Total release size: 254.4 kB

Release files / tulving-0.1.1.tar.gz

Download URL tulving-0.1.1.tar.gz
Size 119.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1f9fd41e3be245e74c895ca6c2188af80fe4669c7a60190f1b99ea0e3957ab75
BLAKE2b-256 checksum
How to use checksums
19bebab99eaf354bb7269380f17eceefd098ab118652dd0558c76725e1f2f155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 5, 2026.

Transparency log

Release files / tulving-0.1.1-py3-none-any.whl

Download URL tulving-0.1.1-py3-none-any.whl
Size 134.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f13fd4082963afeb499408a1fa09c3ca47073a3e8d04ed3ff056dd159ae9b72f
BLAKE2b-256 checksum
How to use checksums
814c019f74b54968c6e107efe06544c5a901eccee0749ef7fe5e1f8879142e57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 5, 2026.

Transparency log

Security for tulving 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tulving-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page