Skip to main content

User-sovereign AI memory capsule system with skill extraction

Project description

CapsuleMemory

User-sovereign AI memory capsule system

Track, distill, and seal memories and skills in real-time within a single session, seamlessly embedding them into any AI framework via a portable capsule format.

CI License PyPI Python

English | 中文


Why CapsuleMemory?

Most AI memory systems persist everything automatically, giving users little control over what gets stored. CapsuleMemory takes a different approach:

  • Session Isolation: Nothing persists by default. Users actively choose when to seal a session into a durable capsule.
  • Skill Detection: A rule-based engine identifies reusable skills (code patterns, workflows, procedures) from conversations in real-time.
  • Portable Capsule Format: Export to JSON / MessagePack / Universal format. Import into any system, no vendor lock-in.
  • Framework-agnostic: Drop-in adapters for LangChain, LlamaIndex, or use via REST API / MCP Server.

Quick Start

pip install capsule-memory

Passive Memory (one line per exchange)

from capsule_memory import CapsuleMemory

cm = CapsuleMemory()

# One call handles session lifecycle, auto-recall, and ingestion
result = await cm.remember("I prefer black for formatting", "Noted, using black.", user_id="alice")

# First call returns historical context if available
if "recalled_context" in result:
    print(result["recalled_context"])

# When done, seal to persist
await cm.seal_session(user_id="alice", title="Python Tooling", tags=["python"])

Active Mode (full control)

async with cm.session("user_123") as session:
    await session.ingest(user_message, ai_response)
    # Session auto-seals on exit, or call session.seal() explicitly

Recall memories across sessions

result = await cm.recall(query="deployment steps", user_id="user_123")
print(result["prompt_injection"])  # Ready to inject into any LLM

MCP Server (Claude Code / Cursor / Windsurf / etc.)

Zero-config passive memory — built-in instructions tell the host LLM how to manage memory automatically. No CLAUDE.md or .cursorrules needed.

pip install 'capsule-memory[mcp]'
capsule-memory-mcp

REST API

pip install 'capsule-memory[server]'
capsule-memory serve --port 8000
# Visit http://localhost:8000/docs for interactive API docs

CLI

capsule-memory ingest "How to deploy?" "Use docker-compose" -s my_session
capsule-memory seal -s my_session -t "Deployment Guide" --tag deployment
capsule-memory recall "deployment"

Architecture

Session ─── ingest() ──→ Skill Detection ──→ seal() ──→ Capsule (MEMORY / SKILL / HYBRID)
                              │                              │
                              ▼                              ▼
                        SkillTriggerEvent              Storage Backend
                        (user confirms)           (Local / SQLite / Redis / Qdrant)

Storage Backends

Backend Search Best For
LocalStorage Keyword Development, single-user
SQLiteStorage Vector (384-dim) Production, local deployment
RedisStorage Keyword Multi-service, real-time
QdrantStorage Vector (384-dim) Production, scalable
# Install optional extras
pip install capsule-memory[llm]      # LLM-powered extraction (litellm)
pip install capsule-memory[crypto]   # Encrypted capsule export/import
pip install capsule-memory[sqlite]   # SQLite + sentence-transformers
pip install capsule-memory[redis]    # Redis
pip install capsule-memory[qdrant]   # Qdrant
pip install capsule-memory[all]      # Everything

Integrations

Integration Type Docs
Auto Memory Passive + Active modes Guide
OpenAI Native OpenAI SDK adapter Guide
REST API 16 endpoints, Bearer auth Guide
MCP Server 10 tools, built-in instructions Guide
LangChain Drop-in ConversationBufferMemory Guide
LlamaIndex Drop-in ChatMemoryBuffer Guide
Web Widget Embeddable JS panel Guide
TypeScript SDK @capsule-memory/sdk sdk-js/

Documentation

Full documentation: https://Musenn.github.io/capsule-memory

Contributing

Contributions are welcome! Please open an issue first to discuss what you'd like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/my-feature)
  3. Install dev dependencies: pip install -e ".[dev,server]"
  4. Run tests: pytest tests/
  5. Run linter: ruff check capsule_memory/ tests/
  6. Submit a pull request

License

Licensed under Apache License 2.0.

See NOTICE for attribution requirements.


Created by Xuelin Xu (Musenn)

Copyright 2025-2026 Xuelin Xu. Licensed under Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

capsule_memory-0.1.1.tar.gz (134.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

capsule_memory-0.1.1-py3-none-any.whl (118.6 kB view details)

Uploaded Python 3

File details

Details for the file capsule_memory-0.1.1.tar.gz.

File metadata

  • Download URL: capsule_memory-0.1.1.tar.gz
  • Upload date:
  • Size: 134.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for capsule_memory-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0b5a16eb0511dd75dce2f6e07bc8fb5045640dad051a3b3fba46bae0dbe8820e
MD5 c6fb0e042978919b78a7f63ebf737345
BLAKE2b-256 bb8097bd6fbce66a491e031da8214a379c7e7336422dd19507de2909f3a70c96

See more details on using hashes here.

File details

Details for the file capsule_memory-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: capsule_memory-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 118.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for capsule_memory-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff1f14030eedb9dd50e133c88946e5e4d2fbd97decb8bed32ac1ccbc04a081c3
MD5 4ced7edd9ab78ae2b4fd6c3a0b5a0ed0
BLAKE2b-256 0b6c438f0ccc5fd4847dc33d6575a65e35a7ec319ff6a058ceb65ee92e3afada

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page